mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat(signals): register the v1.25 clinical signals through the registry
Add the clinical-signals wave's new measurement types and wire them through the signal registry so FHIR, correlation eligibility, ingestion, and the measurement-list surfaces derive from one definition each: - MeasurementType: PHQ9_SCORE, GAD7_SCORE, GRIP_STRENGTH, PAIN_NRS, WAIST_CIRCUMFERENCE, WAIST_TO_HEIGHT (+ AssessmentInstrument enum and the MentalHealthAssessment model that backs the screener scores). - Registry: the six measurement/score signals plus the longevity lab panel as kind:"biomarker" entries; the FHIR golden fixture is regenerated in lockstep. Grip-strength and waist-to-height carry a null LOINC (NEEDS-VERIFY) and emit a local text concept until a stable code is confirmed. - FHIR: add the survey observation category for the screener / pain signals. - Labs: extend the biomarker catalogue with ApoB, Lp(a), fasting insulin, and the omega-3 index; add LOINC codes for those plus GGT and hs-CRP; add a computed HOMA-IR helper. - Exhaustive maps updated to keep the enum coverage, category, list-meta, and personal-record drift guards green.
This commit is contained in:
1 parent
3a84a07423
commit
e4875db93e
14 files changed
+706
-2
No files matched your search
@@ -0,0 +1,10 @@
|
||||
-- v1.25 — clinical-signals wave: physical / clinical measurement types.
|
||||
--
|
||||
-- Grip strength (EWGSOP2 sarcopenia limb), pain Numeric Rating Scale (0–10),
|
||||
-- waist circumference (WHO STEPS), and the waist-to-height ratio (WHtR). Each
|
||||
-- is a first-class numeric Measurement type; bands/units are applied at the
|
||||
-- display edge from the signal registry. ADD VALUE IF NOT EXISTS is idempotent.
|
||||
ALTER TYPE "measurement_type" ADD VALUE IF NOT EXISTS 'GRIP_STRENGTH';
|
||||
ALTER TYPE "measurement_type" ADD VALUE IF NOT EXISTS 'PAIN_NRS';
|
||||
ALTER TYPE "measurement_type" ADD VALUE IF NOT EXISTS 'WAIST_CIRCUMFERENCE';
|
||||
ALTER TYPE "measurement_type" ADD VALUE IF NOT EXISTS 'WAIST_TO_HEIGHT';
|
||||
@@ -608,6 +608,7 @@ model User {
|
||||
fitbitConnection FitbitConnection?
|
||||
fitbitOAuthStates FitbitOAuthState[]
|
||||
moodEntries MoodEntry[]
|
||||
mentalHealthAssessments MentalHealthAssessment[]
|
||||
moodTagsCustom MoodTag[] @relation("UserMoodTags")
|
||||
moodTagCategoriesCustom MoodTagCategory[] @relation("UserMoodTagCategories")
|
||||
moodTagsHidden MoodTagHidden[]
|
||||
@@ -1107,10 +1108,90 @@ enum MeasurementType {
|
||||
// The 5-level → ordinal mapping is the single source of truth in
|
||||
// `src/lib/oura/client.ts` (RESILIENCE_LEVELS). Stored as `source = OURA`.
|
||||
RESILIENCE // level (ordinal 1–5) — Oura `daily_resilience.level` (limited=1 … exceptional=5).
|
||||
// ── v1.25 — clinical-signals wave (manual / instrument-derived) ──
|
||||
// PHQ-9 / GAD-7 total scores. Server-derived from a completed
|
||||
// `MentalHealthAssessment` (one measurement row per administration, value =
|
||||
// total). Unit `score`. The raw item answers live encrypted on the
|
||||
// assessment row, never here — these rows carry only the numeric trend so
|
||||
// the existing chart / rollup infra reads them with no item exposure.
|
||||
PHQ9_SCORE // score (0–27) — PHQ-9 depression screen total. Opt-in. See MentalHealthAssessment.
|
||||
GAD7_SCORE // score (0–21) — GAD-7 anxiety screen total. Opt-in. See MentalHealthAssessment.
|
||||
// Maximal isometric handgrip force (best of all trials, either hand). The
|
||||
// EWGSOP2 sarcopenia floor is sex-specific (men < 27 kg, women < 16 kg); the
|
||||
// band is applied at display time, the column stores the raw kg.
|
||||
GRIP_STRENGTH // kg — hand-dynamometer maximal grip (EWGSOP2 sarcopenia limb).
|
||||
// Patient-reported pain intensity on the 0–10 Numeric Rating Scale
|
||||
// (0 = no pain, 10 = worst imaginable). LOINC 72514-3.
|
||||
PAIN_NRS // score (0–10) — pain Numeric Rating Scale.
|
||||
// Waist circumference in cm (WHO STEPS protocol) + the ancestry-robust
|
||||
// waist-to-height ratio (WHtR; keep waist < half your height ⇒ < 0.5).
|
||||
WAIST_CIRCUMFERENCE // cm — waist circumference (WHO bands; ethnicity-aware at display).
|
||||
WAIST_TO_HEIGHT // ratio — waist-to-height ratio (WHtR ≥ 0.5 = increased risk).
|
||||
|
||||
@@map("measurement_type")
|
||||
}
|
||||
|
||||
/// v1.25 — validated mental-health self-assessment instruments: PHQ-9
|
||||
/// (depression) + GAD-7 (anxiety). The discriminator on
|
||||
/// `MentalHealthAssessment`; extensible (WHO-5 / PSS-10 are natural future
|
||||
/// siblings) without a schema change.
|
||||
enum AssessmentInstrument {
|
||||
PHQ9
|
||||
GAD7
|
||||
|
||||
@@map("assessment_instrument")
|
||||
}
|
||||
|
||||
/// v1.25 — one completed administration of a validated mental-health screener
|
||||
/// (PHQ-9 / GAD-7). Opt-in, beside the existing `MoodEntry` (never replaces it).
|
||||
/// The per-item answers are the most sensitive payload, so they live in a
|
||||
/// single AES-256-GCM `Bytes` blob (`responsesEncrypted`) and are never indexed
|
||||
/// nor logged. The derived total / band / item-9 flag are denormalised
|
||||
/// (server-authoritative) for cheap history reads without decrypting. A
|
||||
/// matching `PHQ9_SCORE` / `GAD7_SCORE` Measurement row is written per
|
||||
/// administration (linked by `externalId = assessment:<id>`) so the score rides
|
||||
/// the existing chart / rollup infra — the trend, never the item content.
|
||||
model MentalHealthAssessment {
|
||||
id String @id @default(cuid())
|
||||
userId String @map("user_id")
|
||||
instrument AssessmentInstrument
|
||||
/// The validated translation actually presented (officially-validated wording
|
||||
/// per locale, English fallback otherwise — recorded for the audit trail).
|
||||
locale String
|
||||
/// Instrument variant identifier (e.g. "standard"); future-proofs revisions.
|
||||
version String @default("standard")
|
||||
/// Encrypted JSON blob: { items: number[], functionalDifficulty?: 0..3, schema: 1 }.
|
||||
/// AES-256-GCM via the shared Bytes codec; registered in ENCRYPTED_COLUMNS +
|
||||
/// the rotation script. The item-9 raw value lives ONLY here.
|
||||
responsesEncrypted Bytes @map("responses_encrypted")
|
||||
/// Derived total (PHQ-9 0–27, GAD-7 0–21). Denormalised for fast reads.
|
||||
totalScore Int @map("total_score")
|
||||
/// Derived severity band label (server-authoritative; descriptive, never a diagnosis).
|
||||
severityBand String @map("severity_band")
|
||||
/// PHQ-9 only: item 9 (self-harm ideation) answered > 0. A coarse boolean so
|
||||
/// the history view can re-surface crisis resources without decrypting.
|
||||
item9Flagged Boolean @default(false) @map("item9_flagged")
|
||||
/// Audit stamp: the supportive crisis-resource signpost was shown to the user.
|
||||
/// Never triggers any third-party alert — private, on-device-only signposting.
|
||||
crisisShownAt DateTime? @map("crisis_shown_at")
|
||||
/// Recall-window anchor (when the screener was taken).
|
||||
takenAt DateTime @map("taken_at")
|
||||
tz String?
|
||||
source String @default("WEB")
|
||||
externalId String? @map("external_id")
|
||||
syncVersion Int @default(0) @map("sync_version")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([userId, source, externalId])
|
||||
@@index([userId, instrument, takenAt])
|
||||
@@index([userId, updatedAt, id])
|
||||
@@map("mental_health_assessments")
|
||||
}
|
||||
|
||||
/// v1.10.0 — categorical events (WX-B)
|
||||
/// The device's own classification RESULT / severity for an EVENT row.
|
||||
/// Non-NULL only for the categorical EVENT `MeasurementType`s
|
||||
|
||||
Reference in new issue
Block a user