@ampath/esm-patient-registration-app 6.0.1-pre.6 → 6.0.1-pre.66
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 +23 -24
- package/dist/132.js +1 -0
- package/dist/197.js +1 -0
- package/dist/236.js +1 -0
- package/dist/{735.js.map → 236.js.map} +1 -1
- package/dist/300.js +1 -0
- package/dist/335.js +1 -0
- package/dist/372.js +1 -0
- package/dist/372.js.map +1 -0
- package/dist/41.js +2 -0
- package/dist/41.js.map +1 -0
- package/dist/449.js +1 -0
- package/dist/449.js.map +1 -0
- package/dist/464.js +1 -0
- package/dist/464.js.map +1 -0
- package/dist/495.js +1 -0
- package/dist/495.js.map +1 -0
- package/dist/55.js +1 -0
- package/dist/56.js +1 -0
- package/dist/56.js.map +1 -0
- package/dist/621.js +1 -1
- package/dist/621.js.map +1 -1
- package/dist/629.js +2 -0
- package/dist/629.js.LICENSE.txt +24 -0
- package/dist/629.js.map +1 -0
- package/dist/652.js +1 -0
- package/dist/661.js +1 -0
- package/dist/757.js +1 -1
- package/dist/757.js.map +1 -0
- package/dist/828.js +1 -0
- package/dist/828.js.map +1 -0
- package/dist/830.js +1 -0
- package/dist/830.js.map +1 -0
- package/dist/831.js +2 -0
- package/dist/831.js.map +1 -0
- package/dist/876.js +2 -0
- package/dist/876.js.map +1 -0
- package/dist/879.js +1 -1
- package/dist/913.js +2 -0
- package/dist/{591.js.LICENSE.txt → 913.js.LICENSE.txt} +23 -3
- package/dist/913.js.map +1 -0
- package/dist/927.js +1 -0
- package/dist/927.js.map +1 -0
- package/dist/99.js +1 -0
- package/dist/ampath-esm-patient-registration-app.js +1 -1
- package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +236 -191
- package/dist/ampath-esm-patient-registration-app.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +0 -32
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +6 -9
- package/src/config-schema.ts +19 -10
- package/src/constants.ts +1 -1
- package/src/index.ts +11 -4
- package/src/offline.resources.ts +13 -18
- package/src/offline.ts +6 -4
- package/src/patient-photo.extension.tsx +9 -0
- package/src/patient-registration/field/address/custom-address-field.component.tsx +1 -0
- package/src/patient-registration/field/custom-field.component.tsx +6 -0
- package/src/patient-registration/field/dob/dob.component.tsx +17 -14
- package/src/patient-registration/field/field.resource.ts +3 -3
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +4 -0
- package/src/patient-registration/field/person-attributes/custom-person-attribute-field.component.tsx +56 -0
- package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +22 -7
- package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +2 -2
- package/src/patient-registration/field/phone/phone-field.component.tsx +1 -0
- package/src/patient-registration/form-manager.ts +13 -6
- package/src/patient-registration/patient-registration-hooks.ts +91 -9
- package/src/patient-registration/patient-registration.component.tsx +55 -13
- package/src/patient-registration/{patient-registration.resource.test.tsx → patient-registration.resource.testt.tsx} +3 -3
- package/src/patient-registration/patient-registration.resource.ts +14 -74
- package/src/patient-registration/patient-registration.scss +0 -8
- package/src/patient-registration/patient-registration.types.ts +7 -1
- package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +5 -1
- package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +2 -2
- package/src/patient-verification/assets/counties.json +236 -0
- package/src/patient-verification/assets/verification-assets.ts +11 -0
- package/src/patient-verification/patient-verification-hook.tsx +176 -0
- package/src/patient-verification/patient-verification-utils.ts +179 -0
- package/src/patient-verification/patient-verification.component.tsx +124 -0
- package/src/patient-verification/patient-verification.scss +25 -0
- package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +72 -0
- package/src/patient-verification/verification-modal/empty-prompt.component.tsx +35 -0
- package/src/patient-verification/verification-types.ts +50 -0
- package/src/routes.json +12 -3
- package/translations/am.json +26 -12
- package/translations/ar.json +26 -12
- package/translations/en.json +19 -5
- package/translations/es.json +10 -0
- package/translations/fr.json +6 -0
- package/translations/he.json +18 -0
- package/translations/km.json +18 -0
- package/translations/zh.json +30 -22
- package/translations/zh_CN.json +30 -22
- package/dist/130.js +0 -2
- package/dist/130.js.map +0 -1
- package/dist/152.js +0 -1
- package/dist/152.js.map +0 -1
- package/dist/249.js +0 -2
- package/dist/249.js.LICENSE.txt +0 -46
- package/dist/249.js.map +0 -1
- package/dist/255.js +0 -2
- package/dist/255.js.map +0 -1
- package/dist/271.js +0 -1
- package/dist/303.js +0 -1
- package/dist/303.js.map +0 -1
- package/dist/319.js +0 -1
- package/dist/365.js +0 -1
- package/dist/365.js.map +0 -1
- package/dist/460.js +0 -1
- package/dist/525.js +0 -1
- package/dist/525.js.map +0 -1
- package/dist/537.js +0 -1
- package/dist/537.js.map +0 -1
- package/dist/574.js +0 -1
- package/dist/591.js +0 -2
- package/dist/591.js.map +0 -1
- package/dist/644.js +0 -1
- package/dist/729.js +0 -1
- package/dist/729.js.map +0 -1
- package/dist/735.js +0 -1
- package/dist/784.js +0 -2
- package/dist/784.js.map +0 -1
- package/dist/788.js +0 -1
- package/dist/807.js +0 -1
- package/dist/833.js +0 -1
- package/dist/879.js.map +0 -1
- package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +0 -214
- package/src/patient-registration/field/address/tests/address-search-component.test.tsx +0 -135
- package/src/patient-registration/field/dob/dob.test.tsx +0 -75
- package/src/patient-registration/field/field.test.tsx +0 -294
- package/src/patient-registration/field/id/id-field.test.tsx +0 -107
- package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +0 -60
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +0 -127
- package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +0 -187
- package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +0 -88
- package/src/patient-registration/form-manager.test.ts +0 -67
- package/src/patient-registration/input/basic-input/select/select-input.test.tsx +0 -49
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +0 -132
- package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +0 -107
- package/src/patient-registration/patient-registration.test.tsx +0 -471
- package/src/patient-registration/section/death-info/death-info-section.test.tsx +0 -64
- package/src/patient-registration/section/demographics/demographics-section.test.tsx +0 -83
- package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +0 -100
- package/src/patient-verification/client-registry-constants.ts +0 -13
- package/src/patient-verification/client-registry.component.tsx +0 -66
- package/src/patient-verification/client-registry.scss +0 -1
- package/src/patient-verification/utils.tsx +0 -56
- package/src/patient-verification/verification-modal.scss +0 -20
- package/src/patient-verification/verification.component.tsx +0 -48
- package/src/root.test.tsx +0 -32
- package/src/widgets/cancel-patient-edit.test.tsx +0 -27
- package/src/widgets/display-photo.component.tsx +0 -30
- package/src/widgets/display-photo.test.tsx +0 -37
- package/src/widgets/edit-patient-details-button.test.tsx +0 -41
- /package/dist/{784.js.LICENSE.txt → 41.js.LICENSE.txt} +0 -0
- /package/dist/{130.js.LICENSE.txt → 831.js.LICENSE.txt} +0 -0
- /package/dist/{255.js.LICENSE.txt → 876.js.LICENSE.txt} +0 -0
- /package/src/patient-registration/input/custom-input/identifier/{utils.test.ts → utils.testt.ts} +0 -0
- /package/src/widgets/{delete-identifier-confirmation-modal.test.tsx → delete-identifier-confirmation-modal.testt.tsx} +0 -0
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { BrowserRouter as Router, useParams } from 'react-router-dom';
|
|
3
|
-
import { render, screen, within } from '@testing-library/react';
|
|
4
|
-
import userEvent from '@testing-library/user-event';
|
|
5
|
-
import { showSnackbar, useConfig, usePatient } from '@openmrs/esm-framework';
|
|
6
|
-
import type { AddressTemplate, Encounter } from './patient-registration.types';
|
|
7
|
-
import { type RegistrationConfig } from '../config-schema';
|
|
8
|
-
import { FormManager } from './form-manager';
|
|
9
|
-
import { ResourcesContext } from '../offline.resources';
|
|
10
|
-
import { PatientRegistration } from './patient-registration.component';
|
|
11
|
-
import { saveEncounter, savePatient } from './patient-registration.resource';
|
|
12
|
-
import { mockedAddressTemplate } from '__mocks__';
|
|
13
|
-
import { mockPatient } from 'tools';
|
|
14
|
-
|
|
15
|
-
const mockedUseConfig = useConfig as jest.Mock;
|
|
16
|
-
const mockedUsePatient = usePatient as jest.Mock;
|
|
17
|
-
const mockedSaveEncounter = saveEncounter as jest.Mock;
|
|
18
|
-
const mockedSavePatient = savePatient as jest.Mock;
|
|
19
|
-
const mockedShowSnackbar = showSnackbar as jest.Mock;
|
|
20
|
-
|
|
21
|
-
jest.mock('./field/field.resource', () => ({
|
|
22
|
-
useConcept: jest.fn().mockImplementation((uuid: string) => {
|
|
23
|
-
let data;
|
|
24
|
-
if (uuid == 'weight-uuid') {
|
|
25
|
-
data = {
|
|
26
|
-
uuid: 'weight-uuid',
|
|
27
|
-
display: 'Weight (kg)',
|
|
28
|
-
datatype: { display: 'Numeric', uuid: 'num' },
|
|
29
|
-
answers: [],
|
|
30
|
-
setMembers: [],
|
|
31
|
-
};
|
|
32
|
-
} else if (uuid == 'chief-complaint-uuid') {
|
|
33
|
-
data = {
|
|
34
|
-
uuid: 'chief-complaint-uuid',
|
|
35
|
-
display: 'Chief Complaint',
|
|
36
|
-
datatype: { display: 'Text', uuid: 'txt' },
|
|
37
|
-
answers: [],
|
|
38
|
-
setMembers: [],
|
|
39
|
-
};
|
|
40
|
-
} else if (uuid == 'nationality-uuid') {
|
|
41
|
-
data = {
|
|
42
|
-
uuid: 'nationality-uuid',
|
|
43
|
-
display: 'Nationality',
|
|
44
|
-
datatype: { display: 'Coded', uuid: 'cdd' },
|
|
45
|
-
answers: [
|
|
46
|
-
{ display: 'USA', uuid: 'usa' },
|
|
47
|
-
{ display: 'Mexico', uuid: 'mex' },
|
|
48
|
-
],
|
|
49
|
-
setMembers: [],
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
data: data ?? null,
|
|
54
|
-
isLoading: !data,
|
|
55
|
-
};
|
|
56
|
-
}),
|
|
57
|
-
useConceptAnswers: jest.fn().mockImplementation((uuid: string) => {
|
|
58
|
-
if (uuid == 'nationality-uuid') {
|
|
59
|
-
return {
|
|
60
|
-
data: [
|
|
61
|
-
{ display: 'USA', uuid: 'usa' },
|
|
62
|
-
{ display: 'Mexico', uuid: 'mex' },
|
|
63
|
-
],
|
|
64
|
-
isLoading: false,
|
|
65
|
-
};
|
|
66
|
-
} else if (uuid == 'other-countries-uuid') {
|
|
67
|
-
return {
|
|
68
|
-
data: [
|
|
69
|
-
{ display: 'Kenya', uuid: 'ke' },
|
|
70
|
-
{ display: 'Uganda', uuid: 'ug' },
|
|
71
|
-
],
|
|
72
|
-
isLoading: false,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}),
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
79
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
...originalModule,
|
|
83
|
-
validator: jest.fn(),
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
jest.mock('react-router-dom', () => ({
|
|
88
|
-
...(jest.requireActual('react-router-dom') as any),
|
|
89
|
-
useLocation: () => ({
|
|
90
|
-
pathname: 'openmrs/spa/patient-registration',
|
|
91
|
-
}),
|
|
92
|
-
useHistory: () => [],
|
|
93
|
-
useParams: jest.fn().mockReturnValue({ patientUuid: undefined }),
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
jest.mock('./patient-registration.resource', () => {
|
|
97
|
-
const originalModule = jest.requireActual('./patient-registration.resource');
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
...originalModule,
|
|
101
|
-
saveEncounter: jest.fn(),
|
|
102
|
-
savePatient: jest.fn(),
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
107
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
...originalModule,
|
|
111
|
-
validator: jest.fn(),
|
|
112
|
-
getLocale: jest.fn().mockReturnValue('en'),
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const mockResourcesContextValue = {
|
|
117
|
-
addressTemplate: mockedAddressTemplate as AddressTemplate,
|
|
118
|
-
currentSession: {
|
|
119
|
-
authenticated: true,
|
|
120
|
-
sessionId: 'JSESSION',
|
|
121
|
-
currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
|
|
122
|
-
},
|
|
123
|
-
relationshipTypes: [],
|
|
124
|
-
identifierTypes: [],
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
let mockOpenmrsConfig: RegistrationConfig = {
|
|
128
|
-
sections: ['demographics', 'contact'],
|
|
129
|
-
sectionDefinitions: [
|
|
130
|
-
{ id: 'demographics', name: 'Demographics', fields: ['name', 'gender', 'dob'] },
|
|
131
|
-
{ id: 'contact', name: 'Contact Info', fields: ['address'] },
|
|
132
|
-
{ id: 'relationships', name: 'Relationships', fields: ['relationship'] },
|
|
133
|
-
],
|
|
134
|
-
fieldDefinitions: [],
|
|
135
|
-
fieldConfigurations: {
|
|
136
|
-
dateOfBirth: {
|
|
137
|
-
allowEstimatedDateOfBirth: true,
|
|
138
|
-
useEstimatedDateOfBirth: {
|
|
139
|
-
enabled: true,
|
|
140
|
-
dayOfMonth: new Date().getDay(),
|
|
141
|
-
month: new Date().getMonth(),
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
name: {
|
|
145
|
-
displayMiddleName: true,
|
|
146
|
-
allowUnidentifiedPatients: true,
|
|
147
|
-
defaultUnknownGivenName: 'UNKNOWN',
|
|
148
|
-
defaultUnknownFamilyName: 'UNKNOWN',
|
|
149
|
-
displayReverseFieldOrder: false,
|
|
150
|
-
displayCapturePhoto: true,
|
|
151
|
-
},
|
|
152
|
-
gender: [
|
|
153
|
-
{
|
|
154
|
-
value: 'male',
|
|
155
|
-
label: 'Male',
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
address: {
|
|
159
|
-
useAddressHierarchy: {
|
|
160
|
-
enabled: true,
|
|
161
|
-
useQuickSearch: true,
|
|
162
|
-
searchAddressByLevel: true,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
concepts: {
|
|
167
|
-
patientPhotoUuid: '736e8771-e501-4615-bfa7-570c03f4bef5',
|
|
168
|
-
},
|
|
169
|
-
links: {
|
|
170
|
-
submitButton: '#',
|
|
171
|
-
},
|
|
172
|
-
defaultPatientIdentifierTypes: [],
|
|
173
|
-
registrationObs: {
|
|
174
|
-
encounterTypeUuid: null,
|
|
175
|
-
encounterProviderRoleUuid: 'asdf',
|
|
176
|
-
registrationFormUuid: null,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const path = `/patient/:patientUuid/edit`;
|
|
181
|
-
|
|
182
|
-
const configWithObs = JSON.parse(JSON.stringify(mockOpenmrsConfig));
|
|
183
|
-
configWithObs.fieldDefinitions = [
|
|
184
|
-
{
|
|
185
|
-
id: 'weight',
|
|
186
|
-
type: 'obs',
|
|
187
|
-
label: null,
|
|
188
|
-
uuid: 'weight-uuid',
|
|
189
|
-
placeholder: '',
|
|
190
|
-
validation: { required: false, matches: null },
|
|
191
|
-
answerConceptSetUuid: null,
|
|
192
|
-
customConceptAnswers: [],
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
id: 'chief complaint',
|
|
196
|
-
type: 'obs',
|
|
197
|
-
label: null,
|
|
198
|
-
uuid: 'chief-complaint-uuid',
|
|
199
|
-
placeholder: '',
|
|
200
|
-
validation: { required: false, matches: null },
|
|
201
|
-
answerConceptSetUuid: null,
|
|
202
|
-
customConceptAnswers: [],
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
id: 'nationality',
|
|
206
|
-
type: 'obs',
|
|
207
|
-
label: null,
|
|
208
|
-
uuid: 'nationality-uuid',
|
|
209
|
-
placeholder: '',
|
|
210
|
-
validation: { required: false, matches: null },
|
|
211
|
-
answerConceptSetUuid: null,
|
|
212
|
-
customConceptAnswers: [],
|
|
213
|
-
},
|
|
214
|
-
];
|
|
215
|
-
|
|
216
|
-
configWithObs.sectionDefinitions?.push({
|
|
217
|
-
id: 'custom',
|
|
218
|
-
name: 'Custom',
|
|
219
|
-
fields: ['weight', 'chief complaint', 'nationality'],
|
|
220
|
-
});
|
|
221
|
-
configWithObs.sections.push('custom');
|
|
222
|
-
configWithObs.registrationObs.encounterTypeUuid = 'reg-enc-uuid';
|
|
223
|
-
|
|
224
|
-
const fillRequiredFields = async () => {
|
|
225
|
-
const user = userEvent.setup();
|
|
226
|
-
|
|
227
|
-
const demographicsSection = await screen.findByLabelText('Demographics Section');
|
|
228
|
-
const givenNameInput = within(demographicsSection).getByLabelText(/first/i) as HTMLInputElement;
|
|
229
|
-
const familyNameInput = within(demographicsSection).getByLabelText(/family/i) as HTMLInputElement;
|
|
230
|
-
const dateOfBirthInput = within(demographicsSection).getByLabelText(/date of birth/i) as HTMLInputElement;
|
|
231
|
-
const genderInput = within(demographicsSection).getByLabelText(/Male/) as HTMLSelectElement;
|
|
232
|
-
|
|
233
|
-
await user.type(givenNameInput, 'Paul');
|
|
234
|
-
await user.type(familyNameInput, 'Gaihre');
|
|
235
|
-
await user.clear(dateOfBirthInput);
|
|
236
|
-
await user.type(dateOfBirthInput, '02/08/1993');
|
|
237
|
-
user.click(genderInput);
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
function Wrapper({ children }) {
|
|
241
|
-
return (
|
|
242
|
-
<ResourcesContext.Provider value={mockResourcesContextValue}>
|
|
243
|
-
<Router>{children}</Router>
|
|
244
|
-
</ResourcesContext.Provider>
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
describe('Registering a new patient', () => {
|
|
249
|
-
beforeEach(() => {
|
|
250
|
-
mockedUseConfig.mockReturnValue(mockOpenmrsConfig);
|
|
251
|
-
mockedSavePatient.mockReturnValue({ data: { uuid: 'new-pt-uuid' }, ok: true });
|
|
252
|
-
mockedSaveEncounter.mockClear();
|
|
253
|
-
mockedShowSnackbar.mockClear();
|
|
254
|
-
jest.clearAllMocks();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('renders without crashing', () => {
|
|
258
|
-
render(<PatientRegistration isOffline={false} savePatientForm={jest.fn()} />, { wrapper: Wrapper });
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('has the expected sections', async () => {
|
|
262
|
-
render(<PatientRegistration isOffline={false} savePatientForm={jest.fn()} />, { wrapper: Wrapper });
|
|
263
|
-
|
|
264
|
-
expect(screen.getByLabelText(/Demographics Section/)).not.toBeNull();
|
|
265
|
-
expect(screen.getByLabelText(/Contact Info Section/)).not.toBeNull();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('saves the patient without extra info', async () => {
|
|
269
|
-
const user = userEvent.setup();
|
|
270
|
-
|
|
271
|
-
render(<PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />, {
|
|
272
|
-
wrapper: Wrapper,
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
await fillRequiredFields();
|
|
276
|
-
await user.click(await screen.findByText('Register Patient'));
|
|
277
|
-
expect(mockedSavePatient).toHaveBeenCalledWith(
|
|
278
|
-
expect.objectContaining({
|
|
279
|
-
identifiers: [], //TODO when the identifer story is finished: { identifier: '', identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334', location: '' },
|
|
280
|
-
person: {
|
|
281
|
-
addresses: expect.arrayContaining([expect.any(Object)]),
|
|
282
|
-
attributes: [],
|
|
283
|
-
birthdate: '1993-8-2',
|
|
284
|
-
birthdateEstimated: false,
|
|
285
|
-
gender: expect.stringMatching(/^M$/),
|
|
286
|
-
names: [{ givenName: 'Paul', middleName: '', familyName: 'Gaihre', preferred: true, uuid: undefined }],
|
|
287
|
-
dead: false,
|
|
288
|
-
uuid: expect.anything(),
|
|
289
|
-
},
|
|
290
|
-
uuid: expect.anything(),
|
|
291
|
-
}),
|
|
292
|
-
undefined,
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it('should not save the patient if validation fails', async () => {
|
|
297
|
-
const user = userEvent.setup();
|
|
298
|
-
|
|
299
|
-
const mockedSavePatientForm = jest.fn();
|
|
300
|
-
render(<PatientRegistration isOffline={false} savePatientForm={mockedSavePatientForm} />, { wrapper: Wrapper });
|
|
301
|
-
|
|
302
|
-
const givenNameInput = (await screen.findByLabelText('First Name')) as HTMLInputElement;
|
|
303
|
-
|
|
304
|
-
await user.type(givenNameInput, '5');
|
|
305
|
-
await user.click(screen.getByText('Register Patient'));
|
|
306
|
-
|
|
307
|
-
expect(mockedSavePatientForm).not.toHaveBeenCalled();
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('renders and saves registration obs', async () => {
|
|
311
|
-
const user = userEvent.setup();
|
|
312
|
-
|
|
313
|
-
mockedSaveEncounter.mockResolvedValue({});
|
|
314
|
-
mockedUseConfig.mockReturnValue(configWithObs);
|
|
315
|
-
|
|
316
|
-
render(<PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />, {
|
|
317
|
-
wrapper: Wrapper,
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
await fillRequiredFields();
|
|
321
|
-
const customSection = screen.getByLabelText('Custom Section');
|
|
322
|
-
const weight = within(customSection).getByLabelText('Weight (kg) (optional)');
|
|
323
|
-
await user.type(weight, '50');
|
|
324
|
-
const complaint = within(customSection).getByLabelText('Chief Complaint (optional)');
|
|
325
|
-
await user.type(complaint, 'sad');
|
|
326
|
-
const nationality = within(customSection).getByLabelText('Nationality');
|
|
327
|
-
await user.selectOptions(nationality, 'USA');
|
|
328
|
-
|
|
329
|
-
await user.click(screen.getByText('Register Patient'));
|
|
330
|
-
|
|
331
|
-
expect(mockedSavePatient).toHaveBeenCalled();
|
|
332
|
-
|
|
333
|
-
expect(mockedSaveEncounter).toHaveBeenCalledWith(
|
|
334
|
-
expect.objectContaining<Partial<Encounter>>({
|
|
335
|
-
encounterType: 'reg-enc-uuid',
|
|
336
|
-
patient: 'new-pt-uuid',
|
|
337
|
-
obs: [
|
|
338
|
-
{ concept: 'weight-uuid', value: 50 },
|
|
339
|
-
{ concept: 'chief-complaint-uuid', value: 'sad' },
|
|
340
|
-
{ concept: 'nationality-uuid', value: 'usa' },
|
|
341
|
-
],
|
|
342
|
-
}),
|
|
343
|
-
);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('retries saving registration obs after a failed attempt', async () => {
|
|
347
|
-
const user = userEvent.setup();
|
|
348
|
-
|
|
349
|
-
mockedUseConfig.mockReturnValue(configWithObs);
|
|
350
|
-
|
|
351
|
-
render(<PatientRegistration isOffline={false} savePatientForm={FormManager.savePatientFormOnline} />, {
|
|
352
|
-
wrapper: Wrapper,
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
await fillRequiredFields();
|
|
356
|
-
const customSection = screen.getByLabelText('Custom Section');
|
|
357
|
-
const weight = within(customSection).getByLabelText('Weight (kg) (optional)');
|
|
358
|
-
await user.type(weight, '-999');
|
|
359
|
-
|
|
360
|
-
mockedSaveEncounter.mockRejectedValue({ status: 400, responseBody: { error: { message: 'an error message' } } });
|
|
361
|
-
|
|
362
|
-
const registerPatientButton = screen.getByText('Register Patient');
|
|
363
|
-
|
|
364
|
-
await user.click(registerPatientButton);
|
|
365
|
-
|
|
366
|
-
expect(mockedSavePatient).toHaveBeenCalledTimes(1);
|
|
367
|
-
expect(mockedSaveEncounter).toHaveBeenCalledTimes(1);
|
|
368
|
-
|
|
369
|
-
expect(mockedShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ subtitle: 'an error message' })),
|
|
370
|
-
mockedSaveEncounter.mockResolvedValue({});
|
|
371
|
-
|
|
372
|
-
await user.click(registerPatientButton);
|
|
373
|
-
expect(mockedSavePatient).toHaveBeenCalledTimes(2);
|
|
374
|
-
expect(mockedSaveEncounter).toHaveBeenCalledTimes(2);
|
|
375
|
-
|
|
376
|
-
expect(mockedShowSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'success' }));
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
describe('Updating an existing patient record', () => {
|
|
381
|
-
beforeEach(() => {
|
|
382
|
-
mockedUseConfig.mockReturnValue(mockOpenmrsConfig);
|
|
383
|
-
mockedSavePatient.mockReturnValue({ data: { uuid: 'new-pt-uuid' }, ok: true });
|
|
384
|
-
mockedSaveEncounter.mockClear();
|
|
385
|
-
mockedShowSnackbar.mockClear();
|
|
386
|
-
jest.clearAllMocks();
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('edits patient demographics', async () => {
|
|
390
|
-
const user = userEvent.setup();
|
|
391
|
-
|
|
392
|
-
mockedSavePatient.mockResolvedValue({});
|
|
393
|
-
|
|
394
|
-
const mockedUseParams = useParams as jest.Mock;
|
|
395
|
-
|
|
396
|
-
mockedUseParams.mockReturnValue({ patientUuid: mockPatient.id });
|
|
397
|
-
|
|
398
|
-
mockedUsePatient.mockReturnValue({
|
|
399
|
-
isLoading: false,
|
|
400
|
-
patient: mockPatient,
|
|
401
|
-
patientUuid: mockPatient.id,
|
|
402
|
-
error: null,
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
render(<PatientRegistration isOffline={false} savePatientForm={mockedSavePatient} />, { wrapper: Wrapper });
|
|
406
|
-
|
|
407
|
-
const givenNameInput: HTMLInputElement = screen.getByLabelText(/First Name/);
|
|
408
|
-
const familyNameInput: HTMLInputElement = screen.getByLabelText(/Family Name/);
|
|
409
|
-
const middleNameInput: HTMLInputElement = screen.getByLabelText(/Middle Name/);
|
|
410
|
-
const dateOfBirthInput: HTMLInputElement = screen.getByLabelText('Date of Birth');
|
|
411
|
-
const genderInput: HTMLInputElement = screen.getByLabelText(/Male/);
|
|
412
|
-
|
|
413
|
-
// assert initial values
|
|
414
|
-
expect(givenNameInput.value).toBe('John');
|
|
415
|
-
expect(familyNameInput.value).toBe('Wilson');
|
|
416
|
-
expect(middleNameInput.value).toBeFalsy();
|
|
417
|
-
expect(dateOfBirthInput.value).toBe('4/4/1972');
|
|
418
|
-
expect(genderInput.value).toBe('male');
|
|
419
|
-
|
|
420
|
-
// do some edits
|
|
421
|
-
await user.clear(givenNameInput);
|
|
422
|
-
await user.clear(middleNameInput);
|
|
423
|
-
await user.clear(familyNameInput);
|
|
424
|
-
await user.type(givenNameInput, 'Eric');
|
|
425
|
-
await user.type(middleNameInput, 'Johnson');
|
|
426
|
-
await user.type(familyNameInput, 'Smith');
|
|
427
|
-
await user.click(screen.getByText('Update Patient'));
|
|
428
|
-
|
|
429
|
-
expect(mockedSavePatient).toHaveBeenCalledWith(
|
|
430
|
-
false,
|
|
431
|
-
{
|
|
432
|
-
'0': {
|
|
433
|
-
oldIdentificationNumber: '100732HE',
|
|
434
|
-
},
|
|
435
|
-
'1': {
|
|
436
|
-
openMrsId: '100GEJ',
|
|
437
|
-
},
|
|
438
|
-
addNameInLocalLanguage: undefined,
|
|
439
|
-
additionalFamilyName: '',
|
|
440
|
-
additionalGivenName: '',
|
|
441
|
-
additionalMiddleName: '',
|
|
442
|
-
address: {},
|
|
443
|
-
birthdate: new Date('1972-04-04T00:00:00.000Z'),
|
|
444
|
-
birthdateEstimated: false,
|
|
445
|
-
deathCause: '',
|
|
446
|
-
deathDate: '',
|
|
447
|
-
familyName: 'Smith',
|
|
448
|
-
gender: expect.stringMatching(/male/i),
|
|
449
|
-
givenName: 'Eric',
|
|
450
|
-
identifiers: {},
|
|
451
|
-
isDead: false,
|
|
452
|
-
middleName: 'Johnson',
|
|
453
|
-
monthsEstimated: 0,
|
|
454
|
-
patientUuid: '8673ee4f-e2ab-4077-ba55-4980f408773e',
|
|
455
|
-
relationships: [],
|
|
456
|
-
telephoneNumber: '',
|
|
457
|
-
unidentifiedPatient: undefined,
|
|
458
|
-
yearsEstimated: 0,
|
|
459
|
-
},
|
|
460
|
-
expect.anything(),
|
|
461
|
-
expect.anything(),
|
|
462
|
-
null,
|
|
463
|
-
undefined,
|
|
464
|
-
expect.anything(),
|
|
465
|
-
expect.anything(),
|
|
466
|
-
expect.anything(),
|
|
467
|
-
{ patientSaved: false },
|
|
468
|
-
expect.anything(),
|
|
469
|
-
);
|
|
470
|
-
});
|
|
471
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { Formik, Form } from 'formik';
|
|
4
|
-
import { initialFormValues } from '../../patient-registration.component';
|
|
5
|
-
import { DeathInfoSection } from './death-info-section.component';
|
|
6
|
-
import { type FormValues } from '../../patient-registration.types';
|
|
7
|
-
import { PatientRegistrationContext } from '../../patient-registration-context';
|
|
8
|
-
|
|
9
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
10
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
...originalModule,
|
|
14
|
-
validator: jest.fn(),
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const initialContextValues = {
|
|
19
|
-
currentPhoto: 'data:image/png;base64,1234567890',
|
|
20
|
-
identifierTypes: [],
|
|
21
|
-
inEditMode: false,
|
|
22
|
-
initialFormValues: {} as FormValues,
|
|
23
|
-
isOffline: false,
|
|
24
|
-
setCapturePhotoProps: jest.fn(),
|
|
25
|
-
setFieldValue: jest.fn(),
|
|
26
|
-
setInitialFormValues: jest.fn(),
|
|
27
|
-
validationSchema: null,
|
|
28
|
-
values: {
|
|
29
|
-
isDead: true,
|
|
30
|
-
} as FormValues,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe('Death info section', () => {
|
|
34
|
-
const renderDeathInfoSection = (isDead) => {
|
|
35
|
-
initialContextValues.values.isDead = isDead;
|
|
36
|
-
|
|
37
|
-
return render(
|
|
38
|
-
<PatientRegistrationContext.Provider value={initialContextValues}>
|
|
39
|
-
<Formik initialValues={initialFormValues} onSubmit={jest.fn()}>
|
|
40
|
-
<Form>
|
|
41
|
-
<DeathInfoSection />
|
|
42
|
-
</Form>
|
|
43
|
-
</Formik>
|
|
44
|
-
</PatientRegistrationContext.Provider>,
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
it('shows fields for recording death info when the patient is marked as dead', () => {
|
|
49
|
-
renderDeathInfoSection(true);
|
|
50
|
-
|
|
51
|
-
expect(screen.getByRole('region', { name: /death info section/i })).toBeInTheDocument();
|
|
52
|
-
expect(screen.getByRole('heading', { name: /death info/i })).toBeInTheDocument();
|
|
53
|
-
expect(screen.getByRole('textbox', { name: /is dead \(optional\)/i })).toBeInTheDocument();
|
|
54
|
-
expect(screen.getByRole('textbox', { name: /date of death \(optional\)/i })).toBeInTheDocument();
|
|
55
|
-
expect(screen.getByRole('combobox', { name: /cause of death \(optional\)/i })).toBeInTheDocument();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('has the correct number of inputs if is dead is not checked', async () => {
|
|
59
|
-
renderDeathInfoSection(false);
|
|
60
|
-
|
|
61
|
-
expect(screen.queryByRole('textbox', { name: /date of death \(optional\)/i })).not.toBeInTheDocument();
|
|
62
|
-
expect(screen.queryByRole('combobox', { name: /cause of death \(optional\)/i })).not.toBeInTheDocument();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { Formik, Form } from 'formik';
|
|
4
|
-
import { initialFormValues } from '../../patient-registration.component';
|
|
5
|
-
import { DemographicsSection } from './demographics-section.component';
|
|
6
|
-
import { PatientRegistrationContext } from '../../patient-registration-context';
|
|
7
|
-
import { type FormValues } from '../../patient-registration.types';
|
|
8
|
-
|
|
9
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
10
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
...originalModule,
|
|
14
|
-
validator: jest.fn(),
|
|
15
|
-
useConfig: jest.fn().mockImplementation(() => ({
|
|
16
|
-
fieldConfigurations: { dateOfBirth: { useEstimatedDateOfBirth: { enabled: true, dayOfMonth: 0, month: 0 } } },
|
|
17
|
-
})),
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
jest.mock('../../field/name/name-field.component', () => {
|
|
22
|
-
return {
|
|
23
|
-
NameField: () => (
|
|
24
|
-
<div>
|
|
25
|
-
<input type="text" name="name" />
|
|
26
|
-
</div>
|
|
27
|
-
),
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
jest.mock('../../field/gender/gender-field.component', () => {
|
|
32
|
-
return {
|
|
33
|
-
GenderField: () => (
|
|
34
|
-
<div>
|
|
35
|
-
<input type="text" name="name" />
|
|
36
|
-
</div>
|
|
37
|
-
),
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
jest.mock('../../field/id/id-field.component', () => {
|
|
42
|
-
return {
|
|
43
|
-
IdField: () => (
|
|
44
|
-
<div>
|
|
45
|
-
<input type="text" name="name" />
|
|
46
|
-
</div>
|
|
47
|
-
),
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('demographics section', () => {
|
|
52
|
-
const formValues: FormValues = initialFormValues;
|
|
53
|
-
|
|
54
|
-
const setupSection = async (birthdateEstimated?: boolean, addNameInLocalLanguage?: boolean) => {
|
|
55
|
-
render(
|
|
56
|
-
<Formik initialValues={{ ...initialFormValues, birthdateEstimated, addNameInLocalLanguage }} onSubmit={null}>
|
|
57
|
-
<Form>
|
|
58
|
-
<PatientRegistrationContext.Provider
|
|
59
|
-
value={{
|
|
60
|
-
initialFormValues: null,
|
|
61
|
-
identifierTypes: [],
|
|
62
|
-
validationSchema: {},
|
|
63
|
-
values: { ...initialFormValues, birthdateEstimated, addNameInLocalLanguage },
|
|
64
|
-
inEditMode: false,
|
|
65
|
-
setFieldValue: () => {},
|
|
66
|
-
currentPhoto: 'TEST',
|
|
67
|
-
isOffline: true,
|
|
68
|
-
setCapturePhotoProps: (value) => {},
|
|
69
|
-
}}>
|
|
70
|
-
<DemographicsSection fields={['name', 'gender', 'dob']} id="demographics" />
|
|
71
|
-
</PatientRegistrationContext.Provider>
|
|
72
|
-
</Form>
|
|
73
|
-
</Formik>,
|
|
74
|
-
);
|
|
75
|
-
const allInputs = screen.getAllByRole('textbox') as Array<HTMLInputElement>;
|
|
76
|
-
return allInputs.map((input) => input.name);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
it('inputs corresponding to number of fields', async () => {
|
|
80
|
-
const inputNames = await setupSection();
|
|
81
|
-
expect(inputNames.length).toBe(3);
|
|
82
|
-
});
|
|
83
|
-
});
|