Skip to content
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

Merged
merged 19 commits into from
Aug 2, 2023

Conversation

robertmitchellv
Copy link
Collaborator

@robertmitchellv robertmitchellv commented Aug 1, 2023

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

Robert Mitchell added 2 commits July 31, 2023 15:50
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
Comment on lines 207 to 240
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
Copy link
Collaborator

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.

  1. 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.
  2. bundle should simply be a FHIR bundle. The response and FhirResource 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 the response.FhirResource key.

Copy link
Contributor

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.

and "resourceType" in bundle["response"]["FhirResource"]
):
return bundle["response"]["FhirResource"]["resourceType"] == "Bundle"
return False
Copy link
Contributor

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?

loinc_ecr = "55751-2"
loinc_rr = "88085-6"
loinc_elr = "11502-2"
loinc_vxu = "60484-3"
Copy link
Contributor

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.

Copy link
Contributor

@BradySkylight BradySkylight left a 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
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #755 (7330c0f) into main (1a450e8) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #755   +/-   ##
=======================================
  Coverage   96.32%   96.32%           
=======================================
  Files          45       45           
  Lines        2557     2557           
=======================================
  Hits         2463     2463           
  Misses         94       94           
Flag Coverage Δ
unit-tests 96.32% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@robertmitchellv
Copy link
Collaborator Author

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:
A. leave it where it is in the SDK, close this, and move on to the next ticket, where we'll import the function into the fhir converter's app/main.py; or,
B. put it in the fhir converter's app/main.py rather than the SDK

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 phdi into that container's dependencies.

@BradySkylight
Copy link
Contributor

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: A. leave it where it is in the SDK, close this, and move on to the next ticket, where we'll import the function into the fhir converter's app/main.py; or, B. put it in the fhir converter's app/main.py rather than the SDK

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 phdi into that container's dependencies.

I vote for B

@DanPaseltiner
Copy link
Collaborator

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: A. leave it where it is in the SDK, close this, and move on to the next ticket, where we'll import the function into the fhir converter's app/main.py; or, B. put it in the fhir converter's app/main.py rather than the SDK
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 phdi into that container's dependencies.

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.

@robertmitchellv robertmitchellv changed the title Add minimum provenance to SDK for data source Add minimum provenance to FHIR converter for data source Aug 2, 2023
@robertmitchellv robertmitchellv marked this pull request as ready for review August 2, 2023 21:17
Copy link
Collaborator

@DanPaseltiner DanPaseltiner left a 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.

Comment on lines 186 to 189
if data_source == "":
raise ValueError(
"The data_source parameter must be a defined, non-empty string."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


def add_data_source_to_bundle(bundle: dict, data_source: str) -> dict:
"""
Given a FHIR bundle and a a data source parameter the function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Given a FHIR bundle and a a data source parameter the function
Given a FHIR bundle and a data source parameter the function

Copy link
Collaborator Author

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

@robertmitchellv robertmitchellv merged commit ca1ffbf into main Aug 2, 2023
@robertmitchellv robertmitchellv deleted the robert/add-data-source-to-bundle branch August 2, 2023 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create an add_data_source_to_bundle function in the SDK
3 participants