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

(fix) Pass patient object to banner actions menu #1340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';
import { PatientSearchContext } from '../patient-search-context';
import type { FHIRIdentifier, FHIRPatientType, Identifier, SearchedPatient } from '../types';
import styles from './compact-patient-banner.scss';
import { toFhirPatient } from './compact-patient-search.resource';

interface ClickablePatientContainerProps {
patient: SearchedPatient;
Expand Down Expand Up @@ -56,43 +57,12 @@ const CompactPatientBanner = forwardRef<HTMLDivElement, CompactPatientBannerProp
}
};

// TODO: If/When the online patient search is migrated to the FHIR API at some point, this could
// be removed. In fact, it could maybe be done at this point already, but doing it when the
// search returns FHIR objects is much simpler because the code which uses the `fhirPatients`
// doesn't have to be touched then.
const fhirPatients: Array<FHIRPatientType> = useMemo(() => {
// TODO: If/When the online patient search is migrated to the FHIR API at some point, this could
// be removed. In fact, it could maybe be done at this point already, but doing it when the
// search returns FHIR objects is much simpler because the code which uses the `fhirPatients`
// doesn't have to be touched then.
return patients.map((patient) => {
const preferredAddress = patient.person.addresses?.find((address) => address.preferred);
return {
id: patient.uuid,
name: [
{
id: String(Math.random()), // not used
given: [patient.person.personName.givenName, patient.person.personName.middleName],
family: patient.person.personName.familyName,
text: patient.person.personName.display,
},
],
gender: patient.person.gender,
birthDate: patient.person.birthdate,
deceasedDateTime: patient.person.deathDate,
deceasedBoolean: patient.person.dead,
identifier: patient.identifiers as unknown as Array<FHIRIdentifier>,
address: preferredAddress
? [
{
id: String(Math.random()), // not used
city: preferredAddress.cityVillage,
country: preferredAddress.country,
postalCode: preferredAddress.postalCode,
state: preferredAddress.stateProvince,
use: 'home',
},
]
: [],
telecom: patient.attributes?.filter((attribute) => attribute.attributeType.display == 'Telephone Number'),
};
});
return patients.map(toFhirPatient);
}, [patients]);

return (
Expand All @@ -109,7 +79,7 @@ const CompactPatientBanner = forwardRef<HTMLDivElement, CompactPatientBannerProp
? [preferredIdentifier, ...configuredIdentifiers]
: configuredIdentifiers;

const patientName = getPatientName(patient);
const patientName = getPatientName(patient as fhir.Patient);

return (
<ClickablePatientContainer key={patient.id} patient={patients[index]}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { type FHIRIdentifier, type FHIRPatientType, type SearchedPatient } from '../types';

export function toFhirPatient(patient: SearchedPatient): FHIRPatientType {
const preferredAddress = patient.person.addresses?.find((address) => address.preferred);
return {
id: patient.uuid,
name: [
{
id: String(Math.random()), // not used
given: [patient.person.personName.givenName, patient.person.personName.middleName],
family: patient.person.personName.familyName,
text: patient.person.personName.display,
},
],
gender: patient.person.gender,
birthDate: patient.person.birthdate,
deceasedDateTime: patient.person.deathDate,
deceasedBoolean: patient.person.dead,
identifier: patient.identifiers as unknown as Array<FHIRIdentifier>,
address: preferredAddress
? [
{
id: String(Math.random()), // not used
city: preferredAddress.cityVillage,
country: preferredAddress.country,
postalCode: preferredAddress.postalCode,
state: preferredAddress.stateProvince,
use: 'home',
},
]
: [],
telecom: patient.attributes?.filter((attribute) => attribute.attributeType.display == 'Telephone Number'),
};
}
Comment on lines +3 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chibongho!
This particular change needs to be a part of the whole change in the patient search app to migrate the search API from OpenMRS REST to FHIR.
For now, we need to pass the FHIR object inside the banner actions, which is what we get from the usePatient hook.
Apologies.
Created a ticket here: https://openmrs.atlassian.net/browse/O3-4079

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { type SearchedPatient } from '../../../types';
import styles from './patient-banner.scss';
import { PatientSearchContext } from '../../../patient-search-context';
import { toFhirPatient } from '../../../compact-patient-search/compact-patient-search.resource';

interface PatientBannerProps {
patient: SearchedPatient;
Expand Down Expand Up @@ -57,9 +58,7 @@ const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hid
const isDeceased = !!patient.person.deathDate;

const fhirPatient = React.useMemo(() => {
return {
deceasedDateTime: patient.person.deathDate,
};
return toFhirPatient(patient);
}, [patient]);

return (
Expand Down Expand Up @@ -109,6 +108,7 @@ const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hid
{!hideActionsOverflow ? (
<PatientBannerActionsMenu
patientUuid={patientUuid}
patient={fhirPatient as fhir.Patient}
actionsSlotName={'patient-search-actions-slot'}
additionalActionsSlotState={{
selectPatientAction: nonNavigationSelectPatientAction,
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-search-app/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface FHIRPatientType {
postalCode: string;
country: string;
}>;
telecom: object;
}

export interface FHIRIdentifier {
Expand Down
Loading
Loading