@openmrs/esm-patient-chart-app 11.3.0 → 11.3.1-patch.9310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +27 -24
- package/dist/1119.js +1 -1
- package/dist/1197.js +1 -1
- package/dist/1815.js +2 -0
- package/dist/1815.js.map +1 -0
- package/dist/2146.js +1 -1
- package/dist/2690.js +1 -1
- package/dist/2761.js +1 -1
- package/dist/2761.js.map +1 -1
- package/dist/2859.js +1 -1
- package/dist/2859.js.map +1 -1
- package/dist/3099.js +1 -1
- package/dist/3584.js +1 -1
- package/dist/3697.js +1 -0
- package/dist/3697.js.map +1 -0
- package/dist/4055.js +1 -1
- package/dist/4132.js +1 -1
- package/dist/4300.js +1 -1
- package/dist/4335.js +1 -1
- package/dist/4618.js +1 -1
- package/dist/4632.js +1 -1
- package/dist/4632.js.map +1 -1
- package/dist/4652.js +1 -1
- package/dist/4718.js +1 -1
- package/dist/4754.js +1 -1
- package/dist/4944.js +1 -1
- package/dist/5173.js +1 -1
- package/dist/5205.js +1 -1
- package/dist/5241.js +1 -1
- package/dist/5442.js +1 -1
- package/dist/5661.js +1 -1
- package/dist/5670.js +1 -0
- package/dist/5670.js.map +1 -0
- package/dist/5827.js +1 -0
- package/dist/5827.js.map +1 -0
- package/dist/6022.js +1 -1
- package/dist/6336.js +1 -0
- package/dist/6336.js.map +1 -0
- package/dist/6411.js +1 -1
- package/dist/6411.js.map +1 -1
- package/dist/6468.js +1 -1
- package/dist/6529.js +1 -1
- package/dist/6568.js +1 -0
- package/dist/6568.js.map +1 -0
- package/dist/6679.js +1 -1
- package/dist/68.js +2 -0
- package/dist/68.js.map +1 -0
- package/dist/6840.js +1 -1
- package/dist/6859.js +1 -1
- package/dist/6924.js +1 -0
- package/dist/6924.js.map +1 -0
- package/dist/7097.js +1 -1
- package/dist/7159.js +1 -1
- package/dist/723.js +1 -1
- package/dist/7617.js +1 -1
- package/dist/7816.js +2 -0
- package/dist/7816.js.map +1 -0
- package/dist/7818.js +1 -0
- package/dist/7818.js.map +1 -0
- package/dist/7822.js +1 -0
- package/dist/7822.js.map +1 -0
- package/dist/795.js +1 -1
- package/dist/8163.js +1 -1
- package/dist/8260.js +1 -0
- package/dist/8260.js.map +1 -0
- package/dist/8278.js +1 -0
- package/dist/8278.js.map +1 -0
- package/dist/8349.js +1 -1
- package/dist/8454.js +1 -1
- package/dist/8454.js.map +1 -1
- package/dist/8618.js +1 -1
- package/dist/8709.js +1 -1
- package/dist/8709.js.map +1 -1
- package/dist/890.js +1 -1
- package/dist/9007.js +1 -1
- package/dist/9007.js.map +1 -1
- package/dist/9214.js +1 -1
- package/dist/{4727.js → 9294.js} +1 -1
- package/dist/9294.js.map +1 -0
- package/dist/9329.js +1 -0
- package/dist/9329.js.map +1 -0
- package/dist/9538.js +1 -1
- package/dist/9569.js +1 -1
- package/dist/986.js +1 -1
- package/dist/9879.js +1 -1
- package/dist/9895.js +1 -1
- package/dist/9900.js +1 -1
- package/dist/9913.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-patient-chart-app.js +1 -1
- package/dist/openmrs-esm-patient-chart-app.js.buildmanifest.json +457 -453
- package/dist/openmrs-esm-patient-chart-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +5 -4
- package/src/actions-buttons/delete-visit.component.tsx +8 -3
- package/src/actions-buttons/mark-patient-deceased.component.tsx +2 -2
- package/src/actions-buttons/start-visit.component.tsx +10 -5
- package/src/actions-buttons/start-visit.test.tsx +9 -5
- package/src/actions-buttons/stop-visit.component.tsx +1 -1
- package/src/clinical-views/encounter-list/{encounter-list-tabs.component.tsx → encounter-list-tabs.extension.tsx} +10 -6
- package/src/clinical-views/encounter-list/tag.component.test.tsx +306 -0
- package/src/clinical-views/encounter-list/tag.component.tsx +27 -28
- package/src/clinical-views/encounter-tile/encounter-tile.component.tsx +7 -6
- package/src/clinical-views/encounter-tile/tile.scss +0 -1
- package/src/clinical-views/hooks/useEncountersByVisit.ts +13 -0
- package/src/clinical-views/hooks/useLastEncounter.ts +1 -1
- package/src/clinical-views/types.ts +2 -1
- package/src/clinical-views/utils/concept-utils.ts +24 -0
- package/src/clinical-views/utils/helpers.ts +2 -2
- package/src/clinical-views/utils/index.ts +4 -1
- package/src/config-schema.ts +42 -9
- package/src/dashboard.meta.ts +4 -2
- package/src/index.ts +21 -22
- package/src/mark-patient-deceased/mark-patient-deceased-form.test.tsx +22 -11
- package/src/mark-patient-deceased/mark-patient-deceased-form.workspace.tsx +147 -138
- package/src/patient-banner-tags/{visit-attribute-tags.component.tsx → visit-attribute-tags.extension.tsx} +9 -4
- package/src/patient-chart/chart-review/dashboard-view.component.tsx +2 -2
- package/src/patient-chart/patient-chart.component.tsx +19 -36
- package/src/patient-chart/patient-chart.resources.ts +150 -0
- package/src/routes.json +17 -6
- package/src/visit/hooks/useDeleteVisit.test.tsx +39 -42
- package/src/visit/hooks/useDeleteVisit.tsx +33 -17
- package/src/visit/start-visit-button.component.tsx +2 -2
- package/src/visit/start-visit-button.test.tsx +2 -2
- package/src/visit/visit-action-items/edit-visit-details.component.tsx +29 -8
- package/src/visit/visit-form/base-visit-type.component.tsx +2 -2
- package/src/visit/visit-form/exported-visit-form.workspace.tsx +697 -0
- package/src/visit/visit-form/visit-attribute-type.component.tsx +2 -1
- package/src/visit/visit-form/visit-form.resource.ts +2 -1
- package/src/visit/visit-form/visit-form.test.tsx +28 -25
- package/src/visit/visit-form/visit-form.workspace.tsx +63 -643
- package/src/visit/visit-history-table/visit-actions-cell.component.tsx +3 -2
- package/src/visit/visit-history-table/visit-date-cell.component.tsx +1 -0
- package/src/visit/visit-history-table/visit-diagnoses-cell.component.tsx +1 -0
- package/src/visit/visit-history-table/visit-history-table.component.tsx +3 -2
- package/src/visit/visit-history-table/visit-type-cell.component.tsx +1 -0
- package/src/visit/visit-prompt/{delete-visit-dialog.component.tsx → delete-visit-dialog.modal.tsx} +10 -4
- package/src/visit/visit-prompt/delete-visit-dialog.test.tsx +21 -3
- package/src/visit/visit-prompt/{end-visit-dialog.component.tsx → end-visit-dialog.modal.tsx} +7 -1
- package/src/visit/visit-prompt/end-visit-dialog.test.tsx +20 -1
- package/src/visit/visit-prompt/{start-visit-dialog.component.tsx → start-visit-dialog.modal.tsx} +10 -4
- package/src/visit/visit-prompt/start-visit-dialog.test.tsx +3 -3
- package/src/visit/visits-widget/active-visit-buttons/active-visit-buttons.tsx +7 -6
- package/src/visit/visits-widget/current-visit-summary.extension.tsx +48 -0
- package/src/visit/visits-widget/current-visit-summary.test.tsx +45 -25
- package/src/visit/visits-widget/past-visits-components/encounters-table/encounters-table.component.tsx +15 -37
- package/src/visit/visits-widget/past-visits-components/encounters-table/encounters-table.resource.ts +0 -1
- package/src/visit/visits-widget/past-visits-components/medications-summary.component.tsx +2 -3
- package/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx +8 -1
- package/src/visit/visits-widget/past-visits-components/visit-summary.scss +1 -1
- package/src/visit/visits-widget/single-visit-details/visit-timeline/visit-timeline.component.tsx +94 -0
- package/src/visit/visits-widget/single-visit-details/visit-timeline/visit-timeline.scss +60 -0
- package/src/visit/visits-widget/visit-context/retrospective-data-date-time-picker/retrospective-date-time-picker.component.tsx +6 -7
- package/src/visit/visits-widget/visit-context/{visit-context-header.component.tsx → visit-context-header.extension.tsx} +17 -15
- package/src/visit/visits-widget/visit-context/visit-context-header.test.tsx +35 -29
- package/src/visit/visits-widget/visit-context/visit-context-switcher.modal.tsx +15 -13
- package/src/visit/visits-widget/visit-context/visit-context-switcher.test.tsx +31 -9
- package/src/visit/visits-widget/visit-detail-overview.component.tsx +3 -2
- package/src/visit/visits-widget/visit-detail-overview.test.tsx +4 -4
- package/src/visit/visits-widget/visit.resource.tsx +1 -1
- package/translations/am.json +6 -0
- package/translations/ar.json +6 -0
- package/translations/ar_SY.json +6 -0
- package/translations/bn.json +6 -0
- package/translations/de.json +6 -0
- package/translations/en.json +7 -2
- package/translations/en_US.json +6 -0
- package/translations/es.json +6 -0
- package/translations/es_MX.json +6 -0
- package/translations/fr.json +15 -9
- package/translations/he.json +6 -0
- package/translations/hi.json +6 -0
- package/translations/hi_IN.json +6 -0
- package/translations/id.json +6 -0
- package/translations/it.json +24 -18
- package/translations/ka.json +6 -0
- package/translations/km.json +6 -0
- package/translations/ku.json +6 -0
- package/translations/ky.json +6 -0
- package/translations/lg.json +6 -0
- package/translations/ne.json +6 -0
- package/translations/pl.json +6 -0
- package/translations/pt.json +6 -0
- package/translations/pt_BR.json +6 -0
- package/translations/qu.json +6 -0
- package/translations/ro_RO.json +6 -0
- package/translations/ru_RU.json +6 -0
- package/translations/si.json +6 -0
- package/translations/sw.json +6 -0
- package/translations/sw_KE.json +6 -0
- package/translations/tr.json +6 -0
- package/translations/tr_TR.json +6 -0
- package/translations/uk.json +6 -0
- package/translations/uz.json +6 -0
- package/translations/uz@Latn.json +6 -0
- package/translations/uz_UZ.json +6 -0
- package/translations/vi.json +6 -0
- package/translations/zh.json +6 -0
- package/translations/zh_CN.json +6 -0
- package/dist/2537.js +0 -1
- package/dist/2537.js.map +0 -1
- package/dist/2735.js +0 -2
- package/dist/2735.js.map +0 -1
- package/dist/276.js +0 -1
- package/dist/276.js.map +0 -1
- package/dist/3042.js +0 -1
- package/dist/3042.js.map +0 -1
- package/dist/3119.js +0 -1
- package/dist/3119.js.map +0 -1
- package/dist/3184.js +0 -1
- package/dist/3184.js.map +0 -1
- package/dist/385.js +0 -2
- package/dist/385.js.map +0 -1
- package/dist/3905.js +0 -1
- package/dist/3905.js.map +0 -1
- package/dist/4713.js +0 -1
- package/dist/4713.js.map +0 -1
- package/dist/4727.js.map +0 -1
- package/dist/717.js +0 -1
- package/dist/717.js.map +0 -1
- package/dist/9162.js +0 -2
- package/dist/9162.js.map +0 -1
- package/dist/9206.js +0 -1
- package/dist/9206.js.map +0 -1
- package/dist/9615.js +0 -1
- package/dist/9615.js.map +0 -1
- package/src/visit/visits-widget/current-visit-summary.component.tsx +0 -55
- /package/dist/{9162.js.LICENSE.txt → 1815.js.LICENSE.txt} +0 -0
- /package/dist/{385.js.LICENSE.txt → 68.js.LICENSE.txt} +0 -0
- /package/dist/{2735.js.LICENSE.txt → 7816.js.LICENSE.txt} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSWRConfig } from 'swr';
|
|
2
2
|
import { renderHook, act } from '@testing-library/react';
|
|
3
|
-
import { showSnackbar,
|
|
4
|
-
import { invalidateVisitAndEncounterData } from '@openmrs/esm-patient-common-lib';
|
|
3
|
+
import { showSnackbar, type Visit } from '@openmrs/esm-framework';
|
|
4
|
+
import { invalidateVisitAndEncounterData, usePatientChartStore } from '@openmrs/esm-patient-common-lib';
|
|
5
5
|
import { useDeleteVisit } from './useDeleteVisit';
|
|
6
6
|
import { deleteVisit, restoreVisit } from '../visits-widget/visit.resource';
|
|
7
7
|
|
|
@@ -20,17 +20,19 @@ jest.mock('../visits-widget/visit.resource', () => {
|
|
|
20
20
|
|
|
21
21
|
jest.mock('@openmrs/esm-patient-common-lib', () => ({
|
|
22
22
|
invalidateVisitAndEncounterData: jest.fn(),
|
|
23
|
+
usePatientChartStore: jest.fn(),
|
|
23
24
|
}));
|
|
24
25
|
|
|
25
26
|
const mockDeleteVisit = jest.mocked(deleteVisit);
|
|
26
27
|
const mockRestoreVisit = jest.mocked(restoreVisit);
|
|
27
28
|
const mockShowSnackbar = jest.mocked(showSnackbar);
|
|
28
29
|
const mockUseSWRConfig = jest.mocked(useSWRConfig);
|
|
29
|
-
const
|
|
30
|
+
const mockUsePatientChartStore = jest.mocked(usePatientChartStore);
|
|
30
31
|
const mockInvalidateVisitAndEncounterData = jest.mocked(invalidateVisitAndEncounterData);
|
|
31
32
|
|
|
32
|
-
const
|
|
33
|
+
const mockMutateActiveVisit = jest.fn();
|
|
33
34
|
const mockGlobalMutate = jest.fn();
|
|
35
|
+
const mockSetVisitContext = jest.fn();
|
|
34
36
|
|
|
35
37
|
const mockVisitType = {
|
|
36
38
|
uuid: 'visit-type-123',
|
|
@@ -54,16 +56,13 @@ const mockVisit = {
|
|
|
54
56
|
|
|
55
57
|
describe('useDeleteVisit', () => {
|
|
56
58
|
beforeEach(() => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
error: null,
|
|
65
|
-
isLoading: false,
|
|
66
|
-
isValidating: false,
|
|
59
|
+
mockUsePatientChartStore.mockReturnValue({
|
|
60
|
+
patientUuid: 'patient-123',
|
|
61
|
+
patient: null,
|
|
62
|
+
visitContext: null,
|
|
63
|
+
mutateVisitContext: jest.fn(),
|
|
64
|
+
setPatient: jest.fn(),
|
|
65
|
+
setVisitContext: mockSetVisitContext,
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
mockUseSWRConfig.mockReturnValue({
|
|
@@ -76,14 +75,14 @@ describe('useDeleteVisit', () => {
|
|
|
76
75
|
mockDeleteVisit.mockResolvedValue({ data: {} } as any);
|
|
77
76
|
const onVisitDelete = jest.fn();
|
|
78
77
|
|
|
79
|
-
const { result } = renderHook(() => useDeleteVisit(mockVisit, onVisitDelete));
|
|
78
|
+
const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, onVisitDelete));
|
|
80
79
|
|
|
81
80
|
await act(async () => {
|
|
82
81
|
result.current.initiateDeletingVisit();
|
|
83
82
|
});
|
|
84
83
|
|
|
85
84
|
expect(mockDeleteVisit).toHaveBeenCalledWith('visit-123');
|
|
86
|
-
expect(
|
|
85
|
+
expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
|
|
87
86
|
expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
|
|
88
87
|
|
|
89
88
|
expect(mockShowSnackbar).toHaveBeenCalledWith(
|
|
@@ -103,13 +102,13 @@ describe('useDeleteVisit', () => {
|
|
|
103
102
|
mockDeleteVisit.mockRejectedValue(new Error('Delete failed'));
|
|
104
103
|
const onVisitDelete = jest.fn();
|
|
105
104
|
|
|
106
|
-
const { result } = renderHook(() => useDeleteVisit(mockVisit, onVisitDelete));
|
|
105
|
+
const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, onVisitDelete));
|
|
107
106
|
|
|
108
107
|
await act(async () => {
|
|
109
108
|
result.current.initiateDeletingVisit();
|
|
110
109
|
});
|
|
111
110
|
|
|
112
|
-
expect(
|
|
111
|
+
expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
|
|
113
112
|
expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
|
|
114
113
|
|
|
115
114
|
expect(mockShowSnackbar).toHaveBeenCalledWith({
|
|
@@ -125,7 +124,7 @@ describe('useDeleteVisit', () => {
|
|
|
125
124
|
mockRestoreVisit.mockResolvedValue({ data: {} } as any);
|
|
126
125
|
const onVisitRestore = jest.fn();
|
|
127
126
|
|
|
128
|
-
const { result } = renderHook(() => useDeleteVisit(mockVisit, undefined, onVisitRestore));
|
|
127
|
+
const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, undefined, onVisitRestore));
|
|
129
128
|
|
|
130
129
|
// First delete to get the restore function
|
|
131
130
|
mockDeleteVisit.mockResolvedValue({ data: {} } as any);
|
|
@@ -138,14 +137,13 @@ describe('useDeleteVisit', () => {
|
|
|
138
137
|
|
|
139
138
|
// Clear mocks to test restore independently
|
|
140
139
|
jest.clearAllMocks();
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
isValidating: false,
|
|
140
|
+
mockUsePatientChartStore.mockReturnValue({
|
|
141
|
+
patientUuid: 'patient-123',
|
|
142
|
+
patient: null,
|
|
143
|
+
visitContext: null,
|
|
144
|
+
mutateVisitContext: jest.fn(),
|
|
145
|
+
setPatient: jest.fn(),
|
|
146
|
+
setVisitContext: mockSetVisitContext,
|
|
149
147
|
});
|
|
150
148
|
mockUseSWRConfig.mockReturnValue({
|
|
151
149
|
mutate: mockGlobalMutate,
|
|
@@ -158,7 +156,7 @@ describe('useDeleteVisit', () => {
|
|
|
158
156
|
});
|
|
159
157
|
|
|
160
158
|
expect(mockRestoreVisit).toHaveBeenCalledWith('visit-123');
|
|
161
|
-
expect(
|
|
159
|
+
expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
|
|
162
160
|
expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
|
|
163
161
|
|
|
164
162
|
expect(mockShowSnackbar).toHaveBeenCalledWith({
|
|
@@ -174,7 +172,7 @@ describe('useDeleteVisit', () => {
|
|
|
174
172
|
mockRestoreVisit.mockRejectedValue(new Error('Restore failed'));
|
|
175
173
|
const onVisitRestore = jest.fn();
|
|
176
174
|
|
|
177
|
-
const { result } = renderHook(() => useDeleteVisit(mockVisit, undefined, onVisitRestore));
|
|
175
|
+
const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, undefined, onVisitRestore));
|
|
178
176
|
|
|
179
177
|
// First delete to get the restore function
|
|
180
178
|
mockDeleteVisit.mockResolvedValue({ data: {} } as any);
|
|
@@ -186,14 +184,13 @@ describe('useDeleteVisit', () => {
|
|
|
186
184
|
|
|
187
185
|
// Clear mocks to test restore independently
|
|
188
186
|
jest.clearAllMocks();
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
isValidating: false,
|
|
187
|
+
mockUsePatientChartStore.mockReturnValue({
|
|
188
|
+
patientUuid: 'patient-123',
|
|
189
|
+
patient: null,
|
|
190
|
+
visitContext: null,
|
|
191
|
+
mutateVisitContext: jest.fn(),
|
|
192
|
+
setPatient: jest.fn(),
|
|
193
|
+
setVisitContext: mockSetVisitContext,
|
|
197
194
|
});
|
|
198
195
|
mockUseSWRConfig.mockReturnValue({
|
|
199
196
|
mutate: mockGlobalMutate,
|
|
@@ -205,7 +202,7 @@ describe('useDeleteVisit', () => {
|
|
|
205
202
|
restoreFunction();
|
|
206
203
|
});
|
|
207
204
|
|
|
208
|
-
expect(
|
|
205
|
+
expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
|
|
209
206
|
expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
|
|
210
207
|
|
|
211
208
|
expect(mockShowSnackbar).toHaveBeenCalledWith({
|
|
@@ -220,7 +217,7 @@ describe('useDeleteVisit', () => {
|
|
|
220
217
|
it('should manage loading state correctly', async () => {
|
|
221
218
|
mockDeleteVisit.mockResolvedValue({ data: {} } as any);
|
|
222
219
|
|
|
223
|
-
const { result } = renderHook(() => useDeleteVisit(mockVisit));
|
|
220
|
+
const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, () => {}));
|
|
224
221
|
|
|
225
222
|
// Initially not deleting
|
|
226
223
|
expect(result.current.isDeletingVisit).toBe(false);
|
|
@@ -238,7 +235,7 @@ describe('useDeleteVisit', () => {
|
|
|
238
235
|
const visitWithoutPatient = { ...mockVisit, patient: null };
|
|
239
236
|
|
|
240
237
|
expect(() => {
|
|
241
|
-
renderHook(() => useDeleteVisit(visitWithoutPatient));
|
|
238
|
+
renderHook(() => useDeleteVisit(visitWithoutPatient, mockMutateActiveVisit, () => {}));
|
|
242
239
|
}).not.toThrow();
|
|
243
240
|
});
|
|
244
241
|
|
|
@@ -246,7 +243,7 @@ describe('useDeleteVisit', () => {
|
|
|
246
243
|
const visitWithEmptyPatient = { ...mockVisit, patient: { uuid: '' } };
|
|
247
244
|
|
|
248
245
|
expect(() => {
|
|
249
|
-
renderHook(() => useDeleteVisit(visitWithEmptyPatient));
|
|
246
|
+
renderHook(() => useDeleteVisit(visitWithEmptyPatient, mockMutateActiveVisit, () => {}));
|
|
250
247
|
}).not.toThrow();
|
|
251
248
|
});
|
|
252
249
|
|
|
@@ -257,7 +254,7 @@ describe('useDeleteVisit', () => {
|
|
|
257
254
|
};
|
|
258
255
|
|
|
259
256
|
mockDeleteVisit.mockResolvedValue({ data: {} } as any);
|
|
260
|
-
const { result } = renderHook(() => useDeleteVisit(visitWithoutDisplay));
|
|
257
|
+
const { result } = renderHook(() => useDeleteVisit(visitWithoutDisplay, mockMutateActiveVisit, () => {}));
|
|
261
258
|
|
|
262
259
|
await act(async () => {
|
|
263
260
|
result.current.initiateDeletingVisit();
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { useSWRConfig } from 'swr';
|
|
4
|
-
import { type Visit, showSnackbar
|
|
5
|
-
import {
|
|
4
|
+
import { type Visit, showSnackbar } from '@openmrs/esm-framework';
|
|
5
|
+
import {
|
|
6
|
+
invalidateVisitAndEncounterData,
|
|
7
|
+
invalidateVisitByUuid,
|
|
8
|
+
usePatientChartStore,
|
|
9
|
+
} from '@openmrs/esm-patient-common-lib';
|
|
6
10
|
import { deleteVisit, restoreVisit } from '../visits-widget/visit.resource';
|
|
7
11
|
|
|
8
|
-
export function useDeleteVisit(
|
|
12
|
+
export function useDeleteVisit(
|
|
13
|
+
activeVisit: Visit,
|
|
14
|
+
mutateActiveVisit: () => void,
|
|
15
|
+
onVisitDelete = () => {},
|
|
16
|
+
onVisitRestore = () => {},
|
|
17
|
+
) {
|
|
9
18
|
const { t } = useTranslation();
|
|
10
19
|
const { mutate: globalMutate } = useSWRConfig();
|
|
11
|
-
const { mutate: mutateCurrentVisit } = useVisit(visit?.patient?.uuid || '');
|
|
12
20
|
const [isDeletingVisit, setIsDeletingVisit] = useState(false);
|
|
13
|
-
const patientUuid =
|
|
21
|
+
const patientUuid = activeVisit?.patient?.uuid || '';
|
|
22
|
+
const { visitContext, setVisitContext } = usePatientChartStore(patientUuid);
|
|
14
23
|
|
|
15
24
|
const restoreDeletedVisit = () => {
|
|
16
|
-
restoreVisit(
|
|
17
|
-
.then(() => {
|
|
25
|
+
restoreVisit(activeVisit?.uuid)
|
|
26
|
+
.then(({ data: updatedVisit }) => {
|
|
18
27
|
// Update current visit data for critical components (useVisit hook)
|
|
19
|
-
|
|
28
|
+
mutateActiveVisit();
|
|
29
|
+
if (!updatedVisit.stopDatetime) {
|
|
30
|
+
const mutateSavedOrUpdatedVisit = () => invalidateVisitByUuid(globalMutate, updatedVisit.uuid);
|
|
31
|
+
setVisitContext(updatedVisit, mutateSavedOrUpdatedVisit);
|
|
32
|
+
}
|
|
20
33
|
|
|
21
34
|
// Use targeted SWR invalidation instead of global mutateVisit
|
|
22
35
|
invalidateVisitAndEncounterData(globalMutate, patientUuid);
|
|
@@ -24,7 +37,7 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
|
|
|
24
37
|
showSnackbar({
|
|
25
38
|
title: t('visitRestored', 'Visit restored'),
|
|
26
39
|
subtitle: t('visitRestoredSuccessfully', '{{visit}} restored successfully', {
|
|
27
|
-
visit:
|
|
40
|
+
visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
|
|
28
41
|
}),
|
|
29
42
|
kind: 'success',
|
|
30
43
|
});
|
|
@@ -32,12 +45,12 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
|
|
|
32
45
|
})
|
|
33
46
|
.catch(() => {
|
|
34
47
|
// On error, revalidate to get correct state
|
|
35
|
-
|
|
48
|
+
mutateActiveVisit();
|
|
36
49
|
invalidateVisitAndEncounterData(globalMutate, patientUuid);
|
|
37
50
|
showSnackbar({
|
|
38
51
|
title: t('visitNotRestored', "Visit couldn't be restored"),
|
|
39
52
|
subtitle: t('errorWhenRestoringVisit', 'Error occurred when restoring {{visit}}', {
|
|
40
|
-
visit:
|
|
53
|
+
visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
|
|
41
54
|
}),
|
|
42
55
|
kind: 'error',
|
|
43
56
|
});
|
|
@@ -47,20 +60,23 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
|
|
|
47
60
|
const initiateDeletingVisit = () => {
|
|
48
61
|
setIsDeletingVisit(true);
|
|
49
62
|
|
|
50
|
-
deleteVisit(
|
|
63
|
+
deleteVisit(activeVisit?.uuid)
|
|
51
64
|
.then(() => {
|
|
52
|
-
// Update
|
|
53
|
-
|
|
65
|
+
// Update active visit data
|
|
66
|
+
mutateActiveVisit();
|
|
67
|
+
if (activeVisit.uuid == visitContext?.uuid) {
|
|
68
|
+
setVisitContext(null, null);
|
|
69
|
+
}
|
|
54
70
|
|
|
55
71
|
// Use targeted SWR invalidation instead of global mutateVisit
|
|
56
72
|
invalidateVisitAndEncounterData(globalMutate, patientUuid);
|
|
57
73
|
|
|
58
74
|
showSnackbar({
|
|
59
75
|
title: t('visitDeleted', '{{visit}} deleted', {
|
|
60
|
-
visit:
|
|
76
|
+
visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
|
|
61
77
|
}),
|
|
62
78
|
subtitle: t('visitDeletedSuccessfully', '{{visit}} deleted successfully', {
|
|
63
|
-
visit:
|
|
79
|
+
visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
|
|
64
80
|
}),
|
|
65
81
|
kind: 'success',
|
|
66
82
|
actionButtonLabel: t('undo', 'Undo'),
|
|
@@ -70,7 +86,7 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
|
|
|
70
86
|
})
|
|
71
87
|
.catch(() => {
|
|
72
88
|
// On error, revalidate to get correct state
|
|
73
|
-
|
|
89
|
+
mutateActiveVisit();
|
|
74
90
|
invalidateVisitAndEncounterData(globalMutate, patientUuid);
|
|
75
91
|
|
|
76
92
|
showSnackbar({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { Button } from '@carbon/react';
|
|
4
|
-
import {
|
|
4
|
+
import { launchWorkspace2, showSnackbar } from '@openmrs/esm-framework';
|
|
5
5
|
|
|
6
6
|
interface StartVisitButtonProps {
|
|
7
7
|
patientUuid: string;
|
|
@@ -20,7 +20,7 @@ const StartVisitButton = ({ patientUuid, handleReturnToSearchList, hidePatientSe
|
|
|
20
20
|
hidePatientSearch?.();
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
launchWorkspace2(startVisitWorkspaceForm, {
|
|
24
24
|
patientUuid,
|
|
25
25
|
openedFrom: 'patient-chart-start-visit',
|
|
26
26
|
handleReturnToSearchList,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import {
|
|
4
|
+
import { launchWorkspace2 } from '@openmrs/esm-framework';
|
|
5
5
|
import { mockPatient } from 'tools';
|
|
6
6
|
import StartVisitButton from './start-visit-button.component';
|
|
7
7
|
|
|
8
|
-
const mockLaunchWorkspace = jest.mocked(
|
|
8
|
+
const mockLaunchWorkspace = jest.mocked(launchWorkspace2);
|
|
9
9
|
|
|
10
10
|
describe('StartVisitButton', () => {
|
|
11
11
|
it('renders the start visit button', () => {
|
|
@@ -6,13 +6,20 @@ import {
|
|
|
6
6
|
UserHasAccess,
|
|
7
7
|
type Visit,
|
|
8
8
|
getCoreTranslation,
|
|
9
|
-
|
|
9
|
+
launchWorkspace2,
|
|
10
10
|
useLayoutType,
|
|
11
11
|
} from '@openmrs/esm-framework';
|
|
12
|
+
import { type VisitFormProps } from '../visit-form/visit-form.workspace';
|
|
13
|
+
import {
|
|
14
|
+
invalidateVisitAndEncounterData,
|
|
15
|
+
invalidateVisitByUuid,
|
|
16
|
+
type PatientWorkspaceGroupProps,
|
|
17
|
+
} from '@openmrs/esm-patient-common-lib';
|
|
18
|
+
import { useSWRConfig } from 'swr';
|
|
12
19
|
|
|
13
20
|
interface EditVisitDetailsActionItemProps {
|
|
14
|
-
patientUuid: string;
|
|
15
21
|
visit: Visit;
|
|
22
|
+
patient: fhir.Patient;
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* If true, renders as IconButton instead
|
|
@@ -20,18 +27,32 @@ interface EditVisitDetailsActionItemProps {
|
|
|
20
27
|
compact?: boolean;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* This component
|
|
32
|
+
*/
|
|
33
|
+
const EditVisitDetailsActionItem: React.FC<EditVisitDetailsActionItemProps> = ({ visit, patient, compact }) => {
|
|
24
34
|
const { t } = useTranslation();
|
|
35
|
+
const { mutate: globalMutate } = useSWRConfig();
|
|
25
36
|
|
|
26
37
|
const isTablet = useLayoutType() === 'tablet';
|
|
27
38
|
const responsiveSize = isTablet ? 'lg' : 'sm';
|
|
39
|
+
const patientUuid = patient.id;
|
|
28
40
|
|
|
29
41
|
const editVisitDetails = () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
launchWorkspace2<VisitFormProps, {}, PatientWorkspaceGroupProps>(
|
|
43
|
+
'start-visit-workspace-form',
|
|
44
|
+
{ openedFrom: 'patient-chart-edit-visit' },
|
|
45
|
+
{},
|
|
46
|
+
{
|
|
47
|
+
patient,
|
|
48
|
+
patientUuid: patientUuid,
|
|
49
|
+
visitContext: visit,
|
|
50
|
+
mutateVisitContext: () => {
|
|
51
|
+
invalidateVisitByUuid(globalMutate, visit.uuid);
|
|
52
|
+
invalidateVisitAndEncounterData(globalMutate, patientUuid);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
);
|
|
35
56
|
};
|
|
36
57
|
|
|
37
58
|
return (
|
|
@@ -41,14 +41,14 @@ const BaseVisitType: React.FC<BaseVisitTypeProps> = ({ visitTypes }) => {
|
|
|
41
41
|
{isTablet ? (
|
|
42
42
|
<Layer>
|
|
43
43
|
<Search
|
|
44
|
-
labelText=
|
|
44
|
+
labelText={t('searchForAVisitType', 'Search for a visit type')}
|
|
45
45
|
onChange={handleSearchTermChange}
|
|
46
46
|
placeholder={t('searchForAVisitType', 'Search for a visit type')}
|
|
47
47
|
/>
|
|
48
48
|
</Layer>
|
|
49
49
|
) : (
|
|
50
50
|
<Search
|
|
51
|
-
labelText=
|
|
51
|
+
labelText={t('searchForAVisitType', 'Search for a visit type')}
|
|
52
52
|
onChange={handleSearchTermChange}
|
|
53
53
|
placeholder={t('searchForAVisitType', 'Search for a visit type')}
|
|
54
54
|
/>
|