Skip to content

Commit

Permalink
Revert "(feat) HIE-9: Add MPI workflows to OpenMRS frontend (#1313)"
Browse files Browse the repository at this point in the history
This reverts commit e009969.
  • Loading branch information
denniskigen committed Nov 18, 2024
1 parent 38d415f commit 5bbf4fd
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 551 deletions.
16 changes: 0 additions & 16 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,6 @@ export interface RegistrationConfig {
month: number;
};
};
identifier: [{ identifierTypeSystem: string; identifierTypeUuid: string }];
phone: {
personAttributeUuid: string;
validation?: {
Expand Down Expand Up @@ -352,21 +351,6 @@ export const esmPatientRegistrationSchema = {
},
},
},
identifier: {
_type: Type.Array,
_elements: {
identifierTypeSystem: {
_type: Type.String,
_description: 'Identifier system from the fhir server',
},
identifierTypeUuid: {
_type: Type.String,
_default: null,
_description: 'Identifier type uuid of OpenMRS to map the identifier system',
},
},
_default: [],
},
phone: {
personAttributeUuid: {
_type: Type.UUID,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,20 @@ import {
import {
getAddressFieldValuesFromFhirPatient,
getFormValuesFromFhirPatient,
getIdentifierFieldValuesFromFhirPatient,
getPatientUuidMapFromFhirPatient,
getPhonePersonAttributeValueFromFhirPatient,
latestFirstEncounter,
} from './patient-registration-utils';
import { useInitialPatientRelationships } from './section/patient-relationships/relationships.resource';
import dayjs from 'dayjs';
import { useMpiPatient } from './mpi/mpi-patient.resource';

export function useInitialFormValues(patientUuid: string, isLocal: boolean): [FormValues, Dispatch<FormValues>] {
const { freeTextFieldConceptUuid, fieldConfigurations } = useConfig<RegistrationConfig>();
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(isLocal ? patientUuid : null);
const { isLoading: isLoadingMpiPatient, patient: mpiPatient } = useMpiPatient(!isLocal ? patientUuid : null);
const { data: deathInfo, isLoading: isLoadingDeathInfo } = useInitialPersonDeathInfo(isLocal ? patientUuid : null);
const { data: attributes, isLoading: isLoadingAttributes } = useInitialPersonAttributes(isLocal ? patientUuid : null);
const { data: identifiers, isLoading: isLoadingIdentifiers } = useInitialPatientIdentifiers(
isLocal ? patientUuid : null,
);
const { data: relationships, isLoading: isLoadingRelationships } = useInitialPatientRelationships(
isLocal ? patientUuid : null,
);

export function useInitialFormValues(patientUuid: string): [FormValues, Dispatch<FormValues>] {
const { freeTextFieldConceptUuid } = useConfig<RegistrationConfig>();
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(patientUuid);
const { data: deathInfo, isLoading: isLoadingDeathInfo } = useInitialPersonDeathInfo(patientUuid);
const { data: attributes, isLoading: isLoadingAttributes } = useInitialPersonAttributes(patientUuid);
const { data: identifiers, isLoading: isLoadingIdentifiers } = useInitialPatientIdentifiers(patientUuid);
const { data: relationships, isLoading: isLoadingRelationships } = useInitialPatientRelationships(patientUuid);
const { data: encounters } = useInitialEncounters(patientUuid, patientToEdit);

const [initialFormValues, setInitialFormValues] = useState<FormValues>({
Expand Down Expand Up @@ -88,12 +81,12 @@ export function useInitialFormValues(patientUuid: string, isLocal: boolean): [Fo
...initialFormValues,
...getFormValuesFromFhirPatient(patientToEdit),
address: getAddressFieldValuesFromFhirPatient(patientToEdit),
...getPhonePersonAttributeValueFromFhirPatient(patientToEdit, fieldConfigurations.phone.personAttributeUuid),
...getPhonePersonAttributeValueFromFhirPatient(patientToEdit),
birthdateEstimated: !/^\d{4}-\d{2}-\d{2}$/.test(patientToEdit.birthDate),
yearsEstimated,
monthsEstimated,
});
} else if (!isLoadingPatientToEdit && patientUuid && isLocal) {
} else if (!isLoadingPatientToEdit && patientUuid) {
const registration = await getPatientRegistration(patientUuid);

if (!registration._patientRegistrationData.formValues) {
Expand All @@ -108,32 +101,6 @@ export function useInitialFormValues(patientUuid: string, isLocal: boolean): [Fo
})();
}, [isLoadingPatientToEdit, patientToEdit, patientUuid]);

useEffect(() => {
const fetchValues = async () => {
if (mpiPatient?.data?.identifier) {
const identifiers = await getIdentifierFieldValuesFromFhirPatient(
mpiPatient.data,
fieldConfigurations.identifier,
);

const values = {
...initialFormValues,
...getFormValuesFromFhirPatient(mpiPatient.data),
address: getAddressFieldValuesFromFhirPatient(mpiPatient.data),
identifiers,
attributes: getPhonePersonAttributeValueFromFhirPatient(
mpiPatient.data,
fieldConfigurations.phone.personAttributeUuid,
),
};

setInitialFormValues(values);
}
};

fetchValues();
}, [mpiPatient, isLoadingMpiPatient]);

// Set initial patient death info
useEffect(() => {
if (!isLoadingDeathInfo && deathInfo?.dead) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Yup from 'yup';
import camelCase from 'lodash-es/camelCase';
import { openmrsFetch, parseDate, restBaseUrl } from '@openmrs/esm-framework';
import { parseDate } from '@openmrs/esm-framework';
import {
type AddressValidationSchemaType,
type Encounter,
Expand Down Expand Up @@ -192,48 +192,10 @@ export function getPatientIdentifiersFromFhirPatient(patient: fhir.Patient): Arr
});
}

export async function getIdentifierFieldValuesFromFhirPatient(
patient: fhir.Patient,
identifierConfig,
): Promise<{ [identifierFieldName: string]: PatientIdentifierValue }> {
const identifiers: FormValues['identifiers'] = {};

for (const identifier of patient.identifier) {
for (const config of identifierConfig) {
const identifierConfig = config.identifierTypeSystem === identifier.system ? config : null;

if (identifierConfig) {
let identifierTypeName;

const url = `${restBaseUrl}/patientidentifiertype/${identifierConfig.identifierTypeUuid}`;
await openmrsFetch(url).then((response) => {
if (response.status == 200 && response.data) {
identifierTypeName = response.data.name;
}
});

identifiers[identifierTypeName] = {
identifierUuid: null,
preferred: false, // consider identifier.use === 'official' ?? by default autogen is preferred
initialValue: identifier.value,
identifierValue: identifier.value,
identifierTypeUuid: identifierConfig.identifierTypeUuid,
identifierName: identifierTypeName,
required: false,
selectedSource: null,
autoGeneration: false,
};
}
}
}

return identifiers;
}

export function getPhonePersonAttributeValueFromFhirPatient(patient: fhir.Patient, phoneUuid) {
export function getPhonePersonAttributeValueFromFhirPatient(patient: fhir.Patient) {
const result = {};
if (patient.telecom) {
result[phoneUuid] = patient.telecom[0].value;
result['phone'] = patient.telecom[0].value;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ export const PatientRegistration: React.FC<PatientRegistrationProps> = ({ savePa
const config = useConfig() as RegistrationConfig;
const [target, setTarget] = useState<undefined | string>();
const { patientUuid: uuidOfPatientToEdit } = useParams();
const sourcePatientId = new URLSearchParams(search).get('sourceRecord');
const { isLoading: isLoadingPatientToEdit, patient: patientToEdit } = usePatient(uuidOfPatientToEdit);
const { t } = useTranslation();
const [capturePhotoProps, setCapturePhotoProps] = useState<CapturePhotoProps | null>(null);
const [initialFormValues, setInitialFormValues] = useInitialFormValues(
uuidOfPatientToEdit || sourcePatientId,
!!uuidOfPatientToEdit,
);
const [initialFormValues, setInitialFormValues] = useInitialFormValues(uuidOfPatientToEdit);
const [initialAddressFieldValues] = useInitialAddressFieldValues(uuidOfPatientToEdit);
const [patientUuidMap] = usePatientUuidMap(uuidOfPatientToEdit);
const location = currentSession?.sessionLocation?.uuid;
Expand Down
Loading

0 comments on commit 5bbf4fd

Please sign in to comment.