Migration guide

From 7.x to 8.x

Version 8 is built on Pydantic V2 (through fhir-core). The old method names still work but are deprecated; switch to the new ones:

7.x

8.x

obj.dict()

obj.model_dump()

obj.json()

obj.model_dump_json()

obj.yaml()

obj.model_dump_yaml()

obj.xml()

obj.model_dump_xml()

Model.parse_obj(data)

Model.model_validate(data)

Model.parse_raw(json_str)

Model.model_validate_json(json_str)

Model.parse_file(path)

Model.model_validate_json(pathlib.Path(path).read_bytes())

—

Model.model_validate_yaml(...) / Model.model_validate_xml(...)

Model.construct()

Model.model_construct()

Model.add_root_validator(fn)

Subclass with @model_validator; see Validation.

Model.__fields__

Model.model_fields

Breaking: the resource_type attribute is gone. Use obj.get_resource_type(). The resourceType key is still written on output.

>>> from fhir.resources.patient import Patient
>>> Patient().get_resource_type()
'Patient'

Field metadata such as enum_values and enum_reference_types moved to Model.model_fields[name].json_schema_extra.

From 6.x to 7.x

The default models are now FHIR R5. R4 / R4B models moved to the R4B sub-package, so update imports if you want to stay on R4:

- from fhir.resources.patient import Patient
+ from fhir.resources.R4B.patient import Patient

If you upgrade to R5, review:

  1. The FHIR version history.

  2. Differences between R5 and R4B.

  3. If you come from R4, also the differences between R4B and R4.

From versions before 6.x

Old

New

fhirelementfactory.FHIRElementFactory.instantiate(name, data)

get_fhir_model_class(name).model_validate(data)

fhirabstractbase.FHIRAbstractBase(jsondict)

Model.model_validate(jsondict)

obj.as_json()

obj.model_dump() or obj.model_dump_json()

All models now derive from FHIRAbstractModel rather than FHIRAbstractBase.

Release and version policy

Since 5.0.0, fhir.resources follows its own semantic versioning and no longer mirrors the FHIR version number. The FHIR version of the default models is available as fhir.resources.__fhir_version__.