FHIR releases

One installation of fhir.resources ships three FHIR releases side by side. The newest is the top-level package; older releases are sub-packages named after the release.

Release

Version

Import from

Catalogue

R5

5.0.0

fhir.resources.<module>

R5 (FHIR 5.0.0)

R4B

4.3.0

fhir.resources.R4B.<module>

R4B (FHIR 4.3.0)

STU3

3.0.2

fhir.resources.STU3.<module>

STU3 (FHIR 3.0.2)

>>> from fhir.resources.patient import Patient as R5Patient
>>> from fhir.resources.R4B.patient import Patient as R4BPatient
>>> from fhir.resources.STU3.patient import Patient as STU3Patient
>>> R4BPatient.model_validate({"resourceType": "Patient", "id": "a"}).id
'a'

The models of different releases are independent classes, so an R4B Patient is not an instance of the R5 Patient. Never mix elements of different releases within one resource.

Choosing a release

  • Use R5 for new projects unless your counterpart (an EHR, a national profile, a FHIR server) mandates something else.

  • Use R4B when you talk to servers that implement R4 or R4B. Most production FHIR servers today are R4-based.

  • STU3 is kept for legacy integrations.

Why R4B and not R4?

R4B (4.3.0) is a small revision of R4 (4.0.1). Since version 7.0.0, there is no separate R4 sub-package: R4B covers it. R4 documents almost always validate against the R4B models. Where they differ, see the R4 to R4B differences and HL7’s strategies for dealing with R4 and R4B. The background is in discussion #116.

Supporting several releases at once

When the release is only known at runtime (for example from a server’s CapabilityStatement.fhirVersion), pick the package dynamically:

>>> import importlib
>>> def model_class(release: str, name: str):
...     package = "fhir.resources" if release == "R5" else f"fhir.resources.{release}"
...     module = importlib.import_module(f"{package}.{name.lower()}")
...     return getattr(module, name)
>>> model_class("STU3", "Patient")
<class 'fhir.resources.STU3.patient.Patient'>