Skip to content

Commit

Permalink
(feat) : Add cross border work with MPI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldkibet committed Jan 6, 2025
1 parent 9f213f7 commit 3d796ac
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 185 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
import useSWR from 'swr';

const fetcher = (url: string) => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', `Basic ${btoa('kemr:password')}`);
return fetch(url, { headers }).then((res) => res.json());
};

export function useMpiPatient(patientId: string) {
const url = `${fhirBaseUrl}/Patient/${patientId}/$cr`;
const url = `https://hiedhs.intellisoftkenya.com/fhir/Patient?_id=${patientId}`;

const {
data: patient,
error: error,
isLoading: isLoading,
} = useSWR<{ data: fhir.Patient }, Error>(url, openmrsFetch);
const { data: patient, error: error, isLoading: isLoading } = useSWR<{ data: fhir.Bundle }, Error>(url, fetcher);
const patientInfo = patient?.['entry']?.[0]?.resource;

return {
isLoading,
patient,
error: error,
patient: patientInfo,
error,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function useInitialFormValuesLocal(patientUuid: string): [FormValues, Dis
if (!isLoadingObs) {
setInitialFormValues((initialFormValues) => ({ ...initialFormValues, obs: obs, observation: observations }));
}
}, [isLoadingObs]);
}, [isLoadingObs, obs, observations]);

// Set Initial encounter

Expand All @@ -207,7 +207,7 @@ export function useInitialFormValuesLocal(patientUuid: string): [FormValues, Dis
concepts: [...occupation, ...martialStatus, ...education],
}));
}
}, [educationLoad]);
}, [educationLoad, martialStatus, education, occupation]);

return [initialFormValues, setInitialFormValues];
}
Expand Down Expand Up @@ -244,19 +244,18 @@ export function useMpiInitialFormValues(patientUuid: string): [FormValues, Dispa

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

const values = {
...initialMPIFormValues,
...getFormValuesFromFhirPatient(mpiPatient.data),
address: getAddressFieldValuesFromFhirPatient(mpiPatient.data),
identifiers,
...getFormValuesFromFhirPatient(mpiPatient),
address: getAddressFieldValuesFromFhirPatient(mpiPatient),
attributes: getPhonePersonAttributeValueFromFhirPatient(
mpiPatient.data,
mpiPatient,
fieldConfigurations.phone.personAttributeUuid,
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ export function getFormValuesFromFhirPatient(patient: fhir.Patient) {
const result = {} as FormValues;
const patientName = patient.name[0];
const additionalPatientName = patient.name[1];

result.patientUuid = patient.id;
result.givenName = patientName?.given[0];
result.middleName = patientName?.given[1];
result.givenName = patientName?.given?.[0];
result.middleName = patientName?.given?.[1];
result.familyName = patientName?.family;
result.addNameInLocalLanguage = !!additionalPatientName ? true : undefined;
result.additionalGivenName = additionalPatientName?.given?.[0] ?? undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-patient-search-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/esm-patient-search-app/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@kenyaemr/esm-patient-search-app",
"name": "@openmrs/esm-patient-search-app",
"version": "8.0.2",
"description": "Patient search microfrontend for the OpenMRS SPA",
"browser": "dist/kenyaemr-esm-patient-search-app.js",
"browser": "dist/openmrs-esm-patient-search-app.js",
"main": "src/index.ts",
"source": true,
"license": "MPL-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-search-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import patientSearchIconComponent from './patient-search-icon';
import patientSearchButtonComponent from './patient-search-button/patient-search-button.component';
import patientSearchBarComponent from './compact-patient-search-extension';

const moduleName = '@kenyaemr/esm-patient-search-app';
const moduleName = '@openmrs/esm-patient-search-app';

const options = {
featureName: 'patient-search',
Expand Down
10 changes: 7 additions & 3 deletions packages/esm-patient-search-app/src/mpi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function inferModeFromSearchParams(searchParams: URLSearchParams): 'mpi'
}

export function mapToOpenMRSPatient(fhirPatients: fhir.Bundle, nameTemplate: string): Array<SearchedPatient> {
if (!fhirPatients) {
return [];
}

if (fhirPatients.total < 1) {
return [];
}
Expand Down Expand Up @@ -35,9 +39,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 @@ -68,7 +68,7 @@ const PatientBanner: React.FC<PatientBannerProps> = ({ patient, patientUuid, hid

const handleCreatePatientRecord = (externalId: string) => {
navigate({
to: `${window.getOpenmrsSpaBase()}patient-registration?sourceRecord=${externalId}`,
to: `${window.getOpenmrsSpaBase()}patient-registration?sourceRecord=${patient.externalId}`,
});
};

Expand Down
12 changes: 9 additions & 3 deletions packages/esm-patient-search-app/src/patient-search.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function useInfinitePatientSearch(
if (prevPageData && !prevPageData?.data?.link.some((link) => link.relation === 'next')) {
return null;
}
let url = `${fhirBaseUrl}/Patient/$cr-search?name=${searchQuery}`;
let url = `https://hiedhs.intellisoftkenya.com/fhir/Patient?name=${searchQuery}`;

return url;
},
Expand All @@ -106,6 +106,12 @@ export function useInfinitePatientSearch(
openmrsFetch,
);

const fetcher = (url: string) => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', `Basic ${btoa('kemr:password')}`);
return fetch(url, { headers }).then((res) => res.json());
};
const {
data: mpiData,
isLoading: isLoadingMpi,
Expand All @@ -115,15 +121,15 @@ export function useInfinitePatientSearch(
size: mpiSize,
} = useSWRInfinite<InfinitePatientBundleResponse, Error>(
shouldFetch ? (searchMode == 'mpi' ? getExtUrl : null) : null,
openmrsFetch,
searchMode == 'mpi' ? fetcher : openmrsFetch,
);

const { nameTemplate } = useConfig() as PatientSearchConfig;

const mappedData =
searchMode === 'mpi'
? mpiData
? mapToOpenMRSPatient(mpiData ? mpiData[0].data : null, nameTemplate)
? mapToOpenMRSPatient(mpiData ? (mpiData[0] as any) : null, nameTemplate)
: null
: data?.flatMap((response) => response?.data?.results ?? []) ?? null;

Expand Down
Loading

0 comments on commit 3d796ac

Please sign in to comment.