-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minimum provenance to FHIR converter for data source #755
Changes from 2 commits
b31ea86
48fae20
6141092
58e0de1
27c5aed
b2ac5a0
e23bb1c
f4a6d97
dffa872
060d181
b96b29b
56fed1e
4d1fcfa
d9d015c
2048d65
eddeef6
5085229
d056aa3
7330c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,3 +170,71 @@ def get_one_line_address(address: dict) -> str: | |
if address.get("postalCode", ""): | ||
raw_one_line += f" {address['postalCode']}" | ||
return raw_one_line | ||
|
||
|
||
def is_response_fhirresource(bundle: dict) -> bool: | ||
""" | ||
Check if the FHIR bundle being passed as an argument is a | ||
response.FhirResource and that its status is "200 OK". | ||
|
||
:param bundle: The FHIR bundle to check for status "200 OK" | ||
and that it is a response.FhirResource. | ||
:return: A boolean indicating if the FHIR bundle is a | ||
response.FhirResource (True) or not (False). | ||
""" | ||
if ( | ||
"response" in bundle | ||
and "status" in bundle["response"] | ||
and bundle["response"]["status"] == "200 OK" | ||
and "FhirResource" in bundle["response"] | ||
and "resourceType" in bundle["response"]["FhirResource"] | ||
): | ||
return bundle["response"]["FhirResource"]["resourceType"] == "Bundle" | ||
return False | ||
|
||
|
||
def add_data_source_to_bundle(bundle: dict) -> dict: | ||
""" | ||
This function will search the FHIR bundle being passed as | ||
an argument for specific LOINC codes that indicate a minimum | ||
level of provenance for the source of the data, e.g., ELR, | ||
eICR, RR, and VXU. | ||
|
||
:param bundle: The response.FhirResource FHIR bundle to check | ||
for minimum provenance. | ||
:return: The entire FHIR bundle with the new field Meta.source | ||
""" | ||
if is_response_fhirresource(bundle): | ||
# Define the specific LOINC codes | ||
loinc_ecr = "55751-2" | ||
loinc_rr = "88085-6" | ||
loinc_elr = "11502-2" | ||
loinc_vxu = "60484-3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may not be able to expect or rely on a proper loinc code to be part of the FHIR bundle's being passed in. It may be better to have a parameter for the 'source_data' that can then be 'filtered' based upon a list of proper/expected results (ie... elr, ecr, etc...) and then add that to the resource.meta.source. Just my thoughts. |
||
|
||
# Iterate through the "entry" list in the FHIR bundle | ||
for entry in bundle["response"]["FhirResource"]["entry"]: | ||
resource = entry["resource"] | ||
if ( | ||
"type" in resource | ||
and "coding" in resource["type"] | ||
and len(resource["type"]["coding"]) > 0 | ||
): | ||
loinc_code = resource["type"]["coding"][0].get("code") | ||
if loinc_code == loinc_ecr: | ||
# Insert the new field Meta.source | ||
resource["meta"] = { | ||
"source": "eICR_55751-2_public-health-case-report" | ||
} | ||
elif loinc_code == loinc_rr: | ||
# Insert the new field Meta.source | ||
resource["meta"] = { | ||
"source": "RR_88085-6_reportability-response-report" | ||
} | ||
elif loinc_code == loinc_elr: | ||
# Insert the new field Meta.source | ||
resource["meta"] = {"source": "ELR_11502-2_laboratory-report"} | ||
elif loinc_code == loinc_vxu: | ||
# Insert the new field Meta.source | ||
resource["meta"] = {"source": "VXU_60484-3_cdc-immunization-panel"} | ||
|
||
return bundle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really appreciate the spirit of what we are doing here. However there are few things I think we need to change.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this and it makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this anticipated to be used? Are we expecting to always get a FHIR Bundle in an HTTP response?