Skip to content

Commit

Permalink
fix: handle more problem note formats (#2866)
Browse files Browse the repository at this point in the history
* fix: move things to fhir converter, unify make and docker

* ci: remove dotnet testing

* fix: undo debugging docker changes

* fix: more debugging clenaup

* docs: update README with current dev guidance and pointing to the fork

* feat: allow passing the converter tool path as an environment variable

* fix: rename environment variable

* fix: point to converter pr

* fix: sanitize and map the incoming original inner tex

* test: add unit tests

* Update containers/fhir-converter/Dockerfile
  • Loading branch information
mcmcgrath13 authored Nov 7, 2024
1 parent 00b6824 commit 80383e3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion containers/ecr-viewer/src/app/api/fhirPath.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ resolve: "Bundle.entry.resource.where(resourceType = %resourceType).where(id = %

# Clinical Info
activeProblems: "Bundle.entry.resource.where(resourceType='Condition').where(category.coding.code='problem-item-list')"
activeProblemsDisplay: "Condition.code.coding[0].display"
activeProblemsDisplay: "Condition.code.coding.display.first()"
activeProblemsOnsetDate: "Condition.onsetDateTime"
activeProblemsOnsetAge: "Condition.onsetAge.value"
activeProblemsComments: "Condition.note[0].text"
Expand Down
4 changes: 2 additions & 2 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { ToolTipElement } from "@/app/view-data/components/ToolTipElement";
import { ContactPoint } from "fhir/r4";
import sanitizeHtml from "sanitize-html";
import { sanitizeAndMap } from "../view-data/utils/utils";

interface Metadata {
[key: string]: string;
Expand Down Expand Up @@ -486,7 +486,7 @@ function processTable(table: Element): TableRow[] {
}

function getElementContent(el: Node): string {
return sanitizeHtml(el.textContent?.trim() ?? "");
return sanitizeAndMap(el.textContent?.trim() ?? "");
}

/**
Expand Down
18 changes: 17 additions & 1 deletion containers/ecr-viewer/src/app/tests/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isDataAvailable } from "@/app/view-data/utils/utils";
import { isDataAvailable, sanitizeAndMap } from "@/app/view-data/utils/utils";
import { loadYamlConfig } from "@/app/api/utils";
import { Bundle } from "fhir/r4";
import BundleWithTravelHistory from "./assets/BundleTravelHistory.json";
Expand Down Expand Up @@ -550,4 +550,20 @@ describe("Utils", () => {
expect(tip.className).not.toInclude("short-tooltip");
});
});

describe("sanitizeAndMap", () => {
it("should leave alone nice safe HTML", () => {
const html = "<p>hi there</p>";
const actual = sanitizeAndMap(html);
expect(actual).toBe(html);
});

it("should map xml-y HTML", () => {
const html = `<paragraph>hi there</paragraph><content ID="abc">I'm content</content><list><item>one</item><item>two</item></list>`;
const actual = sanitizeAndMap(html);
expect(actual).toBe(
`<p>hi there</p><span>I'm content</span><ul><li>one</li><li>two</li></ul>`,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const BuildRow: React.FC<BuildRowProps> = ({
hiddenRows.push(
<tr hidden={hiddenComment} id={`hidden-comment-${index}`}>
<td colSpan={columns.length} className={"hideableData p-list"}>
{splitStringWith(`${rowCellData}`, "<br>")}
{rowCellData}
</td>
</tr>,
);
Expand Down
10 changes: 6 additions & 4 deletions containers/ecr-viewer/src/app/view-data/components/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import {
PathMappings,
evaluateData,
noData,
sanitizeAndMap,
} from "@/app/view-data/utils/utils";
import {
Bundle,
CarePlanActivity,
CareTeamParticipant,
CodeableConcept,
Coding,
Condition,
FhirResource,
Immunization,
Expand All @@ -38,7 +40,6 @@ import {
} from "fhir/r4";
import { evaluate } from "@/app/view-data/utils/evaluate";
import parse from "html-react-parser";
import sanitizeHtml from "sanitize-html";
import { DisplayDataProps } from "@/app/view-data/components/DataDisplay";
import {
AdministeredMedication,
Expand Down Expand Up @@ -192,8 +193,8 @@ export const returnProblemsTable = (
problemsArray: Condition[],
mappings: PathMappings,
): React.JSX.Element | undefined => {
problemsArray = problemsArray.filter(
(entry) => entry.code?.coding?.[0].display,
problemsArray = problemsArray.filter((entry) =>
entry.code?.coding?.some((c: Coding) => c?.display),
);

if (problemsArray.length === 0) {
Expand All @@ -210,6 +211,7 @@ export const returnProblemsTable = (
{
columnName: "Comments",
infoPath: "activeProblemsComments",
applyToValue: (v) => parse(sanitizeAndMap(v)),
hiddenBaseText: "comment",
},
];
Expand Down Expand Up @@ -497,7 +499,7 @@ export const evaluateClinicalData = (
{
title: "Miscellaneous Notes",
value: parse(
sanitizeHtml(
sanitizeAndMap(
evaluate(fhirBundle, mappings["historyOfPresentIllness"])[0]?.div,
) || "",
),
Expand Down
17 changes: 17 additions & 0 deletions containers/ecr-viewer/src/app/view-data/utils/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { removeHtmlElements } from "@/app/services/formatService";
import { DisplayDataProps } from "@/app/view-data/components/DataDisplay";
import sanitizeHtml from "sanitize-html";

export interface PathMappings {
[key: string]: string;
Expand Down Expand Up @@ -57,3 +58,19 @@ export const isDataAvailable = (item: DisplayDataProps): Boolean => {
}
return true;
};

/**
* Sanitizes the html while also mapping common hl7v3 tags to html.
* @param val - The string of content to sanitize and map.
* @returns - Returns sanitized and mapped content.
*/
export const sanitizeAndMap = (val: string): string => {
return sanitizeHtml(val, {
transformTags: {
paragraph: "p",
list: "ul",
item: "li",
content: "span",
},
});
};
2 changes: 1 addition & 1 deletion containers/fhir-converter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

# Download FHIR-Converter
RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch v7.0-skylight-3 --single-branch /build/FHIR-Converter
RUN git clone https://github.com/skylight-hq/FHIR-Converter.git --branch v7.0-skylight-4 --single-branch /build/FHIR-Converter

WORKDIR /build/FHIR-Converter

Expand Down

0 comments on commit 80383e3

Please sign in to comment.