feat: baseline-drift, breathing-screening and lab-change insight cards

Add three read-only awareness cards to the Insights overview, each drawn
off an existing engine and each honest about empty state — the section
un-mounts rather than surfacing a husk.

- Health status: surfaces what is drifting from the user's own normal by
  folding the personal-band deviations (coincident-deviation engine) with
  the dated, sustained level shifts (changepoint detector) at
  GET /api/insights/health-status. Awareness only, never a diagnosis.
- Breathing screening: summarises the last 30 nights of the per-night
  sleep-breathing-disturbance index plus device-flagged events at
  GET /api/insights/breathing-screening. Mirrors the device's own
  classification and states plainly that it is a screening signal, not a
  diagnosis — discuss with a clinician.
- Lab changes: pairs the two most-recent numeric lab panels and reports
  each shared analyte's signed delta and reference-band standing at
  GET /api/insights/labs-changes. Neutral framing only.

Each reshaping helper is pure and unit-tested for its present/absent
states. Register the three sections in the insights-layout universe so
they merge in as default-visible, wire them into the overview and the
edit-mode title map, add the query-factory keys, document the routes in
the OpenAPI contract, and translate every new string across all six
locales.
This commit is contained in:
Marc-André Bombeck committed 2026-06-28 03:20:49 +02:00
1 parent 31c35baec2
commit ec3fcea84f
27 files changed
+2148 -13

No files matched your search

+25
View File
@@ -137,4 +137,29 @@ export const insightsKeys = {
*/
insightsCoachRead: (metric: string) =>
["insights", "coach-read", metric] as const,
/**
* v1.25 — baseline-drift read (`/api/insights/health-status`). Combines the
* personal-band deviations + the dated changepoint shifts into one awareness
* card. Pure compute over the rollup tier; the `["insights"]` prefix keeps it
* in the standard invalidation fan-out (a measurement write busts it).
*/
insightsHealthStatus: () => ["insights", "health-status"] as const,
/**
* v1.25 — breathing-disturbance screening read
* (`/api/insights/breathing-screening`). Last ~30 nights of the per-night
* index + device-flagged events. The `["insights"]` prefix carries the
* invalidation fan-out from an Apple Health sleep batch write.
*/
insightsBreathingScreening: () =>
["insights", "breathing-screening"] as const,
/**
* v1.25 — "what changed since your last panel" read
* (`/api/insights/labs-changes`). The two most-recent numeric lab panels'
* shared-analyte deltas. The `["insights"]` prefix keeps it in the standard
* invalidation fan-out.
*/
insightsLabsChanges: () => ["insights", "labs-changes"] as const,
};