Files
HealthLog/src/lib/fhir/illness-snomed.ts
T
Marc-André Bombeck 9a29de4b02 feat(fhir): code illness conditions and lab observations
Close the three FHIR R4 coding gaps in the health-record export. Both are
export-layer only — no schema column, no migration, no contract change.

Illness Conditions now carry a broad SNOMED CT category concept per
IllnessType (infectious disease, allergy, injury, mental disorder, autoimmune
disease, chronic disease, with the generic Disease root as the fallback for an
unknown type) instead of the single generic placeholder. The user's own label
stays on code.text, the class on category.text, and the unconfirmed +
patient-reported guard rails are unchanged — the export still asserts no
specific diagnosis.

Lab Observations resolve a curated analyte to a real LOINC coding alongside the
user's code.text for the common biomarkers (HbA1c, lipid panel, ferritin, TSH,
vitamin D, creatinine, eGFR, ALT, AST, CRP, fasting glucose, hemoglobin), with
analyte-key and EN/DE alias normalisation. The canonical UCUM code is stamped
on the value only when the recorded unit matches the mapped canonical symbol;
an unmapped analyte or a non-matching unit keeps the honest text-only code and
display-only unit, never a fabricated code. The resolver takes an optional
canonical-name argument so a future Biomarker-catalog link can take precedence
over the free-text analyte without a further change here.
2026-06-20 09:48:22 +02:00

63 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* v1.18.8 — HealthLog `IllnessType` → broad SNOMED CT category concept.
*
* The condition journal records PATIENT-REPORTED categories, not clinician
* diagnoses. Each `IllnessType` therefore maps to a BROAD, well-known SNOMED
* CT category concept (a disease class), NEVER a specific diagnosis. The
* user's own free-text label rides `Condition.code.text` and the broad class
* is also surfaced as `Condition.category.text`; this coded concept is the
* honest middle ground — a downstream system reads "an infectious-disease
* class condition the patient reported", not a fabricated specific diagnosis.
*
* The builder keeps `verificationStatus: unconfirmed` and the
* "patient-reported, not a clinical diagnosis" note on every Condition, so the
* category coding can never be mistaken for a confirmed finding.
*
* Concept ids are REFERENCED (not redistributed) per the SNOMED CT licence,
* matching the existing route / body-site coding convention in `resources.ts`.
* Each id below is a real SNOMED CT International concept; the category-level
* choice is deliberate (a class, not a leaf disorder).
*
* Systems: SNOMED CT — http://snomed.info/sct
*
* No ICD-10 coding is emitted: a category-level ICD-10 chapter (e.g. "A00–B99
* Certain infectious diseases") is a chapter RANGE, not a billable leaf code,
* and asserting a single chapter code per journal category would over-state
* what the patient recorded. SNOMED-only is the honest choice here.
*/
/** SNOMED CT category concept for a patient-reported illness class. */
export interface IllnessSnomedCategory {
code: string;
display: string;
}
/**
* `IllnessType` enum value → broad SNOMED CT category concept.
*
* - INFECTION → 40733004 "Infectious disease (disorder)"
* - ALLERGY → 106190000 "Allergy (disorder)"
* - INJURY → 417163006 "Traumatic AND/OR non-traumatic injury (disorder)"
* (spans both, the honest broad class for a journal entry)
* - MENTAL_HEALTH → 74732009 "Mental disorder (disorder)"
* - AUTOIMMUNE → 85828009 "Autoimmune disease (disorder)"
* - CHRONIC → 27624003 "Chronic disease (disorder)"
* - OTHER → 64572001 "Disease (disorder)" — the generic root, the
* correct fallback for an unspecified class.
*
* An unknown / future enum value resolves to the generic `DISEASE_SNOMED`
* root via the builder's fallback, never a guessed specific concept.
*/
export const ILLNESS_TYPE_SNOMED: Record<string, IllnessSnomedCategory> = {
INFECTION: { code: "40733004", display: "Infectious disease" },
ALLERGY: { code: "106190000", display: "Allergy" },
INJURY: {
code: "417163006",
display: "Traumatic AND/OR non-traumatic injury",
},
MENTAL_HEALTH: { code: "74732009", display: "Mental disorder" },
AUTOIMMUNE: { code: "85828009", display: "Autoimmune disease" },
CHRONIC: { code: "27624003", display: "Chronic disease" },
OTHER: { code: "64572001", display: "Disease" },
};