@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,120 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { act, fireEvent, render, screen } from '@testing-library/react';
|
3
|
+
import { type EncounterContext, FormContext } from '../../../form-context';
|
4
|
+
import Dropdown from './dropdown.component';
|
5
|
+
import { type FormField } from '../../../types';
|
6
|
+
|
7
|
+
const question: FormField = {
|
8
|
+
label: 'Patient past program.',
|
9
|
+
type: 'obs',
|
10
|
+
questionOptions: {
|
11
|
+
rendering: 'select',
|
12
|
+
concept: '1c43b05b-b6d8-4eb5-8f37-0b14f5347568',
|
13
|
+
answers: [
|
14
|
+
{
|
15
|
+
label: 'HIV Care and Treatment',
|
16
|
+
value: '6ddd933a-e65c-4f35-8884-c555b50c55e1',
|
17
|
+
},
|
18
|
+
{
|
19
|
+
label: 'Oncology Screening and Diagnosis Program',
|
20
|
+
value: '12f7be3d-fb5d-47dc-b5e3-56c501be80a6',
|
21
|
+
},
|
22
|
+
{
|
23
|
+
label: 'Fight Malaria Initiative',
|
24
|
+
value: '14cd2628-8a33-4b93-9c10-43989950bba0',
|
25
|
+
},
|
26
|
+
],
|
27
|
+
},
|
28
|
+
meta: {},
|
29
|
+
id: 'patient-past-program',
|
30
|
+
};
|
31
|
+
|
32
|
+
const encounterContext: EncounterContext = {
|
33
|
+
patient: {
|
34
|
+
id: '833db896-c1f0-11eb-8529-0242ac130003',
|
35
|
+
},
|
36
|
+
location: {
|
37
|
+
uuid: '41e6e516-c1f0-11eb-8529-0242ac130003',
|
38
|
+
},
|
39
|
+
encounter: {
|
40
|
+
uuid: '873455da-3ec4-453c-b565-7c1fe35426be',
|
41
|
+
obs: [],
|
42
|
+
},
|
43
|
+
sessionMode: 'enter',
|
44
|
+
encounterDate: new Date(2020, 11, 29),
|
45
|
+
setEncounterDate: (value) => {},
|
46
|
+
encounterProvider: '2c95f6f5-788e-4e73-9079-5626911231fa',
|
47
|
+
setEncounterProvider: jest.fn,
|
48
|
+
setEncounterLocation: jest.fn,
|
49
|
+
encounterRole: '8cb3a399-d18b-4b62-aefb-5a0f948a3809',
|
50
|
+
setEncounterRole: jest.fn,
|
51
|
+
};
|
52
|
+
|
53
|
+
const renderForm = (initialValues) => {
|
54
|
+
render(<></>);
|
55
|
+
};
|
56
|
+
|
57
|
+
describe.skip('dropdown input field', () => {
|
58
|
+
afterEach(() => {
|
59
|
+
// teardown
|
60
|
+
question.meta = {};
|
61
|
+
});
|
62
|
+
|
63
|
+
it('should record new obs', async () => {
|
64
|
+
await renderForm({});
|
65
|
+
// setup
|
66
|
+
const dropdownWidget = screen.getByRole('combobox', { name: /Patient past program./ });
|
67
|
+
|
68
|
+
// assert initial values
|
69
|
+
await act(async () => {
|
70
|
+
expect(question.meta.submission).toBe(undefined);
|
71
|
+
});
|
72
|
+
|
73
|
+
// choose an option
|
74
|
+
fireEvent.click(dropdownWidget);
|
75
|
+
const fightMalariaOption = screen.getByText('Fight Malaria Initiative');
|
76
|
+
fireEvent.click(fightMalariaOption);
|
77
|
+
|
78
|
+
// verify
|
79
|
+
await act(async () => {
|
80
|
+
expect(question.meta.submission.newValue).toEqual({
|
81
|
+
concept: '1c43b05b-b6d8-4eb5-8f37-0b14f5347568',
|
82
|
+
formFieldNamespace: 'rfe-forms',
|
83
|
+
formFieldPath: 'rfe-forms-patient-past-program',
|
84
|
+
value: '14cd2628-8a33-4b93-9c10-43989950bba0',
|
85
|
+
});
|
86
|
+
});
|
87
|
+
});
|
88
|
+
|
89
|
+
it('should edit obs', async () => {
|
90
|
+
// setup
|
91
|
+
question.meta.previousValue = {
|
92
|
+
uuid: '305ed1fc-c1fd-11eb-8529-0242ac130003',
|
93
|
+
person: '833db896-c1f0-11eb-8529-0242ac130003',
|
94
|
+
obsDatetime: encounterContext.encounterDate,
|
95
|
+
concept: '1c43b05b-b6d8-4eb5-8f37-0b14f5347568',
|
96
|
+
location: { uuid: '41e6e516-c1f0-11eb-8529-0242ac130003' },
|
97
|
+
order: null,
|
98
|
+
groupMembers: [],
|
99
|
+
voided: false,
|
100
|
+
value: '6ddd933a-e65c-4f35-8884-c555b50c55e1',
|
101
|
+
};
|
102
|
+
await renderForm({ 'patient-past-program': question.meta.previousValue.value });
|
103
|
+
const dropdownWidget = screen.getByRole('combobox', { name: /Patient past program./ });
|
104
|
+
|
105
|
+
// do some edits
|
106
|
+
fireEvent.click(dropdownWidget);
|
107
|
+
const oncologyScreeningOption = screen.getByText('Oncology Screening and Diagnosis Program');
|
108
|
+
fireEvent.click(oncologyScreeningOption);
|
109
|
+
|
110
|
+
// verify
|
111
|
+
await act(async () => {
|
112
|
+
expect(question.meta.submission.newValue).toEqual({
|
113
|
+
uuid: '305ed1fc-c1fd-11eb-8529-0242ac130003',
|
114
|
+
value: '12f7be3d-fb5d-47dc-b5e3-56c501be80a6',
|
115
|
+
formFieldNamespace: 'rfe-forms',
|
116
|
+
formFieldPath: 'rfe-forms-patient-past-program',
|
117
|
+
});
|
118
|
+
});
|
119
|
+
});
|
120
|
+
});
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
2
|
+
import { useTranslation } from 'react-i18next';
|
3
|
+
import { Layer, TextInput } from '@carbon/react';
|
4
|
+
import styles from './text.scss';
|
5
|
+
import { useFormProviderContext } from '../../../provider/form-provider';
|
6
|
+
import { type FormFieldInputProps } from '../../../types';
|
7
|
+
import { isTrue } from '../../../utils/boolean-utils';
|
8
|
+
import { shouldUseInlineLayout } from '../../../utils/form-helper';
|
9
|
+
import FieldValueView from '../../value/view/field-value-view.component';
|
10
|
+
import FieldLabel from '../../field-label/field-label.component';
|
11
|
+
|
12
|
+
const TextField: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings, setFieldValue }) => {
|
13
|
+
const { t } = useTranslation();
|
14
|
+
const [lastBlurredValue, setLastBlurredValue] = useState(null);
|
15
|
+
const { layoutType, sessionMode, workspaceLayout } = useFormProviderContext();
|
16
|
+
|
17
|
+
const onBlur = (event) => {
|
18
|
+
event.preventDefault();
|
19
|
+
if (lastBlurredValue !== value) {
|
20
|
+
setLastBlurredValue(value);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
const isInline = useMemo(() => {
|
25
|
+
if (['view', 'embedded-view'].includes(sessionMode) || isTrue(field.readonly)) {
|
26
|
+
return shouldUseInlineLayout(field.inlineRendering, layoutType, workspaceLayout, sessionMode);
|
27
|
+
}
|
28
|
+
return false;
|
29
|
+
}, [sessionMode, field.readonly, field.inlineRendering, layoutType, workspaceLayout]);
|
30
|
+
|
31
|
+
return sessionMode == 'view' || sessionMode == 'embedded-view' ? (
|
32
|
+
<FieldValueView
|
33
|
+
label={t(field.label)}
|
34
|
+
value={value}
|
35
|
+
conceptName={field.meta?.concept?.display}
|
36
|
+
isInline={isInline}
|
37
|
+
/>
|
38
|
+
) : (
|
39
|
+
!field.isHidden && (
|
40
|
+
<>
|
41
|
+
<div className={styles.boldedLabel}>
|
42
|
+
<Layer>
|
43
|
+
<TextInput
|
44
|
+
id={field.id}
|
45
|
+
labelText={<FieldLabel field={field} />}
|
46
|
+
onChange={setFieldValue}
|
47
|
+
onBlur={onBlur}
|
48
|
+
name={field.id}
|
49
|
+
value={value}
|
50
|
+
disabled={field.isDisabled}
|
51
|
+
readOnly={isTrue(field.readonly)}
|
52
|
+
invalid={errors.length > 0}
|
53
|
+
invalidText={errors[0]?.message}
|
54
|
+
warn={warnings.length > 0}
|
55
|
+
warnText={warnings.length && warnings[0].message}
|
56
|
+
maxLength={field.questionOptions.max || TextInput.maxLength}
|
57
|
+
/>
|
58
|
+
</Layer>
|
59
|
+
</div>
|
60
|
+
</>
|
61
|
+
)
|
62
|
+
);
|
63
|
+
};
|
64
|
+
|
65
|
+
export default TextField;
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, fireEvent, screen, act } from '@testing-library/react';
|
3
|
+
import { type EncounterContext } from '../../../form-context';
|
4
|
+
import { type FormField } from '../../../types';
|
5
|
+
|
6
|
+
const question: FormField = {
|
7
|
+
label: 'Patient Name',
|
8
|
+
id: 'patient-name',
|
9
|
+
type: 'obs',
|
10
|
+
questionOptions: {
|
11
|
+
rendering: 'text',
|
12
|
+
concept: 'your_concept_uuid_here',
|
13
|
+
},
|
14
|
+
meta: {},
|
15
|
+
};
|
16
|
+
|
17
|
+
const question2: FormField = {
|
18
|
+
label: 'Patient Name',
|
19
|
+
id: 'patient-name',
|
20
|
+
type: 'obs',
|
21
|
+
questionOptions: {
|
22
|
+
rendering: 'text',
|
23
|
+
concept: 'your_concept_uuid_here',
|
24
|
+
},
|
25
|
+
meta: {},
|
26
|
+
};
|
27
|
+
|
28
|
+
const encounterContext: EncounterContext = {
|
29
|
+
patient: {
|
30
|
+
id: '833db896-c1f0-11eb-8529-0242ac130003',
|
31
|
+
},
|
32
|
+
location: {
|
33
|
+
uuid: '41e6e516-c1f0-11eb-8529-0242ac130003',
|
34
|
+
},
|
35
|
+
encounter: {
|
36
|
+
uuid: '873455da-3ec4-453c-b565-7c1fe35426be',
|
37
|
+
obs: [],
|
38
|
+
},
|
39
|
+
sessionMode: 'enter',
|
40
|
+
encounterDate: new Date(2020, 11, 29),
|
41
|
+
setEncounterDate: (value) => {},
|
42
|
+
encounterProvider: '2c95f6f5-788e-4e73-9079-5626911231fa',
|
43
|
+
setEncounterProvider: jest.fn,
|
44
|
+
setEncounterLocation: jest.fn,
|
45
|
+
encounterRole: '8cb3a399-d18b-4b62-aefb-5a0f948a3809',
|
46
|
+
setEncounterRole: jest.fn,
|
47
|
+
};
|
48
|
+
|
49
|
+
const renderForm = (intialValues) => {
|
50
|
+
render(<></>);
|
51
|
+
};
|
52
|
+
|
53
|
+
describe.skip('Text field input', () => {
|
54
|
+
afterEach(() => {
|
55
|
+
question.meta = {};
|
56
|
+
});
|
57
|
+
|
58
|
+
it('should record new obs', async () => {
|
59
|
+
await renderForm({});
|
60
|
+
const inputField = screen.getByLabelText('Patient Name');
|
61
|
+
|
62
|
+
await act(async () => {
|
63
|
+
expect(question.meta.submission).toBe(undefined);
|
64
|
+
});
|
65
|
+
|
66
|
+
fireEvent.change(inputField, { target: { value: 'John Doe' } });
|
67
|
+
fireEvent.blur(inputField);
|
68
|
+
|
69
|
+
await act(async () => {
|
70
|
+
expect(question.meta.submission.newValue).toEqual({
|
71
|
+
concept: 'your_concept_uuid_here',
|
72
|
+
formFieldNamespace: 'rfe-forms',
|
73
|
+
formFieldPath: 'rfe-forms-patient-name',
|
74
|
+
value: 'John Doe',
|
75
|
+
});
|
76
|
+
});
|
77
|
+
});
|
78
|
+
|
79
|
+
it('should edit obs', async () => {
|
80
|
+
question.meta.previousValue = {
|
81
|
+
person: '833db896-c1f0-11eb-8529-0242ac130003',
|
82
|
+
obsDatetime: encounterContext.encounterDate,
|
83
|
+
concept: 'your_concept_uuid_here',
|
84
|
+
location: { uuid: '41e6e516-c1f0-11eb-8529-0242ac130003' },
|
85
|
+
order: null,
|
86
|
+
groupMembers: [],
|
87
|
+
voided: false,
|
88
|
+
value: 'Initial Name',
|
89
|
+
};
|
90
|
+
await renderForm({ 'patient-name': question.meta.previousValue });
|
91
|
+
const inputField = screen.getByLabelText('Patient Name');
|
92
|
+
|
93
|
+
fireEvent.change(inputField, { target: { value: 'Updated Name' } });
|
94
|
+
fireEvent.blur(inputField);
|
95
|
+
|
96
|
+
await act(async () => {
|
97
|
+
expect(question.meta.submission.newValue).toEqual({
|
98
|
+
value: 'Updated Name',
|
99
|
+
formFieldNamespace: 'rfe-forms',
|
100
|
+
formFieldPath: 'rfe-forms-patient-name',
|
101
|
+
});
|
102
|
+
});
|
103
|
+
});
|
104
|
+
});
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
2
|
+
import { useTranslation } from 'react-i18next';
|
3
|
+
import { Layer, TextArea as TextAreaInput } from '@carbon/react';
|
4
|
+
import { shouldUseInlineLayout } from '../../../utils/form-helper';
|
5
|
+
import { isTrue } from '../../../utils/boolean-utils';
|
6
|
+
import { type FormFieldInputProps } from '../../../types';
|
7
|
+
import FieldValueView from '../../value/view/field-value-view.component';
|
8
|
+
import styles from './text-area.scss';
|
9
|
+
import { useFormProviderContext } from '../../../provider/form-provider';
|
10
|
+
import FieldLabel from '../../field-label/field-label.component';
|
11
|
+
|
12
|
+
const TextArea: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings, setFieldValue }) => {
|
13
|
+
const { t } = useTranslation();
|
14
|
+
const [lastBlurredValue, setLastBlurredValue] = useState(value);
|
15
|
+
const { layoutType, sessionMode, workspaceLayout } = useFormProviderContext();
|
16
|
+
|
17
|
+
const onBlur = (event) => {
|
18
|
+
event.preventDefault();
|
19
|
+
if (lastBlurredValue !== value) {
|
20
|
+
setLastBlurredValue(value);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
const isInline = useMemo(() => {
|
25
|
+
if (['view', 'embedded-view'].includes(sessionMode) || isTrue(field.readonly)) {
|
26
|
+
return shouldUseInlineLayout(field.inlineRendering, layoutType, workspaceLayout, sessionMode);
|
27
|
+
}
|
28
|
+
return false;
|
29
|
+
}, [sessionMode, field.readonly, field.inlineRendering, layoutType, workspaceLayout]);
|
30
|
+
|
31
|
+
return sessionMode == 'view' || sessionMode == 'embedded-view' ? (
|
32
|
+
<FieldValueView
|
33
|
+
label={t(field.label)}
|
34
|
+
value={value}
|
35
|
+
conceptName={field.meta?.concept?.display}
|
36
|
+
isInline={isInline}
|
37
|
+
/>
|
38
|
+
) : (
|
39
|
+
!field.isHidden && (
|
40
|
+
<div className={styles.boldedLabel}>
|
41
|
+
<Layer>
|
42
|
+
<TextAreaInput
|
43
|
+
id={field.id}
|
44
|
+
labelText={<FieldLabel field={field} />}
|
45
|
+
name={field.id}
|
46
|
+
onChange={setFieldValue}
|
47
|
+
onBlur={onBlur}
|
48
|
+
value={value || ''}
|
49
|
+
rows={field.questionOptions.rows || 4}
|
50
|
+
disabled={field.isDisabled}
|
51
|
+
readOnly={field.readonly}
|
52
|
+
invalid={errors.length > 0}
|
53
|
+
invalidText={errors[0]?.message}
|
54
|
+
warn={warnings.length > 0}
|
55
|
+
warnText={warnings[0]?.message}
|
56
|
+
/>
|
57
|
+
</Layer>
|
58
|
+
</div>
|
59
|
+
)
|
60
|
+
);
|
61
|
+
};
|
62
|
+
|
63
|
+
export default TextArea;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
2
|
+
import { Toggle as ToggleInput } from '@carbon/react';
|
3
|
+
import { type FormFieldInputProps } from '../../../types';
|
4
|
+
import { isTrue } from '../../../utils/boolean-utils';
|
5
|
+
import { shouldUseInlineLayout } from '../../../utils/form-helper';
|
6
|
+
import FieldValueView from '../../value/view/field-value-view.component';
|
7
|
+
import { isEmpty } from '../../../validators/form-validator';
|
8
|
+
import styles from './toggle.scss';
|
9
|
+
import { useTranslation } from 'react-i18next';
|
10
|
+
import { useFormProviderContext } from '../../../provider/form-provider';
|
11
|
+
|
12
|
+
const Toggle: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings, setFieldValue }) => {
|
13
|
+
const { t } = useTranslation();
|
14
|
+
const context = useFormProviderContext();
|
15
|
+
|
16
|
+
const handleChange = (value) => {
|
17
|
+
setFieldValue(value);
|
18
|
+
};
|
19
|
+
|
20
|
+
useEffect(() => {
|
21
|
+
// The toggle input doesn't support blank values
|
22
|
+
// by default, the value should be false
|
23
|
+
if (!field.meta?.previousValue && context.sessionMode == 'enter') {
|
24
|
+
context.formFieldAdapters[field.type].transformFieldValue(field, value ?? false, context);
|
25
|
+
}
|
26
|
+
}, []);
|
27
|
+
|
28
|
+
const isInline = useMemo(() => {
|
29
|
+
if (['view', 'embedded-view'].includes(context.sessionMode) || isTrue(field.readonly)) {
|
30
|
+
return shouldUseInlineLayout(
|
31
|
+
field.inlineRendering,
|
32
|
+
context.layoutType,
|
33
|
+
context.workspaceLayout,
|
34
|
+
context.sessionMode,
|
35
|
+
);
|
36
|
+
}
|
37
|
+
return false;
|
38
|
+
}, [context.sessionMode, field.readonly, field.inlineRendering, context.layoutType, context.workspaceLayout]);
|
39
|
+
|
40
|
+
return context.sessionMode == 'view' || context.sessionMode == 'embedded-view' ? (
|
41
|
+
<FieldValueView
|
42
|
+
label={t(field.label)}
|
43
|
+
value={!isEmpty(value) ? context.formFieldAdapters[field.type].getDisplayValue(field, value) : value}
|
44
|
+
conceptName={field.meta?.concept?.display}
|
45
|
+
isInline={isInline}
|
46
|
+
/>
|
47
|
+
) : (
|
48
|
+
!field.isHidden && (
|
49
|
+
<div className={styles.boldedLabel}>
|
50
|
+
<ToggleInput
|
51
|
+
labelText={t(field.label)}
|
52
|
+
className={styles.boldedLabel}
|
53
|
+
id={field.id}
|
54
|
+
labelA={field.questionOptions.toggleOptions.labelFalse}
|
55
|
+
labelB={field.questionOptions.toggleOptions.labelTrue}
|
56
|
+
onToggle={handleChange}
|
57
|
+
toggled={!!value}
|
58
|
+
disabled={field.isDisabled}
|
59
|
+
readOnly={field.readonly}
|
60
|
+
/>
|
61
|
+
</div>
|
62
|
+
)
|
63
|
+
);
|
64
|
+
};
|
65
|
+
|
66
|
+
export default Toggle;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Tooltip as CarbonTooltip } from '@carbon/react';
|
3
|
+
import { Information } from '@carbon/react/icons';
|
4
|
+
import { type FormField } from '../../../types';
|
5
|
+
import { useTranslation } from 'react-i18next';
|
6
|
+
|
7
|
+
import styles from './tooltip.scss';
|
8
|
+
interface TooltipProps {
|
9
|
+
field: FormField;
|
10
|
+
}
|
11
|
+
|
12
|
+
const Tooltip: React.FC<TooltipProps> = ({ field }) => {
|
13
|
+
const { t } = useTranslation();
|
14
|
+
return (
|
15
|
+
<CarbonTooltip align="top" label={t(field.questionInfo)} description={t(field.questionInfo)}>
|
16
|
+
<button className={styles.tooltip} type="button" data-testid={field.id}>
|
17
|
+
<Information />
|
18
|
+
</button>
|
19
|
+
</CarbonTooltip>
|
20
|
+
);
|
21
|
+
};
|
22
|
+
|
23
|
+
export default Tooltip;
|