@openmrs/esm-fast-data-entry-app 1.4.2-pre.702 → 1.4.2-pre.706
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/__mocks__/react-i18next.js +16 -4
- package/dist/1003.js +1 -1
- package/dist/1003.js.map +1 -1
- package/dist/9814.js +1 -1
- package/dist/9814.js.map +1 -1
- package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +6 -6
- package/dist/routes.json +1 -1
- package/e2e/core/test.ts +1 -1
- package/e2e/fixtures/api.ts +1 -1
- package/e2e/pages/sample-test.ts +1 -1
- package/e2e/specs/form-workflow.spec.ts +160 -0
- package/package.json +1 -1
- package/src/FormBootstrap.test.tsx +112 -0
- package/src/FormBootstrap.tsx +4 -1
- package/src/context/FormWorkflowReducer.test.ts +142 -0
- package/src/context/GroupFormWorkflowReducer.test.ts +302 -0
- package/src/context/GroupFormWorkflowReducer.ts +1 -1
- package/src/declarations.d.ts +0 -1
- package/src/group-form-entry-workflow/GroupSessionWorkspace.test.tsx +190 -0
- package/src/group-form-entry-workflow/SessionMetaWorkspace.test.tsx +94 -0
- package/src/group-form-entry-workflow/group-search-header/GroupSearchHeader.test.tsx +121 -0
- package/src/hooks/useGetPatient.test.tsx +113 -0
- package/src/hooks/useGetPatient.ts +13 -4
- package/e2e/specs/sample-test.spec.ts +0 -10
package/e2e/fixtures/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIRequestContext, PlaywrightWorkerArgs, WorkerFixture } from '@playwright/test';
|
|
1
|
+
import type { APIRequestContext, PlaywrightWorkerArgs, WorkerFixture } from '@playwright/test';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A fixture which initializes an [`APIRequestContext`](https://playwright.dev/docs/api/class-apirequestcontext)
|
package/e2e/pages/sample-test.ts
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type APIRequestContext, expect } from '@playwright/test';
|
|
2
|
+
import { test } from '../core';
|
|
3
|
+
|
|
4
|
+
type OpenmrsSessionResponse = {
|
|
5
|
+
user: {
|
|
6
|
+
uuid: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type OpenmrsForm = {
|
|
11
|
+
uuid: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
published?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type OpenmrsFormResponse = {
|
|
17
|
+
results?: Array<OpenmrsForm>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type FhirPatient = {
|
|
21
|
+
id: string;
|
|
22
|
+
name?: Array<{
|
|
23
|
+
given?: Array<string>;
|
|
24
|
+
family?: string;
|
|
25
|
+
}>;
|
|
26
|
+
identifier?: Array<{
|
|
27
|
+
value?: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type FhirBundle<T> = {
|
|
32
|
+
entry?: Array<{
|
|
33
|
+
resource: T;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const workflowStorageVersion = '1.1.0';
|
|
38
|
+
const workflowStorageName = 'openmrs:fastDataEntryWorkflowState';
|
|
39
|
+
const formRepresentation =
|
|
40
|
+
'(uuid,name,display,encounterType:(uuid,name,viewPrivilege,editPrivilege),version,published,retired,resources:(uuid,name,dataType,valueReference))';
|
|
41
|
+
|
|
42
|
+
const getPatientName = (patient: FhirPatient) =>
|
|
43
|
+
`${patient.name?.[0]?.given?.join(' ') ?? ''} ${patient.name?.[0]?.family ?? ''}`.trim();
|
|
44
|
+
|
|
45
|
+
const getPatientIdentifier = (patient: FhirPatient) => patient.identifier?.[0]?.value?.trim() ?? '';
|
|
46
|
+
|
|
47
|
+
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
48
|
+
|
|
49
|
+
async function getAdminUserUuid(api: APIRequestContext) {
|
|
50
|
+
const response = await api.get('session');
|
|
51
|
+
expect(response.ok()).toBeTruthy();
|
|
52
|
+
|
|
53
|
+
const session = (await response.json()) as OpenmrsSessionResponse;
|
|
54
|
+
return session.user.uuid;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function getTestFormUuid(api: APIRequestContext) {
|
|
58
|
+
const response = await api.get(`form?v=custom:${formRepresentation}`);
|
|
59
|
+
expect(response.ok()).toBeTruthy();
|
|
60
|
+
|
|
61
|
+
const payload = (await response.json()) as OpenmrsFormResponse;
|
|
62
|
+
const form = payload.results?.find((candidate) => candidate.published && !/component/i.test(candidate.name ?? ''));
|
|
63
|
+
|
|
64
|
+
expect(form?.uuid, 'Expected at least one published non-component form').toBeTruthy();
|
|
65
|
+
return form.uuid;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function getTwoPatients(api: APIRequestContext) {
|
|
69
|
+
const response = await api.get(`${process.env.E2E_BASE_URL}/ws/fhir2/R4/Patient?_count=20`);
|
|
70
|
+
expect(response.ok()).toBeTruthy();
|
|
71
|
+
|
|
72
|
+
const bundle = (await response.json()) as FhirBundle<FhirPatient>;
|
|
73
|
+
const patients =
|
|
74
|
+
bundle.entry
|
|
75
|
+
?.map(({ resource }) => resource)
|
|
76
|
+
.filter((patient) => getPatientName(patient) && getPatientIdentifier(patient)) ?? [];
|
|
77
|
+
|
|
78
|
+
const uniquePatients = patients.filter(
|
|
79
|
+
(patient, index) =>
|
|
80
|
+
patients.findIndex((candidate) => candidate.id === patient.id) === index &&
|
|
81
|
+
patients.findIndex((candidate) => getPatientIdentifier(candidate) === getPatientIdentifier(patient)) === index,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(uniquePatients.length, 'Expected at least two patients with names and identifiers').toBeGreaterThanOrEqual(2);
|
|
85
|
+
return uniquePatients.slice(0, 2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
test('switches active patients from the workflow side panel and persists the selection', async ({ page, api }) => {
|
|
89
|
+
const [userUuid, formUuid, [firstPatient, secondPatient]] = await Promise.all([
|
|
90
|
+
getAdminUserUuid(api),
|
|
91
|
+
getTestFormUuid(api),
|
|
92
|
+
getTwoPatients(api),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const storageKey = `${workflowStorageName}:${userUuid}`;
|
|
96
|
+
const storageValue = JSON.stringify({
|
|
97
|
+
_storageVersion: workflowStorageVersion,
|
|
98
|
+
activeFormUuid: formUuid,
|
|
99
|
+
userUuid,
|
|
100
|
+
forms: {
|
|
101
|
+
[formUuid]: {
|
|
102
|
+
workflowState: 'EDIT_FORM',
|
|
103
|
+
activePatientUuid: firstPatient.id,
|
|
104
|
+
activeEncounterUuid: null,
|
|
105
|
+
patientUuids: [firstPatient.id, secondPatient.id],
|
|
106
|
+
encounters: {},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
await page.addInitScript(
|
|
112
|
+
({ key, value }) => {
|
|
113
|
+
window.localStorage.clear();
|
|
114
|
+
window.localStorage.setItem(key, value);
|
|
115
|
+
},
|
|
116
|
+
{ key: storageKey, value: storageValue },
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
await page.goto(`forms/form/${formUuid}`);
|
|
120
|
+
|
|
121
|
+
await expect(page.getByText('Forms filled')).toBeVisible();
|
|
122
|
+
|
|
123
|
+
const firstPatientCard = page.getByRole('button', {
|
|
124
|
+
name: new RegExp(escapeRegExp(getPatientIdentifier(firstPatient))),
|
|
125
|
+
});
|
|
126
|
+
const secondPatientCard = page.getByRole('button', {
|
|
127
|
+
name: new RegExp(escapeRegExp(getPatientIdentifier(secondPatient))),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await expect(firstPatientCard).toBeVisible();
|
|
131
|
+
await expect(secondPatientCard).toBeVisible();
|
|
132
|
+
|
|
133
|
+
await secondPatientCard.click();
|
|
134
|
+
|
|
135
|
+
await expect
|
|
136
|
+
.poll(async () => {
|
|
137
|
+
return page.evaluate(
|
|
138
|
+
({ key, currentFormUuid }) => {
|
|
139
|
+
const data = JSON.parse(window.localStorage.getItem(key) ?? '{}');
|
|
140
|
+
return data.forms?.[currentFormUuid]?.activePatientUuid ?? null;
|
|
141
|
+
},
|
|
142
|
+
{ key: storageKey, currentFormUuid: formUuid },
|
|
143
|
+
);
|
|
144
|
+
})
|
|
145
|
+
.toBe(secondPatient.id);
|
|
146
|
+
|
|
147
|
+
await firstPatientCard.click();
|
|
148
|
+
|
|
149
|
+
await expect
|
|
150
|
+
.poll(async () => {
|
|
151
|
+
return page.evaluate(
|
|
152
|
+
({ key, currentFormUuid }) => {
|
|
153
|
+
const data = JSON.parse(window.localStorage.getItem(key) ?? '{}');
|
|
154
|
+
return data.forms?.[currentFormUuid]?.activePatientUuid ?? null;
|
|
155
|
+
},
|
|
156
|
+
{ key: storageKey, currentFormUuid: formUuid },
|
|
157
|
+
);
|
|
158
|
+
})
|
|
159
|
+
.toBe(firstPatient.id);
|
|
160
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-fast-data-entry-app",
|
|
3
|
-
"version": "1.4.2-pre.
|
|
3
|
+
"version": "1.4.2-pre.706",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "O3 frontend module for fast data entry using the OpenMRS Angular Form Engine",
|
|
6
6
|
"browser": "dist/openmrs-esm-fast-data-entry-app.js",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, render, screen } from '@testing-library/react';
|
|
3
|
+
import { detach, ExtensionSlot } from '@openmrs/esm-framework';
|
|
4
|
+
import GroupFormWorkflowContext from './context/GroupFormWorkflowContext';
|
|
5
|
+
import useGetPatient from './hooks/useGetPatient';
|
|
6
|
+
import FormBootstrap from './FormBootstrap';
|
|
7
|
+
|
|
8
|
+
jest.mock('./hooks/useGetPatient', () => jest.fn());
|
|
9
|
+
|
|
10
|
+
const mockDetach = jest.mocked(detach);
|
|
11
|
+
const mockExtensionSlot = jest.mocked(ExtensionSlot);
|
|
12
|
+
const mockUseGetPatient = useGetPatient as jest.MockedFunction<typeof useGetPatient>;
|
|
13
|
+
|
|
14
|
+
const renderFormBootstrap = (props = {}) =>
|
|
15
|
+
render(
|
|
16
|
+
<GroupFormWorkflowContext.Provider
|
|
17
|
+
value={
|
|
18
|
+
{
|
|
19
|
+
activeSessionMeta: {
|
|
20
|
+
sessionName: 'April Session',
|
|
21
|
+
practitionerName: 'Alice',
|
|
22
|
+
sessionDate: '2026-04-15',
|
|
23
|
+
sessionNotes: 'Follow-up notes',
|
|
24
|
+
},
|
|
25
|
+
} as never
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<FormBootstrap
|
|
29
|
+
formUuid="triage-form"
|
|
30
|
+
patientUuid="patient-1"
|
|
31
|
+
visitUuid="visit-1"
|
|
32
|
+
visitTypeUuid="visit-type-1"
|
|
33
|
+
encounterUuid="encounter-1"
|
|
34
|
+
handlePostResponse={jest.fn()}
|
|
35
|
+
handleEncounterCreate={jest.fn()}
|
|
36
|
+
handleOnValidate={jest.fn()}
|
|
37
|
+
hidePatientBanner={true}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
</GroupFormWorkflowContext.Provider>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
describe('FormBootstrap', () => {
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
mockExtensionSlot.mockImplementation(() => <div data-testid="form-widget-slot" />);
|
|
46
|
+
mockUseGetPatient.mockReturnValue({
|
|
47
|
+
id: 'patient-1',
|
|
48
|
+
name: [{ given: ['Ada'], family: 'Lovelace' }],
|
|
49
|
+
} as fhir.Patient);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
jest.useRealTimers();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('passes the expected widget state once the patient is available', () => {
|
|
57
|
+
renderFormBootstrap();
|
|
58
|
+
|
|
59
|
+
expect(screen.getByTestId('form-widget-slot')).toBeInTheDocument();
|
|
60
|
+
|
|
61
|
+
const [{ name, state }] = mockExtensionSlot.mock.calls[0];
|
|
62
|
+
expect(name).toBe('form-widget-slot');
|
|
63
|
+
expect(state).toEqual(
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
view: 'form',
|
|
66
|
+
formUuid: 'triage-form',
|
|
67
|
+
visitUuid: 'visit-1',
|
|
68
|
+
visitTypeUuid: 'visit-type-1',
|
|
69
|
+
patientUuid: 'patient-1',
|
|
70
|
+
patient: expect.objectContaining({ id: 'patient-1' }),
|
|
71
|
+
encounterUuid: 'encounter-1',
|
|
72
|
+
showDiscardSubmitButtons: false,
|
|
73
|
+
hideControls: true,
|
|
74
|
+
hidePatientBanner: true,
|
|
75
|
+
preFilledQuestions: {
|
|
76
|
+
sessionName: 'April Session',
|
|
77
|
+
practitionerName: 'Alice',
|
|
78
|
+
sessionDate: '2026-04-15',
|
|
79
|
+
sessionNotes: 'Follow-up notes',
|
|
80
|
+
encDate: '2026-04-15',
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('refreshes the widget after submit and detaches it on unmount', () => {
|
|
87
|
+
jest.useFakeTimers();
|
|
88
|
+
const handlePostResponse = jest.fn();
|
|
89
|
+
const { unmount } = renderFormBootstrap({ handlePostResponse });
|
|
90
|
+
|
|
91
|
+
const [{ state }] = mockExtensionSlot.mock.calls[0];
|
|
92
|
+
const handlePostResponseFromState = state.handlePostResponse as (encounter: { uuid: string }) => void;
|
|
93
|
+
|
|
94
|
+
act(() => {
|
|
95
|
+
handlePostResponseFromState({ uuid: 'encounter-2' });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(handlePostResponse).toHaveBeenCalledWith({ uuid: 'encounter-2' });
|
|
99
|
+
expect(screen.queryByTestId('form-widget-slot')).not.toBeInTheDocument();
|
|
100
|
+
|
|
101
|
+
act(() => {
|
|
102
|
+
jest.advanceTimersByTime(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(screen.getByTestId('form-widget-slot')).toBeInTheDocument();
|
|
106
|
+
expect(mockExtensionSlot).toHaveBeenCalledTimes(2);
|
|
107
|
+
|
|
108
|
+
unmount();
|
|
109
|
+
|
|
110
|
+
expect(mockDetach).toHaveBeenCalledWith('form-widget-slot', 'form-widget-slot');
|
|
111
|
+
});
|
|
112
|
+
});
|
package/src/FormBootstrap.tsx
CHANGED
|
@@ -130,6 +130,7 @@ const FormBootstrap = ({
|
|
|
130
130
|
hidePatientBanner,
|
|
131
131
|
}: FormParams) => {
|
|
132
132
|
const patient = useGetPatient(patientUuid);
|
|
133
|
+
const isPatientMatch = patient?.id === patientUuid;
|
|
133
134
|
const { activeSessionMeta } = useContext(GroupFormWorkflowContext);
|
|
134
135
|
|
|
135
136
|
useEffect(() => {
|
|
@@ -146,9 +147,11 @@ const FormBootstrap = ({
|
|
|
146
147
|
}, 1);
|
|
147
148
|
};
|
|
148
149
|
|
|
150
|
+
const isReady = showForm && formUuid && patientUuid && patient && isPatientMatch;
|
|
151
|
+
|
|
149
152
|
return (
|
|
150
153
|
<div>
|
|
151
|
-
{
|
|
154
|
+
{isReady && (
|
|
152
155
|
<ExtensionSlot
|
|
153
156
|
name="form-widget-slot"
|
|
154
157
|
state={{
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { navigate } from '@openmrs/esm-framework';
|
|
2
|
+
import { initialWorkflowState } from './FormWorkflowContext';
|
|
3
|
+
import reducer, { fdeWorkflowStorageName, fdeWorkflowStorageVersion } from './FormWorkflowReducer';
|
|
4
|
+
|
|
5
|
+
const mockNavigate = jest.mocked(navigate);
|
|
6
|
+
|
|
7
|
+
const buildState = (formStateOverrides = {}) => ({
|
|
8
|
+
...initialWorkflowState,
|
|
9
|
+
activeFormUuid: 'triage-form',
|
|
10
|
+
userUuid: 'user-1',
|
|
11
|
+
forms: {
|
|
12
|
+
'triage-form': {
|
|
13
|
+
workflowState: 'NEW_PATIENT',
|
|
14
|
+
activePatientUuid: null,
|
|
15
|
+
activeEncounterUuid: null,
|
|
16
|
+
patientUuids: [],
|
|
17
|
+
encounters: {},
|
|
18
|
+
...formStateOverrides,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('FormWorkflowReducer', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
localStorage.clear();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('initializes a fresh workflow state when there is no saved session', () => {
|
|
29
|
+
const state = reducer(initialWorkflowState, {
|
|
30
|
+
type: 'INITIALIZE_WORKFLOW_STATE',
|
|
31
|
+
activeFormUuid: 'triage-form',
|
|
32
|
+
userUuid: 'user-1',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(state.activeFormUuid).toBe('triage-form');
|
|
36
|
+
expect(state.forms['triage-form']).toMatchObject({
|
|
37
|
+
workflowState: 'NEW_PATIENT',
|
|
38
|
+
activePatientUuid: null,
|
|
39
|
+
activeEncounterUuid: null,
|
|
40
|
+
patientUuids: [],
|
|
41
|
+
encounters: {},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(JSON.parse(localStorage.getItem(`${fdeWorkflowStorageName}:user-1`))).toMatchObject({
|
|
45
|
+
_storageVersion: fdeWorkflowStorageVersion,
|
|
46
|
+
activeFormUuid: 'triage-form',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('restores a saved workflow and applies a patient from the URL when provided', () => {
|
|
51
|
+
localStorage.setItem(
|
|
52
|
+
`${fdeWorkflowStorageName}:user-1`,
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
_storageVersion: fdeWorkflowStorageVersion,
|
|
55
|
+
activeFormUuid: 'triage-form',
|
|
56
|
+
userUuid: 'user-1',
|
|
57
|
+
forms: {
|
|
58
|
+
'triage-form': {
|
|
59
|
+
workflowState: 'REVIEW',
|
|
60
|
+
activePatientUuid: null,
|
|
61
|
+
activeEncounterUuid: null,
|
|
62
|
+
patientUuids: ['patient-a'],
|
|
63
|
+
encounters: {},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const state = reducer(initialWorkflowState, {
|
|
70
|
+
type: 'INITIALIZE_WORKFLOW_STATE',
|
|
71
|
+
activeFormUuid: 'triage-form',
|
|
72
|
+
newPatientUuid: 'patient-b',
|
|
73
|
+
userUuid: 'user-1',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(state.forms['triage-form']).toMatchObject({
|
|
77
|
+
workflowState: 'EDIT_FORM',
|
|
78
|
+
activePatientUuid: 'patient-b',
|
|
79
|
+
});
|
|
80
|
+
expect(state.forms['triage-form'].patientUuids).toEqual(['patient-a', 'patient-b']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('dispatches the submit event and moves the workflow into SUBMIT_FOR_NEXT', () => {
|
|
84
|
+
const dispatchEventSpy = jest.spyOn(window, 'dispatchEvent');
|
|
85
|
+
const state = buildState({
|
|
86
|
+
workflowState: 'EDIT_FORM',
|
|
87
|
+
activePatientUuid: 'patient-a',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const nextState = reducer(state, {
|
|
91
|
+
type: 'SUBMIT_FOR_NEXT',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(nextState.forms['triage-form'].workflowState).toBe('SUBMIT_FOR_NEXT');
|
|
95
|
+
expect(dispatchEventSpy).toHaveBeenCalledTimes(1);
|
|
96
|
+
|
|
97
|
+
const event = dispatchEventSpy.mock.calls[0][0] as CustomEvent;
|
|
98
|
+
expect(event.type).toBe('ampath-form-action');
|
|
99
|
+
expect(event.detail).toEqual({
|
|
100
|
+
formUuid: 'triage-form',
|
|
101
|
+
patientUuid: 'patient-a',
|
|
102
|
+
action: 'onSubmit',
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('stores the encounter and returns to NEW_PATIENT after saving for next', () => {
|
|
107
|
+
const state = buildState({
|
|
108
|
+
workflowState: 'SUBMIT_FOR_NEXT',
|
|
109
|
+
activePatientUuid: 'patient-a',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const nextState = reducer(state, {
|
|
113
|
+
type: 'SAVE_ENCOUNTER',
|
|
114
|
+
encounterUuid: 'encounter-1',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
expect(nextState.forms['triage-form']).toMatchObject({
|
|
118
|
+
workflowState: 'NEW_PATIENT',
|
|
119
|
+
activePatientUuid: null,
|
|
120
|
+
activeEncounterUuid: null,
|
|
121
|
+
encounters: {
|
|
122
|
+
'patient-a': 'encounter-1',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('destroys the active form session and navigates back to the forms page after complete', () => {
|
|
128
|
+
const state = buildState({
|
|
129
|
+
workflowState: 'SUBMIT_FOR_COMPLETE',
|
|
130
|
+
activePatientUuid: 'patient-a',
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const nextState = reducer(state, {
|
|
134
|
+
type: 'SAVE_ENCOUNTER',
|
|
135
|
+
encounterUuid: 'encounter-1',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(nextState.activeFormUuid).toBeNull();
|
|
139
|
+
expect(nextState.forms).toEqual({});
|
|
140
|
+
expect(mockNavigate).toHaveBeenCalledWith({ to: '${openmrsSpaBase}/forms' });
|
|
141
|
+
});
|
|
142
|
+
});
|