Skip to content
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

add mutiple names and addresses #2911

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
69 changes: 58 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,41 @@ 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) {
return nameList.map((name) => {
if (name.use === "official") {
return formatName(name.given, name.family, name.prefix, name.suffix);
}
})[0];
mcmcgrath13 marked this conversation as resolved.
Show resolved Hide resolved
} else if (nameList.length == 1) {
return nameList.map((name) => {
return formatName(name.given, name.family, name.prefix, name.suffix);
})[0];
} else {
return nameList
.map((name) => {
return formatName(
name.given,
name.family,
name.prefix,
name.suffix,
name?.use,
);
})
mcmcgrath13 marked this conversation as resolved.
Show resolved Hide resolved
.join("\n");
}
}
};

/**
Expand Down Expand Up @@ -94,12 +119,34 @@ 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 == 1) {
return addresses.map((address) => {
return formatAddress(
address.line,
address.city,
address.state,
address.postalCode,
address.country,
);
})[0];
} else if (addresses.length > 1) {
return addresses
mcmcgrath13 marked this conversation as resolved.
Show resolved Hide resolved
.map((address) => {
lina-roth marked this conversation as resolved.
Show resolved Hide resolved
return formatAddress(
address.line,
address.city,
address.state,
address.postalCode,
address.country,
address?.use,
);
})
.join("\n\n");
} else {
return "";
}
};

/**
Expand Down Expand Up @@ -252,7 +299,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
Loading