diff --git a/jest.config.js b/jest.config.js
index 82b65f646..8c427b8d9 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -32,13 +32,14 @@ const config = {
'^@carbon/charts-react$': path.resolve(__dirname, '__mocks__', '@carbon__charts-react.ts'),
'^dexie$': require.resolve('dexie'),
'^lodash-es/(.*)$': 'lodash/$1',
+ '^lodash-es$': 'lodash',
'^react-i18next$': path.resolve(__dirname, '__mocks__', 'react-i18next.js'),
},
testEnvironment: 'jsdom',
testPathIgnorePatterns: [
- "/node_modules/",
- "/e2e/" // Ignore the e2e directory containing Playwright tests
- ]
+ '/node_modules/',
+ '/e2e/', // Ignore the e2e directory containing Playwright tests
+ ],
};
module.exports = config;
diff --git a/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx b/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx
index 4d30c467e..2986aab6b 100644
--- a/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx
+++ b/packages/esm-commons-lib/src/components/cohort-patient-list/helpers.tsx
@@ -6,9 +6,8 @@ import localizedFormat from 'dayjs/plugin/localizedFormat';
import relativeTime from 'dayjs/plugin/relativeTime';
import { AddPatientToListOverflowMenuItem } from '../modals/add-patient-to-list-modal.component';
import { fetchPatientLastEncounter } from '../../api/api';
-import { changeWorkspaceContext } from '@openmrs/esm-patient-common-lib';
import { launchForm } from '../../utils/ohri-forms-commons';
-import { navigate } from '@openmrs/esm-framework';
+import { navigate, WorkspaceWindow } from '@openmrs/esm-framework';
interface PatientMetaConfig {
location: { name: string };
@@ -55,21 +54,23 @@ export const LaunchableFormMenuItem = ({
} else {
setIsLoading(false);
}
- }, []);
+ }, [continueEncounterActionText, encounterType, encounterUuid, launchableForm.editLatestEncounter, patientUuid]);
return (
<>
{isLoading ? (
) : (
- {
- changeWorkspaceContext(patientUuid);
- launchForm(form, encounterUuid ? 'edit' : 'enter', moduleName, form.name, encounterUuid, null, null);
- navigate({ to: patientUrl });
- }}
- />
+ <>
+ {
+ launchForm(form, encounterUuid ? 'edit' : 'enter', moduleName, form.name, encounterUuid, null, null);
+ navigate({ to: patientUrl });
+ }}
+ />
+
+ >
)}
>
);
@@ -94,7 +95,7 @@ export const ViewSummaryMenuItem = ({ patientUuid, ViewSummary, encounterType })
} else {
setIsLoading(false);
}
- }, []);
+ }, [ViewSummary.editLatestEncounter, encounterType, encounterUuid, patientUuid, viewSummaryActionText]);
return (
<>
@@ -132,7 +133,7 @@ export const ViewTptSummaryMenuItem = ({ patientUuid, ViewTptSummary, encounterT
} else {
setIsLoading(false);
}
- }, []);
+ }, [ViewTptSummary.editLatestEncounter, encounterType, patientUuid, encounterUuid, viewTptSummaryActionText]);
return (
<>
diff --git a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx
index a849aa717..4c4352a33 100644
--- a/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx
+++ b/packages/esm-commons-lib/src/components/encounter-list/encounter-list.component.tsx
@@ -13,7 +13,6 @@ import { useEncounterRows } from '../../hooks/useEncounterRows';
import { OpenmrsEncounter } from '../../api/types';
import { useFormsJson } from '../../hooks/useFormsJson';
import { usePatientDeathStatus } from '../../hooks/usePatientDeathStatus';
-import { mutate } from 'swr';
export interface EncounterListColumn {
key: string;
@@ -42,6 +41,7 @@ export interface EncounterListProps {
workspaceWindowSize?: 'minimized' | 'maximized';
};
filter?: (encounter: any) => boolean;
+ afterFormSaveAction?: () => void;
}
export const EncounterList: React.FC = ({
@@ -53,6 +53,7 @@ export const EncounterList: React.FC = ({
formList,
filter,
launchOptions,
+ afterFormSaveAction,
}) => {
const { t } = useTranslation();
const [paginatedRows, setPaginatedRows] = useState([]);
@@ -63,7 +64,12 @@ export const EncounterList: React.FC = ({
const { isDead } = usePatientDeathStatus(patientUuid);
const formNames = useMemo(() => formList.map((form) => form.name), []);
const { formsJson, isLoading: isLoadingFormsJson } = useFormsJson(formNames);
- const { encounters, isLoading, onFormSave } = useEncounterRows(patientUuid, encounterType, filter);
+ const { encounters, isLoading, onFormSave } = useEncounterRows(
+ patientUuid,
+ encounterType,
+ filter,
+ afterFormSaveAction,
+ );
const { moduleName, workspaceWindowSize, displayText, hideFormLauncher } = launchOptions;
const defaultActions = useMemo(
@@ -104,12 +110,7 @@ export const EncounterList: React.FC = ({
const abortController = new AbortController();
deleteEncounter(encounterUuid, abortController)
.then(() => {
- mutate(
- (key) =>
- typeof key === "string" && key.startsWith("/ws/rest/v1/encounter"),
- undefined,
- { revalidate: true }
- );
+ onFormSave();
showSnackbar({
isLowContrast: true,
title: t('encounterDeleted', 'Encounter deleted'),
@@ -125,10 +126,14 @@ export const EncounterList: React.FC = ({
kind: 'error',
});
});
+
+ // Update encounters after deletion
+ const updatedEncounters = encounters.filter((enc) => enc.uuid !== encounterUuid);
+ constructPaginatedTableRows(updatedEncounters, currentPage, pageSize);
close();
},
});
- }, [])
+ }, []);
useEffect(() => {
if (!isLoadingFormsJson) {
@@ -223,15 +228,15 @@ export const EncounterList: React.FC = ({
// If custom config is available, generate actions accordingly; otherwise, fallback to the default actions.
const actions = tableRow.actions?.length ? tableRow.actions : defaultActions;
tableRow['actions'] = (
-
+
{actions.map((actionItem, index) => (
{
e.preventDefault();
- actionItem.mode == 'delete' ?
- handleDeleteEncounter(encounter.uuid, encounter.encounterType.name)
+ actionItem.mode == 'delete'
+ ? handleDeleteEncounter(encounter.uuid, encounter.encounterType.name)
: launchEncounterForm(
forms.find((form) => form.name == actionItem?.form?.name),
moduleName,
@@ -242,7 +247,7 @@ export const EncounterList: React.FC = ({
actionItem.intent,
workspaceWindowSize,
patientUuid,
- );
+ );
}}
/>
))}
@@ -252,7 +257,7 @@ export const EncounterList: React.FC = ({
});
setPaginatedRows(rows);
},
- [columns, defaultActions, forms, moduleName, workspaceWindowSize, patientUuid, onFormSave],
+ [columns, defaultActions, forms, moduleName, onFormSave, workspaceWindowSize, patientUuid, handleDeleteEncounter],
);
useEffect(() => {
@@ -265,7 +270,7 @@ export const EncounterList: React.FC = ({
if (forms.length == 1 && !forms[0]['availableIntents']?.length) {
// we only have one form with no intents
// just return the "Add" button
- return (
+ return (