T0019 — FHIR model generator and model packages
Part of the roadmap. Phase 1 · wave 2 · size L.
Goal
Generate compact R4 and R5 models from the official StructureDefinitions and publish them as ModelProviders (design notes, ADR-0008).
Scope
tools/model-gen:- downloads
hl7.fhir.r4.core@4.0.1andhl7.fhir.r5.core@5.0.0from the FHIR package registry into a local cache that is not committed - reads the snapshots
- emits a deterministic, compact TypeScript data module
- downloads
- What the data module contains: types, base types, kinds, abstractness; elements with name, types, whether they repeat and whether they are choices; backbone types named by path;
contentReferenceresolved; the primitive → System mapping. packages/fhir-r4(@callis/fhir-r4) andpackages/fhir-r5(@callis/fhir-r5):ModelProviderimplementations over the generated data, exported asr4andr5, with a peer dependency on@callis/core.- A CI job (on changes to
tools/model-genor a manual trigger) that checks regeneration gives no diff.
Design notes
- A generator in
tools/model-genreadsStructureDefinitionsnapshots from the official FHIR NPM packages (hl7.fhir.r4.core@4.0.1,hl7.fhir.r5.core@5.0.0) at development time. - For each version it emits a compact TypeScript module with:
- types, base types, kinds and abstractness
- elements: name, types, whether they repeat, whether they are choices
- backbone element types named by path (
Patient.contact) - resolved
contentReferences (Questionnaire.item.item→Questionnaire.item) - the primitive → System type mapping
- These are published as
@callis/fhir-r4and@callis/fhir-r5, each exporting a ready-madeModelProvider. R4B can be added cheaply later. - The generated output is committed, so diffs are reviewable and builds need no network. A CI job checks that regenerating gives no diff.
- Size budget: at most 60 kB gzip per model, to be measured.
- Richer metadata for
elementDefinition(),slice(),checkModifiers()andconformsTo()(phase 2) goes in a separate entry point, so the default model stays small.
Acceptance criteria
- All resources and data types from the core packages are present. Spot checks:
Patient.deceasedis a choice ofboolean | dateTimeQuestionnaire.item.itemresolves toQuestionnaire.itemBundle.entry.resourcehas typeResourceObservation.value[x]lists the correct types per version
- Running the generator twice gives byte-identical output.
- Gzip size per model is reported. Over 60 kB needs a justification in the PR.
- Both generated providers pass
describeModelProviderContractover all generated resource and datatype roots, including primitive and derived-primitive mappings,Quantity/Age, and choice elements (#56).