Skip to content

Commit

Permalink
Correct FHIR produced by TCRS
Browse files Browse the repository at this point in the history
  • Loading branch information
JNygaard-Skylight authored and joshnygaard committed Jan 2, 2025
1 parent 61ac6d5 commit ad4a202
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 44 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
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
8 changes: 6 additions & 2 deletions containers/trigger-code-reference/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ad4a202

Please sign in to comment.