-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: add pager (and others) to contact info #2936
Changes from all commits
96fd5e1
e83f0cc
239f496
8e1b8a3
ec1cf90
7bfb92d
7b04236
8b19376
d704fac
8fff3a0
89c1505
67b3c02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,36 +563,64 @@ export const removeHtmlElements = (element: string): string => { | |
return element.replace(regex, ""); | ||
}; | ||
|
||
const contactSortOrder = [ | ||
"phone", | ||
"fax", | ||
"sms", | ||
"pager", | ||
"url", | ||
"email", | ||
"other", | ||
"", | ||
]; | ||
|
||
/** | ||
* Converts contact points into an array of phone numbers and emails | ||
* Sorts an array of contact points in display order (`contactSortOrder`). | ||
* @param contactPoints - array of contact points | ||
* @returns array of phone numbers and emails | ||
* @returns sorted array of contact points | ||
*/ | ||
const sortContacts = (contactPoints: ContactPoint[]): ContactPoint[] => { | ||
return contactPoints.sort((a, b) => { | ||
const aInd = | ||
contactSortOrder.indexOf(a.system ?? "") ?? contactSortOrder.length; | ||
const bInd = | ||
contactSortOrder.indexOf(b.system ?? "") ?? contactSortOrder.length; | ||
return aInd - bInd; | ||
}); | ||
}; | ||
|
||
/** | ||
* 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 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 contactPoint of contactPoints) { | ||
if (contactPoint.system === "phone" && contactPoint.value) { | ||
const phoneNumberUse = toSentenceCase(contactPoint.use); | ||
contactArr.push( | ||
[phoneNumberUse, formatPhoneNumber(contactPoint.value)] | ||
.filter((c) => c) | ||
.join(": "), | ||
); | ||
} else if (contactPoint.system === "email" && contactPoint.value) { | ||
contactArr.push(contactPoint.value); | ||
} else if (contactPoint.system === "fax" && contactPoint.value) { | ||
const faxNumberUse = toSentenceCase(contactPoint.use ?? ""); | ||
for (const { system, value, use } of sortContacts(contactPoints)) { | ||
// No value, nothing to format/show | ||
if (!value) continue; | ||
|
||
if (system === "phone") { | ||
const phoneNumberUse = toSentenceCase(use); | ||
contactArr.push( | ||
[faxNumberUse, "Fax:", formatPhoneNumber(contactPoint.value ?? "")] | ||
.join(" ") | ||
.trim(), | ||
[phoneNumberUse, formatPhoneNumber(value)].filter((c) => c).join(": "), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh, good call! Thanks!! |
||
); | ||
} else if (system === "email") { | ||
contactArr.push(value); | ||
} else { | ||
const _use = toSentenceCase(use ?? ""); | ||
const _system = toSentenceCase(system ?? ""); | ||
const _value = ["fax", "pager", "sms"].includes(system as string) | ||
? formatPhoneNumber(value) | ||
: value; | ||
contactArr.push([_use, `${_system}:`, _value].join(" ").trim()); | ||
} | ||
} | ||
return contactArr; | ||
return contactArr.join("\n"); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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[] = [ | ||
|
@@ -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[] = [ | ||
|
@@ -659,7 +659,7 @@ describe("formatContactPoint", () => { | |
}, | ||
]; | ||
const actual = formatContactPoint(contactPoints); | ||
expect(actual).toEqual(["[email protected]", "medicine@example.com"]); | ||
expect(actual).toEqual("[email protected]\nmedicine@example.com"); | ||
}); | ||
it("should return fax information ", () => { | ||
const contactPoints: ContactPoint[] = [ | ||
|
@@ -674,7 +674,40 @@ 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: "[email protected]", | ||
}, | ||
{ | ||
system: "pager", | ||
value: "+1 313 555-1235", | ||
}, | ||
{ | ||
system: "phone", | ||
value: "+1 313 555-1236", | ||
}, | ||
{ | ||
system: "email", | ||
value: "[email protected]", | ||
}, | ||
{ | ||
system: "other", | ||
value: "123", | ||
}, | ||
]; | ||
const actual = formatContactPoint(contactPoints); | ||
expect(actual).toEqual( | ||
"313-555-1236\nWork Fax: 313-555-1234\nPager: 313-555-1235\[email protected]\[email protected]\nOther: 123", | ||
); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a JSDoc for this helper function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added!