Commit Graph

40 Commits

Author SHA1 Message Date
Andrew Charlwood 506769470d feat: add get_directorate_from_diagnosis() function (Task 2.1)
- Added DirectorateAssignment dataclass for return type
- Added get_directorate_from_diagnosis() function to diagnosis_lookup.py
- Logic: Try diagnosis-based lookup first (direct SNOMED match)
- Returns FALLBACK source if no match found, letting caller handle fallback
- Extracts PatientPseudonym from UPID (last part after provider code)
- Updated __all__ exports with new dataclass and function
- Tested: function handles no-match cases correctly
2026-02-05 14:19:18 +00:00
Andrew Charlwood b44d22de2c feat: add direct SNOMED lookup functions (Task 1.3)
Add two new functions to diagnosis_lookup.py for direct SNOMED code matching:

- get_drug_snomed_codes(drug_name): Query ref_drug_snomed_mapping for all
  SNOMED codes mapped to a drug. Returns list of DrugSnomedMapping with
  snomed_code, snomed_description, search_term, primary_directorate.
  Tested: ADALIMUMAB returns 1320 mappings across 10 Search_Terms.

- patient_has_indication_direct(patient_pseudonym, mappings, connector):
  Query PrimaryCareClinicalCoding for exact SNOMED code matches.
  Returns most recent match by EventDateTime with DirectSnomedMatchResult.

Both functions follow existing patterns in the module and are exported
in __all__. The lookup is case-insensitive for drug names.
2026-02-05 14:14:55 +00:00
Andrew Charlwood 6d68b5eaa5 feat: add SNOMED mapping loader script (Task 1.2)
- Create data_processing/load_snomed_mapping.py with:
  - migrate_drug_snomed_mapping() for CSV to SQLite migration
  - get_drug_snomed_mapping_counts() for statistics
  - verify_drug_snomed_mapping_migration() for validation
  - clean_snomed_code() to remove trailing .0 from SNOMED codes
  - CLI interface: python -m data_processing.load_snomed_mapping

- Loaded 144,056 mappings from enriched CSV:
  - 707 unique drugs
  - 187 unique search terms
  - 21,265 unique SNOMED codes
2026-02-05 14:10:36 +00:00
Andrew Charlwood 9943e85761 feat: add ref_drug_snomed_mapping schema (Task 1.1)
- Add REF_DRUG_SNOMED_MAPPING_SCHEMA with 11 columns for direct SNOMED mapping
- Add 5 indexes for lookup performance (drug, cleaned_drug, snomed, search_term, composite)
- Add create_drug_snomed_mapping_table() helper function
- Update helper functions (drop, get_counts, verify_exists) to include new table
- Table is included in REFERENCE_TABLES_SCHEMA and created by migration
2026-02-05 14:06:31 +00:00
Andrew Charlwood fa72fb3098 docs: mark all tasks complete in IMPLEMENTATION_PLAN.md 2026-02-05 02:17:17 +00:00
Andrew Charlwood 9b466b4e6c feat: add hover/focus states and clean up unused styles (Task 5.6)
- Add subtle hover states to KPI badges, dropdown triggers, tabs
- Add consistent focus rings for accessibility (2px Pale Blue)
- Update button styles with focus/active states
- Clean up unused styles: compact_kpi_* (Option B), unused imports
- All interactive elements now have appropriate hover/focus feedback
2026-02-05 02:16:01 +00:00
Andrew Charlwood 754e98dbe5 feat: refine top bar with style helpers (Task 5.5)
- Use top_bar_style() for 48px height container
- Use logo_style() for 28px height logo (was 36px)
- Use top_bar_tab_style() for 28px height pills
- Simplify data freshness to single line
- Remove max_width constraint for full-width bar
- Lighter shadow (SM instead of MD)
2026-02-05 02:08:01 +00:00
Andrew Charlwood ef2a109528 feat: full-width responsive chart layout (Task 5.4)
- Remove PAGE_MAX_WIDTH constraint from main_content()
- Update chart_display() with calc(100vh - 152px) height
- Update icicle_figure with autosize=True and reduced margins
- Update chart_section() with flex layout for height fill
- Update page_layout() with 100vh height
2026-02-05 02:03:55 +00:00
Andrew Charlwood 826dd1c022 feat: compact KPI badges integrated into filter strip (Task 5.3)
- Add kpi_badge() and kpi_badges() functions for inline pill-style KPIs
- Integrate KPI badges into filter_section() on the right side
- Remove separate kpi_row() from main_content() layout
- Zero extra vertical height - KPIs now share the filter strip row

Design: Follows Option A from DESIGN_SYSTEM.md (preferred approach)
2026-02-05 01:59:00 +00:00
Andrew Charlwood d2bed71078 feat: compact filter section as single horizontal strip (Task 5.2)
- Redesign filter_section() as 48px horizontal strip
- Remove "Filters" header (saves vertical space)
- Compact initiated_filter_dropdown() and last_seen_filter_dropdown()
  - 32px height triggers via compact_dropdown_trigger_style()
  - Labels moved inside dropdown panels
- Compact searchable_dropdown() component
  - 32px trigger height, no external label
  - Reduced panel item height (150px max, was 200px)
  - Smaller search input (size="1"), tighter spacing
- All filters now in ONE row with divider separator

Target: filter section height ≤ 60px (from ~200px)
2026-02-05 01:53:38 +00:00
Andrew Charlwood 0a68c2a5a5 feat: update design tokens for SaaS redesign (Task 5.1)
- Typography: Reduce sizes (Display 32→28, H1 24→18, H2 20→16, Caption 12→11)
- Spacing: Tighten scale by ~25% (SM 8→6, MD 12→8, LG 16→12, etc.)
- Shadows: Lighter values for modern feel
- Colors: Modernize semantic colors (#10B981 success, #EF4444 error)
- Layout: TOP_BAR_HEIGHT 64→48px, new FILTER_STRIP_HEIGHT 48px

New style helpers added:
- compact_kpi_card_style/value/label - 50% smaller KPI cards
- kpi_badge_style - inline pill variant for zero-height KPIs
- filter_strip_style - horizontal single-row container
- compact_dropdown_trigger_style - 32px height triggers
- chart_container_style/wrapper - full-width flex-grow
- top_bar_style/tab/logo - compact 48px top bar

All tokens verified via import and Reflex compile.
2026-02-05 01:46:58 +00:00
Andrew Charlwood 76e0d64820 docs: complete Task 4.3 Documentation
Update CLAUDE.md with new pathway data architecture:
- Add Pathway Data Architecture section with date filter table
- Update package structure with cli/ and pathway_pipeline.py
- Add CLI module and pathway pipeline documentation
- Update data flow diagrams (pre-computed vs legacy)
- Add pathway tables to database schema section
- Add CLI commands section with usage examples
- Add Breaking Changes section documenting:
  - Date filter changes (pickers -> dropdowns)
  - Data refresh model (real-time -> pre-computed)
  - State variable changes
  - Icicle chart enhancements

Mark all Task 4.3 subtasks complete in IMPLEMENTATION_PLAN.md
Update completion criteria status
2026-02-05 00:56:34 +00:00
Andrew Charlwood 870d2e6e0e feat: complete Task 4.2 Performance Testing - all targets met 2026-02-05 00:50:14 +00:00
Andrew Charlwood cabaa72e9d feat: complete Task 4.1 End-to-End Validation
All 5 validation tests pass:
- Hierarchy structure: 6 levels (Root→Trust→Directory→Drug→Pathway)
- Patient counts: 11,118 patients, £130.5M from root node
- Treatment statistics: average_spacing, cost_pp_pa populated
- Drug filtering: drug_sequence column for LIKE patterns
- Customdata: All 10 fields present and populated
2026-02-05 00:43:55 +00:00
Andrew Charlwood a6f1d8b30e feat: replace date pickers with select dropdowns (Task 3.3)
- Created initiated_filter_dropdown() and last_seen_filter_dropdown() components
- Uses rx.select.root pattern with static options for Reflex compatibility
- Updated filter_section() to use new dropdown components
- Removed old date_range_picker() function (replaced by new dropdowns)
- Data freshness indicator already working in top_bar via load_pathway_data()
- Verified: py_compile PASS, imports PASS, reflex compile PASS (11.1s)
2026-02-05 00:37:18 +00:00
Andrew Charlwood ced994f93f feat: update icicle_figure with full 10-field customdata (Task 3.2)
Updated the icicle_figure computed property in AppState to use the full
10-field customdata structure matching visualization/plotly_generator.py:

- value (patient count)
- colour (proportion of parent)
- cost (total cost)
- costpp (cost per patient)
- first_seen (first intervention date)
- last_seen (last intervention date)
- first_seen_parent (earliest date in parent)
- last_seen_parent (latest date in parent)
- average_spacing (dosing information)
- cost_pp_pa (cost per patient per annum)

Updated texttemplate and hovertemplate to display treatment statistics
including duration, dosing, and full cost breakdown.
2026-02-05 00:30:22 +00:00
Andrew Charlwood 7948ca7da3 feat: update AppState to query pre-computed pathway_nodes (Task 3.1)
- Add dropdown state for date filters (selected_initiated, selected_last_seen)
- Add date_filter_id computed property combining the two selections
- Add load_pathway_data() method to query pathway_nodes table
- Add recalculate_parent_totals() for filtered hierarchies
- Update all filter handlers to call load_pathway_data()
- Update KPI calculations from root node data

Phase 3 Reflex integration: Task 3.1 complete
2026-02-05 00:26:21 +00:00
Andrew Charlwood adc1dbfc58 feat: complete Task 2.2 - test refresh pipeline with Snowflake data
Tested full refresh pipeline end-to-end with real Snowflake data:
- Fixed trust filter to read Name column from defaultTrusts.csv
- Fixed Decimal type handling in calculate_cost_per_patient_per_annum
- Fixed array handling in convert_to_records for average_administered
- Added required reference CSV files to data/ directory
- Configured Snowflake connection (account, warehouse, user)

Results:
- Snowflake fetch: 656,695 records in ~7s
- Transformations: 519,848 records after UPID/drug/directory
- Pathway nodes: 293 for all_6mo (8 trusts, 14 directories)
- Total processing time: ~6.2 minutes
2026-02-05 00:20:12 +00:00
Andrew Charlwood 092fdbba5a feat: add CLI refresh command for pathway data (Task 2.1)
Add cli/refresh_pathways.py with:
- refresh_pathways() main function for full pipeline orchestration
- insert_pathway_records() for SQLite insertion
- log_refresh_start/complete/failed() for refresh tracking
- CLI with --minimum-patients, --provider-codes, --dry-run, --verbose

Uses existing pipeline functions:
- fetch_and_transform_data() from pathway_pipeline.py
- process_all_date_filters() for 6 date filter combinations
- Schema helpers from data_processing/schema.py
2026-02-04 23:30:11 +00:00
Andrew Charlwood 9bb4748588 docs: mark Task 1.3 complete (migration already handled by schema)
Task 1.3 (Create Migration Script) is satisfied by existing code:
- python -m data_processing.migrate creates all pathway tables
- pathway_date_filters auto-populated via INSERT OR REPLACE in schema
- Verified: fresh database creates all 3 tables with 6 date filters
2026-02-04 23:25:14 +00:00
Andrew Charlwood 5945649ae3 feat: add pathway pipeline module (Task 1.2)
Create data_processing/pathway_pipeline.py with:
- DateFilterConfig dataclass for date filter configuration
- DATE_FILTER_CONFIGS with 6 pre-defined combinations
- compute_date_ranges() for computing actual dates from config
- fetch_and_transform_data() for Snowflake fetch + transformations
- process_pathway_for_date_filter() using existing generate_icicle_chart()
- extract_denormalized_fields() to parse trust/directory/drugs from ids
- convert_to_records() for SQLite insertion
- process_all_date_filters() convenience function
2026-02-04 23:21:39 +00:00
Andrew Charlwood 34396fef5e feat: add pathway data architecture schema (Task 1.1)
Add three new tables to support pre-computed pathway data:
- pathway_date_filters: 6 pre-defined date filter combinations
- pathway_nodes: pre-computed pathway hierarchy with all visualization data
- pathway_refresh_log: tracks data refresh status

Includes:
- 8 indexes for efficient filtering by date_filter_id, trust, directory, drug
- Helper functions: create/drop/verify/get_counts for pathway tables
- clear_pathway_nodes() for selective or full data clearing
- get_pathway_refresh_status() for checking last refresh
- Integration with existing ALL_TABLES_SCHEMA and combined helpers
2026-02-04 23:17:27 +00:00
Andrew Charlwood b93af40ac4 feat: implement debounced inputs for filter performance (Task 5.2)
- Wrap date inputs with rx.debounce_input() (300ms timeout)
- Wrap dropdown search inputs with rx.debounce_input() (300ms timeout)
- Prevents excessive filter/chart updates during user input
- Satisfies "instant (debounced) updates" completion criterion
2026-02-04 19:25:57 +00:00
Andrew Charlwood 6c3b3abf03 feat: improve error handling with user-friendly messages (Task 5.3)
- Updated all error messages to be more descriptive and actionable
- Verified error states render correctly in UI (loading, error, empty)
- Confirmed filter handlers check data_loaded before applying filters
- Error handling covers: missing DB, empty DB, SQLite errors, filter errors
2026-02-04 19:20:57 +00:00
Andrew Charlwood 0dd99e6a42 docs: complete visual polish audit against DESIGN_SYSTEM.md (Task 5.1)
- Verified all design tokens match spec exactly
- Confirmed responsive behavior via flex_wrap patterns
- Audited hover states and transitions
- Validated chart colorscale uses design system palette
2026-02-04 19:16:47 +00:00
Andrew Charlwood 307094eca3 docs: verify data loading, filter logic, and chart generation (Task 5.4 partial) 2026-02-04 19:08:09 +00:00
Andrew Charlwood e099538ea9 feat: enable app_v2 via package init, verify reflex compilation
- Update pathways_app/__init__.py to re-export app from app_v2
- Verified reflex run compiles 33/33 components successfully
- App runs on localhost:3003 (frontend) and :8002 (backend)
- Mark completion criteria "App compiles" as verified
2026-02-04 18:59:08 +00:00
Andrew Charlwood 158d873750 feat: integrate rx.plotly() chart component (Task 4.3)
- Replace chart_ready_placeholder() with chart_display() function
- chart_display() wraps rx.plotly() with AppState.icicle_figure
- Chart updates reactively when filters change via computed property
- Loading, error, and empty states already handled in chart_section()
2026-02-04 18:49:13 +00:00
Andrew Charlwood ec8f8dc198 feat: implement reactive Plotly icicle chart generation (Task 4.2)
- Add plotly.graph_objects import
- Create icicle_figure computed property (@rx.var)
- NHS-inspired blue gradient colorscale (Heritage Blue → Pale Blue)
- Custom hover template with patient count, percentage, and cost
- Responsive height (600px), transparent background
- Maintain hierarchy order with sort=False
2026-02-04 18:45:22 +00:00
Andrew Charlwood 14f970d37b 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)
2026-02-04 18:41:37 +00:00
Andrew Charlwood cd15ab6cdf feat: implement filter logic with reactive KPI updates (Task 3.3)
- Add apply_filters() method that queries SQLite with current filter state
- Handle initiated date filter (first intervention date range)
- Handle last seen date filter (last intervention date range)
- Handle drug and directorate multi-select filters
- Use CTE pattern for efficient patient-level date filtering
- Update KPI values (unique_patients, total_drugs, total_cost) on filter change
- Call apply_filters() from all filter event handlers
- Call apply_filters() after initial data load
2026-02-04 14:17:27 +00:00
Andrew Charlwood f38ccfc128 feat: implement data loading from SQLite (Task 3.2)
- Add load_data() method to AppState that connects to SQLite database
- Populate available_drugs, available_directorates, available_indications from DB
- Detect latest date in dataset and set filter defaults accordingly
- Load KPI values: total_records, unique_patients, total_drugs, total_cost
- Add on_load handler to trigger data loading on page initialization
- Handle database errors gracefully with meaningful error messages
2026-02-04 14:11:03 +00:00
Andrew Charlwood fead4bf7dd feat: complete core state variables (Task 3.1)
- Add datetime imports for date handling
- Add data state variables: last_updated, raw_data, latest_date_in_data
- Set last_seen date defaults (6 months ago to today)
- Add last_updated_display computed var for top bar
- Update top bar to show dynamic refresh timestamp
2026-02-04 14:03:28 +00:00
Andrew Charlwood 17478c96ae feat: implement chart container with state-based rendering (Task 2.4)
- Add chart_loading_skeleton() with animated bar chart and spinner
- Add chart_error_state() for displaying errors with guidance
- Add chart_empty_state() for when filters yield no results
- Add chart_ready_placeholder() for Phase 4 Plotly integration
- Rewrite chart_section() with 4-state rx.cond() logic
- Fix icon names (triangle-alert) and color references (SLATE_500)

This completes Phase 2 Layout Components.
2026-02-04 13:59:01 +00:00
Andrew Charlwood 2df3a0976b feat: implement KPI row with reactive metrics (Task 2.3)
- Create kpi_card() component with icon, value, label, and highlight option
- Create kpi_row() with 4 KPI cards: Unique Patients, Drug Types, Total Cost, Indication Match
- Add computed vars for formatted KPI display values
- Add placeholder KPI state variables (unique_patients, total_drugs, total_cost, indication_match_rate)
- Use design system tokens for styling with hover effects
- Responsive flex-wrap layout for smaller screens
2026-02-04 13:52:57 +00:00
Andrew Charlwood b2d4afd408 feat: implement filter section with date pickers and searchable dropdowns (Task 2.2)
- Add date_range_picker() component with enable/disable checkbox
- Add searchable_dropdown() component with search, select all, clear
- Implement filter_section() with layout for dates and multi-selects
- Add comprehensive state management in AppState:
  - Filter toggle states (initiated_filter_enabled, last_seen_filter_enabled)
  - Date values for both ranges
  - Dropdown visibility state
  - Selection state for drugs, indications, directorates
  - Search text state for filtering options
  - Event handlers for all filter interactions
  - Computed vars for filtered options and selection counts
- Style components using design tokens from styles.py
- Debounced handlers deferred to Phase 3.3 (Filter Logic)
2026-02-04 13:46:57 +00:00
Andrew Charlwood a8d9f7b757 feat: implement top navigation bar (Task 2.1)
- Add chart_tab() component for chart type pills
- Implement full top_bar() with logo, title, chart tabs, data freshness
- Heritage Blue background with white text, 64px fixed height
- Reactive data freshness indicator using rx.cond for loading states
- Added Transitions import to styles
2026-02-04 13:40:31 +00:00
Andrew Charlwood 072ce852af feat: complete app skeleton (Task 1.2)
- Add app_v2.py with basic Reflex app structure
- AppState class with placeholder state variables
- Layout components: top_bar, filter_section, kpi_row, chart_section
- Page layout matching DESIGN_SYSTEM.md structure
- Theme configured with design system colors
- Google Fonts for Inter and JetBrains Mono
2026-02-04 13:35:45 +00:00
Andrew Charlwood 2bd28f5f22 feat: create design tokens module (styles.py)
- Add Colors class with NHS-inspired blue palette and neutrals
- Add Typography class with font family, sizes, weights
- Add Spacing, Radii, Shadows, Transitions classes
- Add helper functions: card_style(), button_*_style(), input_style()
- Add KPI card and text style helpers
- Add layout constants (TOP_BAR_HEIGHT, PAGE_MAX_WIDTH)

All tokens match DESIGN_SYSTEM.md specifications.
2026-02-04 13:10:35 +00:00
Andrew Charlwood fdd33a67af Initial commit before Ralph loop 2026-02-04 13:04:29 +00:00