feat(healthkit): add a categorical device-event row class

Add a discrete EVENT row class to the Measurement model for the
device-flagged health notifications a wearable produces on its own —
irregular-rhythm, high/low heart rate, walking-steadiness and
breathing-disturbance alerts.

Following the sleep-stage / glucose-context nullable-context precedent,
this is an additive nullable column on the existing table, not a new
storage paradigm. Five new MeasurementType values carry the event class
and a new rhythm_classification enum column carries the device's own
verdict / severity (migration 0105, with a CHECK that pins the column to
the event types). An event row stores value 1 and the device verdict;
it never participates in trend, rollup, chart or personal-record
analytics.

For the irregular-rhythm class, HealthLog ingests only the
classification RESULT the device's own certified on-device algorithm
already produced. It never ingests a raw ECG waveform, never
re-classifies, and never derives a verdict of its own.

The Apple Health batch ingest maps the five category identifiers, with
the device's HKCategoryValue codepoint resolved to the stored
classification; an unknown codepoint degrades to a fallback verdict
rather than dropping the event.
This commit is contained in:
Marc-André Bombeck committed 2026-06-02 22:07:28 +02:00
1 parent 635e64ace7
commit b06b1cada4
7 files changed
+416 -16

No files matched your search

@@ -90,6 +90,12 @@ export const MEASUREMENT_TYPE_LABEL_KEYS: Record<string, string> = {
STAIR_ASCENT_SPEED: "measurements.typeStairAscentSpeed",
STAIR_DESCENT_SPEED: "measurements.typeStairDescentSpeed",
BREATHING_DISTURBANCES: "measurements.typeBreathingDisturbances",
// ── v1.10.0 — categorical events (WX-B) ──
IRREGULAR_RHYTHM_NOTIFICATION: "measurements.typeIrregularRhythmNotification",
HIGH_HEART_RATE_EVENT: "measurements.typeHighHeartRateEvent",
LOW_HEART_RATE_EVENT: "measurements.typeLowHeartRateEvent",
WALKING_STEADINESS_EVENT: "measurements.typeWalkingSteadinessEvent",
BREATHING_DISTURBANCE_EVENT: "measurements.typeBreathingDisturbanceEvent",
};
export const MEASUREMENT_TYPE_ICONS: Record<string, LucideIcon> = {
@@ -167,6 +173,15 @@ export const MEASUREMENT_TYPE_ICONS: Record<string, LucideIcon> = {
STAIR_ASCENT_SPEED: Gauge,
STAIR_DESCENT_SPEED: Gauge,
BREATHING_DISTURBANCES: Wind,
// ── v1.10.0 — categorical events (WX-B) ──
// Activity carries the irregular-rhythm trace shape; HeartPulse the
// high/low-HR cardio pair; Footprints the steadiness/mobility family;
// Wind the breathing family (SpO2 + respiratory rate already use it).
IRREGULAR_RHYTHM_NOTIFICATION: Activity,
HIGH_HEART_RATE_EVENT: HeartPulse,
LOW_HEART_RATE_EVENT: HeartPulse,
WALKING_STEADINESS_EVENT: Footprints,
BREATHING_DISTURBANCE_EVENT: Wind,
};
export const MEASUREMENT_TYPE_COLORS: Record<string, string> = {
@@ -235,4 +250,13 @@ export const MEASUREMENT_TYPE_COLORS: Record<string, string> = {
STAIR_ASCENT_SPEED: "bg-chart-2/20 text-chart-2",
STAIR_DESCENT_SPEED: "bg-chart-2/20 text-chart-2",
BREATHING_DISTURBANCES: "bg-chart-5/20 text-chart-5",
// ── v1.10.0 — categorical events (WX-B) ──
// chart-3 (cardio family) carries the rhythm + heart-rate events;
// chart-2 (activity/mobility) carries the steadiness event; chart-5
// (respiratory/pulse family) carries the breathing event.
IRREGULAR_RHYTHM_NOTIFICATION: "bg-chart-3/20 text-chart-3",
HIGH_HEART_RATE_EVENT: "bg-chart-3/20 text-chart-3",
LOW_HEART_RATE_EVENT: "bg-chart-3/20 text-chart-3",
WALKING_STEADINESS_EVENT: "bg-chart-2/20 text-chart-2",
BREATHING_DISTURBANCE_EVENT: "bg-chart-5/20 text-chart-5",
};