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) Use the new workspace container #1892

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
@@ -1,18 +1,17 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import {
fetchPatientsFinalHIVStatus,
getCohortList,
} from '../../api.resource';
import dayjs from 'dayjs';

import { fetchPatientsFinalHIVStatus, getCohortList } from '../../api.resource';
import { TableEmptyState } from '../empty-state/table-empty-state.component';
import { DataTableSkeleton } from '@carbon/react';
import { basePath } from '../../constants';
import { useTranslation } from 'react-i18next';
import { useFormsJson } from '../../hooks/useFormsJson';
import { columns, consolidatatePatientMeta, type PatientListColumn } from './helpers';
import styles from './cohort-patient-list.scss';
import { PatientTable } from '../patient-table/patient-table.component';

import styles from './cohort-patient-list.scss';

interface CohortPatientListProps {
cohortId: string;
cohortSlotName: string;
Expand Down Expand Up @@ -42,15 +41,13 @@ interface CohortPatientListProps {

export const CohortPatientList: React.FC<CohortPatientListProps> = ({
cohortId,
cohortSlotName,
isReportingCohort,
otherColumns,
excludeColumns,
queryParams,
associatedEncounterType,
launchableForm,
addPatientToListOptions,
extraAssociatedEncounterTypes,
moduleName,
viewPatientProgramSummary,
viewTptPatientProgramSummary,
Expand All @@ -60,57 +57,8 @@ export const CohortPatientList: React.FC<CohortPatientListProps> = ({
const [allPatients, setAllPatients] = useState([]);
const columnAtLastIndex = 'actions';
const forms = useMemo(() => [launchableForm.name], [launchableForm]);
const { formsJson, isLoading: isLoadingFormsJson } = useFormsJson(forms);

useEffect(() => {
getCohortList(cohortId, queryParams, isReportingCohort, associatedEncounterType)
.then((data) => {
if(data) {
const mappedPatients = data.filter((patient) => patient !== null)
.map((mappedData) => {
const patient = constructPatient(mappedData?.patient);
patient.url = `${window.spaBase}/patient/${patient?.uuid}/chart/`;
return {
...patient,
encounter: mappedData,
...consolidatatePatientMeta(mappedData, formsJson[0], {
isDynamicCohort: isReportingCohort,
location: mappedData.location,
encounterType: associatedEncounterType,
moduleName,
launchableFormProps: launchableForm,
addPatientToListOptions: {
...addPatientToListOptions,
displayText: t('moveToListSideNav', 'Move to list'),
},
viewTptPatientProgramSummary,
viewPatientProgramSummary,
}),
};
})
setAllPatients(mappedPatients);
setIsLoading(false);
}
}).catch((error) => {
console.error('Error fetching cohort data:', error);
setIsLoading(false);
})
}, []);

useEffect(() => {
const fetchHivResults = excludeColumns ? !excludeColumns.includes('hivResult') : true;
if ((!isLoading || !associatedEncounterType) && !loadedHIVStatuses && fetchHivResults) {
Promise.all(allPatients.map((patient) => fetchPatientsFinalHIVStatus(patient.uuid))).then((results) => {
results.forEach((hivResult, index) => {
allPatients[index].hivResult = hivResult;
if (index == allPatients.length - 1) {
setAllPatients([...allPatients]);
setLoadedHIVStatuses(true);
}
});
});
}
}, [allPatients, associatedEncounterType, excludeColumns, isLoading, loadedHIVStatuses]);
const { formsJson } = useFormsJson(forms);
const { t } = useTranslation();

const constructPatient = useCallback(
(rawPatient) => {
Expand Down Expand Up @@ -140,7 +88,70 @@ export const CohortPatientList: React.FC<CohortPatientListProps> = ({
[isReportingCohort, launchableForm?.targetDashboard],
);

const { t } = useTranslation();
useEffect(() => {
getCohortList(cohortId, queryParams, isReportingCohort, associatedEncounterType)
.then((data) => {
if (data) {
const mappedPatients = data
.filter((patient) => patient !== null)
.map((mappedData) => {
const patient = constructPatient(mappedData?.patient);
patient.url = `${window.spaBase}/patient/${patient?.uuid}/chart/`;
return {
...patient,
encounter: mappedData,
...consolidatatePatientMeta(mappedData, formsJson[0], {
isDynamicCohort: isReportingCohort,
location: mappedData.location,
encounterType: associatedEncounterType,
moduleName,
launchableFormProps: launchableForm,
addPatientToListOptions: {
...addPatientToListOptions,
displayText: t('moveToListSideNav', 'Move to list'),
},
viewTptPatientProgramSummary,
viewPatientProgramSummary,
}),
};
});
setAllPatients(mappedPatients);
setIsLoading(false);
}
})
.catch((error) => {
console.error('Error fetching cohort data:', error);
setIsLoading(false);
});
}, [
addPatientToListOptions,
associatedEncounterType,
cohortId,
constructPatient,
formsJson,
isReportingCohort,
launchableForm,
moduleName,
queryParams,
t,
viewPatientProgramSummary,
viewTptPatientProgramSummary,
]);

useEffect(() => {
const fetchHivResults = excludeColumns ? !excludeColumns.includes('hivResult') : true;
if ((!isLoading || !associatedEncounterType) && !loadedHIVStatuses && fetchHivResults) {
Promise.all(allPatients.map((patient) => fetchPatientsFinalHIVStatus(patient.uuid))).then((results) => {
results.forEach((hivResult, index) => {
allPatients[index].hivResult = hivResult;
if (index == allPatients.length - 1) {
setAllPatients([...allPatients]);
setLoadedHIVStatuses(true);
}
});
});
}
}, [allPatients, associatedEncounterType, excludeColumns, isLoading, loadedHIVStatuses]);

const finalColumns = useMemo(() => {
let filteredColumns = [...columns];
Expand All @@ -164,12 +175,8 @@ export const CohortPatientList: React.FC<CohortPatientListProps> = ({
filteredColumns.push(column);
}

return filteredColumns
}, [
excludeColumns,
otherColumns,
columns,
]);
return filteredColumns;
}, [excludeColumns, otherColumns]);

return (
<div className={styles.table1}>
Expand All @@ -181,12 +188,7 @@ export const CohortPatientList: React.FC<CohortPatientListProps> = ({
message={t('noPatientSidenav', 'There are no patients in this list.')}
/>
) : (
<PatientTable
columns={finalColumns}
isFetching={isLoading}
isLoading={isLoading}
patients={allPatients}
/>
<PatientTable columns={finalColumns} isFetching={isLoading} isLoading={isLoading} patients={allPatients} />
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import relativeTime from 'dayjs/plugin/relativeTime';
import { AddPatientToListOverflowMenuItem } from '../modals/add-patient-to-list-modal.component';
import { fetchPatientLastEncounter } from '../../api.resource';
import { launchForm } from '../../utils/ohri-forms-commons';
import { navigate, WorkspaceWindow } from '@openmrs/esm-framework';
import { navigate, WorkspaceContainer } from '@openmrs/esm-framework';

interface PatientMetaConfig {
location: { name: string };
Expand Down Expand Up @@ -69,7 +69,7 @@ export const LaunchableFormMenuItem = ({
navigate({ to: patientUrl });
}}
/>
<WorkspaceWindow contextKey={`patient/${patientUuid}`} />
<WorkspaceContainer contextKey={`patient/${patientUuid}`} />
</>
)}
</>
Expand Down
Loading
Loading