Data model
The storage model is flat SQLite with FHIR-inspired names and relationships. It is FHIR-shaped, not FHIR-bound, so integrations can map to supported FHIR versions without making an external release the internal contract.
FHIR gives structure; terminologies give meaning. FHIR decides which resource a fact is and which fields it carries — an observation with a code, a value, a subject, a time. SNOMED CT and LOINC decide what the code denotes: that this is serum ferritin and not a phrase somebody typed. The two are orthogonal, and both are required. A correct FHIR shape wrapped around free text is unreadable to a receiving system; a correct code in the wrong resource is unfindable. ICD arrives with imported diagnoses and is a classification built for reporting, not a clinical vocabulary — it does not substitute for SNOMED. This is why terminology work is a prerequisite for standards-shaped export rather than a parallel track.
Core records cover practitioners, conditions, encounters, documents,
medications and recorded intakes, observations, symptoms, journal entries,
procedures, devices, and profile data. Genomics keeps raw sequencing files,
coverage intervals, genes, variants, and associations distinct. Which family
member carries which variant is a row in pedigree_member_variants, not a list
on the member: inheritance tracing asks who else carries a variant, and a JSON
column can only answer the reverse. Zygosity sits on that row because it
describes a person's genome rather than the variant.
Imaging retains Study → Series → Instance structure behind the unified record
facade. imaging_annotation_snapshots stores one validated, versioned
Cornerstone annotation snapshot per series with a revision used for optimistic
concurrency. View transforms are not stored as clinical-looking record data.
Original documents and sequencing files are content-addressed. Derived document extractions point back to their document, page, and source region and carry a review status. This keeps evidence separate from reviewable inference.
Medication dosing is structured: medication_doses holds recurring per-day
dose times (time_of_day, optional dose and food flag, optional weekday
restriction). The Today timeline (src/lib/dosing.ts) groups these into
morning/afternoon/evening slots and derives each dose's state from the current
time and the intake log; a recorded intake links back to the dose it satisfies
via med_intakes.dose_id. The plan (medication_doses) and what was actually
taken (med_intakes) stay separate, consistent with the medication/intake split.
Supplement composition is structured: for kind = 'supplement' rows the
medications.composition column holds versioned JSON (schema 2 — ingredients
with normalized units, serving size, dosing basis, and per-line label provenance
in rawText); legacy free text remains valid and is treated as unstructured,
and schema 1 documents are migrated on read. This applies to supplements only —
prescription and OTC composition is reserved for official registry data (see
ADR-0004).
Each ingredient is recorded on three separate axes: the EU Annex I nutrient
(nutrientKey, the level at which two products collide), the Annex II chemical
form or forms (forms[]), and the origin material (sourceMaterial, which has
no controlled list). Two kinds of row state a number that is already accounted
for elsewhere and are excluded from intake by countableIngredients(): a blend
subtotal (isBlendTotal, with members carrying partOf) and a compound mass
whose elemental content is broken out beneath it (isSaltTotal, with the
element row carrying ofWhich). The full
ingredient statement is kept verbatim in ingredientStatement and is used to
fill in forms the facts panel abbreviated. See
ADR-0008.
A stored pill appearance carries valid_from / valid_to, on both the resolved
pill_profiles row and the pill_appearance_facts it was resolved from. A
tablet's colour or imprint can change while the ŠÚKL code, registration and
strength stay put, so an appearance has to be able to say which packs it
describes; community catalogue claims already carry a window and the local store
would otherwise discard it on the way in. Null means no source stated a period,
not that the appearance is permanent. One row per package is kept — a lapsed
window is flagged for a person to re-check rather than resolved automatically,
because the pack in their hand may be exactly the old one it describes.
Supplement composition is mirrored into medication_ingredients with
source = 'label' and the nutrient name in inn, so the duplicate-substance
check in src/lib/medications/duplicates.ts sees supplements alongside
registry-sourced medicines. Supply tracking
(supply_quantity, supply_unit, supply_updated_at, daily_units) records
stock on hand at a date, from which refill projections are computed in
src/lib/supply.ts.
See the generated database schema inventory
for the current table list. Review src/lib/server/db/schema.ts for field-level
changes.