FHIR support code for the Cumulus project
Project description
Cumulus FHIR Support
This library holds FHIR support code for the Cumulus project as a whole.
Installing
pip install cumulus-fhir-support
API
list_multiline_json_in_dir
Lists available multiline JSON files in the target directory (allowing filtering by FHIR resource).
Files with the .jsonl or .ndjson suffixes are supported.
Files with an additional .gz suffix will also be returned.
import cumulus_fhir_support as cfs
cfs.list_multiline_json_in_dir("/")
# {
# "/con1.ndjson.gz": "Condition",
# "/pat1.jsonl": "Patient",
# "/random.jsonl": None,
# }
cfs.list_multiline_json_in_dir("/", "Patient")
# {
# "/pat1.jsonl": "Patient",
# }
cfs.list_multiline_json_in_dir("/", ["Condition", "Patient"])
# {
# "/con1.ndjson.gz": "Condition",
# "/pat1.jsonl": "Patient",
# }
cfs.list_multiline_json_in_dir("/does-not-exist/")
# {}
cfs.list_multiline_json_in_dir("s3://mybucket/", fsspec_fs=s3_fs)
# {
# "/mybucket/procs.ndjson": "Procedure",
# }
read_multiline_json
Iterates over a single multiline JSON file.
Files with the .gz extension are automatically uncompressed.
import cumulus_fhir_support as cfs
list(cfs.read_multiline_json("/pat1.jsonl"))
# [
# {"resourceType": "Patient", "id": "pat1", "birthDate": "2020-10-16"},
# {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# ]
list(cfs.read_multiline_json("/does-not-exist.ndjson"))
# []
list(cfs.read_multiline_json("/mybucket/procs.ndjson", fsspec_fs=s3_fs))
# [
# {"resourceType": "Procedure", "id": "proc1", "status": "stopped"},
# ]
read_multiline_json_with_details
Lower level function to iterate over a single multiline JSON file, with extra line metadata.
Files with the .gz extension are automatically uncompressed.
import cumulus_fhir_support as cfs
list(cfs.read_multiline_json_with_details("/pat1.jsonl"))
# [
# {
# "json": {"resourceType": "Patient", "id": "pat1", "birthDate": "2020-10-16"},
# "line_num": 0,
# "byte_offset": 0,
# },
# {
# "json": {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# "line_num": 1,
# "byte_offset": 69,
# },
# ]
list(cfs.read_multiline_json_with_details("/pat1.jsonl"), offset=69)
# [
# {
# "json": {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# "line_num": 0,
# "byte_offset": 0,
# },
# ]
read_multiline_json_from_dir
Iterates over every JSON object in a directory (allowing filtering by FHIR resource).
Files with the .gz extension are automatically uncompressed.
import cumulus_fhir_support as cfs
list(cfs.read_multiline_json_from_dir("/"))
# [
# {"resourceType": "Condition", "id": "con1", "onsetDateTime": "2011-11-24"},
# {"resourceType": "Patient", "id": "pat1", "birthDate": "2020-10-16"},
# {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# {"description": "not a fhir object"},
# ]
list(cfs.read_multiline_json_from_dir("/", "Condition"))
# [
# {"resourceType": "Condition", "id": "con1", "onsetDateTime": "2011-11-24"},
# ]
list(cfs.read_multiline_json_from_dir("/", ["Condition", "Patient"]))
# [
# {"resourceType": "Condition", "id": "con1", "onsetDateTime": "2011-11-24"},
# {"resourceType": "Patient", "id": "pat1", "birthDate": "2020-10-16"},
# {"resourceType": "Patient", "id": "pat2", "birthDate": "2013-04-18"},
# ]
list(cfs.read_multiline_json_from_dir("/does-not-exist/"))
# []
list(cfs.read_multiline_json_from_dir("/mybucket/", fsspec_fs=s3_fs))
# [
# {"resourceType": "Procedure", "id": "proc1", "status": "stopped"},
# ]
pyarrow_schema_from_rows
Calculates a schema that can cover a given collection of FHIR objects.
import cumulus_fhir_support as cfs
rows = [
{
"resourceType": "Patient",
"id": "1",
"extension": [{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
"extension": [{
"url": "ombCategory",
"valueCoding": {
"code": "2135-2",
"display": "Hispanic or Latino",
"system": "urn:oid:2.16.840.1.113883.6.238",
},
}],
}],
},
]
# The resulting schema will be both wide (every toplevel column)
# and deep enough for every field in `rows`.
# That is, both the non-present toplevel field "telecom" and the deeper
# field "extension.extension.valueCoding.system" will be in the schema.
schema = cfs.pyarrow_schema_from_rows("Patient", rows)
FhirClient
Connect to a FHIR server with a variety of authentication options and retries built-in.
import cumulus_fhir_support as cfs
client = cfs.FhirClient("https://r4.smarthealthit.org", {"Patient"})
async with client:
response = await client.request("GET", "Patient/2cda5aad-e409-4070-9a15-e1c35c46ed5a")
print(response.json())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cumulus_fhir_support-1.12.0.tar.gz.
File metadata
- Download URL: cumulus_fhir_support-1.12.0.tar.gz
- Upload date:
- Size: 53.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38778fe3dc7d7e99fb0310f786d886c7f49f5ec2cc3f609491edb5200b7664d9
|
|
| MD5 |
dc823423542ebe794fbc18cd0411fff3
|
|
| BLAKE2b-256 |
ed3641b8e2eafcb6f5aea1a013476c6c4c71b6dd545e3119f24ef2c2adf8e002
|
Provenance
The following attestation bundles were made for cumulus_fhir_support-1.12.0.tar.gz:
Publisher:
pypi.yaml on smart-on-fhir/cumulus-fhir-support
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cumulus_fhir_support-1.12.0.tar.gz -
Subject digest:
38778fe3dc7d7e99fb0310f786d886c7f49f5ec2cc3f609491edb5200b7664d9 - Sigstore transparency entry: 1271144121
- Sigstore integration time:
-
Permalink:
smart-on-fhir/cumulus-fhir-support@4bf571666d7d0c285d723ceb4c777da02d9e58ec -
Branch / Tag:
refs/tags/v1.12.0 - Owner: https://github.com/smart-on-fhir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@4bf571666d7d0c285d723ceb4c777da02d9e58ec -
Trigger Event:
release
-
Statement type:
File details
Details for the file cumulus_fhir_support-1.12.0-py3-none-any.whl.
File metadata
- Download URL: cumulus_fhir_support-1.12.0-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9eeb6f110b2405dbd3de401b099d1c54ee577ee4240505cd8dd938e00845332
|
|
| MD5 |
0e8332c55839d9888c78beed138ccbd4
|
|
| BLAKE2b-256 |
04314ca7482ec2454ec882dd5552a086b16f7fe37ff497b2c79a7e6721ae7668
|
Provenance
The following attestation bundles were made for cumulus_fhir_support-1.12.0-py3-none-any.whl:
Publisher:
pypi.yaml on smart-on-fhir/cumulus-fhir-support
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cumulus_fhir_support-1.12.0-py3-none-any.whl -
Subject digest:
c9eeb6f110b2405dbd3de401b099d1c54ee577ee4240505cd8dd938e00845332 - Sigstore transparency entry: 1271144155
- Sigstore integration time:
-
Permalink:
smart-on-fhir/cumulus-fhir-support@4bf571666d7d0c285d723ceb4c777da02d9e58ec -
Branch / Tag:
refs/tags/v1.12.0 - Owner: https://github.com/smart-on-fhir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@4bf571666d7d0c285d723ceb4c777da02d9e58ec -
Trigger Event:
release
-
Statement type: