feat: add trust selection to drawer with filter wiring (Task 5.1)
This commit is contained in:
@@ -32,6 +32,13 @@ def _generate_chart_title(app_state):
|
||||
else:
|
||||
parts.append(f"{len(selected_directorates)} directorates")
|
||||
|
||||
selected_trusts = app_state.get("selected_trusts") or []
|
||||
if selected_trusts:
|
||||
if len(selected_trusts) <= 2:
|
||||
parts.append(", ".join(selected_trusts))
|
||||
else:
|
||||
parts.append(f"{len(selected_trusts)} trusts")
|
||||
|
||||
return " | ".join(parts) if parts else "All Patients"
|
||||
|
||||
|
||||
@@ -53,12 +60,14 @@ def register_chart_callbacks(app):
|
||||
chart_type = app_state.get("chart_type", "directory")
|
||||
selected_drugs = app_state.get("selected_drugs") or None
|
||||
selected_directorates = app_state.get("selected_directorates") or None
|
||||
selected_trusts = app_state.get("selected_trusts") or None
|
||||
|
||||
return query_pathway_data(
|
||||
filter_id=filter_id,
|
||||
chart_type=chart_type,
|
||||
selected_drugs=selected_drugs,
|
||||
selected_directorates=selected_directorates,
|
||||
selected_trusts=selected_trusts,
|
||||
)
|
||||
|
||||
@app.callback(
|
||||
|
||||
@@ -9,14 +9,16 @@ def register_drawer_callbacks(app):
|
||||
Output("drug-drawer", "opened"),
|
||||
Input("sidebar-drug-selection", "n_clicks"),
|
||||
Input("sidebar-indications", "n_clicks"),
|
||||
Input("sidebar-trust-selection", "n_clicks"),
|
||||
prevent_initial_call=True,
|
||||
)
|
||||
def open_drawer(_drug_clicks, _indication_clicks):
|
||||
"""Open the drawer when sidebar Drug Selection or Indications is clicked."""
|
||||
def open_drawer(_drug_clicks, _indication_clicks, _trust_clicks):
|
||||
"""Open the drawer when sidebar Drug Selection, Indications, or Trust Selection is clicked."""
|
||||
return True
|
||||
|
||||
@app.callback(
|
||||
Output("all-drugs-chips", "value"),
|
||||
Output("trust-chips", "value"),
|
||||
Input({"type": "drug-fragment", "index": ALL}, "n_clicks"),
|
||||
Input("clear-drug-filters", "n_clicks"),
|
||||
State("all-drugs-chips", "value"),
|
||||
@@ -27,20 +29,20 @@ def register_drawer_callbacks(app):
|
||||
"""Handle drug fragment badge click (substring match) or clear all filters.
|
||||
|
||||
Fragment click: find all full drug names containing the fragment substring,
|
||||
toggle them in the chip selection.
|
||||
Clear click: reset chip selection to empty.
|
||||
toggle them in the chip selection. Trust chips unchanged.
|
||||
Clear click: reset both drug and trust chip selections.
|
||||
"""
|
||||
triggered = ctx.triggered_id
|
||||
|
||||
# Clear button
|
||||
# Clear button — reset both drug and trust chips
|
||||
if triggered == "clear-drug-filters":
|
||||
return []
|
||||
return [], []
|
||||
|
||||
# Fragment badge click — triggered_id is a dict like {"type": "drug-fragment", "index": "DIR|FRAG"}
|
||||
if isinstance(triggered, dict) and triggered.get("type") == "drug-fragment":
|
||||
# Check if any fragment was actually clicked (not just initial render)
|
||||
if not any(n for n in (fragment_clicks or []) if n):
|
||||
return no_update
|
||||
return no_update, no_update
|
||||
|
||||
fragment_key = triggered["index"] # e.g. "CARDIOLOGY|ABCIXIMAB"
|
||||
fragment = fragment_key.split("|", 1)[-1] if "|" in fragment_key else fragment_key
|
||||
@@ -55,7 +57,7 @@ def register_drawer_callbacks(app):
|
||||
]
|
||||
|
||||
if not matching_drugs:
|
||||
return no_update
|
||||
return no_update, no_update
|
||||
|
||||
# Toggle: if all matching drugs are already selected, deselect them;
|
||||
# otherwise, add them to selection
|
||||
@@ -67,6 +69,6 @@ def register_drawer_callbacks(app):
|
||||
else:
|
||||
updated = current | set(matching_drugs)
|
||||
|
||||
return sorted(updated)
|
||||
return sorted(updated), no_update
|
||||
|
||||
return no_update
|
||||
return no_update, no_update
|
||||
|
||||
@@ -32,12 +32,14 @@ def register_filter_callbacks(app):
|
||||
Input("filter-initiated", "value"),
|
||||
Input("filter-last-seen", "value"),
|
||||
Input("all-drugs-chips", "value"),
|
||||
Input("trust-chips", "value"),
|
||||
State("app-state", "data"),
|
||||
)
|
||||
def update_app_state(
|
||||
_dir_clicks, _ind_clicks, initiated, last_seen, selected_drugs, current_state
|
||||
_dir_clicks, _ind_clicks, initiated, last_seen, selected_drugs,
|
||||
selected_trusts, current_state
|
||||
):
|
||||
"""Update app-state when chart type toggle, date filters, or drug chips change."""
|
||||
"""Update app-state when chart type toggle, date filters, drug chips, or trust chips change."""
|
||||
if not current_state:
|
||||
current_state = {
|
||||
"chart_type": "directory",
|
||||
@@ -46,6 +48,7 @@ def register_filter_callbacks(app):
|
||||
"date_filter_id": "all_6mo",
|
||||
"selected_drugs": [],
|
||||
"selected_directorates": [],
|
||||
"selected_trusts": [],
|
||||
}
|
||||
|
||||
triggered_id = ctx.triggered_id
|
||||
@@ -68,6 +71,7 @@ def register_filter_callbacks(app):
|
||||
"last_seen": last_seen,
|
||||
"date_filter_id": date_filter_id,
|
||||
"selected_drugs": selected_drugs or [],
|
||||
"selected_trusts": selected_trusts or [],
|
||||
}
|
||||
|
||||
# Toggle pill CSS classes
|
||||
|
||||
Reference in New Issue
Block a user