Metadata-Version: 2.4
Name: fhir_core
Version: 1.1.13
Summary: FHIR Core library
Home-page: https://github.com/nazrulworld/fhir-core
Author: Md Nazrul Islam
Author-email: email2nazrul@gmail.com
License: BSD license
Project-URL: CI: Travis, https://travis-ci.org/github/nazrulworld/fhir-core
Project-URL: Coverage: codecov, https://codecov.io/gh/nazrulworld/fhir-core
Project-URL: GitHub: issues, https://github.com/nazrulworld/fhir-core/issues
Project-URL: GitHub: repo, https://github.com/nazrulworld/fhir-core
Keywords: fhir,core,resources,python,hl7,health IT,healthcare
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: pydantic<3.0,>=2.7.4
Provides-Extra: yaml
Requires-Dist: PyYAML>=6.0.1; extra == "yaml"
Provides-Extra: xml
Requires-Dist: lxml; extra == "xml"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: pytest>5.4.0; python_version >= "3.6" and extra == "test"
Requires-Dist: pytest-cov>=2.10.0; python_version >= "3.6" and extra == "test"
Requires-Dist: flake8==6.0; extra == "test"
Requires-Dist: flake8-isort>=6.0.0; extra == "test"
Requires-Dist: flake8-bugbear>=22.12.6; extra == "test"
Requires-Dist: requests==2.23.0; python_version < "3.10" and extra == "test"
Requires-Dist: isort>=5.11.4; extra == "test"
Requires-Dist: black<24.0,>=23.0; python_version >= "3.7" and extra == "test"
Requires-Dist: mypy; extra == "test"
Requires-Dist: PyYAML>=6.0.1; extra == "test"
Requires-Dist: types-PyYAML; extra == "test"
Requires-Dist: types-simplejson; extra == "test"
Requires-Dist: types-requests; extra == "test"
Requires-Dist: setuptools==65.6.3; (python_version >= "3.7" and python_version < "3.12") and extra == "test"
Requires-Dist: setuptools>=68; python_version >= "3.12" and extra == "test"
Requires-Dist: lxml==6.1.3; extra == "test"
Requires-Dist: importlib-metadata>=5.2.0; extra == "test"
Requires-Dist: pytest-runner; extra == "test"
Provides-Extra: dev
Requires-Dist: coverage; extra == "dev"
Requires-Dist: pytest>5.4.0; python_version >= "3.6" and extra == "dev"
Requires-Dist: pytest-cov>=2.10.0; python_version >= "3.6" and extra == "dev"
Requires-Dist: flake8==6.0; extra == "dev"
Requires-Dist: flake8-isort>=6.0.0; extra == "dev"
Requires-Dist: flake8-bugbear>=22.12.6; extra == "dev"
Requires-Dist: requests==2.23.0; python_version < "3.10" and extra == "dev"
Requires-Dist: isort>=5.11.4; extra == "dev"
Requires-Dist: black<24.0,>=23.0; python_version >= "3.7" and extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: PyYAML>=6.0.1; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Requires-Dist: types-simplejson; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: setuptools==65.6.3; (python_version >= "3.7" and python_version < "3.12") and extra == "dev"
Requires-Dist: setuptools>=68; python_version >= "3.12" and extra == "dev"
Requires-Dist: lxml==6.1.3; extra == "dev"
Requires-Dist: importlib-metadata>=5.2.0; extra == "dev"
Requires-Dist: Jinja2==2.11.1; extra == "dev"
Requires-Dist: MarkupSafe==1.1.1; extra == "dev"
Requires-Dist: colorlog==2.10.0; extra == "dev"
Requires-Dist: certifi; extra == "dev"
Requires-Dist: fhirspec; extra == "dev"
Requires-Dist: zest-releaser[recommended]; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

==========
FHIR® Core
==========

.. image:: https://img.shields.io/pypi/v/fhir-core.svg
        :target: https://pypi.python.org/pypi/fhir-core

.. image:: https://img.shields.io/pypi/pyversions/fhir-core.svg
        :target: https://pypi.python.org/pypi/fhir-core
        :alt: Supported Python Versions

.. image:: https://img.shields.io/travis/com/nazrulworld/fhir-core.svg
        :target: https://app.travis-ci.com/github/nazrulworld/fhir-core

.. image:: https://ci.appveyor.com/api/projects/status/1av308hpof6c9u5q?svg=true
        :target: https://ci.appveyor.com/project/nazrulworld/fhir-core
        :alt: Windows Build

.. image:: https://codecov.io/gh/nazrulworld/fhir-core/branch/main/graph/badge.svg
        :target: https://codecov.io/gh/nazrulworld/fhir-core

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. image:: https://static.pepy.tech/personalized-badge/fhir-core?period=total&units=international_system&left_color=black&right_color=green&left_text=Downloads
    :target: https://pepy.tech/project/fhir-core
    :alt: Downloads

.. image:: https://www.hl7.org/fhir/assets/images/fhir-logo-www.png
        :target: https://www.hl7.org/implement/standards/product_brief.cfm?product_id=449
        :alt: HL7® FHIR®

**Powered by Pydantic V2**. This library was developed to support `fhir.resources <https://github.com/nazrulworld/fhir.resources/>`_,
but you are more than welcome to use it for your own purposes. It provides an abstract base class for any `FHIR`_ resource model,
the `Primitive Datatypes <https://build.fhir.org/datatypes.html>`_, and factories to create FHIR resource models and other complex datatypes.


Installation
------------

Install from PyPI::

    pip install fhir-core

Serialization to YAML and XML is optional; install the matching extras::

    pip install fhir-core[yaml,xml]

For the development version, clone https://github.com/nazrulworld/fhir-core and run ``pip install -e .[dev]``.

Usage
-----

**Example 1**: Create an ``Organization`` model with a few 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", "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: List[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()
    >>> org_json_str
    '{"id":"f001","active":true,"name":"Acme Corporation","address":["Road 10","2390","USA"]}'
    >>> Organization.model_validate_json(org_json_str).model_dump() == org.model_dump()
    True

With ``PyYAML`` or ``lxml`` installed, the same model also supports ``model_dump_yaml()`` / ``model_validate_yaml()``
and ``model_dump_xml()`` / ``model_validate_xml()``.

**More complex examples**

1. https://github.com/nazrulworld/fhir-core/blob/main/tests/fixtures/resources/extension.py
2. https://github.com/nazrulworld/fhir-core/blob/main/tests/fixtures/resources/fhirtypes.py
3. https://github.com/nazrulworld/fhir-core/blob/main/tests/fixtures/resources/codesystem.py

.. _`FHIR`: https://www.hl7.org/implement/standards/product_brief.cfm

© Copyright HL7® logo, FHIR® logo and the flaming fire are registered trademarks
owned by `Health Level Seven International <https://www.hl7.org/legal/trademarks.cfm?ref=https://pypi.org/project/fhir-resources/>`_


History
=======

1.1.13 (2026-11-30)
-------------------

Fixes

- Accept a ``uuid`` of any version (for example version 1, 5 or 7) and the nil
  UUID. ``UuidType`` was pydantic's ``UUID4``, which rejects every UUID that is
  not version 4, while the FHIR ``uuid`` type is any RFC 4122 UUID.
- Reject whitespace in ``uri`` and ``canonical`` values. The ``Uri`` pattern
  ``\S*`` was unanchored, so it matched the empty prefix of any string and a
  value such as ``"http://loinc.org "`` validated, while the FHIR ``uri`` regex
  ``\S*`` applies to the whole value #37


1.1.12 (2026-10-18)
-------------------

New feature

- Global model_config customization for FHIR models #21 [developer-rpai]
- Make ``Id`` constraints customizable again: ``max_length`` and ``pattern``
  are now resolved from ``fhir_core.constraints.TYPES_ID_MAX_LENGTH`` /
  ``TYPES_ID_PATTERN`` at schema build time, so patching those values before
  the FHIR models are imported relaxes validation as documented
  nazrulworld/fhir.resources#173

Fixes

- Accept leap seconds (``23:59:60``) in the ``dateTime``, ``instant`` and ``time``
  types as the FHIR specification allows. Python's ``datetime`` cannot represent
  a second of 60, so such a value is validated and kept as the original string
  nazrulworld/fhir.resources#212
- Annotate ``**pydantic_kwargs`` as ``typing.Any`` on the serializer methods
  (``model_dump``, ``model_dump_json``, ``model_dump_yaml``, ``model_dump_xml``,
  ``dict``, ``json``), so strict type checkers no longer see them as Unknown.
- Omit empty lists from ``model_dump()``, ``model_dump_json()`` and
  ``model_dump_yaml()`` output, like ``None`` values, as FHIR elements are never
  empty (the XML serializer already left them out). They are kept when
  ``exclude_none=False`` is passed nazrulworld/fhir.resources#74


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.
