FHIR Helpers
FHIR utilities for HealthChain.
add_coding_to_codeable_concept(codeable_concept, code, system, display=None)
Add a coding to an existing CodeableConcept.
Useful for adding standardized codes (e.g., SNOMED CT) to resources that already have codes from other systems (e.g., ICD-10).
| PARAMETER | DESCRIPTION |
|---|---|
codeable_concept
|
The CodeableConcept to add coding to
TYPE:
|
code
|
The code value from the code system
TYPE:
|
system
|
The code system URI
TYPE:
|
display
|
Optional display text for the code
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CodeableConcept
|
The updated CodeableConcept with the new coding added
TYPE:
|
Example
Add SNOMED CT code to a condition that has ICD-10
condition_code = condition.code condition_code = add_coding_to_codeable_concept( ... condition_code, ... code="44054006", ... system="http://snomed.info/sct", ... display="Type 2 diabetes mellitus" ... )
Source code in healthchain/fhir/helpers.py
add_provenance_metadata(resource, source, tag_code=None, tag_display=None)
Add provenance metadata to a FHIR resource.
Adds source system identifier, timestamp, and optional processing tags to track data lineage and transformations for audit trails.
| PARAMETER | DESCRIPTION |
|---|---|
resource
|
The FHIR resource to annotate
TYPE:
|
source
|
Name of the source system (e.g., "epic", "cerner")
TYPE:
|
tag_code
|
Optional tag code for processing operations (e.g., "aggregated", "deduplicated")
TYPE:
|
tag_display
|
Optional display text for the tag
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Resource
|
The resource with added provenance metadata
TYPE:
|
Example
condition = create_condition(subject="Patient/123", code="E11.9") condition = add_provenance_metadata(condition, "epic", "aggregated", "Aggregated from source")
Source code in healthchain/fhir/helpers.py
add_resource(bundle, resource, full_url=None)
Add a resource to a bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to add to
TYPE:
|
resource
|
The resource to add, e.g. Condition, MedicationStatement, AllergyIntolerance
TYPE:
|
full_url
|
Optional full URL for the resource
TYPE:
|
Source code in healthchain/fhir/bundle_helpers.py
create_allergy_intolerance(patient, code=None, display=None, system='http://snomed.info/sct')
Create a minimal active FHIR AllergyIntolerance. If you need to create a more complex allergy intolerance, use the FHIR AllergyIntolerance resource directly. https://build.fhir.org/allergyintolerance.html
| PARAMETER | DESCRIPTION |
|---|---|
patient
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
code
|
The allergen code
TYPE:
|
display
|
The display name for the allergen
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AllergyIntolerance
|
A FHIR AllergyIntolerance resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_bundle(bundle_type='collection')
Create an empty FHIR Bundle. https://www.hl7.org/fhir/bundle.html
| PARAMETER | DESCRIPTION |
|---|---|
bundle_type
|
The type of bundle (default: collection) Valid types: document, message, transaction, transaction-response, batch, batch-response, history, searchset, collection
TYPE:
|
Source code in healthchain/fhir/bundle_helpers.py
create_condition(subject, clinical_status='active', code=None, display=None, system='http://snomed.info/sct')
Create a minimal active FHIR Condition. If you need to create a more complex condition, use the FHIR Condition resource directly. https://build.fhir.org/condition.html
| PARAMETER | DESCRIPTION |
|---|---|
subject
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
clinical_status
|
REQUIRED. Clinical status (default: active)
TYPE:
|
code
|
The condition code
TYPE:
|
display
|
The display name for the condition
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Condition
|
A FHIR Condition resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_document_reference(data=None, url=None, content_type=None, status='current', description='DocumentReference created by HealthChain', attachment_title='Attachment created by HealthChain')
Create a minimal FHIR DocumentReference. If you need to create a more complex document reference, use the FHIR DocumentReference resource directly. https://build.fhir.org/documentreference.html
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data content of the document attachment
TYPE:
|
url
|
URL where the document can be accessed
TYPE:
|
content_type
|
MIME type of the document (e.g. "application/pdf", "text/xml", "image/png")
TYPE:
|
status
|
REQUIRED. Status of the document reference (default: current)
TYPE:
|
description
|
Description of the document reference
TYPE:
|
attachment_title
|
Title for the document attachment
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DocumentReference
|
A FHIR DocumentReference resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_medication_statement(subject, status='recorded', code=None, display=None, system='http://snomed.info/sct')
Create a minimal recorded FHIR MedicationStatement. If you need to create a more complex medication statement, use the FHIR MedicationStatement resource directly. https://build.fhir.org/medicationstatement.html
| PARAMETER | DESCRIPTION |
|---|---|
subject
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
status
|
REQUIRED. Status of the medication (default: recorded)
TYPE:
|
code
|
The medication code
TYPE:
|
display
|
The display name for the medication
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MedicationStatement
|
A FHIR MedicationStatement resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_resource_from_dict(resource_dict, resource_type)
Create a FHIR resource instance from a dictionary
| PARAMETER | DESCRIPTION |
|---|---|
resource_dict
|
Dictionary representation of the resource
TYPE:
|
resource_type
|
Type of FHIR resource to create
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[Resource]
|
Optional[Resource]: FHIR resource instance or None if creation failed |
Source code in healthchain/fhir/helpers.py
create_single_attachment(content_type=None, data=None, url=None, title='Attachment created by HealthChain')
Create a minimal FHIR Attachment.
Creates a FHIR Attachment resource with basic fields. Either data or url should be provided. If data is provided, it will be base64 encoded.
| PARAMETER | DESCRIPTION |
|---|---|
content_type
|
The MIME type of the content
TYPE:
|
data
|
The actual data content to be base64 encoded
TYPE:
|
url
|
The URL where the data can be found
TYPE:
|
title
|
A title for the attachment (default: "Attachment created by HealthChain")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Attachment
|
A FHIR Attachment resource with basic metadata and content
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_single_codeable_concept(code, display=None, system='http://snomed.info/sct')
Create a minimal FHIR CodeableConcept with a single coding.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
REQUIRED. The code value from the code system
TYPE:
|
display
|
The display name for the code
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CodeableConcept
|
A FHIR CodeableConcept resource with a single coding
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_single_reaction(code, display=None, system='http://snomed.info/sct', severity=None)
Create a minimal FHIR Reaction with a single coding.
Creates a FHIR Reaction object with a single manifestation coding. The manifestation describes the clinical reaction that was observed. The severity indicates how severe the reaction was.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
REQUIRED. The code value from the code system representing the reaction manifestation
TYPE:
|
display
|
The display name for the manifestation code
TYPE:
|
system
|
The code system for the manifestation code (default: SNOMED CT)
TYPE:
|
severity
|
The severity of the reaction (mild, moderate, severe)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
A list containing a single FHIR Reaction dictionary with manifestation and severity fields |
Source code in healthchain/fhir/helpers.py
extract_resources(bundle, resource_type)
Remove resources of a given type from a bundle and return them.
Useful for extracting and separating specific resource types (e.g., OperationOutcome) from a FHIR Bundle, modifying the bundle in place.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The FHIR Bundle to process (modified in place)
TYPE:
|
resource_type
|
The FHIR resource class or string name to extract (e.g., OperationOutcome or "OperationOutcome")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Resource]
|
List[Resource]: All resources of the specified type that were in the bundle |
Source code in healthchain/fhir/bundle_helpers.py
get_resources(bundle, resource_type)
Get all resources of a specific type from a bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to search
TYPE:
|
resource_type
|
String name of the resource type (e.g. "Condition") or the type itself
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Resource]
|
List of resources of the specified type |
Example
bundle = create_bundle()
Using string identifier
conditions = get_resources(bundle, "Condition") medications = get_resources(bundle, "MedicationStatement") allergies = get_resources(bundle, "AllergyIntolerance")
Or using type directly
from fhir.resources.condition import Condition conditions = get_resources(bundle, Condition)
Source code in healthchain/fhir/bundle_helpers.py
merge_bundles(bundles, bundle_type='collection', deduplicate=False, dedupe_key='id')
Merge multiple FHIR bundles into a single bundle.
Combines entries from multiple bundles while preserving resource metadata. Useful for aggregating search results from multiple FHIR sources.
| PARAMETER | DESCRIPTION |
|---|---|
bundles
|
List of bundles to merge
TYPE:
|
bundle_type
|
Type for the merged bundle (default: "collection")
TYPE:
|
deduplicate
|
If True, remove duplicate resources based on dedupe_key
TYPE:
|
dedupe_key
|
Resource attribute to use for deduplication (default: "id")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Bundle
|
A new bundle containing all entries from input bundles |
Example
Merge search results from multiple sources
epic_bundle = gateway.search(Condition, {"patient": "123"}, "epic") cerner_bundle = gateway.search(Condition, {"patient": "123"}, "cerner") merged = merge_bundles([epic_bundle, cerner_bundle], deduplicate=True)
Use in Document workflow
doc = Document(data=merged) doc.fhir.bundle # Contains all conditions from both sources
Source code in healthchain/fhir/bundle_helpers.py
read_content_attachment(document_reference, include_data=True)
Read the attachments in a human readable format from a FHIR DocumentReference content field.
| PARAMETER | DESCRIPTION |
|---|---|
document_reference
|
The FHIR DocumentReference resource
TYPE:
|
include_data
|
Whether to include the data of the attachments. If true, the data will be also be decoded (default: True)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[List[Dict[str, Any]]]
|
Optional[List[Dict[str, Any]]]: List of dictionaries containing attachment data and metadata, or None if no attachments are found: [ { "data": str, "metadata": Dict[str, Any] } ] |
Source code in healthchain/fhir/helpers.py
set_condition_category(condition, category)
Set the category of a FHIR Condition to either 'problem-list-item' or 'encounter-diagnosis'.
| PARAMETER | DESCRIPTION |
|---|---|
condition
|
The FHIR Condition resource to modify
TYPE:
|
category
|
The category to set. Must be 'problem-list-item' or 'encounter-diagnosis'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Condition
|
The modified FHIR Condition resource with the specified category set
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the category is not one of the allowed values. |
Source code in healthchain/fhir/helpers.py
set_resources(bundle, resources, resource_type, replace=True)
Set resources of a specific type in the bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to modify
TYPE:
|
resources
|
The new resources to add
TYPE:
|
resource_type
|
String name of the resource type (e.g. "Condition") or the type itself
TYPE:
|
replace
|
If True, remove existing resources of this type before adding new ones. If False, append new resources to existing ones. Defaults to True.
TYPE:
|
Example
bundle = create_bundle()
Append to existing resources (default behavior)
set_resources(bundle, [condition1, condition2], "Condition") set_resources(bundle, [medication1], "MedicationStatement")
Replace existing resources
set_resources(bundle, [condition3], "Condition", replace=True)
Or using type directly
from fhir.resources.condition import Condition set_resources(bundle, [condition1, condition2], Condition)
Source code in healthchain/fhir/bundle_helpers.py
bundle_helpers
Helper functions for working with FHIR Bundles. Patterns: - create_(): create a new FHIR bundle - add_(): add a resource to a bundle - get_(): get resources from a bundle - set_(): set resources in a bundle - merge_(): merge multiple bundles into a single bundle - extract_(): extract resources from a bundle
add_resource(bundle, resource, full_url=None)
Add a resource to a bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to add to
TYPE:
|
resource
|
The resource to add, e.g. Condition, MedicationStatement, AllergyIntolerance
TYPE:
|
full_url
|
Optional full URL for the resource
TYPE:
|
Source code in healthchain/fhir/bundle_helpers.py
create_bundle(bundle_type='collection')
Create an empty FHIR Bundle. https://www.hl7.org/fhir/bundle.html
| PARAMETER | DESCRIPTION |
|---|---|
bundle_type
|
The type of bundle (default: collection) Valid types: document, message, transaction, transaction-response, batch, batch-response, history, searchset, collection
TYPE:
|
Source code in healthchain/fhir/bundle_helpers.py
extract_resources(bundle, resource_type)
Remove resources of a given type from a bundle and return them.
Useful for extracting and separating specific resource types (e.g., OperationOutcome) from a FHIR Bundle, modifying the bundle in place.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The FHIR Bundle to process (modified in place)
TYPE:
|
resource_type
|
The FHIR resource class or string name to extract (e.g., OperationOutcome or "OperationOutcome")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Resource]
|
List[Resource]: All resources of the specified type that were in the bundle |
Source code in healthchain/fhir/bundle_helpers.py
get_resource_type(resource_type)
Get the resource type class from string or type.
| PARAMETER | DESCRIPTION |
|---|---|
resource_type
|
String name of the resource type (e.g. "Condition") or the type itself
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Type[Resource]
|
The resource type class |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the resource type is not supported or cannot be imported |
Source code in healthchain/fhir/bundle_helpers.py
get_resources(bundle, resource_type)
Get all resources of a specific type from a bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to search
TYPE:
|
resource_type
|
String name of the resource type (e.g. "Condition") or the type itself
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Resource]
|
List of resources of the specified type |
Example
bundle = create_bundle()
Using string identifier
conditions = get_resources(bundle, "Condition") medications = get_resources(bundle, "MedicationStatement") allergies = get_resources(bundle, "AllergyIntolerance")
Or using type directly
from fhir.resources.condition import Condition conditions = get_resources(bundle, Condition)
Source code in healthchain/fhir/bundle_helpers.py
merge_bundles(bundles, bundle_type='collection', deduplicate=False, dedupe_key='id')
Merge multiple FHIR bundles into a single bundle.
Combines entries from multiple bundles while preserving resource metadata. Useful for aggregating search results from multiple FHIR sources.
| PARAMETER | DESCRIPTION |
|---|---|
bundles
|
List of bundles to merge
TYPE:
|
bundle_type
|
Type for the merged bundle (default: "collection")
TYPE:
|
deduplicate
|
If True, remove duplicate resources based on dedupe_key
TYPE:
|
dedupe_key
|
Resource attribute to use for deduplication (default: "id")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Bundle
|
A new bundle containing all entries from input bundles |
Example
Merge search results from multiple sources
epic_bundle = gateway.search(Condition, {"patient": "123"}, "epic") cerner_bundle = gateway.search(Condition, {"patient": "123"}, "cerner") merged = merge_bundles([epic_bundle, cerner_bundle], deduplicate=True)
Use in Document workflow
doc = Document(data=merged) doc.fhir.bundle # Contains all conditions from both sources
Source code in healthchain/fhir/bundle_helpers.py
set_resources(bundle, resources, resource_type, replace=True)
Set resources of a specific type in the bundle.
| PARAMETER | DESCRIPTION |
|---|---|
bundle
|
The bundle to modify
TYPE:
|
resources
|
The new resources to add
TYPE:
|
resource_type
|
String name of the resource type (e.g. "Condition") or the type itself
TYPE:
|
replace
|
If True, remove existing resources of this type before adding new ones. If False, append new resources to existing ones. Defaults to True.
TYPE:
|
Example
bundle = create_bundle()
Append to existing resources (default behavior)
set_resources(bundle, [condition1, condition2], "Condition") set_resources(bundle, [medication1], "MedicationStatement")
Replace existing resources
set_resources(bundle, [condition3], "Condition", replace=True)
Or using type directly
from fhir.resources.condition import Condition set_resources(bundle, [condition1, condition2], Condition)
Source code in healthchain/fhir/bundle_helpers.py
helpers
Convenience functions for creating minimal FHIR resources. Patterns: - create_(): create a new FHIR resource with sensible defaults - useful for dev, use with caution - add_(): add data to resources with list fields safely (e.g. coding) - set_(): set the field of specific resources with soft validation (e.g. category) - read_(): return a human readable format of the data in a resource (e.g. attachments)
add_coding_to_codeable_concept(codeable_concept, code, system, display=None)
Add a coding to an existing CodeableConcept.
Useful for adding standardized codes (e.g., SNOMED CT) to resources that already have codes from other systems (e.g., ICD-10).
| PARAMETER | DESCRIPTION |
|---|---|
codeable_concept
|
The CodeableConcept to add coding to
TYPE:
|
code
|
The code value from the code system
TYPE:
|
system
|
The code system URI
TYPE:
|
display
|
Optional display text for the code
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CodeableConcept
|
The updated CodeableConcept with the new coding added
TYPE:
|
Example
Add SNOMED CT code to a condition that has ICD-10
condition_code = condition.code condition_code = add_coding_to_codeable_concept( ... condition_code, ... code="44054006", ... system="http://snomed.info/sct", ... display="Type 2 diabetes mellitus" ... )
Source code in healthchain/fhir/helpers.py
add_provenance_metadata(resource, source, tag_code=None, tag_display=None)
Add provenance metadata to a FHIR resource.
Adds source system identifier, timestamp, and optional processing tags to track data lineage and transformations for audit trails.
| PARAMETER | DESCRIPTION |
|---|---|
resource
|
The FHIR resource to annotate
TYPE:
|
source
|
Name of the source system (e.g., "epic", "cerner")
TYPE:
|
tag_code
|
Optional tag code for processing operations (e.g., "aggregated", "deduplicated")
TYPE:
|
tag_display
|
Optional display text for the tag
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Resource
|
The resource with added provenance metadata
TYPE:
|
Example
condition = create_condition(subject="Patient/123", code="E11.9") condition = add_provenance_metadata(condition, "epic", "aggregated", "Aggregated from source")
Source code in healthchain/fhir/helpers.py
create_allergy_intolerance(patient, code=None, display=None, system='http://snomed.info/sct')
Create a minimal active FHIR AllergyIntolerance. If you need to create a more complex allergy intolerance, use the FHIR AllergyIntolerance resource directly. https://build.fhir.org/allergyintolerance.html
| PARAMETER | DESCRIPTION |
|---|---|
patient
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
code
|
The allergen code
TYPE:
|
display
|
The display name for the allergen
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AllergyIntolerance
|
A FHIR AllergyIntolerance resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_condition(subject, clinical_status='active', code=None, display=None, system='http://snomed.info/sct')
Create a minimal active FHIR Condition. If you need to create a more complex condition, use the FHIR Condition resource directly. https://build.fhir.org/condition.html
| PARAMETER | DESCRIPTION |
|---|---|
subject
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
clinical_status
|
REQUIRED. Clinical status (default: active)
TYPE:
|
code
|
The condition code
TYPE:
|
display
|
The display name for the condition
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Condition
|
A FHIR Condition resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_document_reference(data=None, url=None, content_type=None, status='current', description='DocumentReference created by HealthChain', attachment_title='Attachment created by HealthChain')
Create a minimal FHIR DocumentReference. If you need to create a more complex document reference, use the FHIR DocumentReference resource directly. https://build.fhir.org/documentreference.html
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data content of the document attachment
TYPE:
|
url
|
URL where the document can be accessed
TYPE:
|
content_type
|
MIME type of the document (e.g. "application/pdf", "text/xml", "image/png")
TYPE:
|
status
|
REQUIRED. Status of the document reference (default: current)
TYPE:
|
description
|
Description of the document reference
TYPE:
|
attachment_title
|
Title for the document attachment
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DocumentReference
|
A FHIR DocumentReference resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_medication_statement(subject, status='recorded', code=None, display=None, system='http://snomed.info/sct')
Create a minimal recorded FHIR MedicationStatement. If you need to create a more complex medication statement, use the FHIR MedicationStatement resource directly. https://build.fhir.org/medicationstatement.html
| PARAMETER | DESCRIPTION |
|---|---|
subject
|
REQUIRED. Reference to the patient (e.g. "Patient/123")
TYPE:
|
status
|
REQUIRED. Status of the medication (default: recorded)
TYPE:
|
code
|
The medication code
TYPE:
|
display
|
The display name for the medication
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MedicationStatement
|
A FHIR MedicationStatement resource with an auto-generated ID prefixed with 'hc-'
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_resource_from_dict(resource_dict, resource_type)
Create a FHIR resource instance from a dictionary
| PARAMETER | DESCRIPTION |
|---|---|
resource_dict
|
Dictionary representation of the resource
TYPE:
|
resource_type
|
Type of FHIR resource to create
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[Resource]
|
Optional[Resource]: FHIR resource instance or None if creation failed |
Source code in healthchain/fhir/helpers.py
create_single_attachment(content_type=None, data=None, url=None, title='Attachment created by HealthChain')
Create a minimal FHIR Attachment.
Creates a FHIR Attachment resource with basic fields. Either data or url should be provided. If data is provided, it will be base64 encoded.
| PARAMETER | DESCRIPTION |
|---|---|
content_type
|
The MIME type of the content
TYPE:
|
data
|
The actual data content to be base64 encoded
TYPE:
|
url
|
The URL where the data can be found
TYPE:
|
title
|
A title for the attachment (default: "Attachment created by HealthChain")
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Attachment
|
A FHIR Attachment resource with basic metadata and content
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_single_codeable_concept(code, display=None, system='http://snomed.info/sct')
Create a minimal FHIR CodeableConcept with a single coding.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
REQUIRED. The code value from the code system
TYPE:
|
display
|
The display name for the code
TYPE:
|
system
|
The code system (default: SNOMED CT)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CodeableConcept
|
A FHIR CodeableConcept resource with a single coding
TYPE:
|
Source code in healthchain/fhir/helpers.py
create_single_reaction(code, display=None, system='http://snomed.info/sct', severity=None)
Create a minimal FHIR Reaction with a single coding.
Creates a FHIR Reaction object with a single manifestation coding. The manifestation describes the clinical reaction that was observed. The severity indicates how severe the reaction was.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
REQUIRED. The code value from the code system representing the reaction manifestation
TYPE:
|
display
|
The display name for the manifestation code
TYPE:
|
system
|
The code system for the manifestation code (default: SNOMED CT)
TYPE:
|
severity
|
The severity of the reaction (mild, moderate, severe)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
A list containing a single FHIR Reaction dictionary with manifestation and severity fields |
Source code in healthchain/fhir/helpers.py
read_content_attachment(document_reference, include_data=True)
Read the attachments in a human readable format from a FHIR DocumentReference content field.
| PARAMETER | DESCRIPTION |
|---|---|
document_reference
|
The FHIR DocumentReference resource
TYPE:
|
include_data
|
Whether to include the data of the attachments. If true, the data will be also be decoded (default: True)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[List[Dict[str, Any]]]
|
Optional[List[Dict[str, Any]]]: List of dictionaries containing attachment data and metadata, or None if no attachments are found: [ { "data": str, "metadata": Dict[str, Any] } ] |
Source code in healthchain/fhir/helpers.py
set_condition_category(condition, category)
Set the category of a FHIR Condition to either 'problem-list-item' or 'encounter-diagnosis'.
| PARAMETER | DESCRIPTION |
|---|---|
condition
|
The FHIR Condition resource to modify
TYPE:
|
category
|
The category to set. Must be 'problem-list-item' or 'encounter-diagnosis'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Condition
|
The modified FHIR Condition resource with the specified category set
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the category is not one of the allowed values. |