Skip to content

Commit

Permalink
Fix FHIR Conversion for Specimen in Lab Info (#2858)
Browse files Browse the repository at this point in the history
* fix FHIR conversion for specimen

* add test

* improve readability
  • Loading branch information
angelathe authored Nov 5, 2024
1 parent 9312bba commit 198d6a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,23 @@
{% endfor -%}
{% endif -%}
{% if comp.procedure.participant.participantRole.id -%}
{% if comp.procedure.participant.participantRole.playingEntity.code.translation -%}
{% assign translations = comp.procedure.participant.participantRole.playingEntity.code.translation | to_array -%}
{% assign playingEntity = comp.procedure.participant.participantRole.playingEntity -%}
{% if playingEntity.code.translation -%}
{% assign translations = playingEntity.code.translation | to_array -%}
{% if translations.first.displayName -%}
{% assign specValue = translations.first.displayName -%}
{% endif -%}
{% elsif comp.procedure.participant.participantRole.id.displayName -%}
{% assign specValue = comp.procedure.participant.participantRole.id.displayName -%}
{% elsif entry.organizer.component.procedure.participant.participantRole.playingEntity.code.displayName -%}
{% assign specValue = comp.procedure.participant.participantRole.playingEntity.code.displayName -%}
{% elsif playingEntity.code.originalText._ %}
{% assign specValue = playingEntity.code.originalText._ -%}
{% elsif playingEntity.code.displayName -%}
{% assign specValue = playingEntity.code.displayName -%}
{% else -%}
{% assign specValue = "None" -%}
{% endif -%}
{% else -%}
{% assign specValue = "None" -%}
{% endif -%}
{% endif -%}
{% endfor-%}
Expand Down
23 changes: 23 additions & 0 deletions containers/fhir-converter/tests/integration/test_FHIR-Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,26 @@ def test_encounter_diagnosis():
assert len(diagnosis_references) == 1

assert "Condition/d282a8e7-21b0-49ff-d7b0-1ce84b5d9b07" in diagnosis_references


@pytest.mark.integration
def test_lab_specimen():
input_data = open(
Path(__file__).parent.parent / "test_files/eICR_with_single_lab.xml"
).read()
request = {"input_data": input_data, "input_type": "ecr", "root_template": "EICR"}
ecr_conversion_response = httpx.post(CONVERT_TO_FHIR, json=request)
assert ecr_conversion_response.status_code == 200

specimen_sources = []
for entry in filter(
lambda entry: entry["resource"]["resourceType"] == "Observation",
ecr_conversion_response.json()["response"]["FhirResource"]["entry"],
):
for ext in entry["resource"].get("extension", []):
if ext["url"] == "http://hl7.org/fhir/R4/specimen.html":
for sub_ext in ext.get("extension", []):
if sub_ext["url"] == "specimen source":
specimen_sources.append(sub_ext["valueString"])

assert len(specimen_sources) == 4

Large diffs are not rendered by default.

0 comments on commit 198d6a2

Please sign in to comment.