feat: implement chart data preparation (Task 4.1)

- Add prepare_chart_data() method for hierarchical chart data
- Build Trust → Directory → Drug hierarchy from filtered SQLite data
- Calculate patient counts and costs at each hierarchy level
- Compute color values (proportions) for visualization
- Generate dynamic chart title based on filter state
- Call prepare_chart_data() from apply_filters() for reactivity
- Mark Task 3.4 complete (KPIs implemented in apply_filters)
This commit is contained in:
Andrew Charlwood
2026-02-04 18:41:37 +00:00
parent cd15ab6cdf
commit 14f970d37b
2 changed files with 286 additions and 6 deletions
+11 -6
View File
@@ -129,17 +129,22 @@ cd pathways_app && timeout 60 python -m reflex run 2>&1 | head -30
- [x] Return filtered DataFrame
### 3.4 KPI Calculations
- [ ] Create computed properties for KPI values:
- [x] Create computed properties for KPI values:
- `unique_patients: int` — COUNT(DISTINCT patient_id) from filtered data
- (Future: drug count, total cost, indication match rate)
- [ ] Ensure KPIs update reactively when filters change
- `total_drugs: int` — COUNT(DISTINCT drug_name_std) from filtered data
- `total_cost: float` — SUM(price_actual) from filtered data
- (Blocked: indication_match_rate requires Snowflake GP data)
- [x] Ensure KPIs update reactively when filters change
- Note: KPIs implemented in apply_filters() method, called by all filter event handlers
## Phase 4: Interactive Chart
### 4.1 Chart Data Preparation
- [ ] Create `prepare_chart_data()` method that transforms filtered data for Plotly icicle
- [ ] Reuse/adapt logic from existing `pathway_analyzer.py`
- [ ] Return data structure compatible with `plotly.express.icicle()`
- [x] Create `prepare_chart_data()` method that transforms filtered data for Plotly icicle
- [x] Reuse/adapt logic from existing `pathway_analyzer.py` (simplified hierarchy: Trust → Directory → Drug)
- [x] Return data structure compatible with `go.Icicle()` (list of dicts with parents, ids, labels, value, cost, colour)
- [x] Generate chart_title based on current filter state
- [x] Call prepare_chart_data() from apply_filters() for reactive updates
### 4.2 Reactive Plotly Integration
- [ ] Create `generate_icicle_chart()` computed property that returns Plotly figure