Skip to content

Commit

Permalink
Merge branch 'angela/2671-lab-value-units' of https://github.com/CDCg…
Browse files Browse the repository at this point in the history
…ov/phdi into angela/2671-lab-value-units
  • Loading branch information
angelathe committed Nov 18, 2024
2 parents 463a173 + 927d508 commit 6c4889a
Show file tree
Hide file tree
Showing 14 changed files with 3,756 additions and 61 deletions.
11 changes: 3 additions & 8 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 All @@ -20,7 +15,7 @@ patientEthnicity: "Bundle.entry.resource.where(resourceType = 'Patient').extensi
patientEthnicityDetailed: "Bundle.entry.resource.where(resourceType = 'Patient').extension.where(url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity').extension.where(url = 'detailed').valueCoding.display"
patientLanguage: "Bundle.entry.resource.where(resourceType = 'Patient').communication.first().language.coding.first().display"
patientTribalAffiliation: "Bundle.entry.resource.where(resourceType = 'Patient').extension.where(url='http: //hl7.org/fhir/us/ecr/StructureDefinition/us-ph-tribal-affiliation-extension').extension.where(url='TribeName').value.display"
patientEmergencyContact: "Bundle.entry.resource.where(resourceType = 'Patient').contact.first()"
patientEmergencyContact: "Bundle.entry.resource.where(resourceType = 'Patient').contact"

# Social History
patientCurrentJobTitle: "Bundle.entry.resource.where(resourceType='Observation').where(meta.profile='http://hl7.org/fhir/us/odh/StructureDefinition/odh-PastOrPresentJob').where(effectivePeriod.end.exists().not()).iif(valueCodeableConcept.coding.display.exists(), valueCodeableConcept.coding.display, valueString)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const EcrPaginationWrapper = ({
useEffect(() => {
const userPreferencesString = localStorage.getItem("userPreferences");
if (userPreferencesString) {
setUserPreferences(JSON.parse(userPreferencesString));
const storedPrefs = JSON.parse(userPreferencesString);
setUserPreferences({ ...defaultPreferences, ...storedPrefs });
}
}, []);

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
97 changes: 70 additions & 27 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 Expand Up @@ -507,26 +546,30 @@ export const evaluateEmergencyContact = (
fhirBundle: Bundle,
mappings: PathMappings,
) => {
const contact = evaluate(
fhirBundle,
mappings.patientEmergencyContact,
)[0] as PatientContact;
const contacts = (evaluate(fhirBundle, mappings.patientEmergencyContact) ??
[]) as PatientContact[];

if (contact) {
const relationship = contact.relationship?.[0].coding?.[0]?.display;
if (contacts.length === 0) return undefined;

const address = formatAddress(
contact.address?.line,
contact.address?.city,
contact.address?.state,
contact.address?.postalCode,
contact.address?.country,
);
return contacts
.map((contact) => {
const relationship = contact.relationship?.[0].coding?.[0]?.display;

const phoneNumbers = formatContactPoint(contact.telecom);
const address = formatAddress(
contact.address?.line,
contact.address?.city,
contact.address?.state,
contact.address?.postalCode,
contact.address?.country,
);

return [relationship, address, phoneNumbers].filter(Boolean).join("\n");
}
const phoneNumbers = formatContactPoint(contact.telecom);

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

/**
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",
);
});
});
Loading

0 comments on commit 6c4889a

Please sign in to comment.