Skip to main content

A package to help with FHIR searching when needed search parameters are not available

Project description

FHIR Search Helper

PyPi Package Link Supported Python versions Downloads

A Python package to support FHIR Searching in contexts where needed search parameters are not supported

Quick Start

NOTE: Currently, the only option for capability_statement_file is 'epic_r4_metadata_edited.json'

from fhirsearchhelper import run_fhir_query

# This is using objects to store search params
output: Bundle | None = run_fhir_query(base_url='https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/', query_headers={'Authorization': 'Bearer 1234567'}, resource_type='Patient', search_params={'resourceType': 'Patient', 'search_params': {'name': 'Smith', 'deceased': 'true'}}, capability_statement_file='epic_r4_metadata_edited.json')

# This is using a raw query
output: Bundle | None = run_fhir_query(query_headers={'Authorization': 'Bearer 1234567'}, query='https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/Patient?name=Smith&deceased=true', capability_statement_file='epic_r4_metadata_edited.json')

A Note on Data Transformations

FHIRSearchHelper performs some data transformation when retrieving data from Epic to handle potential upstream data processing issues.

DocumentReferences

To support NLP of documents, all DocumentReferences that are retrieved that contain URLs that reference a Binary resource where the document text is stored, are "expanded" by retrieving that Binary resource and inserting the content into the DocumentReference.content field of the resource. If one of the attachment types is text/html and text/plain is not also present, the HTML is converted into base64-encoded plain-text for easier upstream NLP operations, without removing existing data.

MedicationRequests

All MedicationRequests that are retrieved that contain medicationReferences instead of medicationCodeableConcepts are "expanded" by retrieving the referenced Medication resource and inserting the codes of that resource into MedicationRequest.medicationCodeableConcept, and removing MedicationRequest.medicationReference.

Encounter Diagnosis Conditions

All Conditions that are retieved that have a Condition.category.code of encounter-diagnosis and do not have Condition.onsetDateTime, are "expanded" by retrieving the referenced Encounter in Condition.encounter and setting Condition.onsetDateTime to Encounter.period.start to indicate the beginning of a Condition. If there is no referenced Encounter or the referenced Encounter does not have a period, the onsetDateTime is set to 9999-12-31.

A Note on CapabilityStatements

In their current form, CapabilityStatements do not have a way to express when a search parameter for a resource is conditionally accepted. For example, in the Epic R4 CapabilityStatement, for the Condition resource, there exists a listed search parameter of code. In the description, there is a note that this search parameter is only accepted when the category is equal to infection. The only way that this conditional information would be known is by manual reading of the description. To alleviate this issue, and to avoid extreme custom handling in this package, currently you must edit the CapabilityStatement of any server with which you would like to use this package and add custom extensions to the search parameter. Keeping with the above example of the search parameter code for the Condition resource, here is what the CapabilityStatement.rest[0].resource.where(type = 'Condition').searchParam.where(name = 'code') element looks like:

{
    "name": "code",
    "type": "token",
    "documentation": "Search for Conditions with a specified code. This is only used when searching for infections.",
    "extension": [
        {
            "url": "true-when",
            "valueString": "category==infection"
        }
    ]
}

Here we have added an extension with a url of true-when that is a machine readable statement denoting when a search parameter is accepted by the server. It currently only supports == to show equality and in to show membership of a list (e.g. "category in [infection, health-problem]"). This also works for when a search parameter is limited in the values it will successfully search for. For example, here is what the CapabilityStatement.rest[0].resource.where(type = 'Condition').searchParam.where(name = 'category') element looks like:

{
    "name": "category",
    "type": "token",
    "documentation": "Search for Condition resources by category.",
    "extension": [
        {
            "url": "true-when",
            "valueString": "category in [dental-finding, encounter-diagnosis, genomics, health-concern, infection, medical-history, problem-list-item, reason-for-visit]"
        }
    ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhirsearchhelper-0.4.1.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhirsearchhelper-0.4.1-py3-none-any.whl (59.2 kB view details)

Uploaded Python 3

File details

Details for the file fhirsearchhelper-0.4.1.tar.gz.

File metadata

  • Download URL: fhirsearchhelper-0.4.1.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fhirsearchhelper-0.4.1.tar.gz
Algorithm Hash digest
SHA256 63425ed44d06bb399e56086679460681ebed071d9322e06fc18c71cfa3ba394f
MD5 21c2fe0c0f7d95bb3342b198bddfd0a8
BLAKE2b-256 aa60454ca6e593b3698f813b923cb625bb083a22e21d4c6f13aa138dd7a37f1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fhirsearchhelper-0.4.1.tar.gz:

Publisher: publish-pypi.yml on SmartChartSuite/FHIRSearchHelper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fhirsearchhelper-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fhirsearchhelper-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d318432f3a1fb84d958df90c7ffa9893ef4f9bd33e57166cc38b5d4f94445ba
MD5 4b9229368910c233ccccf688c58046cf
BLAKE2b-256 f1932bc8026e8027ddf6427cb2d50ef642cce163333a295a0f621f239f399c24

See more details on using hashes here.

Provenance

The following attestation bundles were made for fhirsearchhelper-0.4.1-py3-none-any.whl:

Publisher: publish-pypi.yml on SmartChartSuite/FHIRSearchHelper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page