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 |
|---|---|---|
|
|
Same name; camelCase is kept. |
|
|
Primitive extension; see Extensions. |
|
|
One attribute per choice type. |
|
|
Python keywords get a |
|
|
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