@ampath/esm-patient-registration-app 6.0.1-pre.17 → 6.0.1-pre.170
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 +20 -20
- package/dist/132.js +1 -1
- package/dist/197.js +1 -1
- package/dist/236.js +1 -1
- package/dist/300.js +1 -1
- package/dist/335.js +1 -1
- package/dist/41.js +1 -1
- package/dist/41.js.map +1 -1
- package/dist/449.js +1 -0
- package/dist/449.js.map +1 -0
- package/dist/55.js +1 -1
- package/dist/56.js +1 -1
- package/dist/56.js.map +1 -1
- package/dist/621.js +1 -0
- package/dist/621.js.map +1 -0
- 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 -1
- package/dist/661.js +1 -1
- package/dist/757.js +1 -0
- 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 +1 -1
- package/dist/831.js.map +1 -1
- package/dist/879.js +1 -1
- package/dist/913.js +1 -1
- package/dist/913.js.LICENSE.txt +3 -3
- package/dist/913.js.map +1 -1
- package/dist/927.js +1 -0
- package/dist/927.js.map +1 -0
- package/dist/99.js +1 -1
- package/dist/ampath-esm-patient-registration-app.js +1 -1
- package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +183 -111
- 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 +7 -10
- package/src/config-schema.ts +19 -10
- 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 +133 -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} +4 -4
- package/src/patient-registration/patient-registration.resource.ts +15 -75
- 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 +18 -4
- 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/229.js +0 -2
- package/dist/229.js.LICENSE.txt +0 -56
- package/dist/229.js.map +0 -1
- package/dist/537.js +0 -1
- package/dist/537.js.map +0 -1
- package/dist/885.js +0 -1
- package/dist/885.js.map +0 -1
- package/dist/918.js +0 -1
- package/dist/918.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/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,294 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Form, Formik } from 'formik';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { useConfig } from '@openmrs/esm-framework';
|
|
5
|
-
import { Field } from './field.component';
|
|
6
|
-
import type { AddressTemplate, FormValues } from '../patient-registration.types';
|
|
7
|
-
import { type Resources, ResourcesContext } from '../../offline.resources';
|
|
8
|
-
import { PatientRegistrationContext } from '../patient-registration-context';
|
|
9
|
-
|
|
10
|
-
jest.mock('@openmrs/esm-framework', () => ({
|
|
11
|
-
...jest.requireActual('@openmrs/esm-framework'),
|
|
12
|
-
useConfig: jest.fn(),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
const predefinedAddressTemplate = {
|
|
16
|
-
uuid: 'test-address-template-uuid',
|
|
17
|
-
property: 'layout.address.format',
|
|
18
|
-
description: 'Test Address Template',
|
|
19
|
-
display:
|
|
20
|
-
'Layout - Address Format = <org.openmrs.layout.address.AddressTemplate>\n <nameMappings class="properties">\n <property name="postalCode" value="Location.postalCode"/>\n <property name="address2" value="Location.address2"/>\n <property name="address1" value="Location.address1"/>\n <property name="country" value="Location.country"/>\n <property name="stateProvince" value="Location.stateProvince"/>\n <property name="cityVillage" value="Location.cityVillage"/>\n </nameMappings>\n <sizeMappings class="properties">\n <property name="postalCode" value="10"/>\n <property name="address2" value="40"/>\n <property name="address1" value="40"/>\n <property name="country" value="10"/>\n <property name="stateProvince" value="10"/>\n <property name="cityVillage" value="10"/>\n </sizeMappings>\n <lineByLineFormat>\n <string>address1</string>\n <string>address2</string>\n <string>cityVillage stateProvince country postalCode</string>\n </lineByLineFormat>\n </org.openmrs.layout.address.AddressTemplate>',
|
|
21
|
-
value:
|
|
22
|
-
'<org.openmrs.layout.address.AddressTemplate>\r\n <nameMappings class="properties">\r\n <property name="postalCode" value="Location.postalCode"/>\r\n <property name="address2" value="Location.address2"/>\r\n <property name="address1" value="Location.address1"/>\r\n <property name="country" value="Location.country"/>\r\n <property name="stateProvince" value="Location.stateProvince"/>\r\n <property name="cityVillage" value="Location.cityVillage"/>\r\n </nameMappings>\r\n <sizeMappings class="properties">\r\n <property name="postalCode" value="4"/>\r\n <property name="address1" value="40"/>\r\n <property name="address2" value="40"/>\r\n <property name="country" value="10"/>\r\n <property name="stateProvince" value="10"/>\r\n <property name="cityVillage" value="10"/>\r\n <asset name="cityVillage" value="10"/>\r\n </sizeMappings>\r\n <lineByLineFormat>\r\n <string>address1 address2</string>\r\n <string>cityVillage stateProvince postalCode</string>\r\n <string>country</string>\r\n </lineByLineFormat>\r\n <elementDefaults class="properties">\r\n <property name="country" value=""/>\r\n </elementDefaults>\r\n <elementRegex class="properties">\r\n <property name="address1" value="[a-zA-Z]+$"/>\r\n </elementRegex>\r\n <elementRegexFormats class="properties">\r\n <property name="address1" value="Countries can only be letters"/>\r\n </elementRegexFormats>\r\n </org.openmrs.layout.address.AddressTemplate>',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const mockedIdentifierTypes = [
|
|
26
|
-
{
|
|
27
|
-
fieldName: 'openMrsId',
|
|
28
|
-
format: '',
|
|
29
|
-
identifierSources: [
|
|
30
|
-
{
|
|
31
|
-
uuid: '8549f706-7e85-4c1d-9424-217d50a2988b',
|
|
32
|
-
name: 'Generator for OpenMRS ID',
|
|
33
|
-
description: 'Generator for OpenMRS ID',
|
|
34
|
-
baseCharacterSet: '0123456789ACDEFGHJKLMNPRTUVWXY',
|
|
35
|
-
prefix: '',
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
isPrimary: true,
|
|
39
|
-
name: 'OpenMRS ID',
|
|
40
|
-
required: true,
|
|
41
|
-
uniquenessBehavior: 'UNIQUE' as const,
|
|
42
|
-
uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
fieldName: 'idCard',
|
|
46
|
-
format: '',
|
|
47
|
-
identifierSources: [],
|
|
48
|
-
isPrimary: false,
|
|
49
|
-
name: 'ID Card',
|
|
50
|
-
required: false,
|
|
51
|
-
uniquenessBehavior: 'UNIQUE' as const,
|
|
52
|
-
uuid: 'b4143563-16cd-4439-b288-f83d61670fc8',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
fieldName: 'legacyId',
|
|
56
|
-
format: '',
|
|
57
|
-
identifierSources: [],
|
|
58
|
-
isPrimary: false,
|
|
59
|
-
name: 'Legacy ID',
|
|
60
|
-
required: false,
|
|
61
|
-
uniquenessBehavior: null,
|
|
62
|
-
uuid: '22348099-3873-459e-a32e-d93b17eda533',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
fieldName: 'oldIdentificationNumber',
|
|
66
|
-
format: '',
|
|
67
|
-
identifierSources: [],
|
|
68
|
-
isPrimary: false,
|
|
69
|
-
name: 'Old Identification Number',
|
|
70
|
-
required: false,
|
|
71
|
-
uniquenessBehavior: null,
|
|
72
|
-
uuid: '8d79403a-c2cc-11de-8d13-0010c6dffd0f',
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
fieldName: 'openMrsIdentificationNumber',
|
|
76
|
-
format: '',
|
|
77
|
-
identifierSources: [],
|
|
78
|
-
isPrimary: false,
|
|
79
|
-
name: 'OpenMRS Identification Number',
|
|
80
|
-
required: false,
|
|
81
|
-
uniquenessBehavior: null,
|
|
82
|
-
uuid: '8d793bee-c2cc-11de-8d13-0010c6dffd0f',
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
const mockResourcesContextValue: Resources = {
|
|
87
|
-
addressTemplate: predefinedAddressTemplate as unknown as AddressTemplate,
|
|
88
|
-
currentSession: {
|
|
89
|
-
authenticated: true,
|
|
90
|
-
sessionId: 'JSESSION',
|
|
91
|
-
currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
|
|
92
|
-
},
|
|
93
|
-
relationshipTypes: [],
|
|
94
|
-
identifierTypes: [...mockedIdentifierTypes],
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const initialContextValues = {
|
|
98
|
-
currentPhoto: 'data:image/png;base64,1234567890',
|
|
99
|
-
identifierTypes: [],
|
|
100
|
-
inEditMode: false,
|
|
101
|
-
initialFormValues: {} as FormValues,
|
|
102
|
-
isOffline: false,
|
|
103
|
-
setCapturePhotoProps: jest.fn(),
|
|
104
|
-
setFieldValue: jest.fn(),
|
|
105
|
-
setInitialFormValues: jest.fn(),
|
|
106
|
-
validationSchema: null,
|
|
107
|
-
values: {} as FormValues,
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
describe('Field', () => {
|
|
111
|
-
let ContextWrapper;
|
|
112
|
-
|
|
113
|
-
beforeEach(() => {
|
|
114
|
-
ContextWrapper = ({ children }) => (
|
|
115
|
-
<ResourcesContext.Provider value={mockResourcesContextValue}>
|
|
116
|
-
<Formik initialValues={{}} onSubmit={jest.fn()}>
|
|
117
|
-
<Form>
|
|
118
|
-
<PatientRegistrationContext.Provider value={initialContextValues}>
|
|
119
|
-
{children}
|
|
120
|
-
</PatientRegistrationContext.Provider>
|
|
121
|
-
</Form>
|
|
122
|
-
</Formik>
|
|
123
|
-
</ResourcesContext.Provider>
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
afterEach(() => {
|
|
128
|
-
jest.clearAllMocks();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should render NameField component when name prop is "name"', () => {
|
|
132
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
133
|
-
fieldConfigurations: {
|
|
134
|
-
name: {
|
|
135
|
-
displayMiddleName: true,
|
|
136
|
-
unidentifiedPatient: true,
|
|
137
|
-
defaultUnknownGivenName: 'UNKNOWN',
|
|
138
|
-
defaultUnknownFamilyName: 'UNKNOWN',
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
}));
|
|
142
|
-
|
|
143
|
-
render(<Field name="name" />, { wrapper: ContextWrapper });
|
|
144
|
-
|
|
145
|
-
expect(screen.getByText('Full Name')).toBeInTheDocument();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should render GenderField component when name prop is "gender"', () => {
|
|
149
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
150
|
-
fieldConfigurations: {
|
|
151
|
-
gender: [
|
|
152
|
-
{
|
|
153
|
-
value: 'Male',
|
|
154
|
-
label: 'Male',
|
|
155
|
-
id: 'male',
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
}));
|
|
160
|
-
|
|
161
|
-
render(<Field name="gender" />, { wrapper: ContextWrapper });
|
|
162
|
-
|
|
163
|
-
expect(screen.getByLabelText('Male')).toBeInTheDocument();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should render DobField component when name prop is "dob"', () => {
|
|
167
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
168
|
-
fieldConfigurations: {
|
|
169
|
-
dob: {
|
|
170
|
-
minAgeLimit: 0,
|
|
171
|
-
maxAgeLimit: 120,
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
}));
|
|
175
|
-
render(<Field name="dob" />, { wrapper: ContextWrapper });
|
|
176
|
-
expect(screen.getByText('Birth')).toBeInTheDocument();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should render AddressComponent component when name prop is "address"', () => {
|
|
180
|
-
jest.mock('./address/address-hierarchy.resource', () => ({
|
|
181
|
-
...(jest.requireActual('../address-hierarchy.resource') as jest.Mock),
|
|
182
|
-
useOrderedAddressHierarchyLevels: jest.fn(),
|
|
183
|
-
}));
|
|
184
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
185
|
-
fieldConfigurations: {
|
|
186
|
-
address: {
|
|
187
|
-
useAddressHierarchy: {
|
|
188
|
-
enabled: false,
|
|
189
|
-
useQuickSearch: false,
|
|
190
|
-
searchAddressByLevel: false,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
}));
|
|
195
|
-
|
|
196
|
-
render(<Field name="address" />, { wrapper: ContextWrapper });
|
|
197
|
-
|
|
198
|
-
expect(screen.getByText('Address')).toBeInTheDocument();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should render Identifiers component when name prop is "id"', () => {
|
|
202
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
203
|
-
defaultPatientIdentifierTypes: ['OpenMRS ID'],
|
|
204
|
-
}));
|
|
205
|
-
|
|
206
|
-
const openmrsID = {
|
|
207
|
-
name: 'OpenMRS ID',
|
|
208
|
-
fieldName: 'openMrsId',
|
|
209
|
-
required: true,
|
|
210
|
-
uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
|
|
211
|
-
format: null,
|
|
212
|
-
isPrimary: true,
|
|
213
|
-
identifierSources: [
|
|
214
|
-
{
|
|
215
|
-
uuid: '691eed12-c0f1-11e2-94be-8c13b969e334',
|
|
216
|
-
name: 'Generator 1 for OpenMRS ID',
|
|
217
|
-
autoGenerationOption: {
|
|
218
|
-
manualEntryEnabled: false,
|
|
219
|
-
automaticGenerationEnabled: true,
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
uuid: '01af8526-cea4-4175-aa90-340acb411771',
|
|
224
|
-
name: 'Generator 2 for OpenMRS ID',
|
|
225
|
-
autoGenerationOption: {
|
|
226
|
-
manualEntryEnabled: true,
|
|
227
|
-
automaticGenerationEnabled: true,
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
identifierUuid: 'openmrs-identifier-uuid',
|
|
232
|
-
identifierTypeUuid: 'openmrs-id-identifier-type-uuid',
|
|
233
|
-
initialValue: '12345',
|
|
234
|
-
identifierValue: '12345',
|
|
235
|
-
identifierName: 'OpenMRS ID',
|
|
236
|
-
preferred: true,
|
|
237
|
-
selectedSource: {
|
|
238
|
-
uuid: 'openmrs-id-selected-source-uuid',
|
|
239
|
-
name: 'Generator 1 for OpenMRS ID',
|
|
240
|
-
autoGenerationOption: {
|
|
241
|
-
manualEntryEnabled: false,
|
|
242
|
-
automaticGenerationEnabled: true,
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
autoGenerationSource: null,
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const updatedContextValues = {
|
|
249
|
-
currentPhoto: 'data:image/png;base64,1234567890',
|
|
250
|
-
identifierTypes: [],
|
|
251
|
-
inEditMode: false,
|
|
252
|
-
initialFormValues: { identifiers: { openmrsID } } as unknown as FormValues,
|
|
253
|
-
isOffline: false,
|
|
254
|
-
setCapturePhotoProps: jest.fn(),
|
|
255
|
-
setFieldValue: jest.fn(),
|
|
256
|
-
setInitialFormValues: jest.fn(),
|
|
257
|
-
validationSchema: null,
|
|
258
|
-
values: { identifiers: { openmrsID } } as unknown as FormValues,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
render(
|
|
262
|
-
<ResourcesContext.Provider value={mockResourcesContextValue}>
|
|
263
|
-
<Formik initialValues={{}} onSubmit={jest.fn()}>
|
|
264
|
-
<Form>
|
|
265
|
-
<PatientRegistrationContext.Provider value={updatedContextValues}>
|
|
266
|
-
<Field name="id" />
|
|
267
|
-
</PatientRegistrationContext.Provider>
|
|
268
|
-
</Form>
|
|
269
|
-
</Formik>
|
|
270
|
-
</ResourcesContext.Provider>,
|
|
271
|
-
);
|
|
272
|
-
expect(screen.getByText('Identifiers')).toBeInTheDocument();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('should return null and report an error for an invalid field name', () => {
|
|
276
|
-
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
277
|
-
|
|
278
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
279
|
-
fieldDefinitions: [{ id: 'weight' }],
|
|
280
|
-
}));
|
|
281
|
-
let error = null;
|
|
282
|
-
|
|
283
|
-
try {
|
|
284
|
-
render(<Field name="invalidField" />);
|
|
285
|
-
} catch (err) {
|
|
286
|
-
error = err;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
expect(error).toMatch(/Invalid field name 'invalidField'. Valid options are /);
|
|
290
|
-
expect(screen.queryByTestId('invalid-field')).not.toBeInTheDocument();
|
|
291
|
-
|
|
292
|
-
consoleError.mockRestore();
|
|
293
|
-
});
|
|
294
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { Identifiers } from './id-field.component';
|
|
5
|
-
import { type Resources, ResourcesContext } from '../../../offline.resources';
|
|
6
|
-
import { Form, Formik } from 'formik';
|
|
7
|
-
import { PatientRegistrationContext } from '../../patient-registration-context';
|
|
8
|
-
import { openmrsID, mockedIdentifierTypes } from '__mocks__';
|
|
9
|
-
|
|
10
|
-
jest.mock('@openmrs/esm-framework', () => ({
|
|
11
|
-
...jest.requireActual('@openmrs/esm-framework'),
|
|
12
|
-
useConfig: jest.fn().mockImplementation(() => ({
|
|
13
|
-
defaultPatientIdentifierTypes: ['OpenMRS ID'],
|
|
14
|
-
})),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
describe('Identifiers', () => {
|
|
18
|
-
const mockResourcesContextValue = {
|
|
19
|
-
addressTemplate: {},
|
|
20
|
-
currentSession: {
|
|
21
|
-
authenticated: true,
|
|
22
|
-
sessionId: 'JSESSION',
|
|
23
|
-
currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
|
|
24
|
-
},
|
|
25
|
-
relationshipTypes: [],
|
|
26
|
-
identifierTypes: [...mockedIdentifierTypes],
|
|
27
|
-
} as Resources;
|
|
28
|
-
|
|
29
|
-
it('should render loading skeleton when identifier types are loading', () => {
|
|
30
|
-
render(
|
|
31
|
-
<ResourcesContext.Provider value={[]}>
|
|
32
|
-
<Formik initialValues={{}} onSubmit={null}>
|
|
33
|
-
<Form>
|
|
34
|
-
<PatientRegistrationContext.Provider
|
|
35
|
-
value={{
|
|
36
|
-
setFieldValue: jest.fn(),
|
|
37
|
-
initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
|
|
38
|
-
setInitialFormValues: jest.fn(),
|
|
39
|
-
values: {
|
|
40
|
-
identifiers: { openmrsID },
|
|
41
|
-
},
|
|
42
|
-
}}>
|
|
43
|
-
<Identifiers />
|
|
44
|
-
</PatientRegistrationContext.Provider>
|
|
45
|
-
</Form>
|
|
46
|
-
</Formik>
|
|
47
|
-
</ResourcesContext.Provider>,
|
|
48
|
-
);
|
|
49
|
-
expect(screen.getByTestId('loading-skeleton')).toBeInTheDocument();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should render identifier inputs when identifier types are loaded', () => {
|
|
53
|
-
render(
|
|
54
|
-
<ResourcesContext.Provider value={mockResourcesContextValue}>
|
|
55
|
-
<Formik initialValues={{}} onSubmit={null}>
|
|
56
|
-
<Form>
|
|
57
|
-
<PatientRegistrationContext.Provider
|
|
58
|
-
value={{
|
|
59
|
-
setFieldValue: jest.fn(),
|
|
60
|
-
initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
|
|
61
|
-
setInitialFormValues: jest.fn(),
|
|
62
|
-
values: {
|
|
63
|
-
identifiers: { openmrsID },
|
|
64
|
-
},
|
|
65
|
-
}}>
|
|
66
|
-
<Identifiers />
|
|
67
|
-
</PatientRegistrationContext.Provider>
|
|
68
|
-
</Form>
|
|
69
|
-
</Formik>
|
|
70
|
-
</ResourcesContext.Provider>,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect(screen.getByText('Identifiers')).toBeInTheDocument();
|
|
74
|
-
const configureButton = screen.getByRole('button', { name: 'Configure' });
|
|
75
|
-
expect(configureButton).toBeInTheDocument();
|
|
76
|
-
expect(configureButton).toBeEnabled();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should open identifier selection overlay when "Configure" button is clicked', async () => {
|
|
80
|
-
const user = userEvent.setup();
|
|
81
|
-
|
|
82
|
-
render(
|
|
83
|
-
<ResourcesContext.Provider value={mockResourcesContextValue}>
|
|
84
|
-
<Formik initialValues={{}} onSubmit={null}>
|
|
85
|
-
<Form>
|
|
86
|
-
<PatientRegistrationContext.Provider
|
|
87
|
-
value={{
|
|
88
|
-
setFieldValue: jest.fn(),
|
|
89
|
-
initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
|
|
90
|
-
setInitialFormValues: jest.fn(),
|
|
91
|
-
values: {
|
|
92
|
-
identifiers: { openmrsID },
|
|
93
|
-
},
|
|
94
|
-
}}>
|
|
95
|
-
<Identifiers />
|
|
96
|
-
</PatientRegistrationContext.Provider>
|
|
97
|
-
</Form>
|
|
98
|
-
</Formik>
|
|
99
|
-
</ResourcesContext.Provider>,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const configureButton = screen.getByRole('button', { name: 'Configure' });
|
|
103
|
-
await user.click(configureButton);
|
|
104
|
-
|
|
105
|
-
expect(screen.getByRole('button', { name: 'Close overlay' })).toBeInTheDocument();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { Layer, Select, SelectItem } from '@carbon/react';
|
|
4
|
-
import { useConfig } from '@openmrs/esm-framework';
|
|
5
|
-
import { Input } from '../../input/basic-input/input/input.component';
|
|
6
|
-
import { type CodedPersonAttributeConfig } from '../../patient-registration.types';
|
|
7
|
-
import { useConceptAnswers } from '../field.resource';
|
|
8
|
-
import { usePersonAttributeType } from './person-attributes.resource';
|
|
9
|
-
import styles from './../field.scss';
|
|
10
|
-
|
|
11
|
-
export interface CodedAttributesFieldProps {}
|
|
12
|
-
|
|
13
|
-
export const CodedAttributesField: React.FC<CodedAttributesFieldProps> = () => {
|
|
14
|
-
const { codedPersonAttributes } = useConfig();
|
|
15
|
-
|
|
16
|
-
return codedPersonAttributes?.length ? (
|
|
17
|
-
<div>
|
|
18
|
-
{codedPersonAttributes.map((personAttributeType: CodedPersonAttributeConfig, ind) => (
|
|
19
|
-
<PersonAttributeField
|
|
20
|
-
key={ind}
|
|
21
|
-
personAttributeTypeUuid={personAttributeType.personAttributeUuid}
|
|
22
|
-
conceptUuid={personAttributeType.conceptUuid}
|
|
23
|
-
/>
|
|
24
|
-
))}
|
|
25
|
-
</div>
|
|
26
|
-
) : null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
interface PersonAttributeFieldProps {
|
|
30
|
-
personAttributeTypeUuid: string;
|
|
31
|
-
conceptUuid: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const PersonAttributeField: React.FC<PersonAttributeFieldProps> = ({ personAttributeTypeUuid, conceptUuid }) => {
|
|
35
|
-
const { data: personAttributeType, isLoading } = usePersonAttributeType(personAttributeTypeUuid);
|
|
36
|
-
const { data: conceptAnswers, isLoading: isLoadingConceptAnswers } = useConceptAnswers(conceptUuid);
|
|
37
|
-
|
|
38
|
-
return !isLoading ? (
|
|
39
|
-
<div className={classNames(styles.attributeField, styles.halfWidthInDesktopView)}>
|
|
40
|
-
{!isLoadingConceptAnswers && conceptAnswers?.length ? (
|
|
41
|
-
<Layer>
|
|
42
|
-
<Select
|
|
43
|
-
id={`person-attribute-${personAttributeTypeUuid}`}
|
|
44
|
-
name={`attributes.${personAttributeTypeUuid}`}
|
|
45
|
-
labelText={personAttributeType?.display}>
|
|
46
|
-
{conceptAnswers.map((answer) => (
|
|
47
|
-
<SelectItem key={answer.uuid} value={answer.uuid} text={answer.display} />
|
|
48
|
-
))}
|
|
49
|
-
</Select>
|
|
50
|
-
</Layer>
|
|
51
|
-
) : (
|
|
52
|
-
<Input
|
|
53
|
-
id={`person-attribute-${personAttributeTypeUuid}`}
|
|
54
|
-
labelText={personAttributeType?.display}
|
|
55
|
-
name={`attributes.${personAttributeTypeUuid}`}
|
|
56
|
-
/>
|
|
57
|
-
)}
|
|
58
|
-
</div>
|
|
59
|
-
) : null;
|
|
60
|
-
};
|
package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { useConceptAnswers } from '../field.resource';
|
|
4
|
-
import { CodedPersonAttributeField } from './coded-person-attribute-field.component';
|
|
5
|
-
import { Form, Formik } from 'formik';
|
|
6
|
-
|
|
7
|
-
jest.mock('formik', () => ({
|
|
8
|
-
...jest.requireActual('formik'),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
jest.mock('../field.resource'); // Mock the useConceptAnswers hook
|
|
12
|
-
|
|
13
|
-
const mockedUseConceptAnswers = useConceptAnswers as jest.Mock;
|
|
14
|
-
|
|
15
|
-
describe('CodedPersonAttributeField', () => {
|
|
16
|
-
const conceptAnswers = [
|
|
17
|
-
{ uuid: '1', display: 'Option 1' },
|
|
18
|
-
{ uuid: '2', display: 'Option 2' },
|
|
19
|
-
];
|
|
20
|
-
const personAttributeType = {
|
|
21
|
-
format: 'org.openmrs.Concept',
|
|
22
|
-
display: 'Referred by',
|
|
23
|
-
uuid: '4dd56a75-14ab-4148-8700-1f4f704dc5b0',
|
|
24
|
-
name: '',
|
|
25
|
-
description: '',
|
|
26
|
-
};
|
|
27
|
-
const answerConceptSetUuid = '6682d17f-0777-45e4-a39b-93f77eb3531c';
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
mockedUseConceptAnswers.mockReturnValue({
|
|
32
|
-
data: conceptAnswers,
|
|
33
|
-
isLoading: false,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('shows error if there is no concept answer set provided', () => {
|
|
38
|
-
expect(() => {
|
|
39
|
-
render(
|
|
40
|
-
<Formik initialValues={{}} onSubmit={() => {}}>
|
|
41
|
-
<Form>
|
|
42
|
-
<CodedPersonAttributeField
|
|
43
|
-
id="attributeId"
|
|
44
|
-
personAttributeType={personAttributeType}
|
|
45
|
-
answerConceptSetUuid={null}
|
|
46
|
-
label={personAttributeType.display}
|
|
47
|
-
customConceptAnswers={[]}
|
|
48
|
-
/>
|
|
49
|
-
</Form>
|
|
50
|
-
</Formik>,
|
|
51
|
-
);
|
|
52
|
-
}).toThrow(expect.stringMatching(/has been defined without an answer concept set UUID/i));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('shows error if the concept answer set does not have any concept answers', () => {
|
|
56
|
-
mockedUseConceptAnswers.mockReturnValue({
|
|
57
|
-
data: [],
|
|
58
|
-
isLoading: false,
|
|
59
|
-
});
|
|
60
|
-
expect(() => {
|
|
61
|
-
render(
|
|
62
|
-
<Formik initialValues={{}} onSubmit={() => {}}>
|
|
63
|
-
<Form>
|
|
64
|
-
<CodedPersonAttributeField
|
|
65
|
-
id="attributeId"
|
|
66
|
-
personAttributeType={personAttributeType}
|
|
67
|
-
answerConceptSetUuid={answerConceptSetUuid}
|
|
68
|
-
label={personAttributeType.display}
|
|
69
|
-
customConceptAnswers={[]}
|
|
70
|
-
/>
|
|
71
|
-
</Form>
|
|
72
|
-
</Formik>,
|
|
73
|
-
);
|
|
74
|
-
}).toThrow(expect.stringMatching(/does not have any concept answers/i));
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('renders the conceptAnswers as select options', () => {
|
|
78
|
-
render(
|
|
79
|
-
<Formik initialValues={{}} onSubmit={() => {}}>
|
|
80
|
-
<Form>
|
|
81
|
-
<CodedPersonAttributeField
|
|
82
|
-
id="attributeId"
|
|
83
|
-
personAttributeType={personAttributeType}
|
|
84
|
-
answerConceptSetUuid={answerConceptSetUuid}
|
|
85
|
-
label={personAttributeType.display}
|
|
86
|
-
customConceptAnswers={[]}
|
|
87
|
-
/>
|
|
88
|
-
</Form>
|
|
89
|
-
</Formik>,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(screen.getByLabelText(/Referred by/i)).toBeInTheDocument();
|
|
93
|
-
expect(screen.getByText(/Option 1/i)).toBeInTheDocument();
|
|
94
|
-
expect(screen.getByText(/Option 2/i)).toBeInTheDocument();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('renders customConceptAnswers as select options when they are provided', () => {
|
|
98
|
-
render(
|
|
99
|
-
<Formik initialValues={{}} onSubmit={() => {}}>
|
|
100
|
-
<Form>
|
|
101
|
-
<CodedPersonAttributeField
|
|
102
|
-
id="attributeId"
|
|
103
|
-
personAttributeType={personAttributeType}
|
|
104
|
-
answerConceptSetUuid={answerConceptSetUuid}
|
|
105
|
-
label={personAttributeType.display}
|
|
106
|
-
customConceptAnswers={[
|
|
107
|
-
{
|
|
108
|
-
uuid: 'A',
|
|
109
|
-
label: 'Special Option A',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
uuid: 'B',
|
|
113
|
-
label: 'Special Option B',
|
|
114
|
-
},
|
|
115
|
-
]}
|
|
116
|
-
/>
|
|
117
|
-
</Form>
|
|
118
|
-
</Formik>,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
expect(screen.getByLabelText(/Referred by/i)).toBeInTheDocument();
|
|
122
|
-
expect(screen.getByText(/Special Option A/i)).toBeInTheDocument();
|
|
123
|
-
expect(screen.getByText(/Special Option B/i)).toBeInTheDocument();
|
|
124
|
-
expect(screen.queryByText(/Option 1/i)).not.toBeInTheDocument();
|
|
125
|
-
expect(screen.queryByText(/Option 2/i)).not.toBeInTheDocument();
|
|
126
|
-
});
|
|
127
|
-
});
|