Skip to content

v0.0.18

Latest

Choose a tag to compare

@ryukzak ryukzak released this 27 Jul 07:09
· 111 commits to main since this release

This release focuses on supporting the KBV Base IG (kbv.basis@1.9.0) — a real-world multi-package German IG — with an emphasis on profile support. Generating its profiles surfaced a series of problems in choice type handling, reference target resolution, tree shaking, and introspection; fixing them properly improved profile generation across the board (US Core included), and the Python writer was brought up to parity along the way.

Choice type (value[x]) support in profiles

KBV profiles use open type-sliced choice elements (e.g. Condition.onset[x]), which exposed gaps in how choice constraints were computed and validated:

  • Profiles that narrow a choice element now prohibit all undeclared variants, not just the ones restated as fields. validate() emits the full prohibited list via the new validateChoiceProhibited (TS) / validate_choice_prohibited (PY) helpers — a profile narrowing Extension.value[x] to valueAddress no longer silently accepts resources carrying any other variant (#199, #204)
  • Choice constraints are resolved monotonically across the profile hierarchy: a child profile can never reintroduce a variant an ancestor prohibited; reintroduction attempts are reported with the new #nonMonotonicChoice warning (#200)
  • Open-sliced choice roots that restate nothing (KBV onset[x]/abatement[x]) correctly keep all base variants permitted and emit no checks (#200)

Profile reference targets

KBV profiles reference other profiles (e.g. Condition.subjectKBV_PR_Base_Patient), which used to leak profile names into generated types and validators:

  • Reference targets pointing at profiles are resolved to their base resource type at transform time, so generated Reference<...> unions and validateReference checks always use real resourceType values (Patient/id, never KBV_PR_Base_Patient/id) — and no longer depend on the referenced profile surviving tree shaking (#201)
  • Generated TS reference types keep the replaced profile canonical URL as a comment for traceability: Reference<"Patient" /* ...us-core-patient */> (#205)
  • New followReferences tree-shake option (per rule, or for all roots via treeShakeDefaults) pulls reference targets into the generated set with one flag instead of enumerating every target by hand; following is non-transitive, so it cannot drag in the whole package (#202)

Multi-package introspection fixes

Tree-shaking a single profile out of kbv.basis (which pulls 11 packages) exposed introspection dumping far too much, with wrong attribution:

  • introspection({ fhirSchemas, structureDefinitions }) now dumps only schemas in the tree-shaken index (previously the entire register — 5535 files → 499 for the single-profile KBV example), and StructureDefinitions are attributed to the package that actually declares them (#197)
  • New profileSnapshots flag on introspection.typeSchemas additionally exports flattened profile snapshots for debugging profile resolution (#199)

Python writer parity

  • Ports prohibited-choice-variant validation, slice required-field validation (validate_slice_fields), and inherited base-required field checks from the TypeScript writer (#204)
  • Reference becomes generic: fields are annotated with their targets as Reference[Literal["Patient", ...]], with profile targets resolved to base resources (#204)
  • Tightened profile_helpers.py typing: arbitrary-input parameters go Anyobject, adding a mypy guardrail against un-narrowed access (#194)

TypeSchema format changes

Generated TS/Python output is unaffected, but consumers of the serialized TypeSchema format should note:

  • Slicing is stored separately from fields: field-level slicing moved to a schema-level slicing: Record<fieldName, FieldSlicing> map (#203)
  • Field reference targets changed from a flat identifier array to a FieldReference object with resource (base resource types) and profiles (conformance expectations from targetProfile) (#201)

Other

  • New on-the-fly example and in-memory snapshot tests for the KBV Condition Diagnosis pipeline (kbv.basis@1.9.0 from the Simplifier registry), pinning every stage from FHIR schema to generated TS (#200, #206)
  • CI: bump actions/checkout to v6; update LICENSE year (#195)
All pull requests
  • PY: reduce Any in profile_helpers.py by @ryukzak in #194
  • CI: bump actions/checkout to v6; update LICENSE year by @ryukzak in #195
  • API/TypeSchema: respect tree shaking and fix package attribution in introspection output by @ryukzak in #197
  • TypeSchema/API/TS: prohibit undeclared choice variants, validate them, export profile snapshots by @ryukzak in #199
  • TypeSchema: resolve choice variants monotonically across the profile hierarchy by @ryukzak in #200
  • TypeSchema/TS/PY: resolve reference targets to base resources, keep profile expectations separately by @ryukzak in #201
  • TypeSchema: followReferences tree-shake option to generate referenced types by @ryukzak in #202
  • TS: comment reference types with replaced profile target URLs by @ryukzak in #205
  • PY: port profile validation features and parametrized Reference types from the TypeScript writer by @ryukzak in #204
  • API: snapshot tests for the KBV Condition Diagnosis pipeline by @ryukzak in #206
  • TypeSchema: store slicing separately from fields by @ryukzak in #203

Full Changelog: v0.0.17...v0.0.18