All FHIR Resources are available as python class with built-in initial validation, exporter as json value.

FHIR® (R4 aka 4.0.0) is available as default. Also previous versions are available as Python sub-package (each version name string becomes sub-package name, i.e STU3 ).

Installation

Just a simple pip install fhir.resources or easy_install fhir.resources is enough. But if you want development version, just clone from https://github.com/nazrulworld/fhir.resources and python setup.py install .

Example: 1: Resource object created from json string:

>>> from fhir.resources.organization import Organization >>> from fhir.resources.address import Address >>> json_dict = {"resourceType": "Organization", ... "id": "mmanu", ... "active": True, ... "name": "Acme Corporation", ... "address": [{"country": "Swizterland"}] ... } >>> org = Organization(json_dict) >>> isinstance(org.address[0], Address) >>> True >>> org.address[0].country == "Swizterland" True >>> org.as_json()['active'] is True True

Example: 2: Construct resource object in python way:

>>> org = Organization() >>> org.id = "mmanu" >>> org.active = True >>> org.name = "Acme Corporation" >>> org.address = list() >>> address = Address() >>> address.country = "Swizterland" >>> org.address.append(address) >>> org.as_json() == json_dict True

Example: 3: Auto validation while providing wrong datatype:

>>> from fhir.resources.fhirabstractbase import FHIRValidationError >>> try: ... org = Organization({"id": "fmk", "address": ["i am wrong type"]}) ... raise AssertionError("Code should not come here") ... except FHIRValidationError: ... pass

Example: 4: Using Resource Factory:

This package provides a convenient factory to create FHIR® resource, you never need to import manually each resource class. >>> from fhir.resources.fhirelementfactory import FHIRElementFactory >>> json_dict = {"resourceType": "Organization", ... "id": "mmanu", ... "active": True, ... "name": "Acme Corporation", ... "address": [{"country": "Swizterland"}] ... } >>> org = FHIRElementFactory.instantiate('Organization', json_dict) >>> org.address[0].country == "Swizterland" True >>> org.as_json()['active'] is True True