@openmrs/esm-patient-common-lib 13.0.2-pre.12860 → 13.0.2-pre.12869
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/package.json +1 -1
- package/src/store/patient-chart-store.ts +2 -5
- package/src/workspaces.test.ts +13 -63
- package/src/workspaces.ts +13 -33
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@ export interface PatientChartStore {
|
|
|
5
5
|
patientUuid: string;
|
|
6
6
|
patient: fhir.Patient;
|
|
7
7
|
visitContext: Visit;
|
|
8
|
-
mutateVisitContext: () => void;
|
|
9
8
|
/**
|
|
10
9
|
* The uuid of the visit context the patient-chart workspace group was last launched with.
|
|
11
10
|
* Note that when the visit context is changed, the workspaces group (with stale visit context)
|
|
@@ -27,7 +26,6 @@ const patientChartStore = createGlobalStore<PatientChartStore>(patientChartStore
|
|
|
27
26
|
patientUuid: null,
|
|
28
27
|
patient: null,
|
|
29
28
|
visitContext: null,
|
|
30
|
-
mutateVisitContext: null,
|
|
31
29
|
workspaceGroupVisitUuid: null,
|
|
32
30
|
workspaceGroupProps: null,
|
|
33
31
|
});
|
|
@@ -36,8 +34,8 @@ const patientChartStoreActions = {
|
|
|
36
34
|
setPatient(_, patient: fhir.Patient) {
|
|
37
35
|
return { patient, patientUuid: patient?.id ?? null };
|
|
38
36
|
},
|
|
39
|
-
setVisitContext(_, visitContext: Visit
|
|
40
|
-
return { visitContext
|
|
37
|
+
setVisitContext(_, visitContext: Visit) {
|
|
38
|
+
return { visitContext };
|
|
41
39
|
},
|
|
42
40
|
} satisfies Actions<PatientChartStore>;
|
|
43
41
|
|
|
@@ -87,7 +85,6 @@ export function usePatientChartStore(patientUuid: string) {
|
|
|
87
85
|
} else {
|
|
88
86
|
const fakeStore: typeof store = {
|
|
89
87
|
...store,
|
|
90
|
-
mutateVisitContext: null,
|
|
91
88
|
setVisitContext: () => {},
|
|
92
89
|
patient: null,
|
|
93
90
|
patientUuid: null,
|
package/src/workspaces.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { act, renderHook } from '@testing-library/react';
|
|
3
|
-
import { launchWorkspace2, showModal,
|
|
3
|
+
import { launchWorkspace2, showModal, useLayoutType, type Visit } from '@openmrs/esm-framework';
|
|
4
4
|
import { setPatientChartWorkspaceGroupVisitUuid, usePatientChartStore } from './store/patient-chart-store';
|
|
5
5
|
import { useSystemVisitSetting } from './useSystemVisitSetting';
|
|
6
6
|
import {
|
|
@@ -17,7 +17,6 @@ vi.mock('./useSystemVisitSetting', () => ({
|
|
|
17
17
|
}));
|
|
18
18
|
|
|
19
19
|
const mockShowModal = vi.mocked(showModal);
|
|
20
|
-
const mockUseFeatureFlag = vi.mocked(useFeatureFlag);
|
|
21
20
|
const mockUseSystemVisitSetting = vi.mocked(useSystemVisitSetting);
|
|
22
21
|
|
|
23
22
|
const patient = { id: 'patient-uuid' } as fhir.Patient;
|
|
@@ -59,23 +58,21 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
59
58
|
afterEach(() => {
|
|
60
59
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
61
60
|
act(() => {
|
|
62
|
-
result.current.setVisitContext(null
|
|
61
|
+
result.current.setVisitContext(null);
|
|
63
62
|
result.current.setPatient(null);
|
|
64
63
|
setPatientChartWorkspaceGroupVisitUuid(null);
|
|
65
64
|
});
|
|
66
65
|
});
|
|
67
66
|
|
|
68
67
|
it('resolves true without prompting when the patient already has a visit context', async () => {
|
|
69
|
-
mockUseFeatureFlag.mockReturnValue(false);
|
|
70
68
|
const result = setUpStartVisitIfNeeded();
|
|
71
|
-
act(() => result.current.store.setVisitContext(visit
|
|
69
|
+
act(() => result.current.store.setVisitContext(visit));
|
|
72
70
|
|
|
73
71
|
await expect(result.current.startVisitIfNeeded()).resolves.toBe(true);
|
|
74
72
|
expect(mockShowModal).not.toHaveBeenCalled();
|
|
75
73
|
});
|
|
76
74
|
|
|
77
75
|
it('waits for the workspace group to have the new visit before resolving a started visit', async () => {
|
|
78
|
-
mockUseFeatureFlag.mockReturnValue(false);
|
|
79
76
|
const result = setUpStartVisitIfNeeded();
|
|
80
77
|
|
|
81
78
|
let promise: Promise<boolean>;
|
|
@@ -86,7 +83,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
86
83
|
const { onVisitStarted } = getModalProps('start-visit-dialog');
|
|
87
84
|
|
|
88
85
|
await act(async () => {
|
|
89
|
-
result.current.store.setVisitContext(visit
|
|
86
|
+
result.current.store.setVisitContext(visit);
|
|
90
87
|
onVisitStarted();
|
|
91
88
|
});
|
|
92
89
|
expect(settlement.settled).toBe(false);
|
|
@@ -96,7 +93,6 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
96
93
|
});
|
|
97
94
|
|
|
98
95
|
it('resolves false and closes the dialog when starting a visit is cancelled', async () => {
|
|
99
|
-
mockUseFeatureFlag.mockReturnValue(false);
|
|
100
96
|
const dispose = vi.fn();
|
|
101
97
|
mockShowModal.mockReturnValue(dispose);
|
|
102
98
|
const result = setUpStartVisitIfNeeded();
|
|
@@ -113,7 +109,6 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
113
109
|
});
|
|
114
110
|
|
|
115
111
|
it('resolves every pending prompt once the workspace group has the new visit', async () => {
|
|
116
|
-
mockUseFeatureFlag.mockReturnValue(false);
|
|
117
112
|
const result = setUpStartVisitIfNeeded();
|
|
118
113
|
|
|
119
114
|
let first: Promise<boolean>;
|
|
@@ -128,7 +123,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
128
123
|
expect(dialogs).toHaveLength(2);
|
|
129
124
|
|
|
130
125
|
await act(async () => {
|
|
131
|
-
result.current.store.setVisitContext(visit
|
|
126
|
+
result.current.store.setVisitContext(visit);
|
|
132
127
|
dialogs.forEach(({ onVisitStarted }) => onVisitStarted());
|
|
133
128
|
});
|
|
134
129
|
await act(async () => setPatientChartWorkspaceGroupVisitUuid(visit.uuid));
|
|
@@ -136,52 +131,13 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
136
131
|
await expect(first).resolves.toBe(true);
|
|
137
132
|
await expect(second).resolves.toBe(true);
|
|
138
133
|
});
|
|
139
|
-
|
|
140
|
-
it('waits for the workspace group to have the selected visit before resolving, even after the switcher closes', async () => {
|
|
141
|
-
mockUseFeatureFlag.mockReturnValue(true);
|
|
142
|
-
const result = setUpStartVisitIfNeeded();
|
|
143
|
-
|
|
144
|
-
let promise: Promise<boolean>;
|
|
145
|
-
act(() => {
|
|
146
|
-
promise = result.current.startVisitIfNeeded();
|
|
147
|
-
});
|
|
148
|
-
const settlement = trackSettlement(promise);
|
|
149
|
-
const { onAfterVisitSelected, closeModal } = getModalProps('visit-context-switcher');
|
|
150
|
-
|
|
151
|
-
// The visit context switcher sets the visit context, reports the selection, then closes itself.
|
|
152
|
-
await act(async () => {
|
|
153
|
-
result.current.store.setVisitContext(visit, null);
|
|
154
|
-
onAfterVisitSelected();
|
|
155
|
-
closeModal();
|
|
156
|
-
});
|
|
157
|
-
expect(settlement.settled).toBe(false);
|
|
158
|
-
|
|
159
|
-
await act(async () => setPatientChartWorkspaceGroupVisitUuid(visit.uuid));
|
|
160
|
-
expect(settlement).toEqual({ settled: true, value: true });
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('resolves false when the visit context switcher closes without a selection', async () => {
|
|
164
|
-
mockUseFeatureFlag.mockReturnValue(true);
|
|
165
|
-
const result = setUpStartVisitIfNeeded();
|
|
166
|
-
|
|
167
|
-
let promise: Promise<boolean>;
|
|
168
|
-
act(() => {
|
|
169
|
-
promise = result.current.startVisitIfNeeded();
|
|
170
|
-
});
|
|
171
|
-
const { closeModal } = getModalProps('visit-context-switcher');
|
|
172
|
-
act(() => closeModal());
|
|
173
|
-
|
|
174
|
-
await expect(promise).resolves.toBe(false);
|
|
175
|
-
});
|
|
176
134
|
});
|
|
177
135
|
|
|
178
136
|
describe('getPatientChartWindowProps', () => {
|
|
179
|
-
const mutateVisitContext = vi.fn();
|
|
180
|
-
|
|
181
137
|
afterEach(() => {
|
|
182
138
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
183
139
|
act(() => {
|
|
184
|
-
result.current.setVisitContext(null
|
|
140
|
+
result.current.setVisitContext(null);
|
|
185
141
|
result.current.setPatient(null);
|
|
186
142
|
setPatientChartWorkspaceGroupVisitUuid(null, null);
|
|
187
143
|
});
|
|
@@ -193,12 +149,11 @@ describe('getPatientChartWindowProps', () => {
|
|
|
193
149
|
patient,
|
|
194
150
|
patientUuid: patient.id,
|
|
195
151
|
visitContext: visit,
|
|
196
|
-
mutateVisitContext,
|
|
197
152
|
showPatientBanner: 'tabletOnly' as const,
|
|
198
153
|
};
|
|
199
154
|
act(() => result.current.setPatient(patient));
|
|
200
155
|
act(() => {
|
|
201
|
-
result.current.setVisitContext({ ...visit }
|
|
156
|
+
result.current.setVisitContext({ ...visit });
|
|
202
157
|
setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupProps);
|
|
203
158
|
});
|
|
204
159
|
|
|
@@ -209,7 +164,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
209
164
|
it('falls back to the store values when no workspace group was launched', () => {
|
|
210
165
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
211
166
|
act(() => result.current.setPatient(patient));
|
|
212
|
-
act(() => result.current.setVisitContext(visit
|
|
167
|
+
act(() => result.current.setVisitContext(visit));
|
|
213
168
|
|
|
214
169
|
expect(getPatientChartWindowProps(patient.id)).toEqual({
|
|
215
170
|
patient,
|
|
@@ -224,7 +179,6 @@ describe('getPatientChartWindowProps', () => {
|
|
|
224
179
|
patient: { ...patient, id: 'previous-patient-uuid' },
|
|
225
180
|
patientUuid: 'previous-patient-uuid',
|
|
226
181
|
visitContext: visit,
|
|
227
|
-
mutateVisitContext,
|
|
228
182
|
showPatientBanner: 'tabletOnly' as const,
|
|
229
183
|
};
|
|
230
184
|
act(() => result.current.setPatient(patient));
|
|
@@ -240,7 +194,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
240
194
|
it("does not return another patient's chart context", () => {
|
|
241
195
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
242
196
|
act(() => result.current.setPatient(patient));
|
|
243
|
-
act(() => result.current.setVisitContext(visit
|
|
197
|
+
act(() => result.current.setVisitContext(visit));
|
|
244
198
|
|
|
245
199
|
expect(getPatientChartWindowProps('other-patient-uuid')).toEqual({
|
|
246
200
|
patient: null,
|
|
@@ -319,7 +273,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
319
273
|
afterEach(() => {
|
|
320
274
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
321
275
|
act(() => {
|
|
322
|
-
result.current.setVisitContext(null
|
|
276
|
+
result.current.setVisitContext(null);
|
|
323
277
|
result.current.setPatient(null);
|
|
324
278
|
setPatientChartWorkspaceGroupVisitUuid(null, null);
|
|
325
279
|
});
|
|
@@ -332,7 +286,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
332
286
|
launch: useLaunchWorkspaceRequiringVisit(patient.id, 'some-workspace'),
|
|
333
287
|
}));
|
|
334
288
|
act(() => result.current.store.setPatient(patient));
|
|
335
|
-
act(() => result.current.store.setVisitContext(visit
|
|
289
|
+
act(() => result.current.store.setVisitContext(visit));
|
|
336
290
|
|
|
337
291
|
await act(async () => result.current.launch({ a: 1 } as any, { extra: true }));
|
|
338
292
|
|
|
@@ -351,13 +305,11 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
351
305
|
errorFetchingSystemVisitSetting: null,
|
|
352
306
|
isLoadingSystemVisitSetting: false,
|
|
353
307
|
});
|
|
354
|
-
mockUseFeatureFlag.mockReturnValue(false);
|
|
355
308
|
mockShowModal.mockReturnValue(vi.fn());
|
|
356
309
|
const groupPropsWithoutVisit = {
|
|
357
310
|
patient,
|
|
358
311
|
patientUuid: patient.id,
|
|
359
312
|
visitContext: null,
|
|
360
|
-
mutateVisitContext: null,
|
|
361
313
|
showPatientBanner: 'tabletOnly' as const,
|
|
362
314
|
};
|
|
363
315
|
const { result } = renderHook(() => ({
|
|
@@ -377,7 +329,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
377
329
|
|
|
378
330
|
// The visit is started, and the chart relaunches its workspace group with it
|
|
379
331
|
await act(async () => {
|
|
380
|
-
result.current.store.setVisitContext(visit
|
|
332
|
+
result.current.store.setVisitContext(visit);
|
|
381
333
|
onVisitStarted();
|
|
382
334
|
});
|
|
383
335
|
expect(mockLaunchWorkspace2).not.toHaveBeenCalled();
|
|
@@ -385,7 +337,6 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
385
337
|
patient,
|
|
386
338
|
patientUuid: patient.id,
|
|
387
339
|
visitContext: visit,
|
|
388
|
-
mutateVisitContext: null,
|
|
389
340
|
showPatientBanner: 'tabletOnly' as const,
|
|
390
341
|
};
|
|
391
342
|
await act(async () => setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupPropsWithVisit));
|
|
@@ -407,7 +358,6 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
407
358
|
patient,
|
|
408
359
|
patientUuid: patient.id,
|
|
409
360
|
visitContext: visit,
|
|
410
|
-
mutateVisitContext: null,
|
|
411
361
|
showPatientBanner: 'tabletOnly' as const,
|
|
412
362
|
};
|
|
413
363
|
const { result } = renderHook(() => ({
|
|
@@ -415,7 +365,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
415
365
|
launch: useActionMenuButtonLaunchProps(groupPropsWithVisit, 'some-workspace'),
|
|
416
366
|
}));
|
|
417
367
|
act(() => result.current.store.setPatient(patient));
|
|
418
|
-
act(() => result.current.store.setVisitContext(visit
|
|
368
|
+
act(() => result.current.store.setVisitContext(visit));
|
|
419
369
|
act(() => setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupPropsWithVisit));
|
|
420
370
|
|
|
421
371
|
await expect(result.current.launch.onBeforeWorkspaceLaunch()).resolves.toBe(true);
|
package/src/workspaces.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
launchWorkspace2,
|
|
4
4
|
navigate,
|
|
5
5
|
showModal,
|
|
6
|
-
useFeatureFlag,
|
|
7
6
|
useLayoutType,
|
|
8
7
|
type Visit,
|
|
9
8
|
type Workspace2DefinitionProps,
|
|
@@ -15,7 +14,6 @@ export interface PatientWorkspaceGroupProps {
|
|
|
15
14
|
patient: fhir.Patient;
|
|
16
15
|
patientUuid: string;
|
|
17
16
|
visitContext: Visit;
|
|
18
|
-
mutateVisitContext: () => void;
|
|
19
17
|
/**
|
|
20
18
|
* When the workspaces of this group render the patient banner themselves. The patient chart has its own
|
|
21
19
|
* patient header on desktop, so every group props object it builds sets `'tabletOnly'` (required here so
|
|
@@ -53,8 +51,9 @@ export function useShowPatientBanner(groupProps: PatientBannerGroupProps | null
|
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* The window props taken by workspaces that are shared between the patient chart and other apps
|
|
56
|
-
* (ward, service queues, dispensing, ...).
|
|
57
|
-
*
|
|
54
|
+
* (ward, service queues, dispensing, ...). Whoever opens the window supplies the patient / visit the
|
|
55
|
+
* workspace acts on; these workspaces read group props only for the patient banner mode and as a last
|
|
56
|
+
* resort when a launch supplies no patient (see `SharedWorkspaceGroupProps`). In the patient chart, use
|
|
58
57
|
* `getPatientChartWindowProps` to build them.
|
|
59
58
|
*/
|
|
60
59
|
export interface PatientWorkspaceWindowProps {
|
|
@@ -249,7 +248,6 @@ export function useActionMenuButtonLaunchProps<T extends object>(
|
|
|
249
248
|
export function useStartVisitIfNeeded(patientUuid: string) {
|
|
250
249
|
const { visitContext, workspaceGroupVisitUuid } = usePatientChartStore(patientUuid);
|
|
251
250
|
const { systemVisitEnabled } = useSystemVisitSetting();
|
|
252
|
-
const isRdeEnabled = useFeatureFlag('rde');
|
|
253
251
|
// Setting a new visit context makes the patient chart relaunch its workspace group, which closes
|
|
254
252
|
// any workspace opened before the relaunch. So a pending prompt resolves only once the workspace
|
|
255
253
|
// group has the new visit context.
|
|
@@ -272,35 +270,17 @@ export function useStartVisitIfNeeded(patientUuid: string) {
|
|
|
272
270
|
pendingPromptResolvers.current.push(() => resolve(true));
|
|
273
271
|
};
|
|
274
272
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
},
|
|
285
|
-
onAfterVisitSelected: () => {
|
|
286
|
-
isVisitSelected = true;
|
|
287
|
-
resolveOnceWorkspaceGroupHasVisit();
|
|
288
|
-
},
|
|
289
|
-
size: 'sm',
|
|
290
|
-
});
|
|
291
|
-
} else {
|
|
292
|
-
const dispose = showModal('start-visit-dialog', {
|
|
293
|
-
closeModal: () => dispose(),
|
|
294
|
-
onCancel: () => {
|
|
295
|
-
dispose();
|
|
296
|
-
resolve(false);
|
|
297
|
-
},
|
|
298
|
-
onVisitStarted: resolveOnceWorkspaceGroupHasVisit,
|
|
299
|
-
patientUuid,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
273
|
+
const dispose = showModal('start-visit-dialog', {
|
|
274
|
+
closeModal: () => dispose(),
|
|
275
|
+
onCancel: () => {
|
|
276
|
+
dispose();
|
|
277
|
+
resolve(false);
|
|
278
|
+
},
|
|
279
|
+
onVisitStarted: resolveOnceWorkspaceGroupHasVisit,
|
|
280
|
+
patientUuid,
|
|
281
|
+
});
|
|
302
282
|
});
|
|
303
283
|
}
|
|
304
|
-
}, [visitContext, systemVisitEnabled,
|
|
284
|
+
}, [visitContext, systemVisitEnabled, patientUuid]);
|
|
305
285
|
return startVisitIfNeeded;
|
|
306
286
|
}
|