From 70f3827bcc6c9510612301c94e23262a3e6ab0c9 Mon Sep 17 00:00:00 2001 From: reagan-meant Date: Mon, 30 Dec 2024 22:11:42 +0300 Subject: [PATCH] Address comments --- .../src/config-schema.ts | 8 +-- .../patient-registration-hooks.ts | 4 +- .../patient-registration-utils.ts | 4 +- .../patient-registration.component.tsx | 8 +-- .../patient-registration.test.tsx | 6 +-- .../esm-patient-search-app/src/mpi/utils.ts | 6 +-- .../banner/patient-banner.component.tsx | 12 +---- .../src/patient-search.resource.tsx | 51 ++++++++++++++----- .../translations/en.json | 1 + 9 files changed, 55 insertions(+), 45 deletions(-) diff --git a/packages/esm-patient-registration-app/src/config-schema.ts b/packages/esm-patient-registration-app/src/config-schema.ts index 43bd591f4..3e5805271 100644 --- a/packages/esm-patient-registration-app/src/config-schema.ts +++ b/packages/esm-patient-registration-app/src/config-schema.ts @@ -68,7 +68,7 @@ export interface RegistrationConfig { month: number; }; }; - identifier: [{ identifierTypeSystem: string; identifierTypeUuid: string }]; + identifierMappings: [{ fhirIdentifierSystem: string; openmrsIdentifierTypeUuid: string }]; phone: { personAttributeUuid: string; validation?: { @@ -352,14 +352,14 @@ export const esmPatientRegistrationSchema = { }, }, }, - identifier: { + identifierMappings: { _type: Type.Array, _elements: { - identifierTypeSystem: { + fhirIdentifierSystem: { _type: Type.String, _description: 'Identifier system from the fhir server', }, - identifierTypeUuid: { + openmrsIdentifierTypeUuid: { _type: Type.String, _default: null, _description: 'Identifier type uuid of OpenMRS to map the identifier system', diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts index bb0628547..d96d6070d 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts @@ -188,7 +188,7 @@ export function useInitialFormValuesLocal(patientUuid: string): [FormValues, Dis return [initialFormValues, setInitialFormValues]; } -export function useInitialFormValueMpi(patientUuid: string): [FormValues, Dispatch] { +export function useMpiInitialFormValues(patientUuid: string): [FormValues, Dispatch] { const { fieldConfigurations } = useConfig(); const { isLoading: isLoadingMpiPatient, patient: mpiPatient } = useMpiPatient(patientUuid); @@ -223,7 +223,7 @@ export function useInitialFormValueMpi(patientUuid: string): [FormValues, Dispat if (mpiPatient?.data?.identifier) { const identifiers = await getIdentifierFieldValuesFromFhirPatient( mpiPatient.data, - fieldConfigurations.identifier, + fieldConfigurations.identifierMappings, ); const values = { diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts index 1b17766b2..48ed91872 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts @@ -201,11 +201,11 @@ export async function getIdentifierFieldValuesFromFhirPatient( for (const identifier of patient.identifier) { for (const config of identifierConfig) { - if (config.identifierTypeSystem !== identifier.system) { + if (config.fhirIdentifierSystem !== identifier.system) { continue; } - const url = `${restBaseUrl}/patientidentifiertype/${config.identifierTypeUuid}`; + const url = `${restBaseUrl}/patientidentifiertype/${config.openmrsIdentifierTypeUuid}`; promises.push( openmrsFetch(url) diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx index 5a6d61b03..47eebf77e 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx @@ -22,7 +22,7 @@ import { DummyDataInput } from './input/dummy-data/dummy-data-input.component'; import { cancelRegistration, filterOutUndefinedPatientIdentifiers, scrollIntoView } from './patient-registration-utils'; import { useInitialAddressFieldValues, - useInitialFormValueMpi, + useMpiInitialFormValues, useInitialFormValuesLocal, usePatientUuidMap, } from './patient-registration-hooks'; @@ -30,7 +30,6 @@ import { ResourcesContext } from '../offline.resources'; import { builtInSections, type RegistrationConfig, type SectionDefinition } from '../config-schema'; import { SectionWrapper } from './section/section-wrapper.component'; import BeforeSavePrompt from './before-save-prompt'; -import { type MPIContext } from '../../../esm-patient-search-app/src/patient-search-page/patient-banner/banner/patient-banner.component'; import styles from './patient-registration.scss'; let exportedInitialFormValuesForTesting = {} as FormValues; @@ -47,14 +46,11 @@ export const PatientRegistration: React.FC = ({ savePa const [target, setTarget] = useState(); const { patientUuid: uuidOfPatientToEdit } = useParams(); const sourcePatientId = new URLSearchParams(search).get('sourceRecord'); - /* const { sourceRecord } = useAppContext( - "sourceRecord" - ) */ const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(uuidOfPatientToEdit); const { t } = useTranslation(); const [capturePhotoProps, setCapturePhotoProps] = useState(null); const [initialFormValues, setInitialFormValues] = useInitialFormValuesLocal(uuidOfPatientToEdit); - const [initialMPIFormValues, setInitialMPIFormValues] = useInitialFormValueMpi(sourcePatientId); + const [initialMPIFormValues, setInitialMPIFormValues] = useMpiInitialFormValues(sourcePatientId); const [initialAddressFieldValues] = useInitialAddressFieldValues(uuidOfPatientToEdit); const [patientUuidMap] = usePatientUuidMap(uuidOfPatientToEdit); const location = currentSession?.sessionLocation?.uuid; diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx index feef8cf06..91228489d 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx @@ -112,7 +112,7 @@ jest.mock('./patient-registration.resource', () => ({ jest.mock('./patient-registration-hooks', () => ({ ...jest.requireActual('./patient-registration-hooks'), useInitialFormValuesLocal: jest.fn().mockReturnValue([{}, jest.fn()]), - useInitialFormValueMpi: jest.fn().mockReturnValue([{}, jest.fn()]), + useMpiInitialFormValues: jest.fn().mockReturnValue([{}, jest.fn()]), useInitialAddressFieldValues: jest.fn().mockReturnValue([{}, jest.fn()]), usePatientUuidMap: jest.fn().mockReturnValue([{}, jest.fn()]), })); @@ -182,8 +182,8 @@ const mockOpenmrsConfig: RegistrationConfig = { label: 'Female', }, ], - identifier: [ - { identifierTypeSystem: 'MPI OpenMRS ID', identifierTypeUuid: '8d793bee-c2cc-11de-8d13-0010c6dffd0f' }, + identifierMappings: [ + { fhirIdentifierSystem: 'MPI OpenMRS ID', openmrsIdentifierTypeUuid: '8d793bee-c2cc-11de-8d13-0010c6dffd0f' }, ], address: { useAddressHierarchy: { diff --git a/packages/esm-patient-search-app/src/mpi/utils.ts b/packages/esm-patient-search-app/src/mpi/utils.ts index 9299182a5..27880a659 100644 --- a/packages/esm-patient-search-app/src/mpi/utils.ts +++ b/packages/esm-patient-search-app/src/mpi/utils.ts @@ -35,9 +35,9 @@ export function mapToOpenMRSPatient(fhirPatients: fhir.Bundle, nameTemplate: str deathDate: fhirPatient.deceasedDateTime, personName: { display: formatName(fhirPatient, nameTemplate), - givenName: fhirPatient.name[0].given[0], - familyName: fhirPatient.name[0].family, - middleName: fhirPatient.name[0].given[1], + givenName: fhirPatient?.name?.[0]?.given?.[0], + familyName: fhirPatient?.name?.[0]?.family, + middleName: fhirPatient?.name?.[0]?.given?.[1], }, }, attributes: [], diff --git a/packages/esm-patient-search-app/src/patient-search-page/patient-banner/banner/patient-banner.component.tsx b/packages/esm-patient-search-app/src/patient-search-page/patient-banner/banner/patient-banner.component.tsx index d2ebf85db..2306a1eec 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/patient-banner/banner/patient-banner.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/patient-banner/banner/patient-banner.component.tsx @@ -17,7 +17,6 @@ import { useVisit, navigate, UserFollowIcon, - useDefineAppContext, } from '@openmrs/esm-framework'; import { type PatientSearchConfig } from '../../../config-schema'; import { type SearchedPatient } from '../../../types'; @@ -36,10 +35,6 @@ interface PatientBannerProps { isMPIPatient: boolean; } -export interface MPIContext { - sourceRecord: string; -} - const PatientBanner: React.FC = ({ patient, patientUuid, hideActionsOverflow, isMPIPatient }) => { const { t } = useTranslation(); const { currentVisit } = useVisit(patientUuid); @@ -70,13 +65,8 @@ const PatientBanner: React.FC = ({ patient, patientUuid, hid }; const isDeceased = !!patient.person.deathDate; - /* const [sourceRecord, setSourceRecord ] = useState() - useDefineAppContext("sourceRecord", { - sourceRecord: sourceRecord - }); */ const handleCreatePatientRecord = (externalId: string) => { - //setSourceRecord(externalId); navigate({ to: `${window.getOpenmrsSpaBase()}patient-registration?sourceRecord=${externalId}`, }); @@ -102,7 +92,7 @@ const PatientBanner: React.FC = ({ patient, patientUuid, hid {isMPIPatient && (
- 🌐 {'MPI'} + 🌐 {t('mpi', 'MPI')}
)} diff --git a/packages/esm-patient-search-app/src/patient-search.resource.tsx b/packages/esm-patient-search-app/src/patient-search.resource.tsx index 31b9ac9a3..ccc046eb3 100644 --- a/packages/esm-patient-search-app/src/patient-search.resource.tsx +++ b/packages/esm-patient-search-app/src/patient-search.resource.tsx @@ -86,9 +86,9 @@ export function useInfinitePatientSearch( const getExtUrl = useCallback( ( page, - prevPageData: FetchResponse<{ results: Array; links: Array<{ rel: 'prev' | 'next' }> }>, + prevPageData: FetchResponse<{ results: Array; link: Array<{ relation: 'prev' | 'next' }> }>, ) => { - if (prevPageData && !prevPageData?.data?.links.some((link) => link.rel === 'next')) { + if (prevPageData && !prevPageData?.data?.link.some((link) => link.relation === 'next')) { return null; } let url = `${fhirBaseUrl}/Patient/$cr-search?name=${searchQuery}`; @@ -127,19 +127,42 @@ export function useInfinitePatientSearch( : null : data?.flatMap((response) => response?.data?.results ?? []) ?? null; - return useMemo( - () => ({ + return useMemo(() => { + const isMpiMode = searchMode === 'mpi'; + const currentIsLoading = isMpiMode ? isLoadingMpi : isLoading; + const currentIsValidating = isMpiMode ? isValidatingMpi : isValidating; + const currentSize = isMpiMode ? mpiSize : size; + const currentSetSize = isMpiMode ? setMpiSize : setSize; + const currentError = isMpiMode ? mpiError : error; + + return { data: mappedData, - isLoading, - fetchError: error, - hasMore: data?.at(-1)?.data?.links?.some((link) => link.rel === 'next') ?? false, - isValidating, - setPage: setSize, - currentPage: size, - totalResults: data?.[0]?.data?.totalCount ?? 0, - }), - [mappedData, isLoading, error, data, isValidating, setSize, size], - ); + isLoading: currentIsLoading, + fetchError: currentError, + hasMore: isMpiMode + ? mpiData?.at(-1)?.data?.link?.some((link) => link.relation === 'next') ?? false + : data?.at(-1)?.data?.links?.some((link) => link.rel === 'next') ?? false, + isValidating: currentIsValidating, + setPage: currentSetSize, + currentPage: currentSize, + totalResults: isMpiMode ? mpiData?.[0]?.data?.total ?? 0 : data?.[0]?.data?.totalCount ?? 0, + }; + }, [ + mappedData, + isLoading, + isLoadingMpi, + error, + mpiError, + data, + mpiData, + isValidating, + isValidatingMpi, + setSize, + setMpiSize, + size, + mpiSize, + searchMode, + ]); } /** diff --git a/packages/esm-patient-search-app/translations/en.json b/packages/esm-patient-search-app/translations/en.json index 2fa982ba8..544354146 100644 --- a/packages/esm-patient-search-app/translations/en.json +++ b/packages/esm-patient-search-app/translations/en.json @@ -21,6 +21,7 @@ "filtersAppliedText": "search queries added", "male": "Male", "monthOfBirth": "Month of Birth", + "mpi": "MPI", "nextPage": "Next page", "noPatientChartsFoundMessage": "Sorry, no patient charts were found", "other": "Other",