Skip to content

Commit

Permalink
Add Facility Details section to encounter info (#2614)
Browse files Browse the repository at this point in the history
* Add facility data section to encounter info and add addtl contact address

* Update failing snapshots

* update data.sql

* Test tweak, added conditional check

* Remove extraneous LOC path from liquid template

* Moar snapshot updatin
  • Loading branch information
gordonfarrell authored Sep 26, 2024
1 parent a8faaa5 commit 951a097
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 126 deletions.
242 changes: 121 additions & 121 deletions containers/ecr-viewer/seed-scripts/sql/data.sql

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion containers/ecr-viewer/src/app/api/fhirPath.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ encounterType: "Bundle.entry.resource.where(resourceType='Encounter')[0].class.d
encounterID: "Bundle.entry.resource.where(resourceType='Encounter')[0].identifier"
facilityCity: "Bundle.entry.resource.where(resourceType = 'Location')[0].address.city"
facilityContact: "Bundle.entry.resource.where(resourceType = 'Location')[0].telecom.where(system = 'phone')[0].value"
facilityContactAddress: "Bundle.entry.resource.where(resourceType = 'Encounter')[0].serviceProvider"
facilityCountry: "Bundle.entry.resource.where(resourceType = 'Location')[0].address.country"
facilityLocation: "Bundle.entry.resource.where(resourceType = 'Encounter')[0].location[0].location.reference"
facilityName: "Bundle.entry.resource.where(resourceType = 'Encounter')[0].location[0].location.display"
Expand Down Expand Up @@ -93,7 +94,7 @@ plannedProcedureName: "detail.code.coding[0].display"
plannedProcedureOrderedDate: "extension.where(url = 'dibbs.orderedDate').valueString"
plannedProcedureScheduledDate: "detail.scheduledString"

# Adminstered Medications
# Administered Medications
administeredMedications: "Bundle.entry.resource.section.where(code.coding[0].code = '29549-3').text"
adminMedicationsRefs: "Bundle.entry.resource.section.where(code.coding[0].code = '29549-3').entry.reference"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,34 @@ export const evaluateEncounterData = (
title: "Encounter ID",
value: evaluateEncounterId(fhirBundle, mappings),
},
];
return evaluateData(encounterData);
};

/**
* Evaluates facility data from the FHIR bundle and formats it into structured data for display.
* @param fhirBundle - The FHIR bundle containing facility data.
* @param mappings - The object containing the fhir paths.
* @returns An array of evaluated and formatted facility data.
*/
export const evaluateFacilityData = (
fhirBundle: Bundle,
mappings: PathMappings,
) => {
const facilityContactAddressRef = evaluate(
fhirBundle,
mappings["facilityContactAddress"],
);
let referenceString;

if (facilityContactAddressRef[0]) {
referenceString = facilityContactAddressRef[0].reference;
}
const facilityContactAddress = referenceString
? evaluateReference(fhirBundle, mappings, referenceString).address[0]
: "";

const facilityData = [
{
title: "Facility Name",
value: evaluate(fhirBundle, mappings["facilityName"])[0],
Expand All @@ -363,6 +391,16 @@ export const evaluateEncounterData = (
evaluate(fhirBundle, mappings["facilityCountry"])[0],
),
},
{
title: "Facility Contact Address",
value: formatAddress(
facilityContactAddress.line,
facilityContactAddress.city,
facilityContactAddress.state,
facilityContactAddress.postalCode,
facilityContactAddress.country,
),
},
{
title: "Facility Contact",
value: formatPhoneNumber(
Expand All @@ -378,7 +416,7 @@ export const evaluateEncounterData = (
value: evaluateFacilityId(fhirBundle, mappings),
},
];
return evaluateData(encounterData);
return evaluateData(facilityData);
};

/**
Expand Down
11 changes: 11 additions & 0 deletions containers/ecr-viewer/src/app/tests/components/Encounter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ describe("Encounter", () => {
let container: HTMLElement;
beforeAll(() => {
const encounterData = [
{
title: "Encounter Type",
value: "Ambulatory",
},
{
title: "Encounter ID",
value: "123456789",
},
];
const facilityData = [
{
title: "Facility ID",
value: "2.16.840.1.113883.4.6",
Expand All @@ -32,6 +42,7 @@ describe("Encounter", () => {
container = render(
<EncounterDetails
encounterData={encounterData}
facilityData={facilityData}
providerData={providerData}
/>,
).container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ describe("UnavailableInfo", () => {
},
];
const encounterUnavailableData = [
{
title: "Encounter type",
value: "",
},
];
const facilityUnavailableData = [
{
title: "Facility Address",
value: "",
Expand Down Expand Up @@ -96,6 +102,7 @@ describe("UnavailableInfo", () => {
demographicsUnavailableData={demographicsUnavailability}
socialUnavailableData={socialUnavailability}
encounterUnavailableData={encounterUnavailableData}
facilityUnavailableData={facilityUnavailableData}
providerUnavailableData={providerUnavailableData}
symptomsProblemsUnavailableData={[
...reasonForVisitUnavailableData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,19 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
class="section__line_gray"
/>
</div>
</div>
</div>
<div
class="margin-bottom-4"
>
<h3
class="usa-summary-box__heading padding-bottom-205 unavailable-info"
>
Facility Details
</h3>
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
Expand Down Expand Up @@ -769,6 +782,25 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Facility Contact Address
</div>
<div
class="grid-col maxw7 text-pre-line text-italic text-base"
>
No data
</div>
</div>
<div
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,56 @@ exports[`Encounter should match snapshot 1`] = `
>
Encounter Details
</h4>
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Encounter Type
</div>
<div
class="grid-col maxw7 text-pre-line"
>
Ambulatory
</div>
</div>
<div
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Encounter ID
</div>
<div
class="grid-col maxw7 text-pre-line"
>
123456789
</div>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
</div>
<div>
<h4
class="usa-summary-box__heading padding-y-105"
id="facility-details"
>
Facility Details
</h4>
<div
class="usa-summary-box__text"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@ exports[`UnavailableInfo should match snapshot 1`] = `
>
Encounter Details
</h3>
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Encounter type
</div>
<div
class="grid-col maxw7 text-pre-line text-italic text-base"
>
No data
</div>
</div>
<div
class="section__line_gray"
/>
</div>
</div>
</div>
<div
class="margin-bottom-4"
>
<h3
class="usa-summary-box__heading padding-bottom-205 unavailable-info"
>
Facility Details
</h3>
<div
class="usa-summary-box__text"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
evaluateSocialData,
evaluateEncounterData,
evaluateProviderData,
evaluateFacilityData,
} from "@/app/services/evaluateFhirDataService";
import { evaluateClinicalData } from "./common";
import AccordionContainer from "@repo/ui/accordionContainer";
Expand Down Expand Up @@ -46,6 +47,7 @@ const AccordionContent: React.FC<AccordionContainerProps> = ({
const providerData = evaluateProviderData(fhirBundle, fhirPathMappings);
const clinicalData = evaluateClinicalData(fhirBundle, fhirPathMappings);
const ecrMetadata = evaluateEcrMetadata(fhirBundle, fhirPathMappings);
const facilityData = evaluateFacilityData(fhirBundle, fhirPathMappings);
const labInfoData = evaluateLabInfoData(
fhirBundle,
evaluate(fhirBundle, fhirPathMappings["diagnosticReports"]),
Expand Down Expand Up @@ -99,9 +101,11 @@ const AccordionContent: React.FC<AccordionContainerProps> = ({
content: (
<>
{encounterData.availableData.length > 0 ||
facilityData.availableData.length > 0 ||
providerData.availableData.length > 0 ? (
<EncounterDetails
encounterData={encounterData.availableData}
facilityData={facilityData.availableData}
providerData={providerData.availableData}
/>
) : (
Expand Down Expand Up @@ -183,6 +187,7 @@ const AccordionContent: React.FC<AccordionContainerProps> = ({
demographicsUnavailableData={demographicsData.unavailableData}
socialUnavailableData={social_data.unavailableData}
encounterUnavailableData={encounterData.unavailableData}
facilityUnavailableData={facilityData.unavailableData}
symptomsProblemsUnavailableData={[
...clinicalData.reasonForVisitDetails.unavailableData,
...clinicalData.activeProblemsDetails.unavailableData,
Expand Down
26 changes: 23 additions & 3 deletions containers/ecr-viewer/src/app/view-data/components/Encounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ import {

interface EncounterProps {
encounterData: DisplayDataProps[];
facilityData: DisplayDataProps[];
providerData: DisplayDataProps[];
}

/**
* Functional component for displaying encounter details.
* @param props - Props containing encounter details.
* @param props.encounterData - The encounter data to be displayed.
* @param props.providerData - The provider details to be displayed.
* @param props.encounterData - Encounter details to be displayed.
* @param props.providerData - Provider details to be displayed.
* @param props.facilityData - Facility details to be displayed.
* @returns The JSX element representing the encounter details.
*/
const EncounterDetails = ({ encounterData, providerData }: EncounterProps) => {
const EncounterDetails = ({
encounterData,
facilityData,
providerData,
}: EncounterProps) => {
const renderEncounterDetails = () => {
return (
<>
Expand All @@ -35,6 +41,19 @@ const EncounterDetails = ({ encounterData, providerData }: EncounterProps) => {
);
};

const renderFacilityDetails = () => {
return (
<>
<AccordionH4 id={"facility-details"}>Facility Details</AccordionH4>
<AccordionDiv>
{facilityData.map((item, index) => (
<DataDisplay item={item} key={index} />
))}
</AccordionDiv>
</>
);
};

const renderProviderDetails = () => {
return (
<>
Expand All @@ -51,6 +70,7 @@ const EncounterDetails = ({ encounterData, providerData }: EncounterProps) => {
return (
<AccordionSection>
<div>{encounterData.length > 0 && renderEncounterDetails()}</div>
<div>{facilityData.length > 0 && renderFacilityDetails()}</div>
<div className="margin-top-3">
{providerData.length > 0 && renderProviderDetails()}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface UnavailableInfoProps {
demographicsUnavailableData: DisplayDataProps[];
socialUnavailableData: DisplayDataProps[];
encounterUnavailableData: DisplayDataProps[];
facilityUnavailableData: DisplayDataProps[];
providerUnavailableData: DisplayDataProps[];
symptomsProblemsUnavailableData: DisplayDataProps[];
vitalUnavailableData: DisplayDataProps[];
Expand All @@ -24,6 +25,7 @@ interface UnavailableInfoProps {
* @param props.demographicsUnavailableData The unavailable demographic data
* @param props.socialUnavailableData The unavailable social data
* @param props.encounterUnavailableData The unavailable encounter data
* @param props.facilityUnavailableData The unavailable facility data
* @param props.providerUnavailableData The unavailable provider data
* @param props.symptomsProblemsUnavailableData The unavailable symptoms and problems data
* @param props.immunizationsUnavailableData The unavailable immunizations data
Expand All @@ -37,6 +39,7 @@ const UnavailableInfo: React.FC<UnavailableInfoProps> = ({
demographicsUnavailableData,
socialUnavailableData,
encounterUnavailableData,
facilityUnavailableData,
providerUnavailableData,
symptomsProblemsUnavailableData,
immunizationsUnavailableData,
Expand Down Expand Up @@ -72,6 +75,8 @@ const UnavailableInfo: React.FC<UnavailableInfoProps> = ({
renderSection("Social History", socialUnavailableData)}
{encounterUnavailableData?.length > 0 &&
renderSection("Encounter Details", encounterUnavailableData)}
{facilityUnavailableData?.length > 0 &&
renderSection("Facility Details", facilityUnavailableData)}
{clinicalNotesData?.length > 0 &&
renderSection("Clinical Notes", clinicalNotesData)}
{providerUnavailableData.length > 0 &&
Expand Down
Loading

0 comments on commit 951a097

Please sign in to comment.