feat(medications): keep a medication as a record without tracking intake

A per-medication trackIntake flag (migration 0351, default on for every
existing and new row). With it off the dose, dates and schedule stay stored,
but nothing derives a due dose from them: the reminder worker, the manual
reminder check, the today projector, the auto-miss pass, the low-stock pass,
the doses card, the today list, the outstanding-dose badge, compliance and
its heatmap, the doctor report, the Coach, the BP-status gate, insights,
targets, achievements, the efficacy view and the MCP schedule tool all skip
it.

The medication wire serves such a medication with schedules: [] and the
stored rows in an additive recordedSchedules field, so a client that arms
local reminders from schedules stays silent without an update. Switching
tracking off or back on archives a schedule revision at that instant, the
untracked stretch with an empty payload, so it never counts as missed and
the projector does not put a dose from before the switch back on the card.

A structural guard freezes the set of schedule readers: each one filters on
the flag, derives from dueSchedules, shapes the wire with scheduleWireFields,
or is allowlisted with the reason it derives nothing due. The flag travels
through backup, restore and the medication CSV export.
This commit is contained in:
Marc-André Bombeck committed 2026-09-25 08:57:10 +02:00
1 parent 700de6d228
commit b4c2706ec9
57 files changed
+1490 -182

No files matched your search

@@ -0,0 +1,6 @@
-- Per-medication intake tracking (#1033). A medication with tracking off
-- keeps its dose, dates and schedule as a record, but nothing is due, no
-- reminder is sent and it is left out of adherence. Every existing row
-- defaults to tracking on, so nothing changes for anyone who does not flip it.
ALTER TABLE "medications"
ADD COLUMN "track_intake" BOOLEAN NOT NULL DEFAULT true;
+19
View File
@@ -2610,6 +2610,25 @@ model Medication {
/// never reminded" surface follows structurally from the empty
/// schedule list. Mutually exclusive with `oneShot`.
asNeeded Boolean @default(false) @map("as_needed")
/// v1.39.1 (#1033) — per-medication intake tracking. `true` (the default,
/// and the backfill for every existing row) is the behaviour every
/// medication has always had. `false` keeps the medication as a record:
/// dose, dates and the schedule rows stay stored and shown as information,
/// but nothing derives a due dose from them — no reminder on any channel,
/// no projected or auto-missed slot, no place on the doses card or the
/// take-all flow, and no adherence figure anywhere (compliance, heatmap,
/// doctor report, Coach, BP-status gate, achievements, MCP). Unlike
/// `asNeeded` the schedule rows survive, so every schedule reader that
/// derives a due dose must honour this flag explicitly
/// (`src/lib/medications/intake-tracking.ts`); the structural guard
/// `src/__tests__/medication-intake-tracking-guard.test.ts` holds the list.
/// The medication wire serves such a medication with `schedules: []` and
/// the stored rows under `recordedSchedules`, so a client that arms local
/// reminders from `schedules` stays silent without an update. Switching
/// tracking off or back on archives a schedule revision at that instant
/// (the stretch in between archives with an empty payload), so the rate
/// paths never count the untracked stretch as missed.
trackIntake Boolean @default(true) @map("track_intake")
/// v1.6.0 — route of administration. Decoupled from `treatmentClass`
/// so the injection-site picker can surface for any INJECTION dose.
/// A one-time injection is `oneShot = true` + `deliveryForm =