Skip to content

Commit

Permalink
fix: since all users of formatContactPoint join("\n"), build it in
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcgrath13 committed Nov 20, 2024
1 parent 7bfb92d commit 7b04236
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
6 changes: 3 additions & 3 deletions containers/ecr-viewer/src/app/services/ecrMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const evaluateEcrMetadata = (
},
{
title: "Custodian Contact",
value: formatContactPoint(custodian?.telecom).join("\n"),
value: formatContactPoint(custodian?.telecom),
},
];

Expand Down Expand Up @@ -250,7 +250,7 @@ const evaluateEcrAuthorDetails = (
},
{
title: "Author Contact",
value: formatContactPoint(practitioner?.telecom).join("\n"),
value: formatContactPoint(practitioner?.telecom),
},
{
title: "Author Facility Name",
Expand All @@ -270,7 +270,7 @@ const evaluateEcrAuthorDetails = (
},
{
title: "Author Facility Contact",
value: formatContactPoint(organization?.telecom).join("\n"),
value: formatContactPoint(organization?.telecom),
},
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const evaluateEcrSummaryPatientDetails = (
title: "Patient Contact",
value: formatContactPoint(
evaluate(fhirBundle, fhirPathMappings.patientTelecom),
).join("\n"),
),
},
]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export const evaluateDemographicsData = (
title: "Contact",
value: formatContactPoint(
evaluate(fhirBundle, mappings.patientTelecom),
).join("\n"),
),
},
{
title: "Emergency Contact",
Expand Down Expand Up @@ -491,7 +491,7 @@ export const evaluateProviderData = (
},
{
title: "Provider Contact",
value: formatContactPoint(practitioner?.telecom).join("\n"),
value: formatContactPoint(practitioner?.telecom),
},
{
title: "Provider Facility Name",
Expand Down Expand Up @@ -547,7 +547,7 @@ export const evaluateEmergencyContact = (

const phoneNumbers = formatContactPoint(contact.telecom);

return [relationship, address, ...phoneNumbers]
return [relationship, address, phoneNumbers]
.filter(Boolean)
.join("\n");
})
Expand Down
8 changes: 4 additions & 4 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,13 @@ const sortContacts = (contactPoints: ContactPoint[]): ContactPoint[] => {
* Converts contact points into an array of phone numbers and emails and returns them
* in a consistent sort order for display.
* @param contactPoints - array of contact points
* @returns array of phone numbers and emails
* @returns string of formatted and sorted phone numbers and emails
*/
export const formatContactPoint = (
contactPoints: ContactPoint[] | undefined,
): string[] => {
): string => {
if (!contactPoints || !contactPoints.length) {
return [];
return "";
}
const contactArr: string[] = [];
for (const { system, value, use } of sortContacts(contactPoints)) {
Expand All @@ -616,5 +616,5 @@ export const formatContactPoint = (
contactArr.push([_use, `${_system}:`, _value].join(" ").trim());
}
}
return contactArr;
return contactArr.join("\n");
};
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ describe("formatVitals", () => {
});

describe("formatContactPoint", () => {
it("should return empty array if contact points is null", () => {
it("should return empty string if contact points is null", () => {
const actual = formatContactPoint(undefined);
expect(actual).toBeEmpty();
expect(actual).toBe("");
});
it("should return empty array if contact points is contact points is empty", () => {
it("should return empty string if contact points is contact points is empty", () => {
const actual = formatContactPoint([]);
expect(actual).toBeEmpty();
expect(actual).toBe("");
});
it("should return empty array if contact point value is empty ", () => {
it("should return empty string if contact point value is empty ", () => {
const contactPoints: ContactPoint[] = [
{
system: "phone",
Expand All @@ -629,7 +629,7 @@ describe("formatContactPoint", () => {
},
];
const actual = formatContactPoint(contactPoints);
expect(actual).toBeEmpty();
expect(actual).toBe("");
});
it("should return phone contact information ", () => {
const contactPoints: ContactPoint[] = [
Expand All @@ -644,7 +644,7 @@ describe("formatContactPoint", () => {
},
];
const actual = formatContactPoint(contactPoints);
expect(actual).toEqual(["Work: 248-555-1234", "313-555-1234"]);
expect(actual).toEqual("Work: 248-555-1234\n313-555-1234");
});
it("should return email information ", () => {
const contactPoints: ContactPoint[] = [
Expand All @@ -659,7 +659,7 @@ describe("formatContactPoint", () => {
},
];
const actual = formatContactPoint(contactPoints);
expect(actual).toEqual(["me@example.com", "medicine@example.com"]);
expect(actual).toEqual("me@example.com\nmedicine@example.com");
});
it("should return fax information ", () => {
const contactPoints: ContactPoint[] = [
Expand All @@ -674,7 +674,38 @@ describe("formatContactPoint", () => {
},
];
const actual = formatContactPoint(contactPoints);
expect(actual).toEqual(["Work Fax: 313-555-1234", "Fax: 313-555-1235"]);
expect(actual).toEqual("Work Fax: 313-555-1234\nFax: 313-555-1235");
});
it("should sort by system ", () => {
const contactPoints: ContactPoint[] = [
{
system: "fax",
value: "+13135551234",
use: "work",
},
{
system: "email",
value: "medicine@example.com",
},
{
system: "pager",
value: "+1 313 555-1235",
},
{
system: "phone",
value: "+1 313 555-1236",
},
{
system: "email",
value: "medicine@example.com",
},
{
system: "other",
value: "123",
},
];
const actual = formatContactPoint(contactPoints);
expect(actual).toEqual("313-555-1236\nWork Fax: 313-555-1234\nPager: 313-555-1235\nmedicine@example.com\nmedicine@example.com\nOther: 123");
});
});

Expand Down

0 comments on commit 7b04236

Please sign in to comment.