@openmrs/esm-patient-common-lib 13.0.2-pre.12885 → 13.0.2-pre.12895
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 +13 -13
- package/src/workspaces.test.ts +24 -22
- package/src/workspaces.ts +14 -14
package/package.json
CHANGED
|
@@ -4,18 +4,18 @@ import { type PatientWorkspaceGroupProps } from '../workspaces';
|
|
|
4
4
|
export interface PatientChartStore {
|
|
5
5
|
patientUuid: string;
|
|
6
6
|
patient: fhir.Patient;
|
|
7
|
-
|
|
7
|
+
activeVisit: Visit;
|
|
8
8
|
/**
|
|
9
|
-
* The uuid of the visit
|
|
10
|
-
* Note that when the visit
|
|
11
|
-
* must close and reopen, and during that process its
|
|
12
|
-
* `store.
|
|
9
|
+
* The uuid of the active visit the patient-chart workspace group was last launched with.
|
|
10
|
+
* Note that when the active visit is changed, the workspaces group (with the stale active visit)
|
|
11
|
+
* must close and reopen, and during that process its activeVisit might differ from
|
|
12
|
+
* `store.activeVisit`
|
|
13
13
|
*/
|
|
14
14
|
workspaceGroupVisitUuid?: string | null;
|
|
15
15
|
/**
|
|
16
16
|
* The group props the patient-chart workspace group was last launched with. The workspace system
|
|
17
17
|
* only relaunches the group when the patient or visit uuid changes, so these objects can be older
|
|
18
|
-
* than `patient` / `
|
|
18
|
+
* than `patient` / `activeVisit` above. See `getPatientChartWindowProps`.
|
|
19
19
|
*/
|
|
20
20
|
workspaceGroupProps?: PatientWorkspaceGroupProps | null;
|
|
21
21
|
}
|
|
@@ -25,7 +25,7 @@ const patientChartStoreName = 'patient-chart-global-store';
|
|
|
25
25
|
const patientChartStore = createGlobalStore<PatientChartStore>(patientChartStoreName, {
|
|
26
26
|
patientUuid: null,
|
|
27
27
|
patient: null,
|
|
28
|
-
|
|
28
|
+
activeVisit: null,
|
|
29
29
|
workspaceGroupVisitUuid: null,
|
|
30
30
|
workspaceGroupProps: null,
|
|
31
31
|
});
|
|
@@ -34,13 +34,13 @@ const patientChartStoreActions = {
|
|
|
34
34
|
setPatient(_, patient: fhir.Patient) {
|
|
35
35
|
return { patient, patientUuid: patient?.id ?? null };
|
|
36
36
|
},
|
|
37
|
-
|
|
38
|
-
return {
|
|
37
|
+
setActiveVisit(_, activeVisit: Visit) {
|
|
38
|
+
return { activeVisit };
|
|
39
39
|
},
|
|
40
40
|
} satisfies Actions<PatientChartStore>;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Records the visit
|
|
43
|
+
* Records the active visit the patient-chart workspace group was last launched with.
|
|
44
44
|
* Only the patient chart should call this, after it launches its workspace group.
|
|
45
45
|
*/
|
|
46
46
|
export function setPatientChartWorkspaceGroupVisitUuid(
|
|
@@ -73,7 +73,7 @@ export function getPatientChartStoreState(patientUuid?: string): PatientChartSto
|
|
|
73
73
|
*
|
|
74
74
|
* Workspaces / extensions that can be mounted by other apps (ex: the start visit form in the queue's app,
|
|
75
75
|
* the clinical forms workspace in the ward app)
|
|
76
|
-
* should have the patient /
|
|
76
|
+
* should have the patient / visit explicitly passed in as props.
|
|
77
77
|
*
|
|
78
78
|
* As a safety feature, this hook requires the patientUuid as the input, and only
|
|
79
79
|
* returns the actual store values if input patientUuid matches that in the store.
|
|
@@ -85,10 +85,10 @@ export function usePatientChartStore(patientUuid: string) {
|
|
|
85
85
|
} else {
|
|
86
86
|
const fakeStore: typeof store = {
|
|
87
87
|
...store,
|
|
88
|
-
|
|
88
|
+
setActiveVisit: () => {},
|
|
89
89
|
patient: null,
|
|
90
90
|
patientUuid: null,
|
|
91
|
-
|
|
91
|
+
activeVisit: null,
|
|
92
92
|
workspaceGroupVisitUuid: null,
|
|
93
93
|
workspaceGroupProps: null,
|
|
94
94
|
};
|
package/src/workspaces.test.ts
CHANGED
|
@@ -58,7 +58,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
58
58
|
afterEach(() => {
|
|
59
59
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
60
60
|
act(() => {
|
|
61
|
-
result.current.
|
|
61
|
+
result.current.setActiveVisit(null);
|
|
62
62
|
result.current.setPatient(null);
|
|
63
63
|
setPatientChartWorkspaceGroupVisitUuid(null);
|
|
64
64
|
});
|
|
@@ -66,7 +66,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
66
66
|
|
|
67
67
|
it('resolves true without prompting when the patient already has a visit context', async () => {
|
|
68
68
|
const result = setUpStartVisitIfNeeded();
|
|
69
|
-
act(() => result.current.store.
|
|
69
|
+
act(() => result.current.store.setActiveVisit(visit));
|
|
70
70
|
|
|
71
71
|
await expect(result.current.startVisitIfNeeded()).resolves.toBe(true);
|
|
72
72
|
expect(mockShowModal).not.toHaveBeenCalled();
|
|
@@ -83,7 +83,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
83
83
|
const { onVisitStarted } = getModalProps('start-visit-dialog');
|
|
84
84
|
|
|
85
85
|
await act(async () => {
|
|
86
|
-
result.current.store.
|
|
86
|
+
result.current.store.setActiveVisit(visit);
|
|
87
87
|
onVisitStarted();
|
|
88
88
|
});
|
|
89
89
|
expect(settlement.settled).toBe(false);
|
|
@@ -123,7 +123,7 @@ describe('useStartVisitIfNeeded', () => {
|
|
|
123
123
|
expect(dialogs).toHaveLength(2);
|
|
124
124
|
|
|
125
125
|
await act(async () => {
|
|
126
|
-
result.current.store.
|
|
126
|
+
result.current.store.setActiveVisit(visit);
|
|
127
127
|
dialogs.forEach(({ onVisitStarted }) => onVisitStarted());
|
|
128
128
|
});
|
|
129
129
|
await act(async () => setPatientChartWorkspaceGroupVisitUuid(visit.uuid));
|
|
@@ -137,7 +137,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
137
137
|
afterEach(() => {
|
|
138
138
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
139
139
|
act(() => {
|
|
140
|
-
result.current.
|
|
140
|
+
result.current.setActiveVisit(null);
|
|
141
141
|
result.current.setPatient(null);
|
|
142
142
|
setPatientChartWorkspaceGroupVisitUuid(null, null);
|
|
143
143
|
});
|
|
@@ -148,12 +148,12 @@ describe('getPatientChartWindowProps', () => {
|
|
|
148
148
|
const groupProps = {
|
|
149
149
|
patient,
|
|
150
150
|
patientUuid: patient.id,
|
|
151
|
-
|
|
151
|
+
activeVisit: visit,
|
|
152
152
|
showPatientBanner: 'tabletOnly' as const,
|
|
153
153
|
};
|
|
154
154
|
act(() => result.current.setPatient(patient));
|
|
155
155
|
act(() => {
|
|
156
|
-
result.current.
|
|
156
|
+
result.current.setActiveVisit({ ...visit });
|
|
157
157
|
setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupProps);
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -164,7 +164,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
164
164
|
it('falls back to the store values when no workspace group was launched', () => {
|
|
165
165
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
166
166
|
act(() => result.current.setPatient(patient));
|
|
167
|
-
act(() => result.current.
|
|
167
|
+
act(() => result.current.setActiveVisit(visit));
|
|
168
168
|
|
|
169
169
|
expect(getPatientChartWindowProps(patient.id)).toEqual({
|
|
170
170
|
patient,
|
|
@@ -178,7 +178,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
178
178
|
const previousPatientGroupProps = {
|
|
179
179
|
patient: { ...patient, id: 'previous-patient-uuid' },
|
|
180
180
|
patientUuid: 'previous-patient-uuid',
|
|
181
|
-
|
|
181
|
+
activeVisit: visit,
|
|
182
182
|
showPatientBanner: 'tabletOnly' as const,
|
|
183
183
|
};
|
|
184
184
|
act(() => result.current.setPatient(patient));
|
|
@@ -194,7 +194,7 @@ describe('getPatientChartWindowProps', () => {
|
|
|
194
194
|
it("does not return another patient's chart context", () => {
|
|
195
195
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
196
196
|
act(() => result.current.setPatient(patient));
|
|
197
|
-
act(() => result.current.
|
|
197
|
+
act(() => result.current.setActiveVisit(visit));
|
|
198
198
|
|
|
199
199
|
expect(getPatientChartWindowProps('other-patient-uuid')).toEqual({
|
|
200
200
|
patient: null,
|
|
@@ -232,9 +232,11 @@ describe('getPatientAndVisitProps', () => {
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it('falls back to group props when a launch supplies neither window props nor workspace props', () => {
|
|
235
|
-
expect(getPatientAndVisitProps(null, undefined, { patient, patientUuid: patient.id,
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
expect(getPatientAndVisitProps(null, undefined, { patient, patientUuid: patient.id, activeVisit: visit })).toEqual({
|
|
236
|
+
patient,
|
|
237
|
+
patientUuid: patient.id,
|
|
238
|
+
visitContext: visit,
|
|
239
|
+
});
|
|
238
240
|
});
|
|
239
241
|
|
|
240
242
|
it("doesn't mix the group's visit into a patient given by the window", () => {
|
|
@@ -242,7 +244,7 @@ describe('getPatientAndVisitProps', () => {
|
|
|
242
244
|
getPatientAndVisitProps({ patient, patientUuid: patient.id, visitContext: null }, undefined, {
|
|
243
245
|
patient,
|
|
244
246
|
patientUuid: patient.id,
|
|
245
|
-
|
|
247
|
+
activeVisit: visit,
|
|
246
248
|
}),
|
|
247
249
|
).toEqual({ patient, patientUuid: patient.id, visitContext: null });
|
|
248
250
|
});
|
|
@@ -253,7 +255,7 @@ describe('getPatientAndVisitProps', () => {
|
|
|
253
255
|
getPatientAndVisitProps(
|
|
254
256
|
undefined,
|
|
255
257
|
{ patient, patientUuid: patient.id, visitContext: visit },
|
|
256
|
-
{ patient: otherPatient, patientUuid: 'other',
|
|
258
|
+
{ patient: otherPatient, patientUuid: 'other', activeVisit: null },
|
|
257
259
|
),
|
|
258
260
|
).toEqual({ patient, patientUuid: patient.id, visitContext: visit });
|
|
259
261
|
});
|
|
@@ -273,7 +275,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
273
275
|
afterEach(() => {
|
|
274
276
|
const { result } = renderHook(() => usePatientChartStore(patient.id));
|
|
275
277
|
act(() => {
|
|
276
|
-
result.current.
|
|
278
|
+
result.current.setActiveVisit(null);
|
|
277
279
|
result.current.setPatient(null);
|
|
278
280
|
setPatientChartWorkspaceGroupVisitUuid(null, null);
|
|
279
281
|
});
|
|
@@ -286,7 +288,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
286
288
|
launch: useLaunchWorkspaceRequiringVisit(patient.id, 'some-workspace'),
|
|
287
289
|
}));
|
|
288
290
|
act(() => result.current.store.setPatient(patient));
|
|
289
|
-
act(() => result.current.store.
|
|
291
|
+
act(() => result.current.store.setActiveVisit(visit));
|
|
290
292
|
|
|
291
293
|
await act(async () => result.current.launch({ a: 1 } as any, { extra: true }));
|
|
292
294
|
|
|
@@ -309,7 +311,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
309
311
|
const groupPropsWithoutVisit = {
|
|
310
312
|
patient,
|
|
311
313
|
patientUuid: patient.id,
|
|
312
|
-
|
|
314
|
+
activeVisit: null,
|
|
313
315
|
showPatientBanner: 'tabletOnly' as const,
|
|
314
316
|
};
|
|
315
317
|
const { result } = renderHook(() => ({
|
|
@@ -329,14 +331,14 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
329
331
|
|
|
330
332
|
// The visit is started, and the chart relaunches its workspace group with it
|
|
331
333
|
await act(async () => {
|
|
332
|
-
result.current.store.
|
|
334
|
+
result.current.store.setActiveVisit(visit);
|
|
333
335
|
onVisitStarted();
|
|
334
336
|
});
|
|
335
337
|
expect(mockLaunchWorkspace2).not.toHaveBeenCalled();
|
|
336
338
|
const groupPropsWithVisit = {
|
|
337
339
|
patient,
|
|
338
340
|
patientUuid: patient.id,
|
|
339
|
-
|
|
341
|
+
activeVisit: visit,
|
|
340
342
|
showPatientBanner: 'tabletOnly' as const,
|
|
341
343
|
};
|
|
342
344
|
await act(async () => setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupPropsWithVisit));
|
|
@@ -357,7 +359,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
357
359
|
const groupPropsWithVisit = {
|
|
358
360
|
patient,
|
|
359
361
|
patientUuid: patient.id,
|
|
360
|
-
|
|
362
|
+
activeVisit: visit,
|
|
361
363
|
showPatientBanner: 'tabletOnly' as const,
|
|
362
364
|
};
|
|
363
365
|
const { result } = renderHook(() => ({
|
|
@@ -365,7 +367,7 @@ describe('useLaunchWorkspaceRequiringVisit', () => {
|
|
|
365
367
|
launch: useActionMenuButtonLaunchProps(groupPropsWithVisit, 'some-workspace'),
|
|
366
368
|
}));
|
|
367
369
|
act(() => result.current.store.setPatient(patient));
|
|
368
|
-
act(() => result.current.store.
|
|
370
|
+
act(() => result.current.store.setActiveVisit(visit));
|
|
369
371
|
act(() => setPatientChartWorkspaceGroupVisitUuid(visit.uuid, groupPropsWithVisit));
|
|
370
372
|
|
|
371
373
|
await expect(result.current.launch.onBeforeWorkspaceLaunch()).resolves.toBe(true);
|
package/src/workspaces.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { useSystemVisitSetting } from './useSystemVisitSetting';
|
|
|
13
13
|
export interface PatientWorkspaceGroupProps {
|
|
14
14
|
patient: fhir.Patient;
|
|
15
15
|
patientUuid: string;
|
|
16
|
-
|
|
16
|
+
activeVisit: Visit;
|
|
17
17
|
/**
|
|
18
18
|
* When the workspaces of this group render the patient banner themselves. The patient chart has its own
|
|
19
19
|
* patient header on desktop, so every group props object it builds sets `'tabletOnly'` (required here so
|
|
@@ -38,7 +38,7 @@ export type PatientBannerGroupProps = Partial<Pick<PatientWorkspaceGroupProps, '
|
|
|
38
38
|
* `getPatientAndVisitProps`).
|
|
39
39
|
*/
|
|
40
40
|
export type SharedWorkspaceGroupProps = PatientBannerGroupProps &
|
|
41
|
-
Partial<Pick<PatientWorkspaceGroupProps, 'patient' | 'patientUuid' | '
|
|
41
|
+
Partial<Pick<PatientWorkspaceGroupProps, 'patient' | 'patientUuid' | 'activeVisit'>>;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Whether a workspace should render the patient banner itself, as asked for by its workspace group.
|
|
@@ -109,15 +109,15 @@ export function getPatientAndVisitProps(
|
|
|
109
109
|
if (patient || patientUuid) {
|
|
110
110
|
return { patient, patientUuid: patientUuid ?? patient?.id, visitContext };
|
|
111
111
|
}
|
|
112
|
-
return { patient: groupProps?.patient, patientUuid: groupProps?.patientUuid, visitContext: groupProps?.
|
|
112
|
+
return { patient: groupProps?.patient, patientUuid: groupProps?.patientUuid, visitContext: groupProps?.activeVisit };
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Converts the group props of the patient chart into window props.
|
|
117
117
|
*/
|
|
118
118
|
function groupPropsToWindowProps(groupProps: PatientWorkspaceGroupProps): PatientWorkspaceWindowProps {
|
|
119
|
-
const { patient, patientUuid,
|
|
120
|
-
return { patient, patientUuid, visitContext };
|
|
119
|
+
const { patient, patientUuid, activeVisit } = groupProps;
|
|
120
|
+
return { patient, patientUuid, visitContext: activeVisit };
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
@@ -127,7 +127,7 @@ function groupPropsToWindowProps(groupProps: PatientWorkspaceGroupProps): Patien
|
|
|
127
127
|
*
|
|
128
128
|
* The group props are used rather than the latest store values because the window props of an open
|
|
129
129
|
* window are compared (shallowly) with the window props of every later launch into that window, and
|
|
130
|
-
* an incompatible launch prompts the user to close the window. The store's `patient` / `
|
|
130
|
+
* an incompatible launch prompts the user to close the window. The store's `patient` / `activeVisit`
|
|
131
131
|
* objects are replaced on every revalidation, while the group props stay the same until the
|
|
132
132
|
* patient or visit changes, so reading the group props keeps launches compatible.
|
|
133
133
|
*
|
|
@@ -143,7 +143,7 @@ export function getPatientChartWindowProps(patientUuid?: string): PatientWorkspa
|
|
|
143
143
|
return {
|
|
144
144
|
patient: state?.patient ?? null,
|
|
145
145
|
patientUuid: state?.patientUuid ?? patientUuid ?? null,
|
|
146
|
-
visitContext: state?.
|
|
146
|
+
visitContext: state?.activeVisit ?? null,
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -246,23 +246,23 @@ export function useActionMenuButtonLaunchProps<T extends object>(
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
export function useStartVisitIfNeeded(patientUuid: string) {
|
|
249
|
-
const {
|
|
249
|
+
const { activeVisit, workspaceGroupVisitUuid } = usePatientChartStore(patientUuid);
|
|
250
250
|
const { systemVisitEnabled } = useSystemVisitSetting();
|
|
251
|
-
// Setting a new visit
|
|
251
|
+
// Setting a new active visit makes the patient chart relaunch its workspace group, which closes
|
|
252
252
|
// any workspace opened before the relaunch. So a pending prompt resolves only once the workspace
|
|
253
|
-
// group has the new visit
|
|
253
|
+
// group has the new active visit.
|
|
254
254
|
const pendingPromptResolvers = useRef<Array<() => void>>([]);
|
|
255
255
|
|
|
256
256
|
useEffect(() => {
|
|
257
|
-
if (
|
|
257
|
+
if (activeVisit && workspaceGroupVisitUuid === activeVisit.uuid) {
|
|
258
258
|
const resolvers = pendingPromptResolvers.current;
|
|
259
259
|
pendingPromptResolvers.current = [];
|
|
260
260
|
resolvers.forEach((resolvePrompt) => resolvePrompt());
|
|
261
261
|
}
|
|
262
|
-
}, [
|
|
262
|
+
}, [activeVisit, workspaceGroupVisitUuid]);
|
|
263
263
|
|
|
264
264
|
const startVisitIfNeeded = useCallback(async (): Promise<boolean> => {
|
|
265
|
-
if (!systemVisitEnabled ||
|
|
265
|
+
if (!systemVisitEnabled || activeVisit) {
|
|
266
266
|
return true;
|
|
267
267
|
} else {
|
|
268
268
|
return new Promise<boolean>((resolve) => {
|
|
@@ -281,6 +281,6 @@ export function useStartVisitIfNeeded(patientUuid: string) {
|
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
}, [
|
|
284
|
+
}, [activeVisit, systemVisitEnabled, patientUuid]);
|
|
285
285
|
return startVisitIfNeeded;
|
|
286
286
|
}
|