Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty travel histories as unavailable data #3005

Merged
merged 27 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ddeb9a0
fix: update fhir-converter service to point to branch
mcmcgrath13 Dec 4, 2024
743507e
feat: add encounter care team table
mcmcgrath13 Dec 4, 2024
b3a8ac1
fix: unique ids
mcmcgrath13 Dec 4, 2024
958f5c5
test: update snapshot
mcmcgrath13 Dec 5, 2024
a3aaf8b
fix: plumb through date
mcmcgrath13 Dec 5, 2024
d6dc5db
fix: remove status
mcmcgrath13 Dec 5, 2024
b173196
test: update snapshots
mcmcgrath13 Dec 5, 2024
45fa662
fix: make metadata optional
mcmcgrath13 Dec 5, 2024
c6b881e
test: table value logic
mcmcgrath13 Dec 5, 2024
de68b77
test: add snapshot for table
mcmcgrath13 Dec 5, 2024
84bc11a
fix: cleanup
mcmcgrath13 Dec 5, 2024
3ae6963
fix: handle missing name
mcmcgrath13 Dec 5, 2024
eda23b9
Merge branch 'main' into mcm/enc-car-team
mcmcgrath13 Dec 5, 2024
a69feb3
test: update snapshot
mcmcgrath13 Dec 6, 2024
4b144a6
Merge branch 'mcm/enc-car-team' of https://github.com/CDCgov/phdi int…
mcmcgrath13 Dec 6, 2024
f18e6e3
Update design review script (#2997)
angelathe Dec 5, 2024
1a25a14
fix: wip - empty table data
mcmcgrath13 Dec 6, 2024
7f92640
fix: data then render
mcmcgrath13 Dec 6, 2024
63c0e9a
fix: add column name
mcmcgrath13 Dec 6, 2024
e45e56a
fix: divider line
mcmcgrath13 Dec 6, 2024
105d5c5
test: update tests
mcmcgrath13 Dec 6, 2024
2544a6f
test: evaluating empty rows
mcmcgrath13 Dec 6, 2024
9cac865
test: empty travel history
mcmcgrath13 Dec 6, 2024
c73ed7a
Merge branch 'main' into mcm/fix-phantom-travel-history
mcmcgrath13 Dec 9, 2024
2b6eee2
Update containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts
mcmcgrath13 Dec 9, 2024
0dc3f3a
fix: pr feedback
mcmcgrath13 Dec 9, 2024
43a342c
Merge branch 'mcm/fix-phantom-travel-history' of https://github.com/C…
mcmcgrath13 Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ export interface TableJson {
tables?: TableRow[][];
}

export interface TableJson {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a duplicate of the definition immediately above

resultId?: string;
resultName?: string;
tables?: TableRow[][];
}

/**
* Formats a person's name using given name(s), family name, optional prefix(es), and optional suffix(es).
* @param given - Optional array of given name(s).
Expand Down
45 changes: 29 additions & 16 deletions containers/ecr-viewer/src/app/services/socialHistoryService.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Bundle, Observation } from "fhir/r4";
import { PathMappings } from "../view-data/utils/utils";
import EvaluateTable, {
ColumnInfoInput,
} from "../view-data/components/EvaluateTable";
import { PathMappings, noData } from "../view-data/utils/utils";

import { evaluate } from "../view-data/utils/evaluate";
import { evaluateValue } from "./evaluateFhirDataService";
import { returnTableFromJson } from "../view-data/components/common";
import { TableRow, formatDate } from "./formatService";

/**
* Extracts travel history information from the provided FHIR bundle based on the FHIR path mappings.
Expand All @@ -20,35 +21,47 @@ export const evaluateTravelHistoryTable = (
mappings.patientTravelHistory,
);

const columnInfo: ColumnInfoInput[] = [
const columnInfo = [
{
columnName: "Location",
infoPath: "travelHistoryLocation",
},
{
columnName: "Start Date",
infoPath: "travelHistoryStartDate",
applyToValue: formatDate,
},
{
columnName: "End Date",
infoPath: "travelHistoryEndDate",
applyToValue: formatDate,
},
{
columnName: "Purpose",
infoPath: "travelHistoryPurpose",
},
];

if (travelHistory.length > 0) {
return (
<EvaluateTable
resources={travelHistory}
mappings={mappings}
columns={columnInfo}
caption={"Travel History"}
className={"margin-y-0"}
/>
const tables = travelHistory
.map((act) => {
return columnInfo.reduce(
(row, { columnName, infoPath, applyToValue }) => {
let val = evaluateValue(act, mappings[infoPath]);
if (applyToValue) {
val = applyToValue(val) ?? "";
}
return { ...row, [columnName]: { value: val || noData } };
},
{} as TableRow[],
);
})
.filter((row) =>
Object.values(row).some((v) => (v.value as any) !== noData),
);
}
return undefined;

return returnTableFromJson(
{ tables, resultName: "Travel History" },
true,
"caption-data-title margin-y-0",
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"resourceType": "Bundle",
"type": "batch",
"entry": [
{
"fullUrl": "urn:uuid:595b1386-09d2-7dfb-d414-fb1e5043013d",
"resource": {
"resourceType": "Observation",
"id": "595b1386-09d2-7dfb-d414-fb1e5043013d",
"meta": {
"profile": [
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-travel-history"
],
"source": [
"ecr"
]
},
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "420008001",
"display": "Travel"
}
],
"text": "Travel History"
},
"status": "final",
"component": [
{
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
"code": "LOC",
"display": "Location"
}
]
}
}
]
},
"request": {
"method": "PUT",
"url": "Observation/595b1386-09d2-7dfb-d414-fb1e5043013d"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,47 @@ describe("Evaluate table", () => {
it("should not apply a function to the row value if value is null", () => {
render(
<EvaluateTable
resources={[{}]}
mappings={{ getId: "id" }}
resources={[{ id: "hi" }]}
mappings={{ getId: "id", getName: "name" }}
columns={[
{
columnName: "Col1",
infoPath: "getId",
infoPath: "getName",
applyToValue: (value) => value?.toUpperCase(),
},
{
columnName: "Col2",
infoPath: "getId",
},
]}
/>,
);

expect(screen.getByText("Col1")).toBeInTheDocument();
expect(screen.getByText("No data")).toBeInTheDocument();
});
it("should not render totally empty rows", () => {
render(
<EvaluateTable
resources={[{}]}
mappings={{ getId: "id", getName: "name" }}
columns={[
{
columnName: "Col1",
infoPath: "getName",
applyToValue: (value) => value?.toUpperCase(),
},
{
columnName: "Col2",
infoPath: "getId",
},
]}
/>,
);

expect(screen.getByText("Col1")).toBeInTheDocument();
expect(screen.queryByText("No data")).not.toBeInTheDocument();
});
describe("hiddenBaseText", () => {
const pathMapping: PathMappings = { idPath: "id", notePath: "note.text" };
describe("single column", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ exports[`Snapshot test for Procedures (Treatment Details) should match snapshot
</tbody>
</table>
</div>
<div
class="section__line_gray"
/>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ End: 05/13/2022 9:57 AM UTC
>
covid clinical
</div>
<div
class="section__line_gray"
/>
</div>
<div
class="section__line_gray"
/>
</div>
<div
class="text-bold margin-0 margin-bottom-1"
Expand All @@ -311,10 +311,10 @@ End: 05/13/2022 9:57 AM UTC
>
covid lab
</div>
<div
class="section__line_gray"
/>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ exports[`Encounter should match snapshot 1`] = `
</tr>
</table>
</div>
<div
class="section__line_gray"
/>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Travel History should display a table 1`] = `
<div>
<table
class="usa-table usa-table--borderless width-full _fixed_1khz6_1 table-caption-margin margin-y-0 border-top border-left border-right"
class="usa-table usa-table--borderless width-full table-caption-margin caption-normal-weight margin-bottom-2 caption-data-title margin-y-0 border-top border-left border-right"
data-testid="table"
>
<caption>
Expand All @@ -12,25 +12,25 @@ exports[`Travel History should display a table 1`] = `
<thead>
<tr>
<th
class="tableHeader"
class="tableHeader bg-gray-5 minw-10"
scope="col"
>
Location
</th>
<th
class="tableHeader"
class="tableHeader bg-gray-5 minw-10"
scope="col"
>
Start Date
</th>
<th
class="tableHeader"
class="tableHeader bg-gray-5 minw-10"
scope="col"
>
End Date
</th>
<th
class="tableHeader"
class="tableHeader bg-gray-5 minw-10"
scope="col"
>
Purpose
Expand All @@ -39,24 +39,16 @@ exports[`Travel History should display a table 1`] = `
</thead>
<tbody>
<tr>
<td
class="text-top"
>
<td>
Traveled to Singapore, Malaysia and Bali with my family.
</td>
<td
class="text-top"
>
2018-01-18
<td>
01/18/2018
</td>
<td
class="text-top"
>
2018-02-18
<td>
02/18/2018
</td>
<td
class="text-top"
>
<td>
Active duty military (occupation)
</td>
</tr>
Expand Down
9 changes: 9 additions & 0 deletions containers/ecr-viewer/src/app/tests/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isDataAvailable, safeParse } from "@/app/view-data/utils/utils";
import { loadYamlConfig } from "@/app/api/utils";
import { Bundle } from "fhir/r4";
import BundleWithTravelHistory from "./assets/BundleTravelHistory.json";
import BundleWithTravelHistoryEmpty from "./assets/BundleTravelHistoryEmpty.json";
import BundleWithPatient from "./assets/BundlePatient.json";
import BundleWithDeceasedPatient from "./assets/BundlePatientDeceased.json";
import BundleWithSexualOrientation from "./assets/BundleSexualOrientation.json";
Expand Down Expand Up @@ -56,6 +57,14 @@ describe("Utils", () => {
render(actual.availableData[0].value);
expect(screen.getByText("Travel History"));
});
it("should not have travel history when there is an empty travel history observation present", () => {
const actual = evaluateSocialData(
BundleWithTravelHistoryEmpty as unknown as Bundle,
mappings,
);

expect(actual.availableData).toBeEmpty();
});
it("should have patient sexual orientation when available", () => {
const actual = evaluateSocialData(
BundleWithSexualOrientation as unknown as Bundle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,16 @@ export const DataTableDisplay: React.FC<{
item: DisplayDataProps;
themeColor?: string;
}> = ({ item, themeColor = "gray" }): React.JSX.Element => {
item.dividerLine =
item.dividerLine == null || item.dividerLine == undefined
? true
: item.dividerLine;
const dividerLine = item.dividerLine ?? true;
return (
<div className="grid-row">
<div className="grid-col-auto width-full text-pre-line">{item.value}</div>
{item.dividerLine ? (
<div className={`section__line_${themeColor}`} />
) : (
""
)}
</div>
<>
<div className="grid-row">
<div className="grid-col-auto width-full text-pre-line">
{item.value}
</div>
</div>
{dividerLine && <div className={`section__line_${themeColor}`} />}
</>
);
};

Expand Down
Loading
Loading