Skip to content

Commit

Permalink
Render lab result HTML as is if it does not conform to the expected f…
Browse files Browse the repository at this point in the history
…ormat (#2897)

* need to add condition to display labs in old way when possible

* display different tables conditionally

* finish conditional display for lab info and refactor. Needs design review for ecr summary

* [pre-commit.ci] auto fixes from pre-commit hooks

* add some tests

* Tests done, need to update based on design feedback

* Added another test

* just need to make sure the divider line is correct

* fixed the divider

* [pre-commit.ci] auto fixes from pre-commit hooks

* fix: 🗝️

* [pre-commit.ci] auto fixes from pre-commit hooks

* remove console log

* updated snapshot test

* quick fixes

* [pre-commit.ci] auto fixes from pre-commit hooks

* removed another key

* [pre-commit.ci] auto fixes from pre-commit hooks

* refactor evaluateLabInfoData

* [pre-commit.ci] auto fixes from pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Mary McGrath <m.c.mcgrath13@gmail.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 9a009b6 commit 8691ed2
Show file tree
Hide file tree
Showing 16 changed files with 7,565 additions and 257 deletions.
22 changes: 15 additions & 7 deletions containers/ecr-viewer/src/app/services/ecrSummaryService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
} from "./evaluateFhirDataService";
import { DisplayDataProps } from "@/app/view-data/components/DataDisplay";
import { returnProblemsTable } from "@/app/view-data/components/common";
import { LabReport, evaluateLabInfoData } from "./labsService";
import {
LabReport,
evaluateLabInfoData,
isLabReportElementDataList,
} from "./labsService";
import { ConditionSummary } from "@/app/view-data/components/EcrSummary";
import React from "react";

Expand Down Expand Up @@ -338,12 +342,16 @@ export const evaluateEcrSummaryRelevantLabResults = (
"h4",
);

resultsArray = relevantLabElements.flatMap((element) =>
element.diagnosticReportDataElements.map((reportElement) => ({
value: reportElement,
dividerLine: false,
})),
);
if (isLabReportElementDataList(relevantLabElements)) {
resultsArray = relevantLabElements.flatMap((element) =>
element.diagnosticReportDataElements.map((reportElement) => ({
value: reportElement,
dividerLine: false,
})),
);
} else {
resultsArray.push(...relevantLabElements);
}

if (lastDividerLine) {
resultsArray.push({ dividerLine: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import fhirpath_r4_model from "fhirpath/fhir-context/r4";
import { Element } from "fhir/r4";
import { DisplayDataProps } from "@/app/view-data/components/DataDisplay";
import { evaluateTravelHistoryTable } from "./socialHistoryService";
import { Path } from "fhirpath";

/**
* Evaluates patient name from the FHIR bundle and formats it into structured data for display.
Expand Down Expand Up @@ -570,7 +571,7 @@ export const evaluateReference = (
* @param path - The path within the resource to extract the value from.
* @returns - The evaluated value as a string.
*/
export const evaluateValue = (entry: Element, path: string): string => {
export const evaluateValue = (entry: Element, path: string | Path): string => {
let originalValue = evaluate(entry, path, undefined, fhirpath_r4_model)[0];

let value = "";
Expand Down
21 changes: 19 additions & 2 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,11 @@ export function formatTablesToJSON(htmlString: string): TableJson[] {
}

// <table><caption>{name}</caption></table>
const tableWithCaptionArray = doc.querySelectorAll("table:has(caption)");
const tableWithCaptionArray = doc.querySelectorAll(
"table:has(caption)",
) as NodeListOf<HTMLTableElement>;
if (tableWithCaptionArray.length > 0) {
doc.querySelectorAll("table").forEach((table) => {
tableWithCaptionArray.forEach((table) => {
const resultName = getElementContent(table.caption as Node);
const resultId = getDataId(table) ?? undefined;
jsonArray.push({ resultId, resultName, tables: [processTable(table)] });
Expand All @@ -397,9 +399,24 @@ export function formatTablesToJSON(htmlString: string): TableJson[] {
}
sibling = sibling.nextElementSibling;
}

if (tables.length > 0) jsonArray.push({ resultName, tables });
});

if (jsonArray.length > 0) {
return jsonArray;
}
}

// <table/>
const tableWithNoCaptionArray = doc.querySelectorAll("table");
if (tableWithNoCaptionArray.length > 0) {
tableWithNoCaptionArray.forEach((table) => {
const resultName = "";
const resultId = getDataId(table) ?? undefined;
jsonArray.push({ resultId, resultName, tables: [processTable(table)] });
});

return jsonArray;
}

Expand Down
Loading

0 comments on commit 8691ed2

Please sign in to comment.