API Reference¶
to_fhir¶
Collection of utils for writing FHIR mappings.
- class DataAbsentReason(*values)[source]¶
Bases:
StrEnumCodes from the
data-absent-reasoncode system.See CodeSystem: DataAbsentReason. Members are their own FHIR code, so
DataAbsentReason.NOT_ASKED == "not-asked".- UNKNOWN = 'unknown'¶
The value is expected to exist but is not known.
- ASKED_UNKNOWN = 'asked-unknown'¶
The source was asked but does not know the value.
- TEMP_UNKNOWN = 'temp-unknown'¶
There is reason to expect (from the workflow) that the value may become known.
- NOT_ASKED = 'not-asked'¶
The workflow didn’t lead to this value being known.
- ASKED_DECLINED = 'asked-declined'¶
The source was asked but declined to answer.
- MASKED = 'masked'¶
The information is not available due to security, privacy or related reasons.
- NOT_APPLICABLE = 'not-applicable'¶
There is no proper value for this element (e.g. last menstrual period for a male).
- UNSUPPORTED = 'unsupported'¶
The source system wasn’t capable of supporting this element.
- AS_TEXT = 'as-text'¶
The content of the data is represented in the resource narrative.
- ERROR = 'error'¶
Some system or workflow process error means that the information is not available.
- NOT_A_NUMBER = 'not-a-number'¶
The numeric value is undefined or unrepresentable due to a floating point error.
- NEGATIVE_INFINITY = 'negative-infinity'¶
The numeric value is excessively low and unrepresentable due to a floating point error.
- POSITIVE_INFINITY = 'positive-infinity'¶
The numeric value is excessively high and unrepresentable due to a floating point error.
- NOT_PERFORMED = 'not-performed'¶
The value is not available because the observation procedure was not performed.
- NOT_PERMITTED = 'not-permitted'¶
The value is not permitted in this context (e.g. due to profiles, or the base data types).
- class DataAndProvenanceBundles(data_bundle: Bundle, provenance_bundle: Bundle)[source]¶
Bases:
NamedTupleA pair of FHIR bundles: one holding data resources, one holding provenance resources.
- data_bundle: Bundle¶
The bundle containing data resources (e.g. Patient, Observation).
- provenance_bundle: Bundle¶
The bundle containing Provenance and optionally Device resources.
- class TransactionBuilder[source]¶
Bases:
objectBuilder for FHIR transaction bundles, using the update-as-create approach by default.
- fail_on_duplicate_entries() Self[source]¶
Raise when multiple resources with the same id are added, once the bundle is built.
- add_delete_entry(resource: Reference) Self[source]¶
Add a reference to a resource that should be deleted as part of the transaction.
- add_delete_entries(*resources: Reference) Self[source]¶
Add references to resources that should be deleted as part of the transaction.
- with_full_url_base(base_url: str) Self[source]¶
Set an absolute base URL used to build each entry’s
fullUrl.Each entry’s
fullUrlbecomes<base_url>/<ResourceType>/<id>, making it absolute as FHIR requires. PlainResourceType/idreferences used elsewhere in the bundle (e.g. in aProvenance.target) still resolve correctly against it, since those match by the tail of a hierarchicalfullUrl. The base URL does not need to be a real, dereferenceable server endpoint.- Parameters:
base_url – An absolute base URL, e.g.
https://example.org/fhir. A trailing slash is optional.
- with_provenance(who: Reference | Device, what: Reference) Self[source]¶
Include a Provenance resource in the bundle.
If the bundle contains both delete and update/create entries, two Provenance resources are included. The
Provenance.idis derived from the hash ofwhoandwhat.- Parameters:
who – The agent responsible for the transformation or deletion, as
Provenance .agent.who. This is typically the transformation service itself. Passing aDeviceadds that resource to the bundle and references it instead.what – A reference to the resource that is the source of the transformation, as
Provenance.entity.what.
- build() Bundle[source]¶
Build a FHIR Bundle with the configured type.
- Raises:
ValueError –
fail_on_duplicate_entries()is enabled and duplicate resource ids were found.
- build_with_separate_provenance() DataAndProvenanceBundles[source]¶
Build the data resources and the provenance resources as two separate bundles.
The data bundle holds only the data resources and delete entries; the provenance bundle holds the Provenance resource(s) and, if configured via
with_provenance(), the Device. The provenance bundle is always of typetransaction.- Raises:
RuntimeError – Provenance has not been enabled via
with_provenance().ValueError –
fail_on_duplicate_entries()is enabled and duplicate resource ids were found.
- create_reference_to(resource: Resource) Reference[source]¶
Create a reference to
resource, in the formResourceType/id.- Parameters:
resource – The FHIR resource to create a reference to. It must have a non-blank id.
- Raises:
ValueError – The resource has no id, or a blank one.
- create_reference_to_identifier(identifier: Identifier, resource_type: str, *, algorithm: str = 'sha256') Reference[source]¶
Create a reference to the resource identified by
identifier.The reference is of the form
<resource_type>/sha256(system|value).- Parameters:
identifier – An identifier of the FHIR resource to create a reference to.
resource_type – The resource type to include in the reference.
algorithm – The
hashlibalgorithm to hash with.
- Raises:
ValueError – The identifier’s system or value is missing or blank.
- data_absent_reason(reason: DataAbsentReason | None = None) Extension[source]¶
Return a fresh data-absent-reason extension.
- Parameters:
reason – The reason the value is absent. When omitted, the returned extension is a bare template without a value.
to_fhir.transaction_builder¶
Builder for creating FHIR transaction bundles.
- class DataAndProvenanceBundles(data_bundle: Bundle, provenance_bundle: Bundle)[source]¶
Bases:
NamedTupleA pair of FHIR bundles: one holding data resources, one holding provenance resources.
- data_bundle: Bundle¶
The bundle containing data resources (e.g. Patient, Observation).
- provenance_bundle: Bundle¶
The bundle containing Provenance and optionally Device resources.
- class TransactionBuilder[source]¶
Bases:
objectBuilder for FHIR transaction bundles, using the update-as-create approach by default.
- fail_on_duplicate_entries() Self[source]¶
Raise when multiple resources with the same id are added, once the bundle is built.
- add_delete_entry(resource: Reference) Self[source]¶
Add a reference to a resource that should be deleted as part of the transaction.
- add_delete_entries(*resources: Reference) Self[source]¶
Add references to resources that should be deleted as part of the transaction.
- with_full_url_base(base_url: str) Self[source]¶
Set an absolute base URL used to build each entry’s
fullUrl.Each entry’s
fullUrlbecomes<base_url>/<ResourceType>/<id>, making it absolute as FHIR requires. PlainResourceType/idreferences used elsewhere in the bundle (e.g. in aProvenance.target) still resolve correctly against it, since those match by the tail of a hierarchicalfullUrl. The base URL does not need to be a real, dereferenceable server endpoint.- Parameters:
base_url – An absolute base URL, e.g.
https://example.org/fhir. A trailing slash is optional.
- with_provenance(who: Reference | Device, what: Reference) Self[source]¶
Include a Provenance resource in the bundle.
If the bundle contains both delete and update/create entries, two Provenance resources are included. The
Provenance.idis derived from the hash ofwhoandwhat.- Parameters:
who – The agent responsible for the transformation or deletion, as
Provenance .agent.who. This is typically the transformation service itself. Passing aDeviceadds that resource to the bundle and references it instead.what – A reference to the resource that is the source of the transformation, as
Provenance.entity.what.
- build() Bundle[source]¶
Build a FHIR Bundle with the configured type.
- Raises:
ValueError –
fail_on_duplicate_entries()is enabled and duplicate resource ids were found.
- build_with_separate_provenance() DataAndProvenanceBundles[source]¶
Build the data resources and the provenance resources as two separate bundles.
The data bundle holds only the data resources and delete entries; the provenance bundle holds the Provenance resource(s) and, if configured via
with_provenance(), the Device. The provenance bundle is always of typetransaction.- Raises:
RuntimeError – Provenance has not been enabled via
with_provenance().ValueError –
fail_on_duplicate_entries()is enabled and duplicate resource ids were found.
to_fhir.fhir_codings¶
Factory functions for default Coding templates used across to-FHIR®.
Each function returns a fresh instance, since Coding is mutable.
to_fhir.fhir_extensions¶
Factory functions for default Extension templates used across to-FHIR®.
- DATA_ABSENT_REASON_URL = 'http://hl7.org/fhir/StructureDefinition/data-absent-reason'¶
The data-absent-reason extension URL.
- DATA_ABSENT_REASON_CODE_SYSTEM = 'http://terminology.hl7.org/CodeSystem/data-absent-reason'¶
The code system backing
DataAbsentReason.
- class DataAbsentReason(*values)[source]¶
Bases:
StrEnumCodes from the
data-absent-reasoncode system.See CodeSystem: DataAbsentReason. Members are their own FHIR code, so
DataAbsentReason.NOT_ASKED == "not-asked".- UNKNOWN = 'unknown'¶
The value is expected to exist but is not known.
- ASKED_UNKNOWN = 'asked-unknown'¶
The source was asked but does not know the value.
- TEMP_UNKNOWN = 'temp-unknown'¶
There is reason to expect (from the workflow) that the value may become known.
- NOT_ASKED = 'not-asked'¶
The workflow didn’t lead to this value being known.
- ASKED_DECLINED = 'asked-declined'¶
The source was asked but declined to answer.
- MASKED = 'masked'¶
The information is not available due to security, privacy or related reasons.
- NOT_APPLICABLE = 'not-applicable'¶
There is no proper value for this element (e.g. last menstrual period for a male).
- UNSUPPORTED = 'unsupported'¶
The source system wasn’t capable of supporting this element.
- AS_TEXT = 'as-text'¶
The content of the data is represented in the resource narrative.
- ERROR = 'error'¶
Some system or workflow process error means that the information is not available.
- NOT_A_NUMBER = 'not-a-number'¶
The numeric value is undefined or unrepresentable due to a floating point error.
- NEGATIVE_INFINITY = 'negative-infinity'¶
The numeric value is excessively low and unrepresentable due to a floating point error.
- POSITIVE_INFINITY = 'positive-infinity'¶
The numeric value is excessively high and unrepresentable due to a floating point error.
- NOT_PERFORMED = 'not-performed'¶
The value is not available because the observation procedure was not performed.
- NOT_PERMITTED = 'not-permitted'¶
The value is not permitted in this context (e.g. due to profiles, or the base data types).
- data_absent_reason(reason: DataAbsentReason | None = None) Extension[source]¶
Return a fresh data-absent-reason extension.
- Parameters:
reason – The reason the value is absent. When omitted, the returned extension is a bare template without a value.
to_fhir.fhir_systems¶
Canonical FHIR coding system URIs used across to-FHIR®.
- UCUM = 'http://unitsofmeasure.org'¶
The UCUM system.
- LOINC = 'http://loinc.org'¶
The LOINC system.
- SNOMED = 'http://snomed.info/sct'¶
The SNOMED CT system.
- ATC = 'http://fhir.de/CodeSystem/bfarm/atc'¶
The ATC system.
- OPS = 'http://fhir.de/CodeSystem/bfarm/ops'¶
The OPS system.
- ICD10GM = 'http://fhir.de/CodeSystem/bfarm/icd-10-gm'¶
The ICD-10-GM system.
- PZN = 'http://fhir.de/CodeSystem/ifa/pzn'¶
The PZN system.
to_fhir.id_utils¶
Utilities for deterministic FHIR resource ids.
- DEFAULT_ALGORITHM = 'sha256'¶
The hash algorithm used unless a different
hashlibalgorithm is requested.
- from_identifier(identifier: Identifier, resource_type: str | None = None, *, algorithm: str = 'sha256') str[source]¶
Compute a deterministic id from a FHIR identifier by hashing its system and value.
- Parameters:
identifier – The FHIR identifier to compute the id from.
resource_type – When given, the id is returned as the relative reference
<resource_type>/<id>instead of the bare id.algorithm – The
hashlibalgorithm to hash with, e.g."sha256".
- Returns:
The deterministic id, optionally qualified with
resource_type.- Raises:
ValueError – The identifier’s system or value is missing or blank.
to_fhir.reference_utils¶
Utilities for creating FHIR references to resources.
- create_reference_to(resource: Resource) Reference[source]¶
Create a reference to
resource, in the formResourceType/id.- Parameters:
resource – The FHIR resource to create a reference to. It must have a non-blank id.
- Raises:
ValueError – The resource has no id, or a blank one.
- create_reference_to_identifier(identifier: Identifier, resource_type: str, *, algorithm: str = 'sha256') Reference[source]¶
Create a reference to the resource identified by
identifier.The reference is of the form
<resource_type>/sha256(system|value).- Parameters:
identifier – An identifier of the FHIR resource to create a reference to.
resource_type – The resource type to include in the reference.
algorithm – The
hashlibalgorithm to hash with.
- Raises:
ValueError – The identifier’s system or value is missing or blank.