FHIR Core Library

1.1.7 · active · verified Mon Apr 13

fhir-core is a Python library providing an abstract base class for FHIR resource models and Primitive Datatypes, along with factories to create FHIR resource models and other complex datatypes. It is powered by Pydantic V2, ensuring data validation and efficient serialization/deserialization. This library is primarily developed to support the 'fhir.resources' library but can be used independently. As of March 2026, the current version is 1.1.7, with frequent patch releases.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a simple FHIR 'Organization' model inheriting from `FHIRAbstractModel` and populate it with data. It showcases the use of `fhir_core.types` for primitive FHIR data types and Pydantic's `Field` for alias and validation.

from typing import List
from pydantic import Field
from fhir_core.fhirabstractmodel import FHIRAbstractModel
from fhir_core.types import IdType, BooleanType, StringType

class Organization(FHIRAbstractModel):
    resourceType: StringType = Field('Organization', const=True)
    id: IdType = Field(None, alias='id')
    active: BooleanType = Field(None, alias='active')
    name: StringType = Field(None, alias='name')
    address: List[dict] = Field(None, alias='address') # Simplified for example

data = {
    "id": "f001",
    "active": True,
    "name": "Acme Corporation",
    "address": [
        {
            "use": "work",
            "line": ["534 Erewhon St"],
            "city": "PleasantVille",
            "state": "Vic",
            "postalCode": "3999",
            "country": "ZZ"
        }
    ]
}

organization_instance = Organization(**data)

print(organization_instance.json(indent=2))

view raw JSON →