Migrate internal FHIR models to R4B#195
Merged
jenniferjiangkells merged 7 commits intomainfrom Mar 30, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
The
fhir.resourceslibrary uses R5 as its default (top-level) import - every time you dofrom fhir.resources import Patient, you get the R5 model. However, in practice, FHIR R4 is the most widely adopted standard in production EHR systems by a significant margin. Deserializing real-world EHR responses with R5 models can cause two categories of failure:MedicationStatementwas renamedMedicationUsage;DeviceUseStatementwas merged intoDeviceUsage. Any R4 server returning these would error immediately.MedicationRequesthas separatemedicationCodeableConcept/medicationReferencefields; R5 merged these intomedication: CodeableReference. Deserializing an R4 response with an R5 model discards the medication data with no error raised.Solution
Migrate all internal HealthChain models to R4B.
fhir.resourcesprovides R4B as its R4-compatible subpackage (fhir.resources.r4b) and treats it as the authoritative R4-era model - R4B is structurally equivalent to R4 for the overwhelming majority of resources, carrying forward R4 shapes with targeted corrections. HealthChain aligns with this decision so real-world EHR responses deserialize correctly by default.The healthchain.fhir.r4b import surface
Rather than exposing
fhir.resources.r4bdirectly to users, HealthChain re-exports FHIR types throughhealthchain.fhir.r4b:As a wrapper, HealthChain should own this import path. If the underlying
fhir.resourceslibrary changes its packaging, version strategy, or module structure in a future release, only HealthChain's re-export layer needs to update - user code stays the same. It also keeps the API surface intentional: only types that HealthChain actively supports and tests against are surfaced here.Version conversion
convert_resource(resource, "R5")remains available for interop with R5/STU3 systems. It serializes and re-deserializes the resource - best-effort, not lossless. Fields absent in the target version are dropped.Changes
fhir.resources.R4Bhealthchain.fhir.r4badded as the canonical public import surface for R4B resource classesBreaking
version=removed from allcreate_*helpersset_default_version/reset_default_versionremoved fromhealthchain.fhir- global state is messy to managebundle_to_dataframeobservation columns renamedobs_{code}_{display}for consistency