refactor: remove Trends tab from Patient Pathways (Task E.1)

Remove trends tab, metric toggle, render helper, and callback I/O
from Patient Pathways view. Trends will be re-added as a standalone
3rd view in E.2-E.4. Preserved get_trend_data() and create_trend_figure()
for reuse.
This commit is contained in:
Andrew Charlwood
2026-02-07 22:07:01 +00:00
parent 03ebaa057d
commit d052d2b16d
5 changed files with 162 additions and 67 deletions
+6 -35
View File
@@ -417,25 +417,6 @@ def _render_doses(app_state, title):
return create_dosing_distribution_figure(data, title)
def _render_trends(app_state, title, metric="patients"):
"""Build the temporal trends line chart."""
from dash_app.data.queries import get_trend_data
from visualization.plotly_generator import create_trend_figure
selected_dirs = (app_state or {}).get("selected_directorates") or []
selected_drugs = (app_state or {}).get("selected_drugs") or []
directory = selected_dirs[0] if len(selected_dirs) == 1 else None
drug = selected_drugs[0] if len(selected_drugs) == 1 else None
try:
data = get_trend_data(metric=metric, directory=directory, drug=drug)
except Exception:
log.exception("Failed to load trend data")
return _empty_figure("Failed to load trend data.")
return create_trend_figure(data, title, metric=metric)
def register_chart_callbacks(app):
"""Register tab switching, pathway data loading, and chart rendering callbacks."""
@@ -515,21 +496,18 @@ def register_chart_callbacks(app):
Output("pathway-chart", "figure"),
Output("chart-subtitle", "children"),
Output("heatmap-metric-wrapper", "style"),
Output("trends-metric-wrapper", "style"),
Input("chart-data", "data"),
Input("active-tab", "data"),
Input("app-state", "data"),
Input("heatmap-metric-toggle", "value"),
Input("trends-metric-toggle", "value"),
)
def update_chart(chart_data, active_tab, app_state, heatmap_metric, trends_metric):
def update_chart(chart_data, active_tab, app_state, heatmap_metric):
"""Render the active tab's chart from chart-data nodes."""
active_tab = active_tab or "icicle"
chart_type = (app_state or {}).get("chart_type", "directory")
# Show/hide metric toggles based on active tab
# Show/hide metric toggle based on active tab
heatmap_toggle_style = {} if active_tab == "heatmap" else {"display": "none"}
trends_toggle_style = {} if active_tab == "trends" else {"display": "none"}
if chart_type == "indication":
subtitle = "Trust \u2192 Indication \u2192 Drug \u2192 Patient Pathway"
@@ -537,24 +515,17 @@ def register_chart_callbacks(app):
subtitle = "Trust \u2192 Directorate \u2192 Drug \u2192 Patient Pathway"
if not chart_data:
return no_update, no_update, heatmap_toggle_style, trends_toggle_style
return no_update, no_update, heatmap_toggle_style
error_msg = chart_data.get("error")
if error_msg:
return _empty_figure(error_msg), subtitle, heatmap_toggle_style, trends_toggle_style
# Trends tab doesn't depend on chart-data nodes
if active_tab == "trends":
title = _generate_chart_title(app_state) if app_state else ""
metric = trends_metric or "patients"
fig = _render_trends(app_state, title, metric=metric)
return fig, subtitle, heatmap_toggle_style, trends_toggle_style
return _empty_figure(error_msg), subtitle, heatmap_toggle_style
if not chart_data.get("nodes"):
return _empty_figure(
"No matching pathways found.\n"
"Try adjusting your filters."
), subtitle, heatmap_toggle_style, trends_toggle_style
), subtitle, heatmap_toggle_style
# Lazy rendering — only compute the active tab's chart
title = _generate_chart_title(app_state) if app_state else ""
@@ -609,4 +580,4 @@ def register_chart_callbacks(app):
tab_label = dict(TAB_DEFINITIONS).get(active_tab, active_tab)
fig = _empty_figure(f"{tab_label} chart — coming soon")
return fig, subtitle, heatmap_toggle_style, trends_toggle_style
return fig, subtitle, heatmap_toggle_style
-18
View File
@@ -14,7 +14,6 @@ TAB_DEFINITIONS = [
("network", "Network"),
("timeline", "Timeline"),
("doses", "Doses"),
("trends", "Trends"),
]
# Full set retained for Trust Comparison dashboard (Phase 10.8)
@@ -95,23 +94,6 @@ def make_chart_card():
),
],
),
# Trends metric toggle — visible only when trends tab active
html.Div(
id="trends-metric-wrapper",
style={"display": "none"},
children=[
dmc.SegmentedControl(
id="trends-metric-toggle",
data=[
{"value": "patients", "label": "Patients"},
{"value": "total_cost", "label": "Cost"},
{"value": "cost_pp_pa", "label": "Cost p.a."},
],
value="patients",
size="xs",
),
],
),
],
),
# Chart area with loading spinner
-8
View File
@@ -30,7 +30,6 @@ from data_processing.pathway_queries import (
get_drug_network as _get_drug_network,
get_drug_timeline as _get_drug_timeline,
get_dosing_distribution as _get_dosing_distribution,
get_trend_data as _get_trend_data,
)
DB_PATH = Path(__file__).resolve().parents[2] / "data" / "pathways.db"
@@ -252,10 +251,3 @@ def get_dosing_distribution(
return _get_dosing_distribution(DB_PATH, date_filter_id, chart_type, directory, trust)
def get_trend_data(
metric: str = "patients",
directory: Optional[str] = None,
drug: Optional[str] = None,
) -> list[dict]:
"""Time-series trend data from pathway_trends table."""
return _get_trend_data(DB_PATH, metric, directory, drug)