Naming conventions

The Python API follows the FHIR names as closely as possible. This page lists the few places where it has to differ.

Modules and classes

  • Module: the resource or data type name in lower case — fhir.resources.medicationrequest.

  • Class: the exact FHIR name — MedicationRequest.

  • Backbone elements (the nested, unnamed parts of a resource) are classes in the same module, named by joining the path in CamelCase: Patient.contact → PatientContact, Bundle.entry.request → BundleEntryRequest.

>>> from fhir.resources.patient import Patient, PatientContact
>>> from fhir.resources.bundle import BundleEntryRequest

Fields

FHIR element

Python attribute

Why

birthDate

birthDate

Same name; camelCase is kept.

_birthDate

birthDate__ext

Primitive extension; see Extensions.

value[x] → valueQuantity

valueQuantity

One attribute per choice type.

class, import, for …

class_fhir, import_fhir, for_fhir

Python keywords get a _fhir suffix.

_class, _import …

class_fhir__ext, import_fhir__ext

Extension of a keyword-named primitive.

Serialization always writes the FHIR name. When constructing a model you can use either name:

>>> from fhir.resources.structuremap import StructureMap
>>> sm = StructureMap.model_validate({
...     "resourceType": "StructureMap", "url": "http://example.org/sm",
...     "name": "Example", "status": "draft",
...     "import": ["http://example.org/StructureMap/other"],
...     "group": [{"name": "g", "input": [{"name": "src", "mode": "source"}],
...                "rule": [{"source": [{"context": "src"}]}]}],
... })
>>> sm.import_fhir
['http://example.org/StructureMap/other']
>>> '"import"' in sm.model_dump_json()
True