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

Check that RR isn't already present before attempting to merge with eICR #870

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions phdi/fhir/conversion/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def add_rr_data_to_eicr(rr, ecr):
rr = etree.fromstring(rr)
ecr = etree.fromstring(ecr)

if ecr.xpath('//*[@code="88085-6"]'):
print("This eCR has already been merged with RR data.")
return etree.tostring(ecr, encoding="unicode", method="xml")

# Create the tags for elements we'll be looking for
rr_tags = [
"templateId",
Expand Down
17 changes: 17 additions & 0 deletions tests/assets/fhir-converter/rr_extraction/merged_eICR.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><section><templateId extension="2017-04-01" root="2.16.840.1.113883.10.20.15.2.1.2"/>
<id root="4efa0e5c-c34c-429f-b5de-f1a13aef4a28"/>
<code code="88085-6" codeSystem="2.16.840.1.113883.6.1" displayName="Reportability response report Document Public health"/>
<title>Reportability Response</title>
<effectiveTime value="20220228190403+0000"/>
<confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25" displayName="Normal"/>
<entry>
<act classCode="ACT" moodCode="EVN">
<templateId extension="2017-04-01" root="2.16.840.1.113883.10.20.15.2.3.29"/>
<id root="39d966b9-8a3a-4024-93d8-138e97d5898a"/>
<code code="RRVS19" codeSystem="2.16.840.1.114222.4.5.274" codeSystemName="PHIN VS (CDC Local Coding System)" displayName="eICR processed"/>
</act>
</entry>
<entry typeCode="DRIV">
<organizer classCode="CLUSTER" moodCode="EVN"/>
</entry>
</section></ClinicalDocument>
27 changes: 27 additions & 0 deletions tests/fhir/conversion/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,30 @@ def test_add_rr_to_ecr():
assert temps is not None
assert temps.attrib["root"] == "2.16.840.1.113883.10.20.15.2.3.29"
assert "RRVS19" in status_code.attrib["code"]


def test_add_rr_to_ecr_rr_already_present(capfd):
with open(
pathlib.Path(__file__).parent.parent.parent
/ "assets"
/ "fhir-converter"
/ "rr_extraction"
/ "CDA_RR.xml"
) as fp:
rr = fp.read()

# This eICR has already been merged with an RR
with open(
pathlib.Path(__file__).parent.parent.parent
/ "assets"
/ "fhir-converter"
/ "rr_extraction"
/ "merged_eICR.xml"
) as fp:
ecr = fp.read()

merged_ecr = add_rr_data_to_eicr(rr, ecr)
assert merged_ecr == ecr

out, err = capfd.readouterr()
assert "This eCR has already been merged with RR data." in out
Loading