FHIR® Core
Powered by Pydantic V2. This library is developed for the support of the another libray fhir.resources but you are more than welcome to use it for your own purpose. It provides an abstract base class for any FHIR resource model and Primitive Datatypes along with factories to create FHIR resource model and other complex datatypes.
Installation
Just a simple pip install fhir-core. But if you want development version, just clone from https://github.com/nazrulworld/fhir-core and pip install -e .[dev].
Usages
Example: 1: This example creates an Organization class with some of its attributes (id, active, name, address):
>>> from typing import List
>>> from pydantic import Field
>>> from fhir_core.fhirabstractmodel import FHIRAbstractModel
>>> from fhir_core.types import IdType, BooleanType, StringType
>>> data = {
... "id": "f001",
... "active": True,
... "name": "Acme Corporation",
... "address": ["Road 10": "Acme corporation", "2390", "USA"}]
... }
>>> class Organization(FHIRAbstractModel):
... __resource_type__ = "Organization"
... id: IdType = Field(None, title="Id", alias="id", json_schema_extra={"element_property": True})
... active: BooleanType = Field(None, title="Active", alias="active", json_schema_extra={"element_property": True})
... name: StringType = Field(None, title="Name", alias="name", json_schema_extra={"element_property": True})
... address: ListType[StringType] = Field(None, title="Address lines", alias="address", json_schema_extra={"element_property": True})
...
... @classmethod
def elements_sequence(cls):
return ["id", "active", "name", "address"]
...
>>> org = Organization.model_validate(data)
>>> org.active is True
True
>>> org_json_str = org.model_dump_json()
>>> Organization.model_validate_json(org_json_str).model_dump() == org.model_dump()
True
Complex examples
© Copyright HL7® logo, FHIR® logo and the flaming fire are registered trademarks owned by Health Level Seven International
History
1.1.11 (2026-09-13)
Reject None elements in lists of complex types; primitive lists keep their null placeholders nazrulworld/fhir.resources#208 [asaraog]
Serialize the FHIR uuid type as the URI the specification asks for, urn:uuid:<uuid>, instead of a bare UUID nazrulworld/fhir.resources#180
Restore the lower bounds on unsignedInt and positiveInt so negative values no longer validate nazrulworld/fhir.resources#207 [asaraog]
Resolve the FHIR version prefix through the class MRO so model_dump_xml() works on subclasses nazrulworld/fhir.resources#209 [asaraog]
Fix KeyError during model_dump() when a subclass overrides a field’s default and drops its alias nazrulworld/fhir.resources#182 [asaraog]
1.1.10 (2026-07-25)
Fix issue #23 with annotated_types package after 0.8.0
1.1.9 (2026-06-28)
Fix regression where input to Decimal type can lose exponent i.e. 1.0 remains 1.0 not 1 #20
For primitive type’s value required validation, empty extension is now acceptable.
1.1.8 (2026-04-30)
Fixes: Decimal values lose precision during serialization — Decimal(‘19’) becomes 19.0 in both model_dump() and model_dump_json() fhir.resources#203 [cmodevcodes]
1.1.7 (2026-03-22)
Fixes error in supporting multiple fhir version into xml utilities.
1.1.6 (2026-03-19)
Fix FHIR_TYPES_MAPS global state prevents using multiple FHIR versions in same process https://github.com/nazrulworld/fhir.resources/issues/202
1.1.5 (2026-01-29)
Fixes the issue #16 “Encounter.class missing when serializing to XML”.
Fixes the issue #14 “Wrong serialization of Instant type” [dhallam].
1.1.4 (2025-07-11)
Fixes the issue #13 “pyright struggles with default position args”.
1.1.3 (2025-07-10)
Fixes business logic for xml serializer, when summary move is active.
1.1.2 (2025-07-09)
Fixes nested ignoring (non primitive field serialization), if summary mode is enabled.
Issue #12 missing xmlparser argument for FHIRAbstractModel.model_validate_xml.
1.1.1 (2025-07-04)
Extra field property name is_summery_element has been renamed to summary_element_property
1.1.0 (2025-07-01)
New features
Issue 11: <https://github.com/nazrulworld/fhir-core/issues/11>_ Added support for FHIR _summary based filter during serialization.
1.0.2 (2025-06-23)
Fixes
Issue: deprecated access of model_fields in Pydantic model instances. https://github.com/nazrulworld/fhir-core/issues/9.
1.0.1 (2025-03-23)
Fixes
External issue https://github.com/nazrulworld/fhir.resources/issues/175
1.0.0 (2024-12-25)
XML serialization/deserialization support has been added.
Remove dependency on typed-ast as it is not needed and won’t work in later Python versions.
Fix typo in test case.
Raising ‘ValueError’ has been suspended inside Fhir Model Validation ‘fhir_model_validator()’, if None value is provided.
0.1.3 (2024-10-24)
Improves missing value validation message, as error type is now model_field_validation.missing.
0.1.2 (2024-10-09)
Improve validation error message.
0.1.1 (2024-10-09)
Version policy updated, now .bx suffix has been removed.
Fixes
Business logic for None type validation against FHIR Model validator as None value is acceptable! Instead, you should make Pydantic field optional.
0.1.0b9 (2024-10-02)
Fixes
Issue: AttributeError: ‘NoneType’ object has no attribute ‘__resource_type__’ https://github.com/nazrulworld/fhir.resources/issues/164#issuecomment-2338404044
0.1.0b8 (2024-08-04)
YAML dump & validate options are added into FHIRAbstractModel.
0.1.0b7 (2024-07-31)
typing hint added for the function ´´create_fhir_type´´ and ´´create_fhir_element_or_resource_type´´.
0.1.0b6 (2024-07-30)
Core configurations for types Id & String are coming from constraint module.
Default maximum char length Id is now 255.
0.1.0b5 (2024-07-28)
Fixes the function that is checking is_primitive, as missing bytes and bytesarray are added.
Encoding is handled for Base64Binary type.
0.1.0b4 (2024-07-28)
Fixes extension serialization.
0.1.0b3 (2024-07-28)
Fixes the function that is checking is_primitive.
Fixes validator for Resource & Element types.
0.1.0b2 (2024-07-27)
Bugfixes
Fixes pattern as string for some of primitives types. fx UriType.
Fixes model serializer.
0.1.0b1 (2024-07-26)
The first beta release! and this release is not stable enough to use in production.
Metadata
Release files for fhir-core 1.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fhir_core-1.1.11.tar.gz | 37.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fhir_core-1.1.11-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 69.6 kB
Release files / fhir_core-1.1.11.tar.gz
| Download URL | fhir_core-1.1.11.tar.gz |
|---|---|
| Size | 37.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c726bd3da2b46292ddda5fa98330cde4707291ec33db8883779a2e0f539fec4b
|
|
BLAKE2b-256 checksum How to use checksums |
027e5beca7a70a87f5c2c541ca5196013df016eec4a8a018f90289d50cd7ea05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.10
|
Release files / fhir_core-1.1.11-py2.py3-none-any.whl
| Download URL | fhir_core-1.1.11-py2.py3-none-any.whl |
|---|---|
| Size | 32.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d41069bc9a683982e4caf87fa13f5e25c7ae2882c5ad53cdceaeb08af3d5024c
|
|
BLAKE2b-256 checksum How to use checksums |
b1b51afdec83071f7a282284e0390af5b4e039340b0d1edace437652528891f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.10
|