{"id":19618876,"url":"https://github.com/nazrulworld/fhir.resources","last_synced_at":"2025-10-05T23:02:02.736Z","repository":{"id":37597274,"uuid":"165297877","full_name":"nazrulworld/fhir.resources","owner":"nazrulworld","description":"FHIR Resources https://www.hl7.org/fhir/resourcelist.html","archived":false,"fork":false,"pushed_at":"2025-03-23T15:43:47.000Z","size":11496,"stargazers_count":440,"open_issues_count":48,"forks_count":115,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-05-13T05:48:32.716Z","etag":null,"topics":["fhir","fhirbase","fhirpath","healthcare","healthcare-application","healthcare-data","hl7","ihe","plone","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/fhir.resources/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nazrulworld.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-11T19:26:41.000Z","updated_at":"2025-05-04T20:08:29.000Z","dependencies_parsed_at":"2023-02-08T17:15:20.086Z","dependency_job_id":"9d5a3472-3f6b-4a63-87bf-814cacdbcec2","html_url":"https://github.com/nazrulworld/fhir.resources","commit_stats":{"total_commits":367,"total_committers":11,"mean_commits":33.36363636363637,"dds":0.2343324250681199,"last_synced_commit":"3f61a5e7963657ed354e2d02b938c62569583299"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazrulworld%2Ffhir.resources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazrulworld%2Ffhir.resources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazrulworld%2Ffhir.resources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazrulworld%2Ffhir.resources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nazrulworld","download_url":"https://codeload.github.com/nazrulworld/fhir.resources/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129481,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fhir","fhirbase","fhirpath","healthcare","healthcare-application","healthcare-data","hl7","ihe","plone","python"],"created_at":"2024-11-11T11:11:09.636Z","updated_at":"2025-10-05T23:02:02.730Z","avatar_url":"https://github.com/nazrulworld.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===============================\nFHIR® Resources (R5, R4B, STU3)\n===============================\n\n.. image:: https://img.shields.io/pypi/v/fhir.resources.svg\n        :target: https://pypi.python.org/pypi/fhir.resources\n\n.. image:: https://img.shields.io/pypi/pyversions/fhir.resources.svg\n        :target: https://pypi.python.org/pypi/fhir.resources\n        :alt: Supported Python Versions\n\n.. image:: https://img.shields.io/travis/com/nazrulworld/fhir.resources.svg\n        :target: https://app.travis-ci.com/github/nazrulworld/fhir.resources\n\n.. image:: https://ci.appveyor.com/api/projects/status/0qu5vyue1jwxb4km?svg=true\n        :target: https://ci.appveyor.com/project/nazrulworld/fhir-resources\n        :alt: Windows Build\n\n.. image:: https://codecov.io/gh/nazrulworld/fhir.resources/branch/master/graph/badge.svg\n        :target: https://codecov.io/gh/nazrulworld/fhir.resources\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n.. image:: https://static.pepy.tech/personalized-badge/fhir-resources?period=total\u0026units=international_system\u0026left_color=black\u0026right_color=green\u0026left_text=Downloads\n    :target: https://pepy.tech/project/fhir-resources\n    :alt: Downloads\n\n.. image:: https://www.hl7.org/fhir/assets/images/fhir-logo-www.png\n        :target: https://www.hl7.org/implement/standards/product_brief.cfm?product_id=449\n        :alt: HL7® FHIR®\n\n\nFHIR_ (Fast Healthcare Interoperability Resources) is a specification for exchanging healthcare information electronically.\nIt is designed to facilitate the exchange of data between different healthcare systems and applications, and is commonly used to build APIs (Application Programming Interfaces) for healthcare data.\nIt is based on modern web technologies, and is designed to be easy to use and implement.\nIt uses a modular approach, with a set of \"resources\" that represent different types of healthcare data (such as patients, observations, and diagnoses).\nThese resources can be combined and extended as needed to support a wide range of healthcare use cases.\n\n\nThis \"fhir.resources\" package is powered by pydantic_ V2, so it become faster in performance.\nObviously it is written in modern python and has data validation built-in.\nIt provides tools and classes for all of the `FHIR Resources \u003chttps://www.hl7.org/fhir/resourcelist.html\u003e`_ defined in the FHIR specification,\nand allows you to create and manipulate FHIR resources in Python. You can then use these resources to build FHIR-based APIs or to work with FHIR data in other ways.\n\n\n* Easy to construct, easy to extended validation, easy to export.\n* By inheriting behaviour from pydantic_, compatible with `ORM \u003chttps://en.wikipedia.org/wiki/Object-relational_mapping\u003e`_.\n* Full support of FHIR® Extensibility for Primitive Data Types are available.\n* Previous release of FHIR® Resources are available.\n* Free software: BSD license\n\n**Experimental XML and YAML serialization and deserialization supports. See [Advanced Usages] section!**\n\nFHIR® Version Info\n------------------\n\nFHIR® (Release R5, version 5.0.0) is available as default. Also previous versions are available as Python sub-package\n(each release name string becomes sub-package name, i.e ``R4B`` ).\nFrom ``fhir.resources`` version 7.0.0; there is no FHIR ``R4`` instead of ``R4B`` is available as sub-package.\n\n**Available Previous Versions**:\n\n* ``R4B`` (4.3.0)\n* ``STU3`` (3.0.2)\n\nInstallation\n------------\n\nJust a simple ``pip install fhir.resources`` is enough. But if you want development\nversion, just clone from https://github.com/nazrulworld/fhir.resources and ``pip install -e .[dev]``.\n\n\nUsages\n------\n\n**Example: 1**: This example creates a new Organization resource with some of its attributes (id, active, name, address)::\n\n    \u003e\u003e\u003e from fhir.resources.organization import Organization\n    \u003e\u003e\u003e from fhir.resources.address import Address\n    \u003e\u003e\u003e data = {\n    ...     \"id\": \"f001\",\n    ...     \"active\": True,\n    ...     \"name\": \"Acme Corporation\",\n    ...     \"address\": [{\"country\": \"Switzerland\"}]\n    ... }\n    \u003e\u003e\u003e org = Organization(**data)\n    \u003e\u003e\u003e org.get_resource_type() == \"Organization\"\n    True\n    \u003e\u003e\u003e isinstance(org.address[0], Address)\n    True\n    \u003e\u003e\u003e org.address[0].country == \"Switzerland\"\n    True\n    \u003e\u003e\u003e org.model_dump()['active'] is True\n    True\n\n**Example: 2**: This example creates a new Organization resource from json string::\n\n    \u003e\u003e\u003e from fhir.resources.organization import Organization\n    \u003e\u003e\u003e from fhir.resources.address import Address\n    \u003e\u003e\u003e json_str = '''{\"resourceType\": \"Organization\",\n    ...     \"id\": \"f001\",\n    ...     \"active\": True,\n    ...     \"name\": \"Acme Corporation\",\n    ...     \"address\": [{\"country\": \"Switzerland\"}]\n    ... }'''\n    \u003e\u003e\u003e org = Organization.model_validate_json(json_str)\n    \u003e\u003e\u003e isinstance(org.address[0], Address)\n    True\n    \u003e\u003e\u003e org.address[0].country == \"Switzerland\"\n    True\n    \u003e\u003e\u003e org.dict()['active'] is True\n    True\n\n\n**Example: 3**: This example creates a new Patient resource from json object(py dict)::\n\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e from fhir.resources.humanname import HumanName\n    \u003e\u003e\u003e from datetime import date\n    \u003e\u003e\u003e json_obj = {\"resourceType\": \"Patient\",\n    ...     \"id\": \"p001\",\n    ...     \"active\": True,\n    ...     \"name\": [\n    ...         {\"text\": \"Adam Smith\"}\n    ...      ],\n    ...     \"birthDate\": \"1985-06-12\"\n    ... }\n    \u003e\u003e\u003e pat = Patient.model_validate(json_obj)\n    \u003e\u003e\u003e isinstance(pat.name[0], HumanName)\n    True\n    \u003e\u003e\u003e pat.birthDate == date(year=1985, month=6, day=12)\n    True\n    \u003e\u003e\u003e pat.active is True\n    True\n\n\n**Example: 4**: This example creates a new Patient resource from json file::\n\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e import os\n    \u003e\u003e\u003e import pathlib\n    \u003e\u003e\u003e filename = pathlib.Path(\"foo/bar.json\")\n    \u003e\u003e\u003e pat = Patient.model_validate_json(filename.read_bytes())\n    \u003e\u003e\u003e pat.get_resource_type() == \"Patient\"\n    True\n\n\n**Example: 5**: This example creates a new Organization resource in python way::\n\n    \u003e\u003e\u003e from fhir.resources.organization import Organization\n    \u003e\u003e\u003e from fhir.resources.address import Address\n    \u003e\u003e\u003e json_obj = {\"resourceType\": \"Organization\",\n    ...     \"id\": \"f001\",\n    ...     \"active\": True,\n    ...     \"name\": \"Acme Corporation\",\n    ...     \"address\": [{\"country\": \"Switzerland\"}]\n    ... }\n\n    \u003e\u003e\u003e org = Organization.model_construct()\n    \u003e\u003e\u003e org.id = \"f001\"\n    \u003e\u003e\u003e org.active = True\n    \u003e\u003e\u003e org.name = \"Acme Corporation\"\n    \u003e\u003e\u003e org.address = list()\n    \u003e\u003e\u003e address = Address.model_construct()\n    \u003e\u003e\u003e address.country = \"Switzerland\"\n    \u003e\u003e\u003e org.address.append(address)\n    \u003e\u003e\u003e org.model_dump() == json_obj\n    True\n\n.. note::\n    Please note that due to the way the validation works, you will run into issues if you are using ``model_construct()`` to create\n    resources that have more than one mandatory field. See `this comment in issue#56 \u003chttps://github.com/nazrulworld/fhir.resources/issues/56#issuecomment-784520234\u003e`_ for details.\n\n\n**Example: 5**: Auto validation while providing wrong datatype::\n\n    \u003e\u003e\u003e try:\n    ...     org = Organization({\"id\": \"fmk\", \"address\": [\"i am wrong type\"]})\n    ...     raise AssertionError(\"Code should not come here\")\n    ... except ValueError:\n    ...     pass\n\n\n\nAdvanced Usages\n---------------\n\nFHIR Comments (JSON)\n~~~~~~~~~~~~~~~~~~~~\n\nIt is possible to add comments inside json like xml, but need to follow some convention, what is suggested by `Grahame Grieve \u003chttp://www.healthintersections.com.au/?p=2569\u003e`_;\nis implemented here.\n\nAlso it is possible to generate json string output without comments.\n\nExamples::\n\n    \u003e\u003e\u003e observation_str = b\"\"\"{\n    ...  \"resourceType\": \"Observation\",\n    ...  \"id\": \"f001\",\n    ...    \"fhir_comments\": [\n    ...      \"   a specimen identifier - e.g. assigned when the specimen was taken by the orderer/placer  use the accession number for the filling lab   \",\n    ...      \"  Placer ID  \"\n    ...    ],\n    ...  \"text\": {\n    ...      \"fhir_comments\": [\n    ...      \"   a specimen identifier - e.g. assigned when the specimen was taken by the orderer/placer  use the accession number for the filling lab   \",\n    ...      \"  Placer ID  \"\n    ...    ],\n    ...    \"status\": \"generated\",\n    ...    \"div\": \"\u003cdiv xmlns=\\\"http://www.w3.org/1999/xhtml\\\"\u003e.........\u003c/div\u003e\"\n    ...  },\n    ...  \"identifier\": [\n    ...    {\n    ...      \"use\": \"official\",\n    ...      \"system\": \"http://www.bmc.nl/zorgportal/identifiers/observations\",\n    ...      \"value\": \"6323\"\n    ...    }\n    ...  ],\n    ...  \"status\": \"final\",\n    ...  \"_status\": {\n    ...      \"fhir_comments\": [\n    ...            \"  EH: Note to balloters  - lots of choices for whole blood I chose this.  \"\n    ...          ]\n    ...  },\n    ...  \"code\": {\n    ...    \"coding\": [\n    ...      {\n    ...        \"system\": \"http://loinc.org\",\n    ...        \"code\": \"15074-8\",\n    ...        \"display\": \"Glucose [Moles/volume] in Blood\"\n    ...      }\n    ...    ]\n    ...  },\n    ...  \"subject\": {\n    ...    \"reference\": \"Patient/f001\",\n    ...    \"display\": \"P. van de Heuvel\"\n    ...  },\n    ...  \"effectivePeriod\": {\n    ...    \"start\": \"2013-04-02T09:30:10+01:00\"\n    ...  },\n    ...  \"issued\": \"2013-04-03T15:30:10+01:00\",\n    ...  \"performer\": [\n    ...    {\n    ...      \"reference\": \"Practitioner/f005\",\n    ...      \"display\": \"A. Langeveld\"\n    ...    }\n    ...  ],\n    ...  \"valueQuantity\": {\n    ...    \"value\": 6.3,\n    ...    \"unit\": \"mmol/l\",\n    ...    \"system\": \"http://unitsofmeasure.org\",\n    ...    \"code\": \"mmol/L\"\n    ...  },\n    ...  \"interpretation\": [\n    ...    {\n    ...      \"coding\": [\n    ...        {\n    ...          \"system\": \"http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation\",\n    ...          \"code\": \"H\",\n    ...          \"display\": \"High\"\n    ...        }\n    ...      ]\n    ...    }\n    ...  ],\n    ...  \"referenceRange\": [\n    ...    {\n    ...      \"low\": {\n    ...        \"value\": 3.1,\n    ...        \"unit\": \"mmol/l\",\n    ...        \"system\": \"http://unitsofmeasure.org\",\n    ...        \"code\": \"mmol/L\"\n    ...      },\n    ...      \"high\": {\n    ...        \"value\": 6.2,\n    ...        \"unit\": \"mmol/l\",\n    ...        \"system\": \"http://unitsofmeasure.org\",\n    ...        \"code\": \"mmol/L\"\n    ...      }\n    ...    }\n    ...  ]\n    ... }\"\"\"\n    \u003e\u003e\u003e from fhir.resources.observation import Observation\n    \u003e\u003e\u003e obj = Observation.model_validate_json(observation_str)\n    \u003e\u003e\u003e \"fhir_comments\" in obj.model_dump_json()\n    \u003e\u003e\u003e # Test comments filtering\n    \u003e\u003e\u003e \"fhir_comments\" not in obj.model_dump_json(exclude_comments=True)\n\n\nSpecial Case: Missing data\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n`In some cases \u003chttps://www.hl7.org/fhir/extensibility.html#Special-Case\u003e`_, implementers might\nfind that they do not have appropriate data for an element with minimum cardinality = 1.\nIn this case, the element must be present, but unless the resource or a profile on it has made the\nactual value of the primitive data type mandatory, it is possible to provide an extension that\nexplains why the primitive value is not present.\nExample (required ``intent`` element is missing but still valid because of extension)::\n\n    \u003e\u003e\u003e json_str = b\"\"\"{\n    ...    \"resourceType\": \"MedicationRequest\",\n    ...    \"id\": \"1620518\",\n    ...    \"meta\": {\n    ...        \"versionId\": \"1\",\n    ...        \"lastUpdated\": \"2020-10-27T11:04:42.215+00:00\",\n    ...        \"source\": \"#z072VeAlQWM94jpc\",\n    ...        \"tag\": [\n    ...            {\n    ...                \"system\": \"http://www.alpha.alp/use-case\",\n    ...                \"code\": \"EX20\"\n    ...            }\n    ...        ]\n    ...    },\n    ...    \"status\": \"completed\",\n    ...    \"_intent\": {\n    ...        \"extension\": [\n    ...            {\n    ...                \"url\": \"http://hl7.org/fhir/StructureDefinition/data-absent-reason\",\n    ...                \"valueCode\": \"unknown\"\n    ...            }\n    ...        ]\n    ...    },\n    ...    \"medicationReference\": {\n    ...        \"reference\": \"Medication/1620516\",\n    ...        \"display\": \"Erythromycin 250 MG Oral Tablet\"\n    ...    },\n    ...    \"subject\": {\n    ...        \"reference\": \"Patient/1620472\"\n    ...    },\n    ...    \"encounter\": {\n    ...        \"reference\": \"Encounter/1620506\",\n    ...        \"display\": \"Follow up encounter\"\n    ...    },\n    ...    \"authoredOn\": \"2018-06-16\",\n    ...    \"requester\": {\n    ...        \"reference\": \"Practitioner/1620502\",\n    ...        \"display\": \"Dr. Harold Hippocrates\"\n    ...    },\n    ...    \"reasonReference\": [\n    ...        {\n    ...            \"reference\": \"Condition/1620514\",\n    ...            \"display\": \"Otitis Media\"\n    ...        }\n    ...    ],\n    ...    \"dosageInstruction\": [\n    ...        {\n    ...            \"text\": \"250 mg 4 times per day for 10 days\",\n    ...            \"timing\": {\n    ...                \"repeat\": {\n    ...                    \"boundsDuration\": {\n    ...                        \"value\": 10,\n    ...                        \"unit\": \"day\",\n    ...                        \"system\": \"http://unitsofmeasure.org\",\n    ...                        \"code\": \"d\"\n    ...                    },\n    ...                    \"frequency\": 4,\n    ...                    \"period\": 1,\n    ...                    \"periodUnit\": \"d\"\n    ...                }\n    ...            },\n    ...            \"doseAndRate\": [\n    ...                {\n    ...                    \"doseQuantity\": {\n    ...                        \"value\": 250,\n    ...                        \"unit\": \"mg\",\n    ...                        \"system\": \"http://unitsofmeasure.org\",\n    ...                        \"code\": \"mg\"\n    ...                    }\n    ...                }\n    ...            ]\n    ...        }\n    ...    ],\n    ...    \"priorPrescription\": {\n    ...        \"reference\": \"MedicationRequest/1620517\",\n    ...        \"display\": \"Amoxicillin prescription\"\n    ...    }\n    ... }\"\"\"\n    \u003e\u003e\u003e from fhir.resources.medicationrequest import MedicationRequest\n    \u003e\u003e\u003e obj = MedicationRequest.model_validate_json(json_str)\n    \u003e\u003e\u003e \"intent\" not in obj.model_dump()\n\n\nCustom Validators\n~~~~~~~~~~~~~~~~~\n**This feature is not available**\n\n``fhir.resources`` is providing the extensive API to create and attach custom validator into any model. See more `about root validator \u003chttps://pydantic-docs.helpmanual.io/usage/validators/#root-validators\u003e`_\nSome convention you have to follow though, while creating a root validator.\n\n1. Number of arguments are fixed, as well as names are also. i.e ``(cls, values)``.\n2. Should return ``values``, unless any exception need to be raised.\n3. Validator should be attached only one time for individual Model. Update [from now, it's not possible to attach multiple time same name validator on same class]\n\nExample 1: Validator for Patient::\n\n    from typing import Dict\n    from fhir.resources.patient import Patient\n\n    import datetime\n\n    def validate_birthdate(cls, values: Dict):\n        if not values:\n            return values\n        if \"birthDate\" not in values:\n            raise ValueError(\"Patient's ``birthDate`` is required.\")\n\n        minimum_date = datetime.date(2002, 1, 1)\n        if values[\"birthDate\"] \u003e minimum_date:\n            raise ValueError(\"Minimum 18 years patient is allowed to use this system.\")\n        return values\n    # we want this validator to execute after data evaluating by individual field validators.\n    Patient.add_root_validator(validate_gender, pre=False)\n\n\nExample 2: Validator for Patient from Validator Class::\n\n    from typing import Dict\n    from fhir.resources.patient import Patient\n\n    import datetime\n\n    class MyValidator:\n        @classmethod\n        def validate_birthdate(cls, values: Dict):\n            if not values:\n                return values\n            if \"birthDate\" not in values:\n                raise ValueError(\"Patient's ``birthDate`` is required.\")\n\n            minimum_date = datetime.date(2002, 1, 1)\n            if values[\"birthDate\"] \u003e minimum_date:\n                raise ValueError(\"Minimum 18 years patient is allowed to use this system.\")\n            return values\n    # we want this validator to execute after data evaluating by individual field validators.\n    Patient.add_root_validator(MyValidator.validate_gender, pre=False)\n\n\n**important notes** It is possible add root validator into any base class like ``DomainResource``.\nIn this case you have to make sure root validator is attached before any import of derived class, other\nthan validator will not trigger for successor class (if imported before) by nature.\n\nENUM Validator\n~~~~~~~~~~~~~~\n\n``fhir.resources`` is providing API for enum constraint for each field (where applicable), but it-self doesn't\nenforce enum based validation! see `discussion here \u003chttps://github.com/nazrulworld/fhir.resources/issues/23\u003e`_.\nIf you want to enforce enum constraint, you have to create a validator for that.\n\nExample: Gender Enum::\n\n    from typing import Dict\n    from fhir.resources.patient import Patient\n\n    def validate_gender(cls, values: Dict):\n        if not values:\n            return values\n        enums = cls.model_fields[\"gender\"].json_schema_extra[\"enum_values\"]\n        if \"gender\" in values and values[\"gender\"] not in enums:\n            raise ValueError(\"write your message\")\n        return values\n\n    Patient.add_root_validator(validate_gender, pre=True)\n\n\nReference Validator\n~~~~~~~~~~~~~~~~~~~\n\n``fhir.resources`` is also providing enum like list of permitted resource types through json_schema_extra ``enum_reference_types``.\nYou can get that list by following above (Enum) approaches  ``resource_types = cls.model_fields[\"managingOrganization\"].json_schema_extra[\"enum_reference_types\"]``\n\n\n\npydantic_ Field Type Support\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAll available fhir resources (types) can be use as pydantic_'s Field's value types. See issue#46 `Support for FastAPI pydantic response models \u003chttps://github.com/nazrulworld/fhir.resources/issues/46\u003e`_.\nThe module ``fhirtypes.py`` contains all fhir resources related types and should trigger validator automatically.\n\n\n``Resource.id aka fhirtypes.Id`` constraint extensibility\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThere are a lots of discussion here here i.) https://bit.ly/360HksL ii.) https://bit.ly/3o1fZgl about the length of ``Resource.Id``'s value.\nBased on those discussions, we recommend that keep your ``Resource.Id`` size within 64 letters (for the seek of intercompatibility with third party system), but we are also providing freedom\nabout the length of Id, in respect with others opinion that 64 chr length is not sufficient, so default length is now 255.\nBut it is offering to customize as your own requirement by doing a monkey patch.\n\nExamples::\n    # ``patch.py``\n    \u003e\u003e\u003e import importlib\n    \u003e\u003e\u003e from fhir_core import constraints\n    \u003e\u003e\u003e from fhir_core import types as ftypes\n    \u003e\u003e\u003e constraints.TYPES_ID_MAX_LENGTH = 64\n    \u003e\u003e\u003e importlib.reload(ftypes)\n\nNote: when you will change that behaviour, that would impact into your whole project.\n\n\nXML Supports\n~~~~~~~~~~~~\nAlong side with JSON string export, it is possible to export as XML string!\nBefore using this feature, make sure associated dependent library is installed. Use ``fhir.resources[xml]`` or ``fhir.resources[all]`` as\nyour project requirements.\n\n**XML schema validator!**\nIt is possible to provide custom xmlparser, during load from file or string, meaning that you can validate\ndata against FHIR xml schema(and/or your custom schema).\n\nExample-1 Export::\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e data = {\"active\": True, \"gender\": \"male\", \"birthDate\": \"2000-09-18\", \"name\": [{\"text\": \"Primal Kons\"}]}\n    \u003e\u003e\u003e patient_obj = Patient(**data)\n    \u003e\u003e\u003e xml_str = patient_obj.model_dump_xml(pretty_print=True)\n    \u003e\u003e\u003e print(xml_str)\n    \u003c?xml version='1.0' encoding='utf-8'?\u003e\n    \u003cPatient xmlns=\"http://hl7.org/fhir\"\u003e\n      \u003cactive value=\"true\"/\u003e\n      \u003cname\u003e\n        \u003ctext value=\"Primal Kons\"/\u003e\n      \u003c/name\u003e\n      \u003cgender value=\"male\"/\u003e\n      \u003cbirthDate value=\"2000-09-18\"/\u003e\n    \u003c/Patient\u003e\n\n\nExample-2 Import from string::\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e data = {\"active\": True, \"gender\": \"male\", \"birthDate\": \"2000-09-18\", \"name\": [{\"text\": \"Primal Kons\"}]}\n    \u003e\u003e\u003e patient_obj = Patient(**data)\n    \u003e\u003e\u003e xml_str = patient_obj.model_dump_xml(pretty_print=True)\n    \u003e\u003e\u003e print(xml_str)\n    \u003e\u003e\u003e data = b\"\"\"\u003c?xml version='1.0' encoding='utf-8'?\u003e\n    ... \u003cPatient xmlns=\"http://hl7.org/fhir\"\u003e\n    ...   \u003cactive value=\"true\"/\u003e\n    ...   \u003cname\u003e\n    ...     \u003ctext value=\"Primal Kons\"/\u003e\n    ...   \u003c/name\u003e\n    ...   \u003cgender value=\"male\"/\u003e\n    ...   \u003cbirthDate value=\"2000-09-18\"/\u003e\n    ... \u003c/Patient\u003e\"\"\"\n    \u003e\u003e\u003e patient = Patient.model_validate_xml(data)\n    \u003e\u003e\u003e print(patient.model_dump_json(indent=2))\n    {\n      \"resourceType\": \"Patient\",\n      \"active\": true,\n      \"name\": [\n        {\n          \"text\": \"Primal Kons\",\n          \"family\": \"Kons\",\n          \"given\": [\n            \"Primal\"\n          ]\n        }\n      ],\n      \"gender\": \"male\",\n      \"birthDate\": \"2000-09-18\"\n    }\n\n    \u003e\u003e\u003e with xml parser\n    \u003e\u003e\u003e import lxml\n    \u003e\u003e\u003e from fhir_core.xml_utils import xml_loads\n    \u003e\u003e\u003e schema = lxml.etree.XMLSchema(file=str(FHIR_XSD_DIR / \"patient.xsd\"))\n    \u003e\u003e\u003e xmlparser = lxml.etree.XMLParser(schema=schema)\n    \u003e\u003e\u003e patient2 = xml_loads(Patient, data, xmlparser=xmlparser)\n    \u003e\u003e\u003e patient2 == patient\n    True\n\nExample-3 Import from file::\n    \u003e\u003e\u003e import pathlib\n    \u003e\u003e\u003e patient3 = Patient.model_validate_xml(pathlib.Path(\"Patient.xml\").read_bytes())\n    \u003e\u003e\u003e patient3 == patient and patient3 == patient2\n    True\n\n\n**XML FAQ**\n\n    - Although generated XML is validated against ``FHIR/patient.xsd`` and ``FHIR/observation.xsd`` in tests, but we suggest you check output of your production data.\n    - Comment feature is included, but we recommend you check in your complex usages.\n\n\nYAML Supports\n~~~~~~~~~~~~~\n\nAlthough there is no official support for YAML documented in FHIR specification, but as an experimental feature, we add this support.\nNow it is possible export/import YAML strings.\nBefore using this feature, make sure associated dependent library is installed. Use ``fhir.resources[yaml]`` or ``fhir.resources[all]`` as\nyour project requirements.\n\nExample-1 Export::\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e data = {\"active\": True, \"gender\": \"male\", \"birthDate\": \"2000-09-18\", \"name\": [{\"text\": \"Primal Kons\", \"family\": \"Kons\", \"given\": [\"Primal\"]}]}\n    \u003e\u003e\u003e patient_obj = Patient(**data)\n    \u003e\u003e\u003e yml_str = patient_obj.model_dump_yaml(indent=2)\n    \u003e\u003e\u003e print(yml_str)\n    resourceType: Patient\n    active: true\n    name:\n    - text: Primal Kons\n      family: Kons\n      given:\n      - Primal\n    gender: male\n    birthDate: 2000-09-18\n\n\nExample-2 Import from YAML string::\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e data = b\"\"\"\n    ... resourceType: Patient\n    ... active: true\n    ... name:\n    ... - text: Primal Kons\n    ...   family: Kons\n    ...   given:\n    ...   - Primal\n    ...  gender: male\n    ...  birthDate: 2000-09-18\n    ... \"\"\"\n    \u003e\u003e\u003e patient_obj = Patient.model_validate_yaml(data)\n    \u003e\u003e\u003e json_str = patient_obj.model_dump_json(indent=2)\n    \u003e\u003e\u003e print(json_str)\n    {\n      \"resourceType\": \"Patient\",\n      \"active\": true,\n      \"name\": [\n        {\n          \"text\": \"Primal Kons\",\n          \"family\": \"Kons\",\n          \"given\": [\n            \"Primal\"\n          ]\n        }\n      ],\n      \"gender\": \"male\",\n      \"birthDate\": \"2000-09-18\"\n    }\n\nExample-3 Import from YAML file::\n    \u003e\u003e\u003e import pathlib\n    \u003e\u003e\u003e from fhir.resources.patient import Patient\n    \u003e\u003e\u003e patient_obj = Patient.model_validate_yaml(pathlib.Path(\"Patient.yml\").read_bytes())\n    \u003e\u003e\u003e json_str = patient_obj.model_dump_json(indent=2)\n    \u003e\u003e\u003e print(json_str)\n    {\n      \"resourceType\": \"Patient\",\n      \"active\": true,\n      \"name\": [\n        {\n          \"text\": \"Primal Kons\",\n          \"family\": \"Kons\",\n          \"given\": [\n            \"Primal\"\n          ]\n        }\n      ],\n      \"gender\": \"male\",\n      \"birthDate\": \"2000-09-18\"\n    }\n\n\n**YAML FAQ**\n\n- We are using https://pyyaml.org/ PyYAML library, for serialization/deserialization but if we find more faster library, we could use that. you are welcome to provide us your suggestion.\n- YAML based comments is not supported yet, instead json comments syntax is used! Of course this comment feature is in our todo list.\n\n\nAllow Empty String\n~~~~~~~~~~~~~~~~~~\n\nAlthough this is not good practice to allow empty string value against FHIR primitive data type ``String``. But\nwe in real life scenario, is it unavoidable sometimes.\n\nExamples::\n    Place this code inside your __init__.py module or any place, just to make sure that this fragment of codes is runtime executed.\n\n    \u003e\u003e\u003e # ``__init__.py``\n    \u003e\u003e\u003e import importlib\n    \u003e\u003e\u003e from fhir_core import constraints\n    \u003e\u003e\u003e from fhir_core import types as ftypes\n    \u003e\u003e\u003e constraints.TYPES_STRING_ALLOW_EMPTY_STR = True\n    \u003e\u003e\u003e importlib.reload(ftypes)\n\n\nFHIR ``summary`` search support\n-------------------------------\nThis package is providing supporting ´´summary mode´´ activated serialization, meaning that you will not need to do extra, if you are planning to support `summary search \u003chttps://www.hl7.org/fhir/search.html#_summary\u003e`_\n\nExample::\n\n    \u003e\u003e\u003e from fhir.resources.organization import Organization\n    \u003e\u003e\u003e json_str = '''{\"resourceType\": \"Organization\",\n    ...     \"text\": {\"status\": \"generated\", \"div\": \"\u003cp\u003esummary example\u003c/p\u003e\"}\n    ...     \"id\": \"f001\",\n    ...     \"active\": True,\n    ...     \"name\": \"Acme Corporation\"\n    ... }'''\n    \u003e\u003e\u003e org = Organization.model_validate_json(json_str)\n    \u003e\u003e\u003e summary_dict = org.model_dump(summary_only=True)\n    \u003e\u003e\u003e \"text\" not in summary_dict\n    True\n    \u003e\u003e\u003e \"active\" in summary_dict\n    True\n    \u003e\u003e\u003e \"name\" in summary_dict\n\nFHIR release R4B over R4\n------------------------\n\nFHIR release R4B is coming with not that much changes over the release of R4. So we decided not to create separate sub-package for R4 like STU3, instead there just overlaps on existing R4. This also means that in future, when we will work on R5; there will be sub-package for R4B and no R4.\nWe suggest you to try make a plan to be upgraded to R4B. Here you could find related information dealing-strategy-R4-R4B_.\n\nYou could find full discussion here https://github.com/nazrulworld/fhir.resources/discussions/116\n\nMigration (from ``7.X.X`` to ``8.X.X``)\n---------------------------------------\n\nThere is no breaking changes in terms of api/functions. But it is recommended that you should use new functions from Pydantic V2\ninstead of using deprecated functions.\n\nReplacements and/or new functions.\n\n- From ``FHIRAbstractModel::dict`` to ``FHIRAbstractModel::model_dump``\n- From ``FHIRAbstractModel::json`` to ``FHIRAbstractModel::model_dump_json``\n- From ``FHIRAbstractModel::yaml`` to ``FHIRAbstractModel::model_dump_yaml``\n- From ``FHIRAbstractModel::xml`` to ``FHIRAbstractModel::model_dump_xml``\n- From ``FHIRAbstractModel::parse_obj`` to ``FHIRAbstractModel::model_validate``\n- From ``FHIRAbstractModel::parse_raw`` to ``FHIRAbstractModel::model_validate_json``\n- From ``FHIRAbstractModel::parse_file`` to no replacement, we suggest you use pathlib (see examples)\n- ``FHIRAbstractModel::model_validate_yaml`` parse YAML string to FHIRAbstractModel.\n- ``FHIRAbstractModel::model_validate_xml`` parse XML string to FHIRAbstractModel.\n\n\nBreaking: removed attributes and/or functions/methods.\n\n- The attribute ``resource_type`` has been removed from base FHIR class. For example no more ``Resource.resource_type`` attribute. Now you have to use Resource.get_resource_type() instead. Although \"resource_type\" key is available when you will serialize as json or python dict.\n\nMigration (from ``6.X.X`` to ``7.0.X``)\n---------------------------------------\n\nFirst of all, you have to correct all imports path, if you wish to keep continue using FHIR release R4B or R4, as those resources\nare moved under sub-package named ``R4B``. Then if you wish to use current ``R5`` release,\nread carefully the following documents.\n\n1. See the full changes history -\u003e https://build.fhir.org/history.html\n2. See complete lists of differences between R5 and R4B -\u003e https://hl7.org/fhir/R5/diff.html\n3. If you are planning to migrate direct from the release ``R4``,\n   then it is important to look at the differences between R4B and R4 here -\u003e https://hl7.org/fhir/R4B/diff.html\n\n\nMigration (from later than ``6.X.X``)\n-------------------------------------\n\nThis migration guide states some underlying changes of ``API`` and replacement, those are commonly used from later than ``6.X.X`` version.\n\n\n``fhir.resources.fhirelementfactory.FHIRElementFactory::instantiate``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n**Replacement:** ``fhir.resources.construct_fhir_element``\n\n- First parameter value is same as previous, the Resource name.\n\n- Second parameter is more flexible than previous! it is possible to provide not only json ``dict`` but also\n  json string or json file path.\n\n- No third parameter, what was in previous version.\n\n\n``fhir.resources.fhirabstractbase.FHIRAbstractBase::__init__``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n**Replacement:** ``fhir.resources.fhirabstractmodel.FHIRAbstractModel::parse_obj\u003cclassmethod\u003e``\n\n- First parameter value is same as previous, json dict.\n\n- No second parameter, what was in previous version.\n\n\n``fhir.resources.fhirabstractbase.FHIRAbstractBase::as_json``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n**Replacement:** ``fhir.resources.fhirabstractmodel.FHIRAbstractModel::dict``\n\n- Output are almost same previous, but there has some difference in case of some date type, for example py date,\n  datetime, Decimal are in object representation.\n\n- It is possible to use ``fhir.resources.fhirabstractmodel.FHIRAbstractModel::json`` as replacement, when\n  json string is required (so not need further, json dumps from dict)\n\n\nNote:\n\nAll resources/classes are derived from ``fhir.resources.fhirabstractmodel.FHIRAbstractModel`` what was previously\nfrom ``fhir.resources.fhirabstractbase.FHIRAbstractBase``.\n\n\nRelease and Version Policy\n--------------------------\n\nStarting from  version ``5.0.0`` we are following our own release policy and we although follow Semantic Versioning scheme like FHIR® version.\nUnlike previous statement (below), releasing now is not dependent on FHIR®.\n\n\n**removed statement**\n\n    This package is following `FHIR® release and versioning policy \u003chttps://www.hl7.org/fhir/versions.html\u003e`_, for example say, FHIR releases next version 4.0.1,\n    we also release same version here.\n\n\nCredits\n-------\n\nAll FHIR® Resources (python classes) are generated using fhir-parser_ which is forked from https://github.com/smart-on-fhir/fhir-parser.git.\n\n\nThis package skeleton was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n.. _`fhir-parser`: https://github.com/nazrulworld/fhir-parser\n.. _`pydantic`: https://pydantic-docs.helpmanual.io/\n.. _`orjson`: https://pypi.org/project/orjson/\n.. _`dealing-strategy-R4-R4B`: https://confluence.hl7.org/display/FHIR/Strategies+for+dealing+with+R4+and+R4B\n.. _`FHIR`: https://www.hl7.org/implement/standards/product_brief.cfm\n\n© Copyright HL7® logo, FHIR® logo and the flaming fire are registered trademarks\nowned by `Health Level Seven International \u003chttps://www.hl7.org/legal/trademarks.cfm?ref=https://pypi.org/project/fhir-resources/\u003e`_\n\n.. role:: strike\n    :class: strike\n.. role:: raw-html(raw)\n    :format: html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazrulworld%2Ffhir.resources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnazrulworld%2Ffhir.resources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazrulworld%2Ffhir.resources/lists"}