Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reagan-meant committed Dec 30, 2024
1 parent b25b124 commit 70f3827
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 45 deletions.
8 changes: 4 additions & 4 deletions packages/esm-patient-registration-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface RegistrationConfig {
month: number;
};
};
identifier: [{ identifierTypeSystem: string; identifierTypeUuid: string }];
identifierMappings: [{ fhirIdentifierSystem: string; openmrsIdentifierTypeUuid: string }];
phone: {
personAttributeUuid: string;
validation?: {
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function useInitialFormValuesLocal(patientUuid: string): [FormValues, Dis
return [initialFormValues, setInitialFormValues];
}

export function useInitialFormValueMpi(patientUuid: string): [FormValues, Dispatch<FormValues>] {
export function useMpiInitialFormValues(patientUuid: string): [FormValues, Dispatch<FormValues>] {
const { fieldConfigurations } = useConfig<RegistrationConfig>();
const { isLoading: isLoadingMpiPatient, patient: mpiPatient } = useMpiPatient(patientUuid);

Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ 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';
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;
Expand All @@ -47,14 +46,11 @@ export const PatientRegistration: React.FC<PatientRegistrationProps> = ({ savePa
const [target, setTarget] = useState<undefined | string>();
const { patientUuid: uuidOfPatientToEdit } = useParams();
const sourcePatientId = new URLSearchParams(search).get('sourceRecord');
/* const { sourceRecord } = useAppContext<MPIContext>(
"sourceRecord"
) */
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(uuidOfPatientToEdit);
const { t } = useTranslation();
const [capturePhotoProps, setCapturePhotoProps] = useState<CapturePhotoProps | null>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()]),
}));
Expand Down Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions packages/esm-patient-search-app/src/mpi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
useVisit,
navigate,
UserFollowIcon,
useDefineAppContext,
} from '@openmrs/esm-framework';
import { type PatientSearchConfig } from '../../../config-schema';
import { type SearchedPatient } from '../../../types';
Expand All @@ -36,10 +35,6 @@ interface PatientBannerProps {
isMPIPatient: boolean;
}

export interface MPIContext {
sourceRecord: string;
}

const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hideActionsOverflow, isMPIPatient }) => {
const { t } = useTranslation();
const { currentVisit } = useVisit(patientUuid);
Expand Down Expand Up @@ -70,13 +65,8 @@ const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hid
};

const isDeceased = !!patient.person.deathDate;
/* const [sourceRecord, setSourceRecord ] = useState<string | undefined>()
useDefineAppContext<MPIContext>("sourceRecord", {
sourceRecord: sourceRecord
}); */

const handleCreatePatientRecord = (externalId: string) => {
//setSourceRecord(externalId);
navigate({
to: `${window.getOpenmrsSpaBase()}patient-registration?sourceRecord=${externalId}`,
});
Expand All @@ -102,7 +92,7 @@ const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hid
{isMPIPatient && (
<div>
<Tag className={styles.mpiTag} type="blue">
&#127760; {'MPI'}
&#127760; {t('mpi', 'MPI')}
</Tag>
</div>
)}
Expand Down
51 changes: 37 additions & 14 deletions packages/esm-patient-search-app/src/patient-search.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export function useInfinitePatientSearch(
const getExtUrl = useCallback(
(
page,
prevPageData: FetchResponse<{ results: Array<SearchedPatient>; links: Array<{ rel: 'prev' | 'next' }> }>,
prevPageData: FetchResponse<{ results: Array<fhir.Bundle>; 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}`;
Expand Down Expand Up @@ -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,
]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-search-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 70f3827

Please sign in to comment.