Skip to content

Fix #11: bundled R4 schema is actually R5 — regenerate from R4 4.0.1, add R5 schema#12

Open
piotrszul wants to merge 1 commit into
masterfrom
fix/11_r4-schema-is-r5
Open

Fix #11: bundled R4 schema is actually R5 — regenerate from R4 4.0.1, add R5 schema#12
piotrszul wants to merge 1 commit into
masterfrom
fix/11_r4-schema-is-r5

Conversation

@piotrszul

Copy link
Copy Markdown
Collaborator

Fixes #11.

Problem

schemas/fhir-schema-r4.json — used by default for every compilation and documented as FHIR R4 — was actually built from FHIR R5 5.0.0 definitions. I confirmed this: the committed file is byte-identical (same md5) to a schema freshly built from R5 source.

For R4 data, any element renamed/removed in R5 (e.g. Encounter.period, absent in R5 which renamed it to actualPeriod) failed to resolve, silently fell back to a JSON column type, and produced wrong/over-broad typing.

Fix (data regeneration — no code change)

The builder (scripts/build-fhir-schema.js) already produces correct output; only the committed artifact came from the wrong source version.

  • Regenerated schemas/fhir-schema-r4.json from genuine R4 4.0.1 profiles-resources.json + profiles-types.json (8,503 keys).
  • Added schemas/fhir-schema-r5.json built from R5 5.0.0 (this is the previous fhir-schema-r4.json content), for running ViewDefinitions against R5 via --schema-file.
  • README: documented the bundled R5 schema.

Diff (current R5 → regenerated R4)

R5-only keys removed 3,960 (e.g. EncounterHistory, Encounter.actualPeriod)
R4 keys restored 1,780 (e.g. Encounter.period, statusHistory, classHistory)
Element types corrected 340 (e.g. ActivityDefinition.location: CodeableReferenceReference)

Verification: Encounter.period now types as STRUCT(start VARCHAR, end VARCHAR); the "unknown type" warnings disappear.

Tests

All 191 tests pass (bun test) against the regenerated R4 schema.

Note: the unrelated reserved-word quoting bug (e.g. Period.end) mentioned in #11 is a separate defect, out of scope here.

The bundled schemas/fhir-schema-r4.json — used by default for every
compilation and documented as FHIR R4 — was actually built from FHIR
R5 5.0.0 definitions (byte-identical to a fresh R5 build). For R4 data,
any element renamed/removed in R5 (e.g. Encounter.period) failed to
resolve, silently fell back to a JSON column type, and produced wrong
typing.

- Regenerate schemas/fhir-schema-r4.json from genuine R4 4.0.1
  profiles-resources.json + profiles-types.json (8,503 keys; restores
  Encounter.period/statusHistory/classHistory, drops R5-only
  actualPeriod/subjectStatus/EncounterHistory, corrects 340 element
  types such as ActivityDefinition.location CodeableReference -> Reference).
- Add schemas/fhir-schema-r5.json built from R5 5.0.0 (the previous
  fhir-schema-r4.json content) for running ViewDefinitions against R5.
- Document the bundled R5 schema and --schema-file usage in README.

No code change required — the builder already produces correct output;
only the committed artifact was generated from the wrong source version.
All 191 tests pass against the regenerated R4 schema.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundled fhir-schema-r4.json contains R5 definitions (e.g. Encounter.actualPeriod, EncounterHistory) — R4 fields silently mistyped

1 participant