From ad4a2020572faad10185e738e0b6e7b44017f400 Mon Sep 17 00:00:00 2001 From: Josh Nygaard Date: Thu, 2 Jan 2025 10:22:06 -0500 Subject: [PATCH] Correct FHIR produced by TCRS --- .../src/app/services/ecrSummaryService.tsx | 56 +++++-------------- .../trigger-code-reference/app/utils.py | 2 +- .../tests/test_utils.py | 8 ++- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/containers/ecr-viewer/src/app/services/ecrSummaryService.tsx b/containers/ecr-viewer/src/app/services/ecrSummaryService.tsx index 192fe8f7fc..416f277c29 100644 --- a/containers/ecr-viewer/src/app/services/ecrSummaryService.tsx +++ b/containers/ecr-viewer/src/app/services/ecrSummaryService.tsx @@ -1,4 +1,10 @@ -import { Address, Bundle, Condition, Extension, Observation } from "fhir/r4"; +import { + Address, + Bundle, + Condition, + DiagnosticReport, + Observation, +} from "fhir/r4"; import { evaluateData, PathMappings } from "@/app/view-data/utils/utils"; import { formatAddress, @@ -13,39 +19,10 @@ import { } from "./evaluateFhirDataService"; import { DisplayDataProps } from "@/app/view-data/components/DataDisplay"; import { returnProblemsTable } from "@/app/view-data/components/common"; -import { - LabReport, - evaluateLabInfoData, - isLabReportElementDataList, -} from "./labsService"; +import { evaluateLabInfoData, isLabReportElementDataList } from "./labsService"; import { ConditionSummary } from "@/app/view-data/components/EcrSummary"; import React from "react"; -/** - * ExtensionConditionCode extends the FHIR Extension interface to include a 'coding' property. - * This property aligns with the CDC's ReportStream specifications for condition - * to code mappings, using 'coding.code' for descriptive names of testing methods. - * - * Refer to the ReportStream documentation for details: - * https://github.com/CDCgov/prime-reportstream/blob/master/prime-router/docs/design/0023-condition-to-code-mapping.md - */ -interface ExtensionConditionCode extends Extension { - coding?: { code: string; system: string }[]; -} - -interface ConditionStamped extends Condition { - extension?: ExtensionConditionCode[]; -} - -interface LabReportStamped extends LabReport { - id: string; - extension?: ExtensionConditionCode[]; -} - -interface ObservationStamped extends Observation { - extension?: ExtensionConditionCode[]; -} - /** * Evaluates and retrieves patient details from the FHIR bundle using the provided path mappings. * @param fhirBundle - The FHIR bundle containing patient data. @@ -266,7 +243,7 @@ export const evaluateEcrSummaryRelevantClinicalDetails = ( return [{ value: noData, dividerLine: true }]; } - const problemsList: ConditionStamped[] = evaluate( + const problemsList: Condition[] = evaluate( fhirBundle, fhirPathMappings["activeProblems"], ); @@ -275,7 +252,7 @@ export const evaluateEcrSummaryRelevantClinicalDetails = ( (ext) => ext.url === "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code" && - ext.coding?.some((item) => item.code === snomedCode), + ext.valueCoding?.code === snomedCode, ), ); @@ -313,7 +290,7 @@ export const evaluateEcrSummaryRelevantLabResults = ( return [{ value: noData, dividerLine: true }]; } - const labReports: LabReportStamped[] = evaluate( + const labReports: DiagnosticReport[] = evaluate( fhirBundle, fhirPathMappings["diagnosticReports"], ); @@ -322,22 +299,19 @@ export const evaluateEcrSummaryRelevantLabResults = ( (ext) => ext.url === "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code" && - ext.coding?.some((item) => item.code === snomedCode), + ext.valueCoding?.code === snomedCode, ), ); const obsIdsWithCode: (string | undefined)[] = ( - evaluate( - fhirBundle, - fhirPathMappings["observations"], - ) as ObservationStamped[] + evaluate(fhirBundle, fhirPathMappings["observations"]) as Observation[] ) .filter((entry) => entry.extension?.some( (ext) => ext.url === "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code" && - ext.coding?.some((item) => item.code === snomedCode), + ext.valueCoding?.code === snomedCode, ), ) .map((entry) => entry.id); @@ -351,7 +325,7 @@ export const evaluateEcrSummaryRelevantLabResults = ( return false; } - return lab.result.some((result) => { + return lab.result?.some((result) => { if (result.reference) { const referenceId = result.reference.replace(/^Observation\//, ""); return obsIds.has(referenceId); diff --git a/containers/trigger-code-reference/app/utils.py b/containers/trigger-code-reference/app/utils.py index 99e0114d03..9688800ac8 100644 --- a/containers/trigger-code-reference/app/utils.py +++ b/containers/trigger-code-reference/app/utils.py @@ -222,7 +222,7 @@ def add_code_extension_and_human_readable_name(resource: dict, code: str) -> dic resource["extension"].append( { "url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code", - "coding": [{"code": code, "system": "http://snomed.info/sct"}], + "valueCoding": {"code": code, "system": "http://snomed.info/sct"}, } ) diff --git a/containers/trigger-code-reference/tests/test_utils.py b/containers/trigger-code-reference/tests/test_utils.py index e7fc777c32..39815d0d6a 100644 --- a/containers/trigger-code-reference/tests/test_utils.py +++ b/containers/trigger-code-reference/tests/test_utils.py @@ -184,7 +184,9 @@ def test_add_code_extension_and_human_readable_name(mock_get_condition_name): for ext in stamped_obs.get("extension", []): if ext == { "url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code", - "coding": [{"code": "test_obs_code", "system": "http://snomed.info/sct"}], + "valueCoding": [ + {"code": "test_obs_code", "system": "http://snomed.info/sct"} + ], }: found_stamp = True break @@ -199,7 +201,9 @@ def test_add_code_extension_and_human_readable_name(mock_get_condition_name): for ext in stamped_condition.get("extension", []): if ext == { "url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code", - "coding": [{"code": "test_cond_code", "system": "http://snomed.info/sct"}], + "valueCoding": [ + {"code": "test_cond_code", "system": "http://snomed.info/sct"} + ], }: found_stamp = True break