feat: add Pathway Cost Effectiveness lollipop chart (Task 9.4)
- Create create_cost_effectiveness_figure() in plotly_generator.py Horizontal lollipop chart with dot size by patient count, colour gradient green→amber→red by cost, retention annotations - Fix calculate_retention_rate() to accept both 'value' and 'patients' keys - Add _render_cost_effectiveness() dispatch in chart.py callbacks - Wire into tab switching for active_tab='cost-effectiveness'
This commit is contained in:
@@ -108,6 +108,33 @@ def _render_market_share(app_state, title):
|
||||
return create_market_share_figure(data, title)
|
||||
|
||||
|
||||
def _render_cost_effectiveness(app_state, chart_data, title):
|
||||
"""Build the cost effectiveness lollipop figure from current filter state."""
|
||||
from dash_app.data.queries import get_pathway_costs
|
||||
from data_processing.parsing import calculate_retention_rate
|
||||
from visualization.plotly_generator import create_cost_effectiveness_figure
|
||||
|
||||
filter_id = (app_state or {}).get("date_filter_id", "all_6mo")
|
||||
chart_type = (app_state or {}).get("chart_type", "directory")
|
||||
|
||||
selected_dirs = (app_state or {}).get("selected_directorates") or []
|
||||
selected_trusts = (app_state or {}).get("selected_trusts") or []
|
||||
directory = selected_dirs[0] if len(selected_dirs) == 1 else None
|
||||
trust = selected_trusts[0] if len(selected_trusts) == 1 else None
|
||||
|
||||
try:
|
||||
data = get_pathway_costs(filter_id, chart_type, directory, trust)
|
||||
except Exception:
|
||||
log.exception("Failed to load pathway cost data")
|
||||
return _empty_figure("Failed to load pathway cost data.")
|
||||
|
||||
if not data:
|
||||
return _empty_figure("No pathway cost data available.\nTry adjusting your filters.")
|
||||
|
||||
retention = calculate_retention_rate(data)
|
||||
return create_cost_effectiveness_figure(data, retention, title)
|
||||
|
||||
|
||||
def register_chart_callbacks(app):
|
||||
"""Register tab switching, pathway data loading, and chart rendering callbacks."""
|
||||
|
||||
@@ -224,6 +251,9 @@ def register_chart_callbacks(app):
|
||||
elif active_tab == "market-share":
|
||||
fig = _render_market_share(app_state, title)
|
||||
|
||||
elif active_tab == "cost-effectiveness":
|
||||
fig = _render_cost_effectiveness(app_state, chart_data, title)
|
||||
|
||||
else:
|
||||
# Placeholder for charts not yet implemented
|
||||
tab_label = dict(TAB_DEFINITIONS).get(active_tab, active_tab)
|
||||
|
||||
Reference in New Issue
Block a user