Skip to content

Commit

Permalink
Update emergency contact number (#2862)
Browse files Browse the repository at this point in the history
* Update format address to accept undefined

* change contact to match r4 spec

* update patient contact relationship fhir evaulatuation

* update toSentenceCase and formatPhoneNumber to accept undefined

* change formatAddress to undefined rather than optional

* use the correct phone number in emergency contact

* filter out null values for emergency contact

* update usage to allow optionals

* update dockerfile to point to related branch

* Use format contact point

* update fhir-converter version
  • Loading branch information
BobanL authored Nov 8, 2024
1 parent 6239898 commit 44d009a
Show file tree
Hide file tree
Showing 10 changed files with 12,377 additions and 80 deletions.
30 changes: 15 additions & 15 deletions containers/ecr-viewer/src/app/services/ecrMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ export const evaluateEcrMetadata = (
{
title: "Custodian Address",
value: formatAddress(
custodian?.address?.[0].line ?? [],
custodian?.address?.[0].city ?? "",
custodian?.address?.[0].state ?? "",
custodian?.address?.[0].postalCode ?? "",
custodian?.address?.[0].country ?? "",
custodian?.address?.[0].line,
custodian?.address?.[0].city,
custodian?.address?.[0].state,
custodian?.address?.[0].postalCode,
custodian?.address?.[0].country,
),
},
{
Expand Down Expand Up @@ -219,11 +219,11 @@ const evaluateEcrAuthorDetails = (
title: "Author Address",
value: practitioner?.address?.map((address) =>
formatAddress(
address.line ?? [],
address.city ?? "",
address.state ?? "",
address.postalCode ?? "",
address.country ?? "",
address.line,
address.city,
address.state,
address.postalCode,
address.country,
),
),
},
Expand All @@ -239,11 +239,11 @@ const evaluateEcrAuthorDetails = (
title: "Author Facility Address",
value: organization?.address?.map((address) =>
formatAddress(
address.line ?? [],
address.city ?? "",
address.state ?? "",
address.postalCode ?? "",
address.country ?? "",
address.line,
address.city,
address.state,
address.postalCode,
address.country,
),
),
},
Expand Down
67 changes: 25 additions & 42 deletions containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Identifier,
Location,
Organization,
PatientContact,
Practitioner,
PractitionerRole,
Quantity,
Expand Down Expand Up @@ -459,11 +460,11 @@ export const evaluateProviderData = (
title: "Provider Address",
value: practitioner?.address?.map((address) =>
formatAddress(
address.line ?? [],
address.city ?? "",
address.state ?? "",
address.postalCode ?? "",
address.country ?? "",
address.line,
address.city,
address.state,
address.postalCode,
address.country,
),
),
},
Expand All @@ -479,11 +480,11 @@ export const evaluateProviderData = (
title: "Provider Facility Address",
value: organization?.address?.map((address) =>
formatAddress(
address.line ?? [],
address.city ?? "",
address.state ?? "",
address.postalCode ?? "",
address.country ?? "",
address.line,
address.city,
address.state,
address.postalCode,
address.country,
),
),
},
Expand All @@ -506,43 +507,25 @@ export const evaluateEmergencyContact = (
fhirBundle: Bundle,
mappings: PathMappings,
) => {
const contact = evaluate(fhirBundle, mappings.patientEmergencyContact)[0];

let formattedContact;
const contact = evaluate(
fhirBundle,
mappings.patientEmergencyContact,
)[0] as PatientContact;

if (contact) {
if (contact.relationship) {
const relationship = contact.relationship;
formattedContact = `${relationship}`;
}
const relationship = contact.relationship?.[0].coding?.[0]?.display;

if (contact.address) {
const address = formatAddress(
contact.address[0].line,
contact.address[0].city,
contact.address[0].state,
contact.address[0].postalCode,
contact.address[0].country,
);
const address = formatAddress(
contact.address?.line,
contact.address?.city,
contact.address?.state,
contact.address?.postalCode,
contact.address?.country,
);

formattedContact = `${formattedContact}\n${address}`;
}

if (contact.telecom) {
const phoneNumbers = evaluate(fhirBundle, mappings.patientPhoneNumbers)
.map(
(phoneNumber) =>
`${
phoneNumber?.use?.charAt(0).toUpperCase() +
phoneNumber?.use?.substring(1)
} ${phoneNumber.value}`,
)
.join("\n");

formattedContact = `${formattedContact}\n${phoneNumbers}`;
}
const phoneNumbers = formatContactPoint(contact.telecom);

return formattedContact;
return [relationship, address, phoneNumbers].filter(Boolean).join("\n");
}
};

Expand Down
22 changes: 12 additions & 10 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ export const formatName = (
* @returns The formatted address string.
*/
export const formatAddress = (
streetAddress: string[],
city: string,
state: string,
zipCode: string,
country: string,
streetAddress: string[] | undefined,
city: string | undefined,
state: string | undefined,
zipCode: string | undefined,
country: string | undefined,
) => {
let address = {
streetAddress: streetAddress || [],
Expand All @@ -80,7 +80,7 @@ export const formatAddress = (
};

return [
address.streetAddress.join("\n"),
address.streetAddress.filter(Boolean).join("\n"),
address.cityState.filter(Boolean).join(", "),
address.zipCodeCountry.filter(Boolean).join(", "),
]
Expand Down Expand Up @@ -217,7 +217,9 @@ const VALID_PHONE_NUMBER_REGEX = /^\d{3}-\d{3}-\d{4}$/;
* @param phoneNumber - The phone number to format.
* @returns The formatted phone number or "Invalid Number" if the input is invalid or undefined if the input is empty.
*/
export const formatPhoneNumber = (phoneNumber: string): string | undefined => {
export const formatPhoneNumber = (
phoneNumber: string | undefined,
): string | undefined => {
if (!phoneNumber || phoneNumber.trim() === "") return undefined;

const formatted = phoneNumber
Expand Down Expand Up @@ -511,7 +513,7 @@ export function extractNumbersAndPeriods(inputValues: string[]): string[] {
* @param str - The string to convert to sentence case.
* @returns The converted sentence-case string. If the input is empty or not a string, the original input is returned.
*/
export function toSentenceCase(str: string) {
export function toSentenceCase(str: string | undefined) {
if (!str) return str;
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
Expand Down Expand Up @@ -566,9 +568,9 @@ export const formatContactPoint = (
const contactArr: string[] = [];
for (const contactPoint of contactPoints) {
if (contactPoint.system === "phone" && contactPoint.value) {
const phoneNumberUse = toSentenceCase(contactPoint.use ?? "");
const phoneNumberUse = toSentenceCase(contactPoint.use);
contactArr.push(
[phoneNumberUse, formatPhoneNumber(contactPoint.value ?? "")]
[phoneNumberUse, formatPhoneNumber(contactPoint.value)]
.filter((c) => c)
.join(": "),
);
Expand Down
17 changes: 6 additions & 11 deletions containers/ecr-viewer/src/app/services/labsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,15 @@ export const evaluateLabOrganizationData = (
matchingOrg = findIdenticalOrg(orgMappings, matchingOrg);
}
const orgAddress = matchingOrg?.address?.[0];
const streetAddress = orgAddress?.line ?? [];
const city = orgAddress?.city ?? "";
const state = orgAddress?.state ?? "";
const postalCode = orgAddress?.postalCode ?? "";
const country = orgAddress?.country ?? "";
const formattedAddress = formatAddress(
streetAddress,
city,
state,
postalCode,
country,
orgAddress?.line,
orgAddress?.city,
orgAddress?.state,
orgAddress?.postalCode,
orgAddress?.country,
);

const contactInfo = formatPhoneNumber(matchingOrg?.telecom?.[0].value ?? "");
const contactInfo = formatPhoneNumber(matchingOrg?.telecom?.[0].value);
const name = matchingOrg?.name ?? "";
const matchingOrgData: DisplayDataProps[] = [
{ title: "Lab Performing Name", value: name },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
evaluatePractitionerRoleReference,
evaluateReference,
evaluateValue,
evaluateEmergencyContact,
} from "@/app/services/evaluateFhirDataService";
import { Bundle } from "fhir/r4";
import { Bundle, Patient } from "fhir/r4";
import BundleWithMiscNotes from "@/app/tests/assets/BundleMiscNotes.json";
import BundleWithPatient from "@/app/tests/assets/BundlePatient.json";
import BundleWithEcrMetadata from "@/app/tests/assets/BundleEcrMetadata.json";
Expand Down Expand Up @@ -180,3 +181,96 @@ describe("Evaluate PractitionerRoleReference", () => {
expect(actual.practitioner).toBeUndefined();
});
});

describe("Evaluate Emergency Contact", () => {
it("should return an emergency contact", () => {
const BundleWithPatientAndContact = JSON.parse(
JSON.stringify(BundleWithPatient),
) as unknown as Bundle;
const patientIndex = BundleWithPatientAndContact.entry!.findIndex(
(entry) => entry.resource?.resourceType === "Patient",
);

(
BundleWithPatientAndContact.entry![patientIndex].resource as Patient
).contact = [
{
relationship: [
{
coding: [
{
display: "sister",
},
],
},
],
telecom: [
{
system: "phone",
value: "+1-615-995-9999",
use: "home",
},
],
address: {
use: "home",
line: ["999 Single Court"],
city: "BEVERLY HILLS",
state: "CA",
country: "USA",
postalCode: "90210",
district: "LOS ANGELE",
},
},
];
const actual = evaluateEmergencyContact(
BundleWithPatientAndContact,
mappings,
);
expect(actual).toEqual(
`sister\n999 Single Court\nBEVERLY HILLS, CA\n90210, USA\nHome: 615-995-9999`,
);
});
it("should not return empty space when address is not available in", () => {
const BundleWithPatientAndContact = JSON.parse(
JSON.stringify(BundleWithPatient),
) as unknown as Bundle;
const patientIndex = BundleWithPatientAndContact.entry!.findIndex(
(entry) => entry.resource?.resourceType === "Patient",
);

(
BundleWithPatientAndContact.entry![patientIndex].resource as Patient
).contact = [
{
relationship: [
{
coding: [
{
display: "sister",
},
],
},
],
telecom: [
{
system: "phone",
value: "+1-615-995-9999",
use: "home",
},
],
},
];
const actual = evaluateEmergencyContact(
BundleWithPatientAndContact,
mappings,
);
expect(actual).toEqual(`sister\nHome: 615-995-9999`);
});
it("should return undefined if a patient has no contact", () => {
const actual = evaluateEmergencyContact(
BundleWithPatient as unknown as Bundle,
mappings,
);
expect(actual).toBeUndefined();
});
});
Loading

0 comments on commit 44d009a

Please sign in to comment.