-
Notifications
You must be signed in to change notification settings - Fork 197
/
config-schema.ts
409 lines (402 loc) · 13.3 KB
/
config-schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import { Type, validator, validators } from '@openmrs/esm-framework';
export interface SectionDefinition {
id: string;
name?: string;
fields: Array<string>;
}
export interface FieldDefinition {
id: string;
type: string;
label?: string;
uuid: string;
placeholder?: string;
showHeading: boolean;
validation?: {
required: boolean;
matches?: string;
};
answerConceptSetUuid?: string;
customConceptAnswers?: Array<CustomConceptAnswer>;
}
export interface CustomConceptAnswer {
uuid: string;
label?: string;
}
export interface Gender {
label?: string;
value: string;
}
export interface RegistrationConfig {
sections: Array<string>;
sectionDefinitions: Array<SectionDefinition>;
fieldDefinitions: Array<FieldDefinition>;
fieldConfigurations: {
name: {
displayMiddleName: boolean;
allowUnidentifiedPatients: boolean;
defaultUnknownGivenName: string;
defaultUnknownFamilyName: string;
displayCapturePhoto: boolean;
displayReverseFieldOrder: boolean;
};
gender: Array<Gender>;
address: {
useAddressHierarchy: {
enabled: boolean;
useQuickSearch: boolean;
searchAddressByLevel: boolean;
};
};
dateOfBirth: {
allowEstimatedDateOfBirth: boolean;
useEstimatedDateOfBirth: {
enabled: boolean;
dayOfMonth: number;
month: number;
};
};
phone: {
personAttributeUuid: string;
};
};
links: {
submitButton: string;
};
concepts: {
patientPhotoUuid: string;
};
defaultPatientIdentifierTypes: Array<string>;
registrationObs: {
encounterTypeUuid: string | null;
encounterProviderRoleUuid: string;
registrationFormUuid: string | null;
};
}
export const builtInSections: Array<SectionDefinition> = [
{
id: 'demographics',
name: 'Basic Info',
fields: ['name', 'gender', 'dob', 'id'],
},
{ id: 'contact', name: 'Contact Details', fields: ['address', 'phone'] },
{ id: 'death', name: 'Death Info', fields: [] },
{ id: 'relationships', name: 'Relationships', fields: [] },
];
// These fields are handled specially in field.component.tsx
export const builtInFields = ['name', 'gender', 'dob', 'id', 'address', 'phone'] as const;
export const esmPatientRegistrationSchema = {
sections: {
_type: Type.Array,
_default: ['demographics', 'contact', 'relationships'],
_description: `An array of strings which are the keys from 'sectionDefinitions' or any of the following built-in sections: '${builtInSections
.map((s) => s.id)
.join("', '")}'.`,
_elements: {
_type: Type.String,
},
},
sectionDefinitions: {
_type: Type.Array,
_elements: {
id: {
_type: Type.String,
_description: `How this section will be referred to in the \`sections\` configuration. To override a built-in section, use that section's id. The built in section ids are '${builtInSections
.map((s) => s.id)
.join("', '")}'.`,
},
name: {
_type: Type.String,
_description: 'The title to display at the top of the section.',
},
fields: {
_type: Type.Array,
_default: [],
_description: `The parts to include in the section. Can be any of the following built-in fields: ${builtInFields.join(
', ',
)}. Can also be an id from an object in the \`fieldDefinitions\` array, which you can use to define custom fields.`,
_elements: { _type: Type.String },
},
},
_default: [],
},
fieldDefinitions: {
_type: Type.Array,
_elements: {
id: {
_type: Type.String,
_description:
'How this field will be referred to in the `fields` element of the `sectionDefinitions` configuration.',
},
type: {
_type: Type.String,
_description: "How this field's data will be stored—a person attribute or an obs.",
_validators: [validators.oneOf(['person attribute', 'obs'])],
},
uuid: {
_type: Type.UUID,
_description: "Person attribute type UUID that this field's data should be saved to.",
},
showHeading: {
_type: Type.Boolean,
_description: 'Whether to show a heading above the person attribute field.',
_default: false,
},
label: {
_type: Type.String,
_default: null,
_description: 'The label of the input. By default, uses the metadata `display` attribute.',
},
placeholder: {
_type: Type.String,
_default: '',
_description: 'Placeholder that will appear in the input.',
},
validation: {
required: { _type: Type.Boolean, _default: false },
matches: {
_type: Type.String,
_default: null,
_description: 'Optional RegEx for testing the validity of the input.',
},
},
answerConceptSetUuid: {
_type: Type.ConceptUuid,
_default: null,
_description:
'For coded questions only. A concept which has the possible responses either as answers or as set members.',
},
customConceptAnswers: {
_type: Type.Array,
_elements: {
uuid: {
_type: Type.UUID,
_description: 'Answer concept UUID',
},
label: {
_type: Type.String,
_default: null,
_description: 'The custom label for the answer concept.',
},
},
_default: [],
_description: 'For coded questions only. Provide ability to add custom concept answers.',
},
},
// Do not add fields here. If you want to add a field in code, add it to built-in fields above.
_default: [],
_description:
'Definitions for custom fields that can be used in sectionDefinitions. Can also be used to override built-in fields.',
},
fieldConfigurations: {
name: {
displayMiddleName: { _type: Type.Boolean, _default: true },
allowUnidentifiedPatients: {
_type: Type.Boolean,
_default: true,
_description: 'Whether to allow registering unidentified patients.',
},
defaultUnknownGivenName: {
_type: Type.String,
_default: 'UNKNOWN',
_description: 'The given/first name to record for unidentified patients.',
},
defaultUnknownFamilyName: {
_type: Type.String,
_default: 'UNKNOWN',
_description: 'The family/last name to record for unidentified patients.',
},
displayCapturePhoto: {
_type: Type.Boolean,
_default: true,
_description: 'Whether to display capture patient photo slot on name field',
},
displayReverseFieldOrder: {
_type: Type.Boolean,
_default: false,
_description: "Whether to display the name fields in the order 'Family name' -> 'Middle name' -> 'First name'",
},
},
gender: {
_type: Type.Array,
_elements: {
value: {
_type: Type.String,
_description:
'Value that will be sent to the server. Limited to FHIR-supported values for Administrative Gender',
_validators: [validators.oneOf(['male', 'female', 'other', 'unknown'])],
},
label: {
_type: Type.String,
_default: null,
_description:
'The label displayed for the sex option, if it should be different from the value (the value will be translated; the English "translation" is upper-case).',
},
},
_default: [
{
value: 'male',
},
{
value: 'female',
},
{
value: 'other',
},
{
value: 'unknown',
},
],
_description:
'The options for sex selection during patient registration. This is Administrative Gender as it is called by FHIR (Possible options are limited to those defined in FHIR Administrative Gender, see https://hl7.org/fhir/R4/valueset-administrative-gender.html).',
},
address: {
useAddressHierarchy: {
enabled: {
_type: Type.Boolean,
_description: 'Whether to use the Address hierarchy in the registration form or not',
_default: true,
},
useQuickSearch: {
_type: Type.Boolean,
_description:
'Whether to use the quick searching through the address saved in the database pre-fill the form.',
_default: true,
},
searchAddressByLevel: {
_type: Type.Boolean,
_description:
"Whether to fill the addresses by levels, i.e. County => subCounty, the current field is dependent on it's previous field.",
_default: false,
},
useAddressHierarchyLabel: {
_type: Type.Object,
_description: 'Whether to use custom labels for address hierarchy',
_default: {},
},
},
},
dateOfBirth: {
allowEstimatedDateOfBirth: {
_type: Type.Boolean,
_description: 'Whether to allow estimated date of birth for a patient during registration',
_default: true,
},
useEstimatedDateOfBirth: {
enabled: {
_type: Type.Boolean,
_description: 'Whether to use a fixed day and month for estimated date of birth',
_default: false,
},
dayOfMonth: {
_type: Type.Number,
_description: 'The custom day of the month use on the estimated date of birth',
_default: 0,
},
month: {
_type: Type.Number,
_description: 'The custom month to use on the estimated date of birth i.e 0 = Jan & 11 = Dec',
_default: 0,
},
},
},
phone: {
personAttributeUuid: {
_type: Type.UUID,
_default: '14d4f066-15f5-102d-96e4-000c29c2a5d7',
_description: 'The UUID of the phone number person attribute type',
},
},
},
links: {
submitButton: {
_type: Type.String,
_default: '${openmrsSpaBase}/patient/${patientUuid}/chart',
_validators: [validators.isUrlWithTemplateParameters(['patientUuid'])],
},
},
concepts: {
patientPhotoUuid: {
_type: Type.ConceptUuid,
_default: '736e8771-e501-4615-bfa7-570c03f4bef5',
},
},
defaultPatientIdentifierTypes: {
_type: Type.Array,
_elements: {
_type: Type.PatientIdentifierTypeUuid,
},
_default: [],
},
registrationObs: {
encounterTypeUuid: {
_type: Type.UUID,
_default: null,
_description:
'Obs created during registration will be associated with an encounter of this type. This must be set in order to use fields of type `obs`.',
},
encounterProviderRoleUuid: {
_type: Type.UUID,
_default: 'a0b03050-c99b-11e0-9572-0800200c9a66',
_description: "The provider role to use for the registration encounter. Default is 'Unkown'.",
},
registrationFormUuid: {
_type: Type.UUID,
_default: null,
_description:
'The form UUID to associate with the registration encounter. By default no form will be associated.',
},
},
_validators: [
validator(
(config: RegistrationConfig) =>
!config.fieldDefinitions.some((d) => d.type == 'obs') || config.registrationObs.encounterTypeUuid != null,
"If fieldDefinitions contains any fields of type 'obs', `registrationObs.encounterTypeUuid` must be specified.",
),
validator(
(config: RegistrationConfig) =>
config.sections.every((s) =>
[...builtInSections, ...config.sectionDefinitions].map((sDef) => sDef.id).includes(s),
),
(config: RegistrationConfig) => {
const allowedSections = [...builtInSections, ...config.sectionDefinitions].map((sDef) => sDef.id);
const badSection = config.sections.find((s) => !allowedSections.includes(s));
return (
`'${badSection}' is not a valid section ID. Valid section IDs include the built-in sections ${stringifyDefinitions(
builtInSections,
)}` +
(config.sectionDefinitions.length
? `; and the defined sections ${stringifyDefinitions(config.sectionDefinitions)}.`
: '.')
);
},
),
validator(
(config: RegistrationConfig) =>
config.sectionDefinitions.every((sectionDefinition) =>
sectionDefinition.fields.every((f) =>
[...builtInFields, ...config.fieldDefinitions.map((fDef) => fDef.id)].includes(f),
),
),
(config: RegistrationConfig) => {
const allowedFields = [...builtInFields, ...config.fieldDefinitions.map((fDef) => fDef.id)];
const badSection = config.sectionDefinitions.find((sectionDefinition) =>
sectionDefinition.fields.some((f) => !allowedFields.includes(f)),
);
const badField = badSection.fields.find((f) => !allowedFields.includes(f));
return (
`The section definition '${
badSection.id
}' contains an invalid field '${badField}'. 'fields' can only contain the built-in fields '${builtInFields.join(
"', '",
)}'` +
(config.fieldDefinitions.length
? `; or the defined fields ${stringifyDefinitions(config.fieldDefinitions)}.`
: '.')
);
},
),
],
};
function stringifyDefinitions(sectionDefinitions: Array<SectionDefinition | FieldDefinition>) {
return `'${sectionDefinitions.map((s) => s.id).join("', '")}'`;
}