Skip to content

Commit

Permalink
Correct FHIR produced by TCRS (#3093)
Browse files Browse the repository at this point in the history
* Correct FHIR produced by TCRS

* Fix tests

* Missed a test

* Another test

* Update test bundles
  • Loading branch information
JNygaard-Skylight authored Jan 3, 2025
1 parent 6f59c59 commit 9f705c7
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 141 deletions.
56 changes: 15 additions & 41 deletions containers/ecr-viewer/src/app/services/ecrSummaryService.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -266,7 +243,7 @@ export const evaluateEcrSummaryRelevantClinicalDetails = (
return [{ value: noData, dividerLine: true }];
}

const problemsList: ConditionStamped[] = evaluate(
const problemsList: Condition[] = evaluate(
fhirBundle,
fhirPathMappings["activeProblems"],
);
Expand All @@ -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,
),
);

Expand Down Expand Up @@ -313,7 +290,7 @@ export const evaluateEcrSummaryRelevantLabResults = (
return [{ value: noData, dividerLine: true }];
}

const labReports: LabReportStamped[] = evaluate(
const labReports: DiagnosticReport[] = evaluate(
fhirBundle,
fhirPathMappings["diagnosticReports"],
);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,10 @@
"extension": [
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "263133002",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "263133002",
"system": "http://snomed.info/sct"
}
}
],
"onsetDateTime": "2019-04-16",
Expand Down
50 changes: 20 additions & 30 deletions containers/ecr-viewer/src/app/tests/assets/BundleEcrSummary.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -566,12 +564,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "50711007",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "50711007",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -640,12 +636,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -795,12 +789,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"subject": {
Expand Down Expand Up @@ -1016,12 +1008,10 @@
"extension": [
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
]
},
Expand Down
20 changes: 8 additions & 12 deletions containers/ecr-viewer/src/app/tests/assets/BundleLab.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
}
],
"subject": {
Expand Down Expand Up @@ -912,12 +910,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
}
],
"subject": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "test-snomed",
"system": "http://snomed.info/sct"
}
}
],
"subject": {
Expand Down
40 changes: 16 additions & 24 deletions containers/ecr-viewer/src/app/tests/assets/BundleLabNoLabIds.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -951,12 +949,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -1380,12 +1376,10 @@
"extension": [
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
]
},
Expand Down Expand Up @@ -1450,12 +1444,10 @@
"extension": [
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion containers/trigger-code-reference/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@
},
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"performer": [
Expand Down Expand Up @@ -378,12 +376,10 @@
"extension": [
{
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": "840539006",
"system": "http://snomed.info/sct"
}
]
"valueCoding": {
"code": "840539006",
"system": "http://snomed.info/sct"
}
}
],
"request": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ def test_tcr_stamping(setup, fhir_bundle):
for ext in extensions:
if ext == {
"url": "https://reportstream.cdc.gov/fhir/StructureDefinition/condition-code",
"coding": [
{
"code": reportable_condition_code,
"system": "http://snomed.info/sct",
}
],
"valueCoding": {
"code": reportable_condition_code,
"system": "http://snomed.info/sct",
},
}:
stamped_resources.append(resource.get("id"))
break
Expand Down
Loading

0 comments on commit 9f705c7

Please sign in to comment.