FHIR model generator
Generates the navigation models in @callis/fhir-r4, @callis/fhir-r5 and @callis/fhir-r6 from official, pinned FHIR core package snapshots. R6 uses the September 2026 draft snapshot, 6.0.0-snapshot1, not final R6. Generated output is committed; normal builds and tests need no network.
pnpm --filter @callis/model-gen generatepnpm --filter @callis/model-gen generate --checkpnpm test --project model-gen --project fhir-r4 --project fhir-r5 --project fhir-r6pnpm buildpnpm check:packages
The first generation downloads hl7.fhir.r4.core@4.0.1 and hl7.fhir.r5.core@5.0.0 from https://packages.fhir.org. Archives are cached in ignored tools/model-gen/.cache/ and checked against committed SHA-256 pins on every run before extraction. Node and tar are development requirements. Delete a damaged cached archive and retry; an intentional upstream update requires reviewing the pin, version, source corrections and package source notices together. CI calls the regeneration workflow on relevant pull requests/pushes and includes its outcome in the required CI result; unrelated changes skip it. The same workflow supports manual dispatch.
R6 downloads hl7.fhir.r6.core@6.0.0-snapshot1 from the explicit published URL https://hl7.org/fhir/6.0.0-snapshot1/hl7.fhir.r6.core.tgz, pinned to SHA-256 c67aad1c83851aa7702f10a210f9e0e2c9fb0a54dcd43fd0826296dc6a175f59. It never uses a floating CI build or silently substitutes another source. Archive integrity is verified before extraction, then manifest name, version, sole fhirVersions entry and CC0 license are checked. The R6 source notice records upstream metadata inconsistencies and the independently verified registry mirror. R4/R5 pins and generated bytes remain unchanged.
R6 additionally emits packages/fhir-r6/inventory.json: the exact source identity, total type count and sorted names grouped as resource, complex, primitive and backbone. The pinned source yields 196 roots and 487 backbones. --check verifies this inventory along with both generated TypeScript files; package tests compare every inventory entry with the generated model. New source versions require explicit contract expectations, including root counts and source-specific Observation choice alternatives.
The generator selects base primitive, complex and resource definitions, not constraint profiles or logical models. It emits sorted type rows with complete direct-child snapshots in definition order, so constrained inherited fields keep their snapshot types/cardinalities. Inline children become path-named backbone types; local contentReference targets resolve to those types, including recursive links. Missing snapshots, unknown bases/types, cycles and unsupported shapes fail generation. Source System types normalize to model types using the source FHIR-type extension (with canonical primitive fallbacks). The extension is read from the element that defines the element (base.path), not from an inherited snapshot copy, because the sources fill the copies inconsistently: R4 types every resource id as string, R5 types 46 datatype ids as id and R6 types 116 resource ids as string. A resource's id is an id and any other id a string, as the published definitions say. R4's Resource.id itself says string, so the R4 release carries an explicit correction in src/cli.ts; generation fails if the source's value changes or no element uses the correction (spec notes).
The private tuple format is [name, kind, baseName|null, abstract, systemType|null, elements]. Elements are [name, typeNames, flags], with array=1 and choice=2. Tuples are deliberately not public API. The provider builder lives once in runtime/provider.ts; the generator copies it into each package as src/provider.ts next to src/model-data.ts, so a published package contains only its own source. The builder precomputes frozen type/element objects and lookup indexes. Both generated files carry a do-not-edit header, and --check verifies both. No required core interface changes, runtime dependency or phase-2 metadata is introduced.
The existing core contract suite runs against all three providers, starting at every generated resource/datatype root. Additional acceptance tests cover recursive references, choices, normalized primitive fields and immutability. Generator tests use synthetic snapshots without network; --check verifies the full official archives produce byte-identical committed output. The package size report enforces 60 KiB gzip for each built model, including its provider code.
Source and license records are next to each generated package in SOURCE.md, which is also shipped in the package. The official FHIR definition data is CC0-1.0; the generator and provider implementation are MIT licensed.