@openmrs/esm-form-engine-lib 2.1.0-pre.1362
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/.editorconfig +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc +58 -0
- package/.husky/pre-commit +6 -0
- package/.husky/pre-push +6 -0
- package/.prettierignore +4 -0
- package/LICENSE.txt +401 -0
- package/README.md +136 -0
- package/__mocks__/concepts.mock.json +140 -0
- package/__mocks__/forms/afe-forms/component_art.json +38 -0
- package/__mocks__/forms/afe-forms/component_preclinic-review.json +38 -0
- package/__mocks__/forms/afe-forms/demo_hts-form.json +62 -0
- package/__mocks__/forms/afe-forms/form-component.json +38 -0
- package/__mocks__/forms/afe-forms/mini-form.json +31 -0
- package/__mocks__/forms/afe-forms/nested-form1.json +38 -0
- package/__mocks__/forms/afe-forms/nested-form2.json +38 -0
- package/__mocks__/forms/afe-forms/test-orders.json +72 -0
- package/__mocks__/forms/afe-forms/test-schema-transformer-form.json +88 -0
- package/__mocks__/forms/rfe-forms/age-validation-form.json +58 -0
- package/__mocks__/forms/rfe-forms/bmi-test-form.json +69 -0
- package/__mocks__/forms/rfe-forms/bsa-test-form.json +69 -0
- package/__mocks__/forms/rfe-forms/component_art.json +1705 -0
- package/__mocks__/forms/rfe-forms/component_preclinic-review.json +480 -0
- package/__mocks__/forms/rfe-forms/conditional-answered-form.json +97 -0
- package/__mocks__/forms/rfe-forms/conditional-required-form.json +281 -0
- package/__mocks__/forms/rfe-forms/demo_hts-form.json +346 -0
- package/__mocks__/forms/rfe-forms/edd-test-form.json +88 -0
- package/__mocks__/forms/rfe-forms/external_data_source_form.json +43 -0
- package/__mocks__/forms/rfe-forms/filter-answer-options-test-form.json +87 -0
- package/__mocks__/forms/rfe-forms/form-component.json +43 -0
- package/__mocks__/forms/rfe-forms/forms-loader.test.schema.ts +209 -0
- package/__mocks__/forms/rfe-forms/historical-expressions-form.json +170 -0
- package/__mocks__/forms/rfe-forms/labour_and_delivery_test_form.json +374 -0
- package/__mocks__/forms/rfe-forms/mini-form.json +29 -0
- package/__mocks__/forms/rfe-forms/mockHistoricalvisitsEncounter.json +89 -0
- package/__mocks__/forms/rfe-forms/months-on-art-form.json +90 -0
- package/__mocks__/forms/rfe-forms/multi-select-form.json +86 -0
- package/__mocks__/forms/rfe-forms/nested-form1.json +43 -0
- package/__mocks__/forms/rfe-forms/nested-form2.json +43 -0
- package/__mocks__/forms/rfe-forms/next-visit-test-form.json +78 -0
- package/__mocks__/forms/rfe-forms/obs-group-test_form.json +137 -0
- package/__mocks__/forms/rfe-forms/obs-list-data.ts +37 -0
- package/__mocks__/forms/rfe-forms/post-submission-test-form.json +116 -0
- package/__mocks__/forms/rfe-forms/reference-by-mapping-form.json +54 -0
- package/__mocks__/forms/rfe-forms/required-form.json +50 -0
- package/__mocks__/forms/rfe-forms/sample_fields.json +36 -0
- package/__mocks__/forms/rfe-forms/test-enrolment-form.json +241 -0
- package/__mocks__/forms/rfe-forms/treatment-end-date-test-form.json +121 -0
- package/__mocks__/forms/rfe-forms/viral-load-status-form.json +75 -0
- package/__mocks__/forms/rfe-forms/zscore-bmi-for-age-form.json +79 -0
- package/__mocks__/forms/rfe-forms/zscore-height-for-age-form.json +79 -0
- package/__mocks__/forms/rfe-forms/zscore-weight-height-form.json +77 -0
- package/__mocks__/packages/hiv/forms/hts_poc/1.0.json +8 -0
- package/__mocks__/packages/hiv/forms/hts_poc/1.1.json +91 -0
- package/__mocks__/packages/test-forms-registry.ts +12 -0
- package/__mocks__/patient.mock.ts +173 -0
- package/__mocks__/react-i18next.js +49 -0
- package/__mocks__/react-markdown.tsx +5 -0
- package/__mocks__/session.mock.ts +117 -0
- package/__mocks__/single-spa-react.js +11 -0
- package/__mocks__/use-initial-values/encounter.mock.json +963 -0
- package/__mocks__/use-initial-values/patient.mock.json +73 -0
- package/__mocks__/visit.mock.ts +19 -0
- package/dist/openmrs-esm-form-engine-lib.js +1 -0
- package/jest.config.js +30 -0
- package/package.json +104 -0
- package/prettier.config.js +8 -0
- package/readme/form-engine.jpeg +0 -0
- package/src/adapters/control-adapter.ts +29 -0
- package/src/adapters/encounter-datetime-adapter.ts +38 -0
- package/src/adapters/encounter-location-adapter.ts +39 -0
- package/src/adapters/encounter-provider-adapter.ts +48 -0
- package/src/adapters/encounter-role-adapter.ts +54 -0
- package/src/adapters/inline-date-adapter.ts +58 -0
- package/src/adapters/obs-adapter.ts +280 -0
- package/src/adapters/obs-comment-adapter.ts +60 -0
- package/src/adapters/orders-adapter.ts +75 -0
- package/src/adapters/patient-identifier-adapter.ts +40 -0
- package/src/adapters/program-state-adapter.ts +52 -0
- package/src/api/index.ts +178 -0
- package/src/components/error/error-modal.component.tsx +37 -0
- package/src/components/error/error.scss +4 -0
- package/src/components/extension/extension-parcel.component.tsx +32 -0
- package/src/components/field-label/field-label.component.tsx +32 -0
- package/src/components/field-label/field-label.scss +11 -0
- package/src/components/group/obs-group.component.tsx +29 -0
- package/src/components/group/obs-group.scss +12 -0
- package/src/components/inputs/content-switcher/content-switcher.component.tsx +71 -0
- package/src/components/inputs/content-switcher/content-switcher.scss +55 -0
- package/src/components/inputs/date/date.component.tsx +149 -0
- package/src/components/inputs/date/date.scss +36 -0
- package/src/components/inputs/file/camera/camera.component.tsx +34 -0
- package/src/components/inputs/file/camera/camera.scss +3 -0
- package/src/components/inputs/file/file.component.tsx +159 -0
- package/src/components/inputs/file/file.scss +101 -0
- package/src/components/inputs/fixed-value/fixed-value.component.tsx +19 -0
- package/src/components/inputs/markdown/markdown-wrapper.component.tsx +14 -0
- package/src/components/inputs/markdown/markdown.component.tsx +8 -0
- package/src/components/inputs/multi-select/multi-select.component.tsx +151 -0
- package/src/components/inputs/multi-select/multi-select.scss +25 -0
- package/src/components/inputs/multi-select/multi-select.test.tsx +90 -0
- package/src/components/inputs/number/number.component.tsx +69 -0
- package/src/components/inputs/number/number.scss +15 -0
- package/src/components/inputs/radio/radio.component.tsx +79 -0
- package/src/components/inputs/radio/radio.scss +36 -0
- package/src/components/inputs/select/dropdown.component.tsx +73 -0
- package/src/components/inputs/select/dropdown.scss +11 -0
- package/src/components/inputs/select/dropdown.test.tsx +120 -0
- package/src/components/inputs/text/text.component.tsx +65 -0
- package/src/components/inputs/text/text.scss +15 -0
- package/src/components/inputs/text/text.test.tsx +104 -0
- package/src/components/inputs/text-area/text-area.component.tsx +63 -0
- package/src/components/inputs/text-area/text-area.scss +11 -0
- package/src/components/inputs/toggle/toggle.component.tsx +66 -0
- package/src/components/inputs/toggle/toggle.scss +12 -0
- package/src/components/inputs/tooltip/tooltip.component.tsx +23 -0
- package/src/components/inputs/tooltip/tooltip.scss +8 -0
- package/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx +187 -0
- package/src/components/inputs/ui-select-extended/ui-select-extended.scss +15 -0
- package/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx +211 -0
- package/src/components/inputs/unspecified/unspecified.component.tsx +74 -0
- package/src/components/inputs/unspecified/unspecified.scss +7 -0
- package/src/components/inputs/unspecified/unspecified.test.tsx +95 -0
- package/src/components/inputs/workspace-launcher/workspace-launcher.component.tsx +35 -0
- package/src/components/inputs/workspace-launcher/workspace-launcher.scss +15 -0
- package/src/components/label/label.component.tsx +20 -0
- package/src/components/label/label.scss +11 -0
- package/src/components/loaders/loader.component.tsx +16 -0
- package/src/components/loaders/loader.scss +20 -0
- package/src/components/patient-banner/patient-banner.component.tsx +20 -0
- package/src/components/patient-banner/patient-banner.scss +12 -0
- package/src/components/previous-value-review/previous-value-review.component.tsx +49 -0
- package/src/components/previous-value-review/previous-value-review.scss +36 -0
- package/src/components/processor-factory/form-processor-factory.component.tsx +127 -0
- package/src/components/renderer/custom-hooks-renderer.component.tsx +30 -0
- package/src/components/renderer/field/fieldLogic.ts +214 -0
- package/src/components/renderer/field/form-field-renderer.component.tsx +281 -0
- package/src/components/renderer/field/form-field-renderer.scss +5 -0
- package/src/components/renderer/form/form-renderer.component.tsx +89 -0
- package/src/components/renderer/form/state.ts +54 -0
- package/src/components/renderer/page/page.renderer.component.tsx +50 -0
- package/src/components/renderer/page/page.renderer.scss +36 -0
- package/src/components/renderer/section/section-renderer.component.tsx +21 -0
- package/src/components/renderer/section/section-renderer.scss +19 -0
- package/src/components/repeat/helpers.test.ts +29 -0
- package/src/components/repeat/helpers.ts +68 -0
- package/src/components/repeat/repeat-controls.component.tsx +38 -0
- package/src/components/repeat/repeat-controls.scss +7 -0
- package/src/components/repeat/repeat.component.tsx +201 -0
- package/src/components/repeat/repeat.scss +30 -0
- package/src/components/repeat/repeat.test.ts +29 -0
- package/src/components/sidebar/sidebar.component.tsx +134 -0
- package/src/components/sidebar/sidebar.scss +121 -0
- package/src/components/value/value.component.tsx +27 -0
- package/src/components/value/value.scss +17 -0
- package/src/components/value/view/field-value-view.component.tsx +33 -0
- package/src/components/value/view/field-value-view.scss +31 -0
- package/src/constants.ts +12 -0
- package/src/datasources/concept-data-source.ts +42 -0
- package/src/datasources/data-source.ts +23 -0
- package/src/datasources/encounter-role-datasource.ts +15 -0
- package/src/datasources/historical-data-source.ts +11 -0
- package/src/datasources/location-data-source.ts +27 -0
- package/src/datasources/provider-datasource.ts +15 -0
- package/src/datasources/select-concept-answers-datasource.ts +15 -0
- package/src/declarations.d.ts +4 -0
- package/src/external-function-context.tsx +8 -0
- package/src/form-context.tsx +42 -0
- package/src/form-engine.component.tsx +178 -0
- package/src/form-engine.scss +140 -0
- package/src/form-engine.test.tsx +817 -0
- package/src/globals.ts +1 -0
- package/src/hooks/useClobData.tsx +21 -0
- package/src/hooks/useConcepts.tsx +55 -0
- package/src/hooks/useDatasourceDependentValue.ts +16 -0
- package/src/hooks/useEncounter.tsx +32 -0
- package/src/hooks/useEncounterRole.tsx +15 -0
- package/src/hooks/useEvaluateFormFieldExpressions.ts +138 -0
- package/src/hooks/useFieldValidationResults.ts +18 -0
- package/src/hooks/useFormCollapse.tsx +36 -0
- package/src/hooks/useFormFieldValidators.ts +22 -0
- package/src/hooks/useFormFieldValueAdapters.ts +24 -0
- package/src/hooks/useFormFields.ts +37 -0
- package/src/hooks/useFormFieldsMeta.ts +48 -0
- package/src/hooks/useFormJson.test.tsx +173 -0
- package/src/hooks/useFormJson.tsx +237 -0
- package/src/hooks/useFormStateHelpers.ts +50 -0
- package/src/hooks/useFormsConfig.tsx +27 -0
- package/src/hooks/useInitialValues.ts +38 -0
- package/src/hooks/usePatientData.tsx +32 -0
- package/src/hooks/usePatientPrograms.ts +32 -0
- package/src/hooks/usePostSubmissionActions.test.tsx +42 -0
- package/src/hooks/usePostSubmissionActions.ts +31 -0
- package/src/hooks/useProcessorDependencies.ts +30 -0
- package/src/hooks/useRestMaxResultsCount.ts +5 -0
- package/src/hooks/useSystemSetting.ts +36 -0
- package/src/hooks/useWorkspaceLayout.ts +29 -0
- package/src/index.ts +12 -0
- package/src/lifecycle.ts +33 -0
- package/src/post-submission-actions/program-enrollment-action.ts +138 -0
- package/src/processors/encounter/encounter-form-processor.ts +337 -0
- package/src/processors/encounter/encounter-processor-helper.ts +320 -0
- package/src/processors/form-processor.ts +41 -0
- package/src/provider/form-factory-helper.ts +100 -0
- package/src/provider/form-factory-provider.tsx +169 -0
- package/src/provider/form-provider.tsx +37 -0
- package/src/registry/inbuilt-components/InbuiltPostSubmissionActions.ts +9 -0
- package/src/registry/inbuilt-components/control-templates.ts +57 -0
- package/src/registry/inbuilt-components/inbuiltControls.ts +99 -0
- package/src/registry/inbuilt-components/inbuiltDataSources.ts +41 -0
- package/src/registry/inbuilt-components/inbuiltFieldValueAdapters.ts +64 -0
- package/src/registry/inbuilt-components/inbuiltTransformers.ts +10 -0
- package/src/registry/inbuilt-components/inbuiltValidators.ts +33 -0
- package/src/registry/inbuilt-components/template-component-map.ts +28 -0
- package/src/registry/registry.test.ts +20 -0
- package/src/registry/registry.ts +261 -0
- package/src/routes.json +1 -0
- package/src/setupI18n.ts +16 -0
- package/src/setupTests.ts +5 -0
- package/src/transformers/default-schema-transformer.test.ts +155 -0
- package/src/transformers/default-schema-transformer.ts +239 -0
- package/src/types/domain.ts +129 -0
- package/src/types/index.ts +130 -0
- package/src/types/schema.ts +238 -0
- package/src/typings.d.ts +9 -0
- package/src/utils/boolean-utils.ts +25 -0
- package/src/utils/common-expression-helpers.ts +503 -0
- package/src/utils/common-utils.test.ts +136 -0
- package/src/utils/common-utils.ts +55 -0
- package/src/utils/error-utils.ts +37 -0
- package/src/utils/expression-parser.test.ts +308 -0
- package/src/utils/expression-parser.ts +158 -0
- package/src/utils/expression-runner.test.ts +387 -0
- package/src/utils/expression-runner.ts +219 -0
- package/src/utils/form-helper.test.ts +482 -0
- package/src/utils/form-helper.ts +210 -0
- package/src/utils/form-page-utils.ts +13 -0
- package/src/utils/forms-loader.test.ts +323 -0
- package/src/utils/forms-loader.ts +306 -0
- package/src/utils/post-submission-action-helper.ts +71 -0
- package/src/utils/test-utils.ts +54 -0
- package/src/utils/zscore-service.ts +59 -0
- package/src/validators/conditional-answered-validator.test.ts +61 -0
- package/src/validators/conditional-answered-validator.ts +17 -0
- package/src/validators/date-validator.test.ts +46 -0
- package/src/validators/date-validator.ts +19 -0
- package/src/validators/default-value-validator.test.ts +90 -0
- package/src/validators/default-value-validator.ts +36 -0
- package/src/validators/form-validator.test.ts +188 -0
- package/src/validators/form-validator.ts +95 -0
- package/src/validators/js-expression-validator.test.ts +118 -0
- package/src/validators/js-expression-validator.ts +44 -0
- package/src/validators/schema.ts +34 -0
- package/src/zscore/bfa_boys_5_above.json +2522 -0
- package/src/zscore/bfa_girls_5_above.json +2522 -0
- package/src/zscore/hfa_boys_5_above.json +2186 -0
- package/src/zscore/hfa_boys_below5.json +22286 -0
- package/src/zscore/hfa_girls_5_above.json +2186 -0
- package/src/zscore/hfa_girls_below5.json +22286 -0
- package/src/zscore/wfl_boys_below5.json +7814 -0
- package/src/zscore/wfl_girls_below5.json +7814 -0
- package/src/zscore-tests/bmi-age.test.tsx +88 -0
- package/src/zscore-tests/height-age.test.tsx +96 -0
- package/src/zscore-tests/weight-height.test.tsx +87 -0
- package/tools/i18next-parser.config.js +93 -0
- package/translations/en.json +47 -0
- package/translations/es.json +38 -0
- package/translations/fr.json +38 -0
- package/translations/km.json +38 -0
- package/tsconfig.json +19 -0
- package/turbo.json +15 -0
- package/webpack.config.js +1 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
import { DefaultFormSchemaTransformer } from './default-schema-transformer';
|
2
|
+
import testForm from '__mocks__/forms/afe-forms/test-schema-transformer-form.json';
|
3
|
+
|
4
|
+
const expectedTransformedSchema = {
|
5
|
+
name: 'AFE form with aliased questions',
|
6
|
+
readonly: false,
|
7
|
+
pages: [
|
8
|
+
{
|
9
|
+
label: 'Page 1',
|
10
|
+
readonly: false,
|
11
|
+
sections: [
|
12
|
+
{
|
13
|
+
label: 'Section 1',
|
14
|
+
isExpanded: true,
|
15
|
+
questions: [
|
16
|
+
{
|
17
|
+
label: 'Multi Checkbox',
|
18
|
+
type: 'obs',
|
19
|
+
required: true,
|
20
|
+
id: 'dem_multi_checkbox',
|
21
|
+
questionOptions: {
|
22
|
+
rendering: 'checkbox',
|
23
|
+
},
|
24
|
+
validators: [
|
25
|
+
{
|
26
|
+
type: 'form_field',
|
27
|
+
},
|
28
|
+
{
|
29
|
+
type: 'default_value',
|
30
|
+
},
|
31
|
+
],
|
32
|
+
meta: {
|
33
|
+
submission: null,
|
34
|
+
},
|
35
|
+
},
|
36
|
+
{
|
37
|
+
label: 'Numeric',
|
38
|
+
id: 'dem_numeric',
|
39
|
+
type: 'obs',
|
40
|
+
required: false,
|
41
|
+
questionOptions: {
|
42
|
+
rendering: 'number',
|
43
|
+
},
|
44
|
+
validators: [
|
45
|
+
{
|
46
|
+
type: 'form_field',
|
47
|
+
},
|
48
|
+
{
|
49
|
+
type: 'default_value',
|
50
|
+
},
|
51
|
+
],
|
52
|
+
meta: {
|
53
|
+
submission: null,
|
54
|
+
},
|
55
|
+
},
|
56
|
+
{
|
57
|
+
label: 'Encounter Provider',
|
58
|
+
id: 'dem_encounter_provider',
|
59
|
+
type: 'encounterProvider',
|
60
|
+
required: false,
|
61
|
+
questionOptions: {
|
62
|
+
rendering: 'encounter-provider',
|
63
|
+
},
|
64
|
+
validators: [
|
65
|
+
{
|
66
|
+
type: 'form_field',
|
67
|
+
},
|
68
|
+
{
|
69
|
+
type: 'default_value',
|
70
|
+
},
|
71
|
+
],
|
72
|
+
meta: {
|
73
|
+
submission: null,
|
74
|
+
},
|
75
|
+
},
|
76
|
+
{
|
77
|
+
id: 'dem_encounter_location',
|
78
|
+
type: 'obsGroup',
|
79
|
+
required: false,
|
80
|
+
questionOptions: {
|
81
|
+
rendering: 'group',
|
82
|
+
},
|
83
|
+
questions: [
|
84
|
+
{
|
85
|
+
label: 'Encounter Location',
|
86
|
+
type: 'encounterLocation',
|
87
|
+
required: false,
|
88
|
+
questionOptions: {
|
89
|
+
rendering: 'encounter-location',
|
90
|
+
},
|
91
|
+
validators: [
|
92
|
+
{
|
93
|
+
type: 'form_field',
|
94
|
+
},
|
95
|
+
{
|
96
|
+
type: 'default_value',
|
97
|
+
},
|
98
|
+
],
|
99
|
+
meta: {
|
100
|
+
submission: null,
|
101
|
+
},
|
102
|
+
},
|
103
|
+
],
|
104
|
+
meta: {
|
105
|
+
submission: null,
|
106
|
+
},
|
107
|
+
},
|
108
|
+
{
|
109
|
+
id: 'labOrder',
|
110
|
+
type: 'testOrder',
|
111
|
+
label: 'Add Lab Order',
|
112
|
+
required: true,
|
113
|
+
questionOptions: {
|
114
|
+
rendering: 'repeating',
|
115
|
+
concept: 'f1742346-cf43-4a17-8c98-720e3f487fc0',
|
116
|
+
orderType: 'testorder',
|
117
|
+
orderSettingUuid: 'INPATIENT',
|
118
|
+
repeatOptions: {
|
119
|
+
limit: 2,
|
120
|
+
},
|
121
|
+
answers: [
|
122
|
+
{
|
123
|
+
concept: '30e2da8f-34ca-4c93-94c8-d429f22d381c',
|
124
|
+
label: 'Option 1',
|
125
|
+
},
|
126
|
+
{
|
127
|
+
concept: '143264AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
128
|
+
label: 'Option 2',
|
129
|
+
},
|
130
|
+
],
|
131
|
+
},
|
132
|
+
validators: [
|
133
|
+
{
|
134
|
+
type: 'form_field',
|
135
|
+
},
|
136
|
+
{
|
137
|
+
type: 'default_value',
|
138
|
+
},
|
139
|
+
],
|
140
|
+
meta: {
|
141
|
+
submission: null,
|
142
|
+
},
|
143
|
+
},
|
144
|
+
],
|
145
|
+
},
|
146
|
+
],
|
147
|
+
},
|
148
|
+
],
|
149
|
+
};
|
150
|
+
|
151
|
+
describe('Default form schema transformer', () => {
|
152
|
+
it('should transform AFE schema to be compatible with RFE', () => {
|
153
|
+
expect(DefaultFormSchemaTransformer.transform(testForm as any)).toEqual(expectedTransformedSchema);
|
154
|
+
});
|
155
|
+
});
|
@@ -0,0 +1,239 @@
|
|
1
|
+
import { type FormField, type FormSchemaTransformer, type FormSchema } from '../types';
|
2
|
+
import { isTrue } from '../utils/boolean-utils';
|
3
|
+
import { hasRendering } from '../utils/common-utils';
|
4
|
+
|
5
|
+
export const DefaultFormSchemaTransformer: FormSchemaTransformer = {
|
6
|
+
transform: (form: FormSchema) => {
|
7
|
+
parseBooleanTokenIfPresent(form, 'readonly');
|
8
|
+
form.pages.forEach((page) => {
|
9
|
+
parseBooleanTokenIfPresent(page, 'readonly');
|
10
|
+
if (page.sections) {
|
11
|
+
page.sections.forEach((section) => {
|
12
|
+
section.questions = handleQuestionsWithDateOptions(section.questions);
|
13
|
+
section.questions = handleQuestionsWithObsComments(section.questions);
|
14
|
+
parseBooleanTokenIfPresent(section, 'readonly');
|
15
|
+
parseBooleanTokenIfPresent(section, 'isExpanded');
|
16
|
+
section?.questions?.forEach((question, index) => handleQuestion(question, form));
|
17
|
+
});
|
18
|
+
}
|
19
|
+
});
|
20
|
+
if (form.meta?.programs) {
|
21
|
+
handleProgramMetaTags(form);
|
22
|
+
}
|
23
|
+
return form;
|
24
|
+
},
|
25
|
+
};
|
26
|
+
|
27
|
+
function handleQuestion(question: FormField, form: FormSchema) {
|
28
|
+
if (question.type === 'programState') {
|
29
|
+
const formMeta = form.meta ?? {};
|
30
|
+
formMeta.programs = formMeta.programs
|
31
|
+
? { ...formMeta.programs, hasProgramFields: true }
|
32
|
+
: { hasProgramFields: true };
|
33
|
+
form.meta = formMeta;
|
34
|
+
}
|
35
|
+
try {
|
36
|
+
sanitizeQuestion(question);
|
37
|
+
setFieldValidators(question);
|
38
|
+
transformByType(question);
|
39
|
+
transformByRendering(question);
|
40
|
+
if (question?.questions?.length) {
|
41
|
+
question.questions.forEach((question) => handleQuestion(question, form));
|
42
|
+
}
|
43
|
+
} catch (error) {
|
44
|
+
console.error(error);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
function handleQuestionsWithDateOptions(sectionQuestions: Array<FormField>): Array<FormField> {
|
49
|
+
const augmentedQuestions: Array<FormField> = [];
|
50
|
+
|
51
|
+
sectionQuestions?.forEach((question) => {
|
52
|
+
augmentedQuestions.push(question);
|
53
|
+
if (question.type !== 'inlineDate' && isTrue(question.questionOptions?.showDate)) {
|
54
|
+
const inlinedDate: FormField = {
|
55
|
+
id: `${question.id}_inline_date`,
|
56
|
+
label: `Date for ${question.label}`,
|
57
|
+
type: 'inlineDate',
|
58
|
+
questionOptions: {
|
59
|
+
rendering: 'date',
|
60
|
+
isTransient: true,
|
61
|
+
},
|
62
|
+
validators: question.questionOptions.shownDateOptions?.validators,
|
63
|
+
disabled: { disableWhenExpression: `isEmpty(${question.id})` },
|
64
|
+
hide: question.questionOptions.shownDateOptions?.hide || question.hide,
|
65
|
+
meta: {
|
66
|
+
targetField: question.id,
|
67
|
+
previousValue: question.meta?.previousValue?.obsDatetime,
|
68
|
+
},
|
69
|
+
};
|
70
|
+
|
71
|
+
augmentedQuestions.push(inlinedDate);
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
return augmentedQuestions;
|
76
|
+
}
|
77
|
+
|
78
|
+
function sanitizeQuestion(question: FormField) {
|
79
|
+
parseBooleanTokenIfPresent(question, 'readonly');
|
80
|
+
parseBooleanTokenIfPresent(question, 'required');
|
81
|
+
parseBooleanTokenIfPresent(question, 'unspecified');
|
82
|
+
parseBooleanTokenIfPresent(question.questionOptions, 'disallowDecimals');
|
83
|
+
parseBooleanTokenIfPresent(question.questionOptions, 'isSearchable');
|
84
|
+
parseBooleanTokenIfPresent(question.questionOptions, 'isTransient');
|
85
|
+
parseBooleanTokenIfPresent(question.questionOptions, 'enablePreviousValue');
|
86
|
+
parseBooleanTokenIfPresent(question.questionOptions, 'allowMultiple');
|
87
|
+
if (!question.meta) {
|
88
|
+
question.meta = {
|
89
|
+
submission: null,
|
90
|
+
};
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
function parseBooleanTokenIfPresent(node: any, token: any) {
|
95
|
+
if (node && typeof node[token] === 'string') {
|
96
|
+
const trimmed = node[token].trim().toLowerCase();
|
97
|
+
if (trimmed === 'true' || trimmed === 'false') {
|
98
|
+
node[token] = trimmed === 'true';
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
return node;
|
103
|
+
}
|
104
|
+
|
105
|
+
function setFieldValidators(question: FormField) {
|
106
|
+
if (hasRendering(question, 'group')) {
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
question.validators = question.validators || [];
|
110
|
+
if (question.validators.findIndex((v) => v.type === 'form_field') < 0) {
|
111
|
+
question.validators.push({ type: 'form_field' });
|
112
|
+
}
|
113
|
+
if (question.validators.findIndex((v) => v.type === 'default_value') < 0) {
|
114
|
+
question.validators.push({ type: 'default_value' });
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
function transformByType(question: FormField) {
|
119
|
+
switch (question.type) {
|
120
|
+
case 'encounterProvider':
|
121
|
+
question.questionOptions.rendering = 'encounter-provider';
|
122
|
+
break;
|
123
|
+
case 'encounterLocation':
|
124
|
+
question.questionOptions.rendering = 'encounter-location';
|
125
|
+
break;
|
126
|
+
case 'encounterRole':
|
127
|
+
question.questionOptions.rendering = 'encounter-role';
|
128
|
+
break;
|
129
|
+
case 'encounterDatetime':
|
130
|
+
question.questionOptions.rendering = hasRendering(question, 'ui-select-extended')
|
131
|
+
? 'date'
|
132
|
+
: question.questionOptions.rendering;
|
133
|
+
break;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
function transformByRendering(question: FormField) {
|
138
|
+
switch (question.questionOptions.rendering as any) {
|
139
|
+
case 'multiCheckbox':
|
140
|
+
question.questionOptions.rendering = 'checkbox';
|
141
|
+
break;
|
142
|
+
case 'numeric':
|
143
|
+
question.questionOptions.rendering = 'number';
|
144
|
+
break;
|
145
|
+
case 'select-concept-answers':
|
146
|
+
handleSelectConceptAnswers(question);
|
147
|
+
break;
|
148
|
+
case 'repeating':
|
149
|
+
case 'group':
|
150
|
+
handleLabOrders(question);
|
151
|
+
break;
|
152
|
+
case 'date':
|
153
|
+
question.datePickerFormat = question.datePickerFormat ?? 'calendar';
|
154
|
+
break;
|
155
|
+
case 'datetime':
|
156
|
+
question.datePickerFormat = question.datePickerFormat ?? 'both';
|
157
|
+
break;
|
158
|
+
case 'workspace-launcher':
|
159
|
+
question.type = 'control';
|
160
|
+
break;
|
161
|
+
case 'markdown':
|
162
|
+
question.type = 'control';
|
163
|
+
break;
|
164
|
+
}
|
165
|
+
return question;
|
166
|
+
}
|
167
|
+
|
168
|
+
function handleLabOrders(question: FormField) {
|
169
|
+
if (hasRendering(question, 'group') && question.questions?.length) {
|
170
|
+
question.questions.forEach(handleLabOrders);
|
171
|
+
}
|
172
|
+
if (question.type === 'testOrder' && question.questionOptions.selectableOrders?.length) {
|
173
|
+
question.questionOptions.answers = question.questionOptions.selectableOrders || [];
|
174
|
+
delete question.questionOptions.selectableOrders;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
function handleSelectConceptAnswers(question: FormField) {
|
179
|
+
if (!question.questionOptions.datasource?.config) {
|
180
|
+
question.questionOptions.datasource = {
|
181
|
+
name: 'select_concept_answers_datasource',
|
182
|
+
config: {
|
183
|
+
concept: question.questionOptions.concept,
|
184
|
+
},
|
185
|
+
};
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
function handleProgramMetaTags(form: FormSchema) {
|
190
|
+
if (form.meta.programs.isEnrollment || form.meta.programs.discontinuationDateQuestionId) {
|
191
|
+
const config = {
|
192
|
+
programUuid: form.meta.programs.uuid,
|
193
|
+
};
|
194
|
+
|
195
|
+
if (form.meta.programs.isEnrollment) {
|
196
|
+
config['enrollmentDate'] = '';
|
197
|
+
} else {
|
198
|
+
config['completionDate'] = form.meta.programs.discontinuationDateQuestionId;
|
199
|
+
}
|
200
|
+
|
201
|
+
form.postSubmissionActions = [
|
202
|
+
{
|
203
|
+
actionId: 'ProgramEnrollmentSubmissionAction',
|
204
|
+
enabled: 'true',
|
205
|
+
config,
|
206
|
+
},
|
207
|
+
];
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
function handleQuestionsWithObsComments(sectionQuestions: Array<FormField>): Array<FormField> {
|
212
|
+
const augmentedQuestions: Array<FormField> = [];
|
213
|
+
|
214
|
+
sectionQuestions?.forEach((question) => {
|
215
|
+
augmentedQuestions.push(question);
|
216
|
+
if (question.type !== 'obsComment' && isTrue(question.questionOptions?.showComment)) {
|
217
|
+
const obsComment: FormField = {
|
218
|
+
id: `${question.id}_obs_comment`,
|
219
|
+
label: `Comment for ${question.label}`,
|
220
|
+
type: 'obsComment',
|
221
|
+
questionOptions: {
|
222
|
+
rendering: 'text',
|
223
|
+
isTransient: true,
|
224
|
+
},
|
225
|
+
validators: question.questionOptions.shownCommentOptions?.validators,
|
226
|
+
disabled: { disableWhenExpression: `isEmpty(${question.id})` },
|
227
|
+
hide: question.questionOptions.shownCommentOptions?.hide || question.hide,
|
228
|
+
meta: {
|
229
|
+
targetField: question.id,
|
230
|
+
previousValue: question.meta?.previousValue?.comment,
|
231
|
+
},
|
232
|
+
};
|
233
|
+
|
234
|
+
augmentedQuestions.push(obsComment);
|
235
|
+
}
|
236
|
+
});
|
237
|
+
|
238
|
+
return augmentedQuestions;
|
239
|
+
}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
import { type OpenmrsResource } from '@openmrs/esm-framework';
|
2
|
+
|
3
|
+
export interface OpenmrsEncounter {
|
4
|
+
uuid?: string;
|
5
|
+
encounterDatetime?: string | Date;
|
6
|
+
patient?: OpenmrsResource | string;
|
7
|
+
location?: OpenmrsResource | string;
|
8
|
+
encounterType?: OpenmrsResource | string;
|
9
|
+
obs?: Array<OpenmrsObs>;
|
10
|
+
orders?: Array<OpenmrsResource>;
|
11
|
+
voided?: boolean;
|
12
|
+
visit?: OpenmrsResource | string;
|
13
|
+
encounterProviders?: Array<Record<string, any>>;
|
14
|
+
form?: OpenmrsFormResource;
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface OpenmrsObs extends OpenmrsResource {
|
18
|
+
concept: any;
|
19
|
+
obsDatetime: string | Date;
|
20
|
+
obsGroup: OpenmrsObs;
|
21
|
+
groupMembers: Array<OpenmrsObs>;
|
22
|
+
comment: string;
|
23
|
+
location: OpenmrsResource;
|
24
|
+
order: OpenmrsResource;
|
25
|
+
encounter: OpenmrsResource;
|
26
|
+
voided: boolean;
|
27
|
+
value: any;
|
28
|
+
formFieldPath: string;
|
29
|
+
formFieldNamespace: string;
|
30
|
+
status: string;
|
31
|
+
interpretation: string;
|
32
|
+
}
|
33
|
+
|
34
|
+
export interface OpenmrsForm {
|
35
|
+
uuid: string;
|
36
|
+
name: string;
|
37
|
+
encounterType: OpenmrsResource;
|
38
|
+
version: string;
|
39
|
+
description: string;
|
40
|
+
published: boolean;
|
41
|
+
retired: boolean;
|
42
|
+
resources: Array<OpenmrsFormResource>;
|
43
|
+
}
|
44
|
+
|
45
|
+
export interface OpenmrsFormResource extends OpenmrsResource {
|
46
|
+
dataType?: string;
|
47
|
+
valueReference?: string;
|
48
|
+
}
|
49
|
+
|
50
|
+
export interface Attachment {
|
51
|
+
id: string;
|
52
|
+
src: string;
|
53
|
+
title: string;
|
54
|
+
description: string;
|
55
|
+
dateTime: string;
|
56
|
+
bytesMimeType: string;
|
57
|
+
bytesContentFamily: string;
|
58
|
+
}
|
59
|
+
|
60
|
+
export interface AttachmentResponse {
|
61
|
+
bytesContentFamily: string;
|
62
|
+
bytesMimeType: string;
|
63
|
+
comment: string;
|
64
|
+
dateTime: string;
|
65
|
+
uuid: string;
|
66
|
+
}
|
67
|
+
|
68
|
+
export interface Order {
|
69
|
+
concept: string;
|
70
|
+
orderer: string;
|
71
|
+
uuid?: string;
|
72
|
+
formFieldPath?: string;
|
73
|
+
type?: string;
|
74
|
+
action?: string;
|
75
|
+
urgency?: string;
|
76
|
+
dateActivated?: string;
|
77
|
+
careSetting?: string;
|
78
|
+
groupMembers?: Order[];
|
79
|
+
encounter?: string;
|
80
|
+
patient?: string;
|
81
|
+
orderNumber?: string;
|
82
|
+
voided?: boolean;
|
83
|
+
}
|
84
|
+
|
85
|
+
export interface ProgramState {
|
86
|
+
name?: string;
|
87
|
+
startDate?: string;
|
88
|
+
uuid?: string;
|
89
|
+
concept: OpenmrsResource;
|
90
|
+
programWorkflow: OpenmrsResource;
|
91
|
+
}
|
92
|
+
|
93
|
+
export interface ProgramWorkflowState {
|
94
|
+
state: ProgramState;
|
95
|
+
endDate?: string;
|
96
|
+
startDate?: string;
|
97
|
+
}
|
98
|
+
|
99
|
+
export interface PatientProgram extends OpenmrsResource {
|
100
|
+
patient?: OpenmrsResource;
|
101
|
+
program?: OpenmrsResource;
|
102
|
+
dateEnrolled?: string;
|
103
|
+
dateCompleted?: string;
|
104
|
+
location?: OpenmrsResource;
|
105
|
+
states?: Array<ProgramWorkflowState>;
|
106
|
+
}
|
107
|
+
|
108
|
+
export interface PatientProgramPayload {
|
109
|
+
program?: string;
|
110
|
+
uuid?: string;
|
111
|
+
display?: string;
|
112
|
+
patient?: string;
|
113
|
+
dateEnrolled?: string;
|
114
|
+
dateCompleted?: string;
|
115
|
+
location?: string;
|
116
|
+
states?: Array<{
|
117
|
+
state?: string;
|
118
|
+
startDate?: string;
|
119
|
+
endDate?: string;
|
120
|
+
}>;
|
121
|
+
}
|
122
|
+
|
123
|
+
export interface PatientIdentifier {
|
124
|
+
uuid?: string;
|
125
|
+
identifier: string;
|
126
|
+
identifierType?: string;
|
127
|
+
location?: string;
|
128
|
+
preferred?: boolean;
|
129
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import { type LayoutType, type OpenmrsResource } from '@openmrs/esm-framework';
|
2
|
+
import { type FormProcessor } from '../processors/form-processor';
|
3
|
+
import { type FormContextProps } from '../provider/form-provider';
|
4
|
+
import { type FormField, type FormSchema } from './schema';
|
5
|
+
import { type OpenmrsEncounter } from './domain';
|
6
|
+
|
7
|
+
export type SessionMode = 'edit' | 'enter' | 'view' | 'embedded-view';
|
8
|
+
|
9
|
+
export interface FormProcessorContextProps {
|
10
|
+
patient: fhir.Patient;
|
11
|
+
formJson: FormSchema;
|
12
|
+
visit: OpenmrsResource;
|
13
|
+
sessionMode: SessionMode;
|
14
|
+
sessionDate: Date;
|
15
|
+
location: OpenmrsResource;
|
16
|
+
currentProvider: OpenmrsResource;
|
17
|
+
layoutType: LayoutType;
|
18
|
+
domainObjectValue?: OpenmrsResource;
|
19
|
+
previousDomainObjectValue?: OpenmrsResource;
|
20
|
+
processor: FormProcessor;
|
21
|
+
formFields?: FormField[];
|
22
|
+
formFieldAdapters?: Record<string, FormFieldValueAdapter>;
|
23
|
+
formFieldValidators?: Record<string, FormFieldValidator>;
|
24
|
+
customDependencies?: Record<string, any>;
|
25
|
+
}
|
26
|
+
|
27
|
+
export interface ValueAndDisplay {
|
28
|
+
value: any;
|
29
|
+
display: string;
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Interface for adapting form field values between primitive and composite formats.
|
34
|
+
*/
|
35
|
+
export interface FormFieldValueAdapter {
|
36
|
+
/**
|
37
|
+
* Adapts a field value from its primitive form to a composite form for backend submission.
|
38
|
+
*/
|
39
|
+
transformFieldValue: (field: FormField, value: any, context: FormContextProps) => any;
|
40
|
+
/**
|
41
|
+
* Extracts the primitive value of a field from an Openmrs object.
|
42
|
+
* @param field - The form field whose value is to be extracted.
|
43
|
+
* @param sourceObject - The Openmrs object to extract the value from eg. patient, encounter etc.
|
44
|
+
*/
|
45
|
+
getInitialValue: (
|
46
|
+
field: FormField,
|
47
|
+
sourceObject: OpenmrsResource,
|
48
|
+
context: FormProcessorContextProps,
|
49
|
+
) => Promise<any> | any;
|
50
|
+
/**
|
51
|
+
* Very similar to `getInitialValue`, but used to extract "previous" values.
|
52
|
+
*/
|
53
|
+
getPreviousValue: (
|
54
|
+
field: FormField,
|
55
|
+
sourceObject: OpenmrsResource,
|
56
|
+
context: FormProcessorContextProps,
|
57
|
+
) => Promise<ValueAndDisplay> | ValueAndDisplay;
|
58
|
+
/**
|
59
|
+
* Extracts the display value from a composite object.
|
60
|
+
*/
|
61
|
+
getDisplayValue: (field: FormField, value: any) => any;
|
62
|
+
/**
|
63
|
+
* Tears down the adapter.
|
64
|
+
*/
|
65
|
+
tearDown: () => void;
|
66
|
+
}
|
67
|
+
|
68
|
+
export interface DataSource<T> {
|
69
|
+
/**
|
70
|
+
* Fetches arbitrary data from a data source
|
71
|
+
*/
|
72
|
+
fetchData(searchTerm?: string, config?: Record<string, any>, uuid?: string): Promise<Array<T>>;
|
73
|
+
/**
|
74
|
+
* Maps a data source item to an object with a uuid and display property
|
75
|
+
*/
|
76
|
+
toUuidAndDisplay(item: T): OpenmrsResource;
|
77
|
+
}
|
78
|
+
|
79
|
+
export interface ControlTemplate {
|
80
|
+
name: string;
|
81
|
+
datasource: DataSourceParameters;
|
82
|
+
}
|
83
|
+
|
84
|
+
export interface DataSourceParameters {
|
85
|
+
name: string;
|
86
|
+
config?: Record<string, any>;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* A form schema transformer is used to bridge the gap caused by different variations of form schemas
|
91
|
+
* in the OpenMRS JSON schema-based form-entry world. It fine-tunes custom schemas to be compliant
|
92
|
+
* with the React Form Engine.
|
93
|
+
*/
|
94
|
+
export interface FormSchemaTransformer {
|
95
|
+
/**
|
96
|
+
* Transforms the raw schema to be compatible with the React Form Engine.
|
97
|
+
*/
|
98
|
+
transform: (form: FormSchema) => FormSchema;
|
99
|
+
}
|
100
|
+
|
101
|
+
export interface PostSubmissionAction {
|
102
|
+
applyAction(
|
103
|
+
formSession: {
|
104
|
+
patient: fhir.Patient;
|
105
|
+
encounters: Array<OpenmrsEncounter>;
|
106
|
+
sessionMode: SessionMode;
|
107
|
+
},
|
108
|
+
config?: Record<string, any>,
|
109
|
+
enabled?: string,
|
110
|
+
): void;
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Field validator
|
115
|
+
*/
|
116
|
+
export interface FormFieldValidator {
|
117
|
+
/**
|
118
|
+
* Validates a field and returns validation errors
|
119
|
+
*/
|
120
|
+
validate(field: FormField, value?: any, config?: any): Array<ValidationResult>;
|
121
|
+
}
|
122
|
+
|
123
|
+
export interface ValidationResult {
|
124
|
+
resultType: 'warning' | 'error';
|
125
|
+
errCode?: string;
|
126
|
+
message: string;
|
127
|
+
}
|
128
|
+
|
129
|
+
export * from './schema';
|
130
|
+
export * from './domain';
|