Care Module plugins — kill switch and core integration
Version: 1.38
Last Updated: 2026-08-03 18:23:23
Status: Adopted — Phase A + Cancer Board V2 shipped (top context panel drives Today’s care plan; Daily status radar with per-tap persist + merged retrospective reads; homepage dashboard-panel; bottom day/mode pickers removed from hub); 8-spoke radar geometry preserved
UI spec: 29-CARE-MODULE-UI-ARCHITECTURE.md · Support flow: 31-CANCER-AT-HOME-SUPPORT-FLOW-UX.md
1. Your instinct is right (with one clarification)
Section titled “1. Your instinct is right (with one clarification)”Yes: Cancer at Home and Breathing & Oxygen should ship as plugins on top of the core app, with an instant off switch so you can launch on the base product alone.
Clarification: They are not optional npm packages. They are feature-flagged product plugins inside the same repo — same deploy, same database, isolated folders and routes. That matches how you already treat commerce (BILLING_TIER_PLANS_ONLY) and product readiness (module_delivery.json).
| Layer | What it gates | Kill switch |
|---|---|---|
Subscription (ModuleGate, tiers.json) | Entitlement — can tenant use observations, calendar, etc.? | Tier plan only |
Care Profile purchase (tenant_pack_purchases) | Unlock slug — can they apply cancer/breathing? | BILLING_TIER_PLANS_ONLY (no pack checkout) |
| Care Module boards (new) | Interactive hub UI — /care/... | CARE_MODULE_BOARDS_ENABLED |
| Preview audience (new) | Who may use boards when enabled | CARE_MODULE_PREVIEW_USER_IDS (default 1) |
The third and fourth layers are independent. You can have pack seeds + base app with boards completely off, or boards on only for user id 1 while you validate UX.
2. Pushback (where I disagree or warn)
Section titled “2. Pushback (where I disagree or warn)”2.1 You cannot avoid some core touchpoints
Section titled “2.1 You cannot avoid some core touchpoints”Pure plugins with zero core changes are not realistic. You need small integration points only:
| # | Core touch | Why |
|---|---|---|
| 1 | Route registration (lazy, behind flag) | App.tsx — /care/* when VITE_CARE_MODULE_BOARDS=true |
| 2 | Per-user feature flag | GET /api/subscriptions/active → feature_flags.care_module_boards (loaded once in ModuleContext; useCareModuleFlags() derives gates — no duplicate request) |
| 3 | Patient context (existing) | Boards read activePatient.care_profile_slug |
You do not need to refactor Dashboard, Observations, or ModuleGate for v1 beyond an optional dashboard chip.
2.2 Do not make Care Boards a tiers.json module yet
Section titled “2.2 Do not make Care Boards a tiers.json module yet”Do not add care_module_cancer to subscription modules. That couples billing to experimental UI and makes kill switches harder.
2.3 Two kill switches, not one
Section titled “2.3 Two kill switches, not one”| Switch | Where | Effect when OFF |
|---|---|---|
| Build-time | VITE_CARE_MODULE_BOARDS=false | Routes and JS chunks not in bundle — safest launch |
| Runtime | CARE_MODULE_BOARDS_ENABLED=false on API | Nav hidden; APIs 404; old clients cannot use boards |
Launch recommendation: both OFF in production until you are happy. Turn on in staging with both true.
2.4 Go-live registry + owner preview toggle (current rollout)
Section titled “2.4 Go-live registry + owner preview toggle (current rollout)”When both deploy flags are true, visibility is driven by backend/care_modules/go_live.json (one status per board slug) and users.care_module_dev_preview for users in CARE_MODULE_PREVIEW_USER_IDS.
| Registry status | Public board + commerce | Preview cohort (preview_user_ids) |
|---|---|---|
live | Everyone with pack access | N/A |
preview | Hidden | Board + Subscriptions offer only when user is in cohort and dev preview toggle is ON |
Default posture: slugs stay preview (not live). Toggle defaults OFF — user id 1 sees the customer view (no board nav, no paid profile cards) until they enable preview on Subscriptions.
Deploy gate: scripts/verify-care-module-preview-gate.ps1 probes slug_board_visible('cancer_at_home', …) — user 1 off → False, user 1 on → True, user 2 off → False.
2.5 module_delivery.json stays honest
Section titled “2.5 module_delivery.json stays honest”Keep condition_templates as partial. Do not mark boards live until product sign-off.
3. Gate chain (who sees a board)
Section titled “3. Gate chain (who sees a board)”4. Plugin layout (repo structure)
Section titled “4. Plugin layout (repo structure)”backend/ care_modules/ flags.py manifest_loader.py manifests/ cancer_at_home.json breathing_difficulties.json routers/ status.py board.py services/ zone_engine.py board_service.py cancer_hub_service.py dashboard_panel_service.py cancer_defaults.py cancer_board_visual.py # enrich_tiles(), icon keys for hub visual layer visit_prep_narrative.py repositories/ care_module_events.py care_module_settings.py migrations/ V011__care_module_events.sql V015__care_module_patient_settings.sql
frontend/src/ care-modules/ CareModuleRoutes.tsx # lazy routes + Suspense + ErrorBoundary per /care/* registry.ts hooks/useCareBoard.ts shared/CareBoardShell.tsx, CareBoardGate.tsx cancer/CareBoardPage.tsx cancer/cancerBoardV2Model.ts # V2 section builders (status, plan, watch, activation, clinic) cancer/cancerCareFlow.ts # buildCancerCareFlow, buildComfortBecauseLine, resolvePainLogFork cancer/cancerBoardVisual.ts cancer/cancerRadarConfig.ts # 8-spoke metadata (Daily cancer status) cancer/radarTapGeometry.ts # tap hit-test (do not change in V2) cancer/components/CancerTodayContextPanel.tsx # cc-card; composes CancerDayPicker + CancerModeToggle cancer/components/CancerStatusSummary.tsx cancer/components/CancerTodayPlan.tsx cancer/components/CancerWatchClosely.tsx cancer/components/CancerActivatedAcrossLynCareOS.tsx cancer/components/CancerClinicHandover.tsx cancer/components/CancerTileCard.tsx cancer/components/CancerDayPicker.tsx cancer/components/CancerModeToggle.tsx cancer/components/CancerPrimarySitePicker.tsx # header Listbox pill (right of title row) cancer/components/CancerComfortDateStrip.tsx # day picker for daily cancer status cancer/components/CancerComfortRadar.tsx cancer/components/CancerComfortRadarChart.tsx # ECharts 8-spoke radar cancer/components/InlineComfortCheckIn.tsx # Daily status wrapper (cancer_symptom_bundle / comfort_round) cancer/components/CareFlowRail.tsx # retained; not mounted on hub cancer/components/BecauseLine.tsx # What this tells us (post-save implication) cancer/components/NextStepFork.tsx # Do now / Later / Skip cancer/components/CollapsibleSection.tsx # chevron groups (other tasks, today, treatment) cancer/VisitPrepPage.tsx breathing/CareBoardPage.tsx components/dashboard/ CareBoardDashboardPanel.tsx CareActionsForTodayBlock.tsx CareProfileIconStrip.tsx CancerTodayStrip.tsx components/care-capture/ CareCaptureOverlay.tsx # portal; phone full-screen / tablet 85vw / desktop ~50% main column CaptureSession.tsx # wizard | stacked layout from manifest SegmentedBar.tsx # tap-segment bar (3–5 choices; Comfort check-in) TrafficLight3.tsx context/ ModuleContext.tsx # active modules + feature_flags (single /subscriptions/active) CareModuleFlagsContext.tsx # useCareModuleFlags() hook only (no extra provider)Core app imports only:
CareModuleRoutesinsideif (CARE_BOARDS_BUILD_ENABLED)useCareModuleFlags()(underModuleProviderinApp.tsx)
4.1 App provider tree (2026-06-04)
Section titled “4.1 App provider tree (2026-06-04)”There is no CareModuleFlagsProvider. Flags come from the same ModuleContext fetch as module entitlements.
AuthProvider └── ProtectedRoute └── ModuleProvider ← GET /subscriptions/active (modules + feature_flags) └── PatientProvider └── AlertProvider └── Layout → pages (Dashboard chip, /care/* gates)CareBoardDashboardChip and CareBoardGate call useCareModuleFlags(); that hook reads careModuleBoards from useModules().
4.2 Capture sessions in manifest JSON
Section titled “4.2 Capture sessions in manifest JSON”Each slug’s backend/care_modules/manifests/{slug}.json defines capture_sessions:
| Field | Purpose |
|---|---|
label | Overlay title |
layout | Optional: wizard (default) or stacked (all steps on one phone screen) |
steps[] | key, widget, family_prompt, choices[] with clinical_value |
Cancer Daily status (inline 8-spoke radar): sessions cancer_symptom_bundle and comfort_round — eight manifest steps (Energy, Pain, Eating, Breath, Mood, Sleep, Fever, Treatment) rendered on CareBoardPage via InlineComfortCheckIn (not overlay). CancerComfortDateStrip selects care_date. Tap ring dots on CancerComfortRadarChart to score each spoke 1–4; postStep on each tap (immediate care_module_events write with care_date + capture_instance_id). completeSession when all eight spokes saved in UI (automatic — no Save button). GET …/comfort-checkin (board): merged latest per spoke across all instances on that date so retrospective edits keep the full spider; optional capture_instance_id query for single-instance reads. Dashed overlay = Past N-day average from GET …/comfort-checkin/spoke-averages. GET …/comfort-checkin/week-series?anchor= returns Mon–Sun merged levels; comfortWeekInsightNarrative.ts turns that into CancerStatusSummary copy (1–7 days of data: single-day snapshots, multi-day trends, per-spoke deterioration questions, team/palliative/emergency hints — hub zone fallback only when the week has zero daily-status days). cancerRadarConfig.ts: fever_worry uses higherIsBetter: false (stored 4 = fever/chills, 1 = no signs). Overlay CaptureSession retained for fever / infusion / oral medicine / tablet pathways from tiles. visit_prep_narrative and hub due-counts include both session ids.
Cancer Board V2 (shipped 2026-06-10): CareBoardPage renders CancerTodayContextPanel (top — cc-card composing CancerDayPicker + CancerModeToggle treatment modes only; day/mode patch + scroll to plan) → CancerStatusSummary (Mon–Sun spoke insights + escalation copy from week-series — 2026-07-31) → CancerTodayPlan (buildTodayPlan / buildPlanSubtitle — day-type and mode steps only; daily status and breakthrough review removed from the numbered plan list 2026-07-31, still available via InlineComfortCheckIn and CancerWatchClosely / tiles) → date strip → InlineComfortCheckIn → Other cancer tasks today (#cancer-other-tasks) → CancerWatchClosely → CancerActivatedAcrossLynCareOS → CancerClinicHandover. /calendar: CalendarFocusDayPanel — writable action pills for the focus date (§4.3). Superseded the read-only CareActionsForTodayBlock, deleted 2026-07-31. gentle_mode: backend only — no hub toggle. Bottom collapsible day/mode sections removed from the hub page. Section data from cancerBoardV2Model.ts against existing hub JSON. CareFlowRail not mounted. Home: GET …/dashboard-panel + CareBoardDashboardPanel. Spec: 31.
Calendar + breakthrough (2026-06-05, MVP completion):
| Integration | Backend | Frontend |
|---|---|---|
| Oncology appointment types | V016 column; patient_appointments.py create/PATCH | AddShiftForm optional type chips |
| Hub day sync | cancer_hub_service.today_oncology_appointments, suggested_day_type_from_calendar, effective_day_type | Calendar suggestion step in CancerTodayPlan + CancerTodayContextPanel day icons (CancerDayPicker → today_day_type) |
| Breakthrough log | resolve_breakthrough_log_route() → hub.breakthrough_log_route | CancerTileCard + LogDose.tsx query params |
| Site tips | PRIMARY_SITE_TIPS in cancer_defaults.py → hub.today.site_tip | Tip card on hub |
| Comfort override | comfort_override_state() → hub.comfort_override | Apricot banner on hub |
| Visit prep discussed | visit_prep_discussed in settings JSONB | VisitPrepPage checkboxes |
| Analytics | /api/analytics/by-reason?reason_pattern=; /care-module-events | Hub tile sparklines from hub metrics |
Manifest reload: manifest_loader.load_manifest() caches by (slug, file mtime_ns) — editing manifests/*.json invalidates on next board request without restarting the API.
4.3 Calendar actions in manifest JSON (2026-07-31)
Section titled “4.3 Calendar actions in manifest JSON (2026-07-31)”A module contributes to the care calendar by declaring calendar_actions in backend/care_modules/manifests/{slug}.json. Each entry is a named bundle of structured tasks (prompt + response buttons) that the family can put on a date with one tap. Adding a module to the calendar is a manifest edit, not a code change.
| Field | Purpose |
|---|---|
id | Stable action id, persisted on each task as source_action_id. Renaming it orphans existing tasks. |
label | Pill text |
icon | Key in CARE_PROFILE_ICON_MAP (care-modules/shared/careProfileVisual.ts) — not a Lucide component name. Applied actions show this icon in the month grid day cell as well as on the focus-day pill. |
suggested_by_appointment_types[] | patient_appointments.appointment_type values that highlight the pill on that date |
tasks[] | Task definitions applied when the action is tapped (see below) |
Each task object:
| Field | Purpose |
|---|---|
id | Stable task id → source_task_id on the row |
title | Stable label (idempotent apply index, exports) |
prompt | Question shown on the focus-day panel |
response_kind | Button set id — see backend/care_modules/calendar_task_responses.py |
Legacy manifest entries that list plain strings in tasks[] normalize to done_pending on apply.
{ "id": "infusion", "label": "Infusion day", "icon": "iv", "suggested_by_appointment_types": ["iv_infusion", "labs"], "tasks": [ { "id": "blood_tests", "title": "Confirm blood tests are done", "prompt": "Have blood tests been done?", "response_kind": "yes_no" }, { "id": "transport", "title": "Arrange driver / transport", "prompt": "Is driver or transport arranged?", "response_kind": "arrangement" } ]}Rules:
- Suggested never auto-applies. A matching appointment highlights the pill; the family still taps to confirm. Inferring the day from the calendar is what the retired
today_day_typesmechanism did wrong. - Task text comes only from the manifest.
calendar_actions_service.find_action()rejects an unknownaction_idwith 404, so a client cannot write arbitrary task text through the action endpoint. - Answers are explicit. The UI renders fixed buttons per
response_kind;PATCH /api/care-tasks/{id}with{ "response_code" }stores the choice and timestamp (V027). Checkbox strikethrough alone is not the product model for module tasks. - A module with no
calendar_actionskey simply has no pills — a valid state, not an error. - Applying is idempotent.
uq_care_tasks_module_action(V026) plusON CONFLICT DO NOTHINGmeans re-tapping writes nothing;DELETEsoft-deletes only that action’s tasks on that date.
Shipping today: cancer_at_home (infusion, tablet, clinic, rest, line care) and breathing_difficulties (oxygen check, respiratory clinic).
| Layer | File |
|---|---|
| Response kinds | backend/care_modules/calendar_task_responses.py · frontend/src/lib/calendarModuleTaskResponses.ts |
| Manifest normalize | backend/care_modules/calendar_task_manifest.py |
| Repository | backend/repositories/care_tasks.py — date-scoped SQL (V026 + V027 columns) |
| Service | backend/care_modules/services/calendar_actions_service.py — manifest lookup, apply, undo, audit on apply/undo |
| Router (gated) | backend/care_modules/routers/calendar_actions.py — behind require_care_module_access |
| Router (ungated) | backend/routers/care_tasks.py, care_shifts.py — read/create dated tasks; PATCH structured response_code |
| Frontend (focus day) | pages/calendar/CalendarFocusDayPanel.tsx, CalendarModuleDayTasks.tsx, ModuleTaskResponseButtons.tsx, useCalendarFocusDay.ts |
| Frontend (month grid) | pages/calendar/useCalendarModuleActionsRange.ts, CalendarMonthGrid.tsx, CalendarDayCell.tsx, lib/calendarViewHelpers.ts (careModuleDayIconKeys, careModuleDayIconsForViewport), careModuleSlugIconKey() in careProfileVisual.ts — desktop lg+: up to five per-action icons; phone/tablet: one module icon |
| API (month at a glance) | GET /api/patients/{id}/care-modules/calendar-actions/range?slug=&start=&end= → CalendarActionsRange.dates |
Tests: backend/tests/test_calendar_actions.py, test_calendar_task_responses.py. Calendar file map and interaction rules: 15-CARE-CALENDAR-COMPOSITION.md.
5. Turn off instantly — operator runbook
Section titled “5. Turn off instantly — operator runbook”Launch base app only (production)
Section titled “Launch base app only (production)”# backend .env / VPSCARE_MODULE_BOARDS_ENABLED=false
# frontend build (CI / docker)VITE_CARE_MODULE_BOARDS=falseRedeploy. Families see: Dashboard, Log, Calendar, Observations — no /care/* routes.
Try plugins locally (user id 1)
Section titled “Try plugins locally (user id 1)”CARE_MODULE_BOARDS_ENABLED=trueCARE_MODULE_PREVIEW_USER_IDS=1VITE_CARE_MODULE_BOARDS=trueApply the Care Profile pack (cancer_at_home or breathing_difficulties) to a test patient — not the care situation (archetype) alone. Then open /care/cancer-at-home or /care/breathing, or use the dashboard Open care board chip.
Peter tenant shortcut (dev):
.\scripts\seed-dev-peter-care-qa.ps1Log in as Peter → tenant peter → switch active person to QA — Breathing board or QA — Cancer board → Home. Optional: People in care → Care profile QA (dev) one-tap apply (user id 1). See 05-DEVELOPER-GUIDE §7.1i–§7.1j.
Runtime off without frontend rebuild
Section titled “Runtime off without frontend rebuild”Set CARE_MODULE_BOARDS_ENABLED=false and restart API. Ideal rollback: both flags false + redeploy frontend.
6. Build programme
Section titled “6. Build programme”| Phase | Deliverable | Flag | Status |
|---|---|---|---|
| P0 | Flags + registry + shell + routes | ON in dev | Done |
| P1 | care_module_events + CaptureSession + board API | ON staging | Done |
| P2 | Breathing MVP tiles (O₂, flare) | Staging sign-off | Next |
| P3 | Cancer MVP hub (visual tiles, fever, visit prep, calendar sync, breakthrough log, dashboard strip) | Staging sign-off | Done (2026-06-05) |
| P4 | Production ON + widen PREVIEW_USER_IDS | Your call | — |
7. Document history
Section titled “7. Document history”| Version | Date | Change |
|---|---|---|
| 1.0 | 2026-06-04 | Plugin + dual kill switch; core integration scope |
| 1.1 | 2026-06-04 | Preview user gate; Mermaid diagrams; Phase A paths |
| 1.3 | 2026-06-04 | Removed CareModuleFlagsProvider; useCareModuleFlags() hook on ModuleContext; §4.1 provider tree |
| 1.4 | 2026-06-04 | Peter dev QA seed (seed_dev_peter_care_qa); archetype vs Care Profile apply path in §5 |
| 1.5 | 2026-06-04 | Cancer MVP: V015 care_module_patient_settings, hub/visit-prep/chips APIs, full CareBoardPage, VisitPrepPage, CancerTodayStrip; P3 marked done |
| 1.6 | 2026-06-04 | CareCaptureOverlay (body portal, z-[1100]); ModuleContext super-admin care-board flag fix; capture vs route tiles documented |
| 1.7 | 2026-06-05 | Overlay opaque bg-canvas fix (bg-background was transparent — hub bleed-through); key={sessionId} on capture mount |
| 1.8 | 2026-06-05 | Responsive overlay: phone full-screen, tablet ~85vw card, desktop ~50% main-column width + backdrop |
| 1.9 | 2026-06-05 | Visit prep narrative: visit_prep_narrative.py, GET …/visit-prep → story; VisitPrepPage story-first UI + clinician text toggle (CANC-H02 lite) |
| 1.10 | 2026-06-05 | Visit prep abbreviated: story.lines bullet facts; lean VisitPrepPage (patient name + desk framing + questions) |
| 1.11 | 2026-06-05 | Cancer hub treatment mode feedback: hub.board_effects, toggle banners, test_cancer_board_effects.py |
| 1.12 | 2026-06-05 | Cancer board crash fix: null-safe CareBoardPage, settings treatment_modes normalize; explicit Suspense on care routes |
| 1.13 | 2026-06-05 | Dashboard + hub labels: infusion visit packing (replaces “chair day” in family UI) |
| 1.14 | 2026-06-05 | Visual cancer hub: cancer_board_visual.py, telemetry tiles, icon mode/day components, LEARNING layout |
| 1.15 | 2026-06-05 | Comfort check-in: manifest comfort_round with "layout": "stacked" + segmented_bar (How are they? · Ready for clinic? · Breakthrough pain?); SegmentedBar.tsx; CaptureSession stacked mode; _primary_cta() gentle/palliative → Comfort check-in |
| 1.16 | 2026-06-05 | Comfort mode QA: manifest_loader mtime cache (manifest edits without API restart); _visible_tiles() gentle path → symptom tile opens comfort_round; dev guide Comfort mode steps |
| 1.17 | 2026-06-05 | Default Comfort check-in: cancer_symptom_bundle → layout: stacked (same 3 steps as comfort_round); _primary_cta() label Comfort check-in; SegmentedBar numbers+legend; overlay contentAlign start for stacked; visit prep counts both session ids |
| 1.18 | 2026-06-05 | Header Where cancer is: CancerPrimarySitePicker beside hub title; Home on patient-name row (cc-btn-soft); bottom-card site select removed |
| 1.19 | 2026-06-05 | Site picker UX: native <select> → Headless UI Listbox; slim rounded-full chip inline with title; compact floating panel on small phones |
| 1.20 | 2026-06-05 | Site picker right-aligned on title row (justify-between); dropdown anchor bottom end |
| 1.21 | 2026-06-05 | Mobile-minimal hub: zone chip; inline spider Comfort check-in; CollapsibleSection for tiles/today/treatment; hero CTA removed on check-in days |
| 1.22 | 2026-06-08 | Care Flow Rail pilot: cancerCareFlow.ts, CareFlowRail, BecauseLine, NextStepFork; link 31 |
| 1.23 | 2026-06-05 | MVP completion: V016 appointment types; calendar→hub day sync; breakthrough /log deep link + sparkline; site tips; comfort override; visit prep discussed; analytics filters |
| 1.27 | 2026-06-10 | Cancer Board V2 shipped: cancerBoardV2Model.ts + five section components; V2 section order on CareBoardPage; Daily cancer status terminology; comfort-checkin APIs and radar geometry unchanged |
| 1.28 | 2026-06-10 | Actions for today UI label replaces “Today is…” on CancerDayPicker section; Comfort mode (gentle_mode) documented as simplify-board-for-today toggle |
| 1.29 | 2026-06-10 | Context panel at top (CancerTodayContextPanel composes pickers in cc-card); plan driven by day/mode; Daily status rename; homepage dashboard-panel; bottom pickers removed from hub |
| 1.30 | 2026-06-10 | Comfort mode toggle removed from hub UI; calendar CareActionsForTodayBlock read-only strip; CareProfileIconGrid removed |
| 1.31 | 2026-07-31 | Daily status: per-tap persist; auto session_completed; comfort-checkin GET merges spokes across capture_instance_id on a care_date; dev guide QA + scroll notes |
| 1.38 | 2026-07-31 23:02:18 | comfortWeekInsightNarrative — 1–7 day insights, escalation copy, fever_worry radar polarity documented |
| 1.37 | 2026-07-31 22:56:05 | CancerStatusSummary weekly spoke narrative — comfort-checkin/week-series, comfortWeekInsightNarrative.ts |
| 1.36 | 2026-07-31 22:47:33 | buildTodayPlan — daily status + breakthrough review dropped from Today’s care plan cards (sections unchanged) |
| 1.35 | 2026-07-31 22:06:59 | §4.3 — structured calendar_actions tasks (prompt, response_kind), V027 persistence, focus-day response buttons |
| 1.33 | 2026-07-31 21:54:00 | §4.3 — month grid icons for applied calendar_actions via range API + careModuleDayIconKeys |
| 1.32 | 2026-07-31 | §4.3 calendar_actions manifest contract — modules contribute tappable action pills to the care calendar that write date-scoped care_tasks (V026). Suggested never auto-applies; titles only from manifest; apply is idempotent. CareActionsForTodayBlock deleted, replaced by CalendarFocusDayPanel |