feat: pathway depth distribution chart tab (Task C.2)
Horizontal bar chart showing patients who stopped at each treatment line depth (exclusive counts, not cumulative like the funnel).
This commit is contained in:
@@ -292,6 +292,31 @@ def _render_funnel(app_state, title):
|
||||
return create_retention_funnel_figure(data, title)
|
||||
|
||||
|
||||
def _render_depth(app_state, title):
|
||||
"""Build the pathway depth distribution figure from current filter state."""
|
||||
from dash_app.data.queries import get_pathway_depth_distribution
|
||||
from visualization.plotly_generator import create_pathway_depth_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_depth_distribution(filter_id, chart_type, directory, trust)
|
||||
except Exception:
|
||||
log.exception("Failed to load pathway depth data")
|
||||
return _empty_figure("Failed to load pathway depth data.")
|
||||
|
||||
if not data:
|
||||
return _empty_figure("No pathway depth data available.\nTry adjusting your filters.")
|
||||
|
||||
return create_pathway_depth_figure(data, title)
|
||||
|
||||
|
||||
def register_chart_callbacks(app):
|
||||
"""Register tab switching, pathway data loading, and chart rendering callbacks."""
|
||||
|
||||
@@ -435,6 +460,9 @@ def register_chart_callbacks(app):
|
||||
elif active_tab == "funnel":
|
||||
fig = _render_funnel(app_state, title)
|
||||
|
||||
elif active_tab == "depth":
|
||||
fig = _render_depth(app_state, title)
|
||||
|
||||
else:
|
||||
# Placeholder for charts not yet implemented
|
||||
tab_label = dict(TAB_DEFINITIONS).get(active_tab, active_tab)
|
||||
|
||||
@@ -9,6 +9,7 @@ TAB_DEFINITIONS = [
|
||||
("sankey", "Sankey"),
|
||||
("heatmap", "Heatmap"),
|
||||
("funnel", "Funnel"),
|
||||
("depth", "Depth"),
|
||||
]
|
||||
|
||||
# Full set retained for Trust Comparison dashboard (Phase 10.8)
|
||||
|
||||
@@ -25,6 +25,7 @@ from data_processing.pathway_queries import (
|
||||
get_trust_durations as _get_trust_durations,
|
||||
get_directorate_summary as _get_directorate_summary,
|
||||
get_retention_funnel as _get_retention_funnel,
|
||||
get_pathway_depth_distribution as _get_pathway_depth_distribution,
|
||||
)
|
||||
|
||||
DB_PATH = Path(__file__).resolve().parents[2] / "data" / "pathways.db"
|
||||
@@ -194,3 +195,13 @@ def get_retention_funnel(
|
||||
) -> list[dict]:
|
||||
"""Patient retention by treatment line depth."""
|
||||
return _get_retention_funnel(DB_PATH, date_filter_id, chart_type, directory, trust)
|
||||
|
||||
|
||||
def get_pathway_depth_distribution(
|
||||
date_filter_id: str = "all_6mo",
|
||||
chart_type: str = "directory",
|
||||
directory: Optional[str] = None,
|
||||
trust: Optional[str] = None,
|
||||
) -> list[dict]:
|
||||
"""Patients who stopped at each treatment line depth (exclusive counts)."""
|
||||
return _get_pathway_depth_distribution(DB_PATH, date_filter_id, chart_type, directory, trust)
|
||||
|
||||
Reference in New Issue
Block a user