@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,38 @@
|
|
1
|
+
import { Button } from '@carbon/react';
|
2
|
+
import React from 'react';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import { type FormField } from '../../types';
|
5
|
+
import { disableRepeatAddButton } from './helpers';
|
6
|
+
import styles from './repeat-controls.scss';
|
7
|
+
interface RepeatingControlsProps {
|
8
|
+
rows: FormField[];
|
9
|
+
question: FormField;
|
10
|
+
questionIndex: number;
|
11
|
+
handleDelete: () => void;
|
12
|
+
handleAdd: () => void;
|
13
|
+
}
|
14
|
+
|
15
|
+
function RepeatControls({ question, rows, handleDelete, handleAdd, questionIndex }: RepeatingControlsProps) {
|
16
|
+
const { t } = useTranslation();
|
17
|
+
return (
|
18
|
+
<div className={styles.actionButtons}>
|
19
|
+
{questionIndex > 0 && (
|
20
|
+
<Button className={styles.button} kind="danger" onClick={handleDelete}>
|
21
|
+
<span>{t('remove', 'Remove')}</span>
|
22
|
+
</Button>
|
23
|
+
)}
|
24
|
+
{questionIndex === rows.length - 1 && (
|
25
|
+
<Button
|
26
|
+
className={styles.button}
|
27
|
+
iconDescription={t('add', 'Add')}
|
28
|
+
kind="primary"
|
29
|
+
disabled={disableRepeatAddButton(question.questionOptions.repeatOptions?.limit, rows.length)}
|
30
|
+
onClick={handleAdd}>
|
31
|
+
<span>{question.questionOptions.repeatOptions?.addText || t('add', 'Add')}</span>
|
32
|
+
</Button>
|
33
|
+
)}
|
34
|
+
</div>
|
35
|
+
);
|
36
|
+
}
|
37
|
+
|
38
|
+
export default RepeatControls;
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
2
|
+
import { FormGroup } from '@carbon/react';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import type { FormField, FormFieldInputProps, RenderType } from '../../types';
|
5
|
+
import { evaluateAsyncExpression, evaluateExpression } from '../../utils/expression-runner';
|
6
|
+
import { isEmpty } from '../../validators/form-validator';
|
7
|
+
import styles from './repeat.scss';
|
8
|
+
import { cloneRepeatField } from './helpers';
|
9
|
+
import { clearSubmission, isViewMode } from '../../utils/common-utils';
|
10
|
+
import RepeatControls from './repeat-controls.component';
|
11
|
+
import { createErrorHandler } from '@openmrs/esm-framework';
|
12
|
+
import { useFormProviderContext } from '../../provider/form-provider';
|
13
|
+
import { FormFieldRenderer } from '../renderer/field/form-field-renderer.component';
|
14
|
+
import { useFormFactory } from '../../provider/form-factory-provider';
|
15
|
+
|
16
|
+
const renderingByTypeMap: Record<string, RenderType> = {
|
17
|
+
obsGroup: 'group',
|
18
|
+
testOrder: 'select',
|
19
|
+
};
|
20
|
+
|
21
|
+
const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
|
22
|
+
const { t } = useTranslation();
|
23
|
+
const isGrouped = useMemo(() => field.questions?.length > 1, [field]);
|
24
|
+
const [counter, setCounter] = useState(0);
|
25
|
+
const [rows, setRows] = useState([]);
|
26
|
+
const context = useFormProviderContext();
|
27
|
+
const { handleConfirmQuestionDeletion } = useFormFactory();
|
28
|
+
const {
|
29
|
+
patient,
|
30
|
+
sessionMode,
|
31
|
+
formFieldAdapters,
|
32
|
+
formFields,
|
33
|
+
methods: { getValues, setValue },
|
34
|
+
addFormField,
|
35
|
+
} = context;
|
36
|
+
|
37
|
+
useEffect(() => {
|
38
|
+
const repeatedFields = formFields.filter(
|
39
|
+
(_field) =>
|
40
|
+
_field.questionOptions.concept === field.questionOptions.concept &&
|
41
|
+
_field.id.startsWith(field.id) &&
|
42
|
+
!_field.meta?.repeat?.wasDeleted,
|
43
|
+
);
|
44
|
+
setCounter(repeatedFields.length - 1);
|
45
|
+
setRows(repeatedFields);
|
46
|
+
}, [formFields, field]);
|
47
|
+
|
48
|
+
const handleAdd = useCallback(
|
49
|
+
(counter: number) => {
|
50
|
+
function evaluateExpressions(field: FormField) {
|
51
|
+
if (field.hide?.hideWhenExpression) {
|
52
|
+
field.isHidden = evaluateExpression(
|
53
|
+
field.hide.hideWhenExpression,
|
54
|
+
{ value: field, type: 'field' },
|
55
|
+
formFields,
|
56
|
+
getValues(),
|
57
|
+
{
|
58
|
+
mode: sessionMode,
|
59
|
+
patient: patient,
|
60
|
+
},
|
61
|
+
);
|
62
|
+
}
|
63
|
+
if (field.questionOptions.calculate?.calculateExpression) {
|
64
|
+
evaluateAsyncExpression(
|
65
|
+
field.questionOptions.calculate?.calculateExpression,
|
66
|
+
{ value: field, type: 'field' },
|
67
|
+
formFields,
|
68
|
+
getValues(),
|
69
|
+
{
|
70
|
+
mode: sessionMode,
|
71
|
+
patient: patient,
|
72
|
+
},
|
73
|
+
).then((result) => {
|
74
|
+
if (!isEmpty(result)) {
|
75
|
+
setValue(field.id, result);
|
76
|
+
formFieldAdapters[field.type]?.transformFieldValue(field, result, context);
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
}
|
81
|
+
const clonedField = cloneRepeatField(field, null, counter);
|
82
|
+
// run necessary expressions
|
83
|
+
if (clonedField.type === 'obsGroup') {
|
84
|
+
clonedField.questions?.forEach((childField) => {
|
85
|
+
evaluateExpressions(childField);
|
86
|
+
addFormField(childField);
|
87
|
+
});
|
88
|
+
} else {
|
89
|
+
evaluateExpressions(clonedField);
|
90
|
+
}
|
91
|
+
addFormField(clonedField);
|
92
|
+
setRows([...rows, clonedField]);
|
93
|
+
},
|
94
|
+
[formFields, field, rows, context],
|
95
|
+
);
|
96
|
+
|
97
|
+
const removeNthRow = (field: FormField) => {
|
98
|
+
if (field.meta.previousValue) {
|
99
|
+
formFieldAdapters[field.type]?.transformFieldValue(field, null, context);
|
100
|
+
field.meta.repeat = { ...(field.meta.repeat || {}), wasDeleted: true };
|
101
|
+
if (field.type === 'obsGroup') {
|
102
|
+
field.questions.forEach((child) => {
|
103
|
+
child.meta.repeat = { ...(field.meta.repeat || {}), wasDeleted: true };
|
104
|
+
formFieldAdapters[child.type]?.transformFieldValue(child, null, context);
|
105
|
+
});
|
106
|
+
}
|
107
|
+
} else {
|
108
|
+
clearSubmission(field);
|
109
|
+
}
|
110
|
+
setRows(rows.filter((q) => q.id !== field.id));
|
111
|
+
};
|
112
|
+
|
113
|
+
const onClickDeleteQuestion = (field: Readonly<FormField>) => {
|
114
|
+
if (handleConfirmQuestionDeletion && typeof handleConfirmQuestionDeletion === 'function') {
|
115
|
+
const result = handleConfirmQuestionDeletion(field);
|
116
|
+
if (result && typeof result.then === 'function' && typeof result.catch === 'function') {
|
117
|
+
result.then(() => removeNthRow(field)).catch(() => createErrorHandler());
|
118
|
+
} else if (typeof result === 'boolean') {
|
119
|
+
result && removeNthRow(field);
|
120
|
+
} else {
|
121
|
+
removeNthRow(field);
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
removeNthRow(field);
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
const nodes = useMemo(() => {
|
129
|
+
return rows.map((field, index) => {
|
130
|
+
const component = (
|
131
|
+
<FormFieldRenderer
|
132
|
+
field={field}
|
133
|
+
valueAdapter={formFieldAdapters[field.type]}
|
134
|
+
repeatOptions={{ targetRendering: getQuestionWithSupportedRendering(field).questionOptions.rendering }}
|
135
|
+
/>
|
136
|
+
);
|
137
|
+
return (
|
138
|
+
<div key={field.id + '_wrapper'}>
|
139
|
+
{index !== 0 && (
|
140
|
+
<div>
|
141
|
+
<hr className={styles.divider} />
|
142
|
+
</div>
|
143
|
+
)}
|
144
|
+
<div className={styles.nodeContainer}>{component}</div>
|
145
|
+
{!isViewMode(sessionMode) && (
|
146
|
+
<RepeatControls
|
147
|
+
question={field}
|
148
|
+
rows={rows}
|
149
|
+
questionIndex={index}
|
150
|
+
handleDelete={() => {
|
151
|
+
onClickDeleteQuestion(field);
|
152
|
+
}}
|
153
|
+
handleAdd={() => {
|
154
|
+
const nextCount = counter + 1;
|
155
|
+
handleAdd(nextCount);
|
156
|
+
setCounter(nextCount);
|
157
|
+
}}
|
158
|
+
/>
|
159
|
+
)}
|
160
|
+
</div>
|
161
|
+
);
|
162
|
+
});
|
163
|
+
}, [rows]);
|
164
|
+
|
165
|
+
if (field.isHidden || !nodes || !hasVisibleField(field)) {
|
166
|
+
return null;
|
167
|
+
}
|
168
|
+
|
169
|
+
return (
|
170
|
+
<React.Fragment>
|
171
|
+
{isGrouped ? (
|
172
|
+
<div className={styles.container}>
|
173
|
+
<FormGroup legendText={t(field.label)} className={styles.boldLegend}>
|
174
|
+
{nodes}
|
175
|
+
</FormGroup>
|
176
|
+
</div>
|
177
|
+
) : (
|
178
|
+
<div>{nodes}</div>
|
179
|
+
)}
|
180
|
+
</React.Fragment>
|
181
|
+
);
|
182
|
+
};
|
183
|
+
|
184
|
+
function hasVisibleField(field: FormField) {
|
185
|
+
if (field.questions?.length) {
|
186
|
+
return field.questions?.some((child) => !child.isHidden);
|
187
|
+
}
|
188
|
+
return !field.isHidden;
|
189
|
+
}
|
190
|
+
|
191
|
+
function getQuestionWithSupportedRendering(field: FormField) {
|
192
|
+
return {
|
193
|
+
...field,
|
194
|
+
questionOptions: {
|
195
|
+
...field.questionOptions,
|
196
|
+
rendering: renderingByTypeMap[field.type] || null,
|
197
|
+
},
|
198
|
+
};
|
199
|
+
}
|
200
|
+
|
201
|
+
export default Repeat;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
.boldLegend > legend {
|
2
|
+
font-weight: bolder;
|
3
|
+
}
|
4
|
+
|
5
|
+
.flexColumn {
|
6
|
+
display: flex;
|
7
|
+
flex-direction: column;
|
8
|
+
margin-right: 2.5rem;
|
9
|
+
flex: 1;
|
10
|
+
}
|
11
|
+
|
12
|
+
.removeButton {
|
13
|
+
@extend .flexColumn;
|
14
|
+
margin-left: 0.5rem;
|
15
|
+
}
|
16
|
+
|
17
|
+
.nodeContainer {
|
18
|
+
margin: 1rem 0rem;
|
19
|
+
}
|
20
|
+
|
21
|
+
.container {
|
22
|
+
margin-top: 0.5rem;
|
23
|
+
margin-bottom: 0.5rem;
|
24
|
+
}
|
25
|
+
|
26
|
+
.divider {
|
27
|
+
border: 1.5px solid #e0e0e0;
|
28
|
+
border-bottom: none;
|
29
|
+
margin: 2rem 0;
|
30
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { updateFieldIdInExpression } from './helpers';
|
2
|
+
|
3
|
+
describe('RepeatingFieldComponent - handleExpressionFieldIdUpdate', () => {
|
4
|
+
it('Should handle update of expression with ids in repeat group', () => {
|
5
|
+
const expression =
|
6
|
+
"infantStatus !== '151849AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' && infantStatus !== '154223AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'";
|
7
|
+
const fieldIds = ['birthDate', 'infantStatus', 'deathDate'];
|
8
|
+
const index = 2;
|
9
|
+
|
10
|
+
const updatedExpression = updateFieldIdInExpression(expression, index, fieldIds);
|
11
|
+
|
12
|
+
expect(updatedExpression).toEqual(
|
13
|
+
"infantStatus_2 !== '151849AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' && infantStatus_2 !== '154223AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'",
|
14
|
+
);
|
15
|
+
});
|
16
|
+
|
17
|
+
it('Should handle update of expression with ids not in repeat group', () => {
|
18
|
+
const expression =
|
19
|
+
"myValue > today() || myValue <= '1/1/1890' || myValue > useFieldValue('visit_date') || myValue < useFieldValue('visit_date')";
|
20
|
+
const fieldIds = ['birthDate', 'infantStatus', 'deathDate'];
|
21
|
+
const index = 1;
|
22
|
+
|
23
|
+
const updatedExpression = updateFieldIdInExpression(expression, index, fieldIds);
|
24
|
+
|
25
|
+
expect(updatedExpression).toEqual(
|
26
|
+
"myValue > today() || myValue <= '1/1/1890' || myValue > useFieldValue('visit_date') || myValue < useFieldValue('visit_date')",
|
27
|
+
);
|
28
|
+
});
|
29
|
+
});
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
2
|
+
import classNames from 'classnames';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import { Button, Toggle } from '@carbon/react';
|
5
|
+
import { isEmpty } from '../../validators/form-validator';
|
6
|
+
import { type FormPage } from '../../types';
|
7
|
+
import styles from './sidebar.scss';
|
8
|
+
import { scrollIntoView } from '../../utils/form-helper';
|
9
|
+
|
10
|
+
interface SidebarProps {
|
11
|
+
allowUnspecifiedAll: boolean;
|
12
|
+
defaultPage: string;
|
13
|
+
handleClose: () => void;
|
14
|
+
hideFormCollapseToggle: () => void;
|
15
|
+
isFormSubmitting: boolean;
|
16
|
+
mode: string;
|
17
|
+
onCancel: () => void;
|
18
|
+
pagesWithErrors: string[];
|
19
|
+
scrollablePages: Set<FormPage>;
|
20
|
+
selectedPage: string;
|
21
|
+
setValues: (values: unknown) => void;
|
22
|
+
values: object;
|
23
|
+
}
|
24
|
+
|
25
|
+
const Sidebar: React.FC<SidebarProps> = ({
|
26
|
+
allowUnspecifiedAll,
|
27
|
+
defaultPage,
|
28
|
+
handleClose,
|
29
|
+
hideFormCollapseToggle,
|
30
|
+
isFormSubmitting,
|
31
|
+
mode,
|
32
|
+
onCancel,
|
33
|
+
pagesWithErrors,
|
34
|
+
scrollablePages,
|
35
|
+
selectedPage,
|
36
|
+
setValues,
|
37
|
+
values,
|
38
|
+
}) => {
|
39
|
+
const { t } = useTranslation();
|
40
|
+
const pages: Array<FormPage> = Array.from(scrollablePages);
|
41
|
+
|
42
|
+
useEffect(() => {
|
43
|
+
if (defaultPage && pages.some(({ label, isHidden }) => label === defaultPage && !isHidden)) {
|
44
|
+
scrollIntoView(joinWord(defaultPage));
|
45
|
+
}
|
46
|
+
}, [defaultPage, scrollablePages]);
|
47
|
+
|
48
|
+
const unspecifiedFields = useMemo(
|
49
|
+
() =>
|
50
|
+
Object.keys(values).filter(
|
51
|
+
(key) => key.endsWith('-unspecified') && isEmpty(values[key.split('-unspecified')[0]]),
|
52
|
+
),
|
53
|
+
[values],
|
54
|
+
);
|
55
|
+
|
56
|
+
const handleClick = (selected) => {
|
57
|
+
const activeId = joinWord(selected);
|
58
|
+
scrollIntoView(activeId);
|
59
|
+
};
|
60
|
+
|
61
|
+
const markAllAsUnspecified = useCallback(
|
62
|
+
(toggled) => {
|
63
|
+
const updatedValues = { ...values };
|
64
|
+
unspecifiedFields.forEach((field) => {
|
65
|
+
updatedValues[field] = toggled;
|
66
|
+
});
|
67
|
+
setValues(updatedValues);
|
68
|
+
},
|
69
|
+
[unspecifiedFields, values, setValues],
|
70
|
+
);
|
71
|
+
|
72
|
+
return (
|
73
|
+
<div className={styles.sidebar}>
|
74
|
+
{pages.map((page, index) => {
|
75
|
+
if (page.isHidden) return null;
|
76
|
+
|
77
|
+
const isCurrentlySelected = joinWord(page.label) === selectedPage;
|
78
|
+
const hasError = pagesWithErrors.includes(page.label);
|
79
|
+
|
80
|
+
return (
|
81
|
+
<div
|
82
|
+
aria-hidden="true"
|
83
|
+
className={classNames({
|
84
|
+
[styles.erroredSection]: isCurrentlySelected && hasError,
|
85
|
+
[styles.activeSection]: isCurrentlySelected && !hasError,
|
86
|
+
[styles.activeErroredSection]: !isCurrentlySelected && hasError,
|
87
|
+
[styles.section]: !isCurrentlySelected && !hasError,
|
88
|
+
})}
|
89
|
+
key={index}
|
90
|
+
onClick={() => handleClick(page.label)}>
|
91
|
+
<div className={styles.sectionLink}>{page.label}</div>
|
92
|
+
</div>
|
93
|
+
);
|
94
|
+
})}
|
95
|
+
{mode !== 'view' && <hr className={styles.divider} />}
|
96
|
+
<div className={styles.sidenavActions}>
|
97
|
+
{allowUnspecifiedAll && mode !== 'view' && (
|
98
|
+
<div className={styles.toggleContainer}>
|
99
|
+
<Toggle
|
100
|
+
id="auto-unspecifier"
|
101
|
+
labelA={t('unspecifyAll', 'Unspecify All')}
|
102
|
+
labelB={t('revert', 'Revert')}
|
103
|
+
labelText=""
|
104
|
+
onToggle={markAllAsUnspecified}
|
105
|
+
/>
|
106
|
+
</div>
|
107
|
+
)}
|
108
|
+
{mode !== 'view' && (
|
109
|
+
<Button className={styles.saveButton} disabled={isFormSubmitting} type="submit">
|
110
|
+
{t('save', 'Save')}
|
111
|
+
</Button>
|
112
|
+
)}
|
113
|
+
<Button
|
114
|
+
className={classNames(styles.saveButton, {
|
115
|
+
[styles.topMargin]: mode === 'view',
|
116
|
+
})}
|
117
|
+
kind="tertiary"
|
118
|
+
onClick={() => {
|
119
|
+
onCancel?.();
|
120
|
+
handleClose?.();
|
121
|
+
hideFormCollapseToggle();
|
122
|
+
}}>
|
123
|
+
{mode === 'view' ? t('close', 'Close') : t('cancel', 'Cancel')}
|
124
|
+
</Button>
|
125
|
+
</div>
|
126
|
+
</div>
|
127
|
+
);
|
128
|
+
};
|
129
|
+
|
130
|
+
function joinWord(value) {
|
131
|
+
return value.replace(/\s/g, '');
|
132
|
+
}
|
133
|
+
|
134
|
+
export default Sidebar;
|
@@ -0,0 +1,121 @@
|
|
1
|
+
@use '@carbon/colors';
|
2
|
+
@use '@carbon/type';
|
3
|
+
|
4
|
+
.sidebar {
|
5
|
+
width: 12rem;
|
6
|
+
min-height: 8rem;
|
7
|
+
overscroll-behavior: contain;
|
8
|
+
margin-right: 1rem;
|
9
|
+
}
|
10
|
+
|
11
|
+
.sidebarList {
|
12
|
+
max-height: 100%;
|
13
|
+
}
|
14
|
+
|
15
|
+
.sidenavActions {
|
16
|
+
margin-left: 0.6rem;
|
17
|
+
}
|
18
|
+
|
19
|
+
@media all and (device-width: 600px) and (device-height: 1024px) and (orientation: portrait) {
|
20
|
+
.sidebar {
|
21
|
+
width: 11rem;
|
22
|
+
max-height: 500px;
|
23
|
+
margin-right: 20px;
|
24
|
+
position: fixed;
|
25
|
+
}
|
26
|
+
|
27
|
+
.sidebarList {
|
28
|
+
max-height: 200px;
|
29
|
+
overflow-y: scroll;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
.link {
|
34
|
+
margin: 0.375rem 0 0.375rem 0.5rem;
|
35
|
+
font-size: 1rem;
|
36
|
+
line-height: 1.43;
|
37
|
+
letter-spacing: 0.16px;
|
38
|
+
color: colors.$gray-100;
|
39
|
+
cursor: pointer;
|
40
|
+
|
41
|
+
:hover {
|
42
|
+
outline: none;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
.section {
|
47
|
+
border-left: 0.5rem solid colors.$teal-20;
|
48
|
+
display: flex;
|
49
|
+
align-items: center;
|
50
|
+
height: 2rem;
|
51
|
+
padding: 0.25rem 0.5rem;
|
52
|
+
background-color: colors.$white;
|
53
|
+
cursor: pointer;
|
54
|
+
}
|
55
|
+
|
56
|
+
/* Tablet */
|
57
|
+
:global(.omrs-breakpoint-lt-desktop) {
|
58
|
+
.section {
|
59
|
+
height: 3rem;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
.sectionLink {
|
64
|
+
@include type.type-style('body-01');
|
65
|
+
color: colors.$gray-100;
|
66
|
+
}
|
67
|
+
|
68
|
+
.activeSection {
|
69
|
+
@extend .section;
|
70
|
+
border-left: 0.5rem solid colors.$teal-50;
|
71
|
+
background-color: #ededed;
|
72
|
+
|
73
|
+
.sectionLink {
|
74
|
+
font-weight: 600;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
.sectionDone {
|
79
|
+
@extend .section;
|
80
|
+
border-left: 0.5rem solid colors.$teal-80;
|
81
|
+
background-color: colors.$green-10;
|
82
|
+
}
|
83
|
+
|
84
|
+
.erroredSection {
|
85
|
+
@extend .section;
|
86
|
+
border-left: 0.5rem solid colors.$red-60;
|
87
|
+
color: colors.$red-70 !important;
|
88
|
+
background-color: colors.$red-20;
|
89
|
+
}
|
90
|
+
|
91
|
+
.activeErroredSection {
|
92
|
+
@extend .erroredSection;
|
93
|
+
font-weight: 600;
|
94
|
+
}
|
95
|
+
|
96
|
+
.divider {
|
97
|
+
border: 0;
|
98
|
+
border-top: 1px solid colors.$gray-40;
|
99
|
+
margin: 2.5rem 0.5rem 1rem;
|
100
|
+
}
|
101
|
+
|
102
|
+
.button {
|
103
|
+
width: 11rem;
|
104
|
+
}
|
105
|
+
|
106
|
+
.topMargin {
|
107
|
+
margin-top: 1.5rem;
|
108
|
+
}
|
109
|
+
|
110
|
+
.saveButton {
|
111
|
+
@extend .button;
|
112
|
+
margin-bottom: 0.625rem;
|
113
|
+
}
|
114
|
+
|
115
|
+
.closeButton {
|
116
|
+
@extend .button;
|
117
|
+
}
|
118
|
+
|
119
|
+
.toggleContainer {
|
120
|
+
margin-bottom: 0.5rem;
|
121
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import styles from './value.scss';
|
3
|
+
|
4
|
+
export const ValueEmpty = () => {
|
5
|
+
return (
|
6
|
+
<div>
|
7
|
+
<span className={styles.empty}>(Blank)</span>
|
8
|
+
</div>
|
9
|
+
);
|
10
|
+
};
|
11
|
+
|
12
|
+
export const ValueDisplay = ({ value }) => {
|
13
|
+
if (Array.isArray(value)) {
|
14
|
+
return <ListDisplay valueArray={value} />;
|
15
|
+
}
|
16
|
+
return <div className={styles.value}>{value}</div>;
|
17
|
+
};
|
18
|
+
|
19
|
+
const ListDisplay = ({ valueArray }) => {
|
20
|
+
return (
|
21
|
+
<ul>
|
22
|
+
{valueArray.map((item) => (
|
23
|
+
<li className={styles.item}>{item}</li>
|
24
|
+
))}
|
25
|
+
</ul>
|
26
|
+
);
|
27
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import LabelField from '../../label/label.component';
|
3
|
+
import { ValueDisplay, ValueEmpty } from '../value.component';
|
4
|
+
import styles from './field-value-view.scss';
|
5
|
+
|
6
|
+
interface FieldValueViewProps {
|
7
|
+
isInline: boolean;
|
8
|
+
label: string;
|
9
|
+
value: any;
|
10
|
+
conceptName: string;
|
11
|
+
}
|
12
|
+
|
13
|
+
const FieldValueView: React.FC<FieldValueViewProps> = ({ label, conceptName, value, isInline }) => (
|
14
|
+
<>
|
15
|
+
{isInline ? (
|
16
|
+
<div className={styles.inlineFlexRow}>
|
17
|
+
<div className={styles.inlineFlexColumn}>
|
18
|
+
<LabelField value={label} tooltipText={conceptName} />
|
19
|
+
</div>
|
20
|
+
<div className={styles.inlineFlexColumn}>{value ? <ValueDisplay value={value} /> : <ValueEmpty />}</div>
|
21
|
+
</div>
|
22
|
+
) : (
|
23
|
+
<div className={styles.readonly}>
|
24
|
+
<div className={styles.formField}>
|
25
|
+
<LabelField value={label} tooltipText={conceptName} />
|
26
|
+
<div className={styles.value}>{value ? <ValueDisplay value={value} /> : <ValueEmpty />}</div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
)}
|
30
|
+
</>
|
31
|
+
);
|
32
|
+
|
33
|
+
export default FieldValueView;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
@use '@carbon/colors';
|
2
|
+
|
3
|
+
.formField {
|
4
|
+
margin-top: 10px;
|
5
|
+
}
|
6
|
+
|
7
|
+
.formField > div > div > label {
|
8
|
+
color: colors.$gray-70;
|
9
|
+
}
|
10
|
+
|
11
|
+
.readonly {
|
12
|
+
border-bottom: 0.5px colors.$gray-30;
|
13
|
+
border-style: solid;
|
14
|
+
}
|
15
|
+
|
16
|
+
.readonly > div {
|
17
|
+
padding-bottom: 7px !important;
|
18
|
+
}
|
19
|
+
|
20
|
+
.value {
|
21
|
+
color: colors.$gray-70;
|
22
|
+
}
|
23
|
+
|
24
|
+
.inlineFlexRow {
|
25
|
+
display: flex;
|
26
|
+
flex-wrap: wrap;
|
27
|
+
}
|
28
|
+
|
29
|
+
.inlineFlexColumn {
|
30
|
+
width: 300px;
|
31
|
+
}
|
package/src/constants.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
export const ConceptTrue = 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3';
|
2
|
+
export const ConceptFalse = '488b58ff-64f5-4f8a-8979-fa79940b1594';
|
3
|
+
export const UnspecifiedValue = 'VALUE_UNSPECIFIED';
|
4
|
+
export const encounterRepresentation =
|
5
|
+
'custom:(uuid,encounterDatetime,encounterType:(uuid,name,description),location:(uuid,name),' +
|
6
|
+
'patient:(uuid,display),encounterProviders:(uuid,provider:(uuid,name),encounterRole:(uuid,name)),' +
|
7
|
+
'orders:(uuid,display,concept:(uuid,display),voided),' +
|
8
|
+
'obs:(uuid,obsDatetime,comment,voided,groupMembers,formFieldNamespace,formFieldPath,concept:(uuid,name:(uuid,name)),value:(uuid,name:(uuid,name),' +
|
9
|
+
'names:(uuid,conceptNameType,name))))';
|
10
|
+
export const FormsStore = 'forms-engine-store';
|
11
|
+
export const PatientChartWorkspaceHeaderSlot = 'patient-chart-workspace-header-slot';
|
12
|
+
export const codedTypes = ['radio', 'checkbox', 'select', 'content-switcher'];
|