Skip to content

Commit

Permalink
add mutiple names and addresses (#2911)
Browse files Browse the repository at this point in the history
* add mutiple names and addresses

* add some tests

* update logic

* typo

* build error

* PR updates

* more pr updates

* In case there is no official use name
  • Loading branch information
lina-roth authored Nov 15, 2024
1 parent 39be57b commit 70735e9
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 41 deletions.
9 changes: 2 additions & 7 deletions containers/ecr-viewer/src/app/api/fhirPath.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
patientGivenName: "Bundle.entry.resource.where(resourceType = 'Patient').name.first().given"
patientFamilyName: "Bundle.entry.resource.where(resourceType = 'Patient').name.first().family"
patientStreetAddress: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().line"
patientCity: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().city"
patientState: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().state"
patientZipCode: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().postalCode"
patientCountry: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().country"
patientNameList: "Bundle.entry.resource.where(resourceType = 'Patient').name"
patientAddressList: "Bundle.entry.resource.where(resourceType = 'Patient').address"
patientPhoneNumbers: "Bundle.entry.resource.where(resourceType = 'Patient').telecom.where(system = 'phone')"
patientEmails: "Bundle.entry.resource.where(resourceType = 'Patient').telecom.where(system = 'email')"
patientCounty: "Bundle.entry.resource.where(resourceType = 'Patient').address.first().county"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const evaluateEcrSummaryPatientDetails = (
return evaluateData([
{
title: "Patient Name",
value: evaluatePatientName(fhirBundle, fhirPathMappings),
value: evaluatePatientName(fhirBundle, fhirPathMappings, false),
},
{
title: "DOB",
Expand Down
61 changes: 50 additions & 11 deletions containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,43 @@ import { evaluateTravelHistoryTable } from "./socialHistoryService";
* Evaluates patient name from the FHIR bundle and formats it into structured data for display.
* @param fhirBundle - The FHIR bundle containing patient contact info.
* @param mappings - The object containing the fhir paths.
* @param isPatientBanner - Whether to format the name for the Patient banner
* @returns The formatted patient name
*/
export const evaluatePatientName = (
fhirBundle: Bundle,
mappings: PathMappings,
isPatientBanner: boolean,
) => {
const givenNames = evaluate(fhirBundle, mappings.patientGivenName).join(" ");
const familyName = evaluate(fhirBundle, mappings.patientFamilyName);

return `${givenNames} ${familyName}`;
const nameList = evaluate(fhirBundle, mappings.patientNameList);

if (nameList.length > 0) {
if (isPatientBanner) {
const name = nameList.find((name) => name.use === "official");
if (name) {
return formatName(name.given, name.family, name.prefix, name.suffix);
} else {
return formatName(
nameList[0].given,
nameList[0].family,
nameList[0].prefix,
nameList[0].suffix,
);
}
} else {
return nameList
.map((name) => {
return formatName(
name.given,
name.family,
name.prefix,
name.suffix,
nameList.length > 1 ? name?.use : undefined,
);
})
.join("\n");
}
}
};

/**
Expand Down Expand Up @@ -94,12 +121,24 @@ export const evaluatePatientAddress = (
fhirBundle: Bundle,
mappings: PathMappings,
) => {
const streetAddresses = evaluate(fhirBundle, mappings.patientStreetAddress);
const city = evaluate(fhirBundle, mappings.patientCity)[0];
const state = evaluate(fhirBundle, mappings.patientState)[0];
const zipCode = evaluate(fhirBundle, mappings.patientZipCode)[0];
const country = evaluate(fhirBundle, mappings.patientCountry)[0];
return formatAddress(streetAddresses, city, state, zipCode, country);
const addresses = evaluate(fhirBundle, mappings.patientAddressList);

if (addresses.length > 0) {
return addresses
.map((address) => {
return formatAddress(
address.line,
address.city,
address.state,
address.postalCode,
address.country,
addresses.length > 1 ? address?.use : undefined,
);
})
.join("\n\n");
} else {
return "";
}
};

/**
Expand Down Expand Up @@ -252,7 +291,7 @@ export const evaluateDemographicsData = (
const demographicsData: DisplayDataProps[] = [
{
title: "Patient Name",
value: evaluatePatientName(fhirBundle, mappings),
value: evaluatePatientName(fhirBundle, mappings, false),
},
{ title: "DOB", value: evaluate(fhirBundle, mappings.patientDOB)[0] },
{
Expand Down
9 changes: 9 additions & 0 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ export interface TableJson {
* @param family - Optional string representing family name or surname.
* @param [prefix] - Optional array of name prefix(es).
* @param [suffix] - Optional array of name suffix(es).
* @param [use] - Optional array of name use(s).
* @returns Formatted name.
*/
export const formatName = (
given?: string[],
family?: string,
prefix?: string[],
suffix?: string[],
use?: string,
) => {
const nameArray: string[] = [];
if (use) {
nameArray.push(toSentenceCase(use) + ":");
}
if (prefix) {
nameArray.push(...prefix);
}
Expand All @@ -64,6 +69,7 @@ export const formatName = (
* @param state - The state or region name.
* @param zipCode - The ZIP code or postal code.
* @param country - The country name.
* @param [use] - Optional address use.
* @returns The formatted address string.
*/
export const formatAddress = (
Expand All @@ -72,14 +78,17 @@ export const formatAddress = (
state: string | undefined,
zipCode: string | undefined,
country: string | undefined,
use?: string | undefined,
) => {
let address = {
use: use || "",
streetAddress: streetAddress || [],
cityState: [city, state],
zipCodeCountry: [zipCode, country],
};

return [
address.use ? toSentenceCase(address.use) + ":" : "",
address.streetAddress.filter(Boolean).join("\n"),
address.cityState.filter(Boolean).join(", "),
address.zipCodeCountry.filter(Boolean).join(", "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ describe("loadYamlConfig", () => {
it("returns the yaml config", () => {
const config = loadYamlConfig();
expect(Object.keys(config).length).toBeGreaterThan(3);
expect(config["patientGivenName"]).toBe(
"Bundle.entry.resource.where(resourceType = 'Patient').name.first().given",
expect(config["patientNameList"]).toBe(
"Bundle.entry.resource.where(resourceType = 'Patient').name",
);
});
});
170 changes: 170 additions & 0 deletions containers/ecr-viewer/src/app/tests/assets/BundlePatientMultiple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"resourceType": "Bundle",
"type": "batch",
"entry": [
{
"fullUrl": "urn:uuid:6b6b3c4c-4884-4a96-b6ab-c46406839cea",
"resource": {
"resourceType": "Patient",
"id": "6b6b3c4c-4884-4a96-b6ab-c46406839cea",
"meta": {
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
],
"source": [
"ecr"
]
},
"identifier": [
{
"system": "urn:oid:2.16.840.1.113883.3.3316.100",
"value": "10308625"
}
],
"name": [
{
"use": "official",
"family": "CASTILLO",
"given": [
"ABEL"
]
},
{
"use": "nickname",
"family": "Kid",
"given": [
"Billy The"
]
}
],
"birthDate": "2015-04-15",
"gender": "male",
"extension": [
{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race",
"extension": [
{
"url": "ombCategory",
"valueCoding": {
"code": "2054-5",
"display": "Black or African American"
}
},
{
"url": "detailed",
"valueCoding": {
"code": "2076-8",
"display": "African"
}
},
{
"url": "text",
"valueString": "Black or African American"
}
]
},
{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
"extension": [
{
"url": "ombCategory",
"valueCoding": {
"code": "2135-2",
"display": "Hispanic or Latino"
}
},
{
"url": "detailed",
"valueCoding": {
"code": "2106-3",
"display": "White"
}
},
{
"url": "text",
"valueString": "Hispanic or Latino"
}
]
},
{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
"extension": [
{
"url": "value",
"valueCodeableConcept": {
"coding": [
{
"code": "M",
"display": "Male",
"system": "urn:oid:2.16.840.1.113883.5.1"
}
]
}
}
]
}
],
"address": [
{
"use": "home",
"line": [
"1050 CARPENTER ST"
],
"city": "EDWARDS",
"state": "CA",
"country": "US",
"postalCode": "93523-2800"
},
{
"use": "vacation",
"line": [
"10 Main St."
],
"city": "City",
"state": "State",
"country": "America",
"postalCode": "7"
},
{
"use": "work",
"line": [
"20001 E. Main St."
],
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001"
}
],
"telecom": [
{
"system": "phone",
"value": "+18184195968",
"use": "home"
},
{
"system": "email",
"value": "[email protected]"
}
],
"communication": [
{
"language": {
"coding": [
{
"system": "urn:ietf:bcp:47",
"code": "en",
"display": "English"
}
]
}
}
]
},
"request": {
"method": "PUT",
"url": "Patient/6b6b3c4c-4884-4a96-b6ab-c46406839cea"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Patient Name
</div>
<div
class="grid-col maxw7 text-pre-line"
>
</div>
</div>
<div
class="section__line_gray"
/>
</div>
<div>
<div
class="grid-row"
Expand Down Expand Up @@ -246,6 +227,25 @@ exports[`Snapshot test for Accordion Content Given no data, info message for emp
<div
class="usa-summary-box__text"
>
<div>
<div
class="grid-row"
>
<div
class="data-title padding-right-1"
>
Patient Name
</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
Loading

0 comments on commit 70735e9

Please sign in to comment.