feat: average administered doses chart tab (Task D.2)

This commit is contained in:
Andrew Charlwood
2026-02-07 03:47:53 +00:00
parent ebf3218431
commit c7e9398d65
6 changed files with 230 additions and 8 deletions
+28
View File
@@ -392,6 +392,31 @@ def _render_timeline(app_state, title):
return create_drug_timeline_figure(data, title)
def _render_doses(app_state, title):
"""Build the average administered doses figure from current filter state."""
from dash_app.data.queries import get_dosing_distribution
from visualization.plotly_generator import create_dosing_distribution_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_dosing_distribution(filter_id, chart_type, directory, trust)
except Exception:
log.exception("Failed to load dosing distribution data")
return _empty_figure("Failed to load dosing distribution data.")
if not data:
return _empty_figure("No dosing distribution data available.\nTry adjusting your filters.")
return create_dosing_distribution_figure(data, title)
def register_chart_callbacks(app):
"""Register tab switching, pathway data loading, and chart rendering callbacks."""
@@ -547,6 +572,9 @@ def register_chart_callbacks(app):
elif active_tab == "timeline":
fig = _render_timeline(app_state, title)
elif active_tab == "doses":
fig = _render_doses(app_state, title)
else:
# Placeholder for charts not yet implemented
tab_label = dict(TAB_DEFINITIONS).get(active_tab, active_tab)
+1
View File
@@ -13,6 +13,7 @@ TAB_DEFINITIONS = [
("scatter", "Scatter"),
("network", "Network"),
("timeline", "Timeline"),
("doses", "Doses"),
]
# Full set retained for Trust Comparison dashboard (Phase 10.8)
+11
View File
@@ -29,6 +29,7 @@ from data_processing.pathway_queries import (
get_duration_cost_scatter as _get_duration_cost_scatter,
get_drug_network as _get_drug_network,
get_drug_timeline as _get_drug_timeline,
get_dosing_distribution as _get_dosing_distribution,
)
DB_PATH = Path(__file__).resolve().parents[2] / "data" / "pathways.db"
@@ -238,3 +239,13 @@ def get_drug_timeline(
) -> list[dict]:
"""Drug timeline data (first_seen, last_seen) for Gantt chart."""
return _get_drug_timeline(DB_PATH, date_filter_id, chart_type, directory, trust)
def get_dosing_distribution(
date_filter_id: str = "all_6mo",
chart_type: str = "directory",
directory: Optional[str] = None,
trust: Optional[str] = None,
) -> list[dict]:
"""Average administered dose counts per drug."""
return _get_dosing_distribution(DB_PATH, date_filter_id, chart_type, directory, trust)