-
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
Conversation
one will check that a FHIR bundle is a response.FhirResource and the other will look for LOINC codes and added info the Meta.source
phdi/fhir/utils.py
Outdated
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" | ||
|
||
# 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 comment
The 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.
- We aren't going to be able to find provenance data within a FHIR bundle, we need to be able to provide a value for provenance data to this function and have it insert the value in
resource.meta
. bundle
should simply be a FHIR bundle. Theresponse
andFhirResource
keys are part of the response object from the FHIR converter, but are not part of the FHIR bundle. The FHIR bundle here is simply the value stored in theresponse.FhirResource
key.
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.
I agree with this and it makes sense.
phdi/fhir/utils.py
Outdated
and "resourceType" in bundle["response"]["FhirResource"] | ||
): | ||
return bundle["response"]["FhirResource"]["resourceType"] == "Bundle" | ||
return False |
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?
phdi/fhir/utils.py
Outdated
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 comment
The 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.
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.
This looks good to me! I like the changes you made
Codecov Report
@@ Coverage Diff @@
## main #755 +/- ##
=======================================
Coverage 96.32% 96.32%
=======================================
Files 45 45
Lines 2557 2557
=======================================
Hits 2463 2463
Misses 94 94
Flags with carried forward coverage won't be shown. Click here to find out more. |
i think this is in a good place now but there's still one matter that needs to be decided before we merge this to main and that relates to where this function should really live. We can: there have been a few conversations about this today in different 1:1 settings with different takes on where it should live so i thought i'd just post here for visibility. it seems the main reason to go with B is to avoid having to import |
I vote for B |
Since we are not already importing the SDK in the FHIR converter and it is already a pretty heavy and complex image I agree with @BradySkylight let's go with option B. If we need this functionality somewhere else in the future we can consider a refactor at that point. |
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.
LGTM! Thanks for putting this together.
phdi/fhir/utils.py
Outdated
if data_source == "": | ||
raise ValueError( | ||
"The data_source parameter must be a defined, non-empty string." | ||
) |
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.
❤️
phdi/fhir/utils.py
Outdated
|
||
def add_data_source_to_bundle(bundle: dict, data_source: str) -> dict: | ||
""" | ||
Given a FHIR bundle and a a data source parameter the function |
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.
Given a FHIR bundle and a a data source parameter the function | |
Given a FHIR bundle and a data source parameter the function |
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.
thanks for catching it! the file moved but i made the change
PULL REQUEST
Summary
Given a FHIR bundle and an data source add
Meta.source
to every resource in the bundle indicating a minimum amount of provenance, e.g.,"ELR"
,"ECR"
, or"VXU"
. Add this provenance inside of the FHIR converter building block before the response is returned so that downstream building blocks can leverage the provenance.Related Issue
Fixes #734 #731