@olaboot/esm-form-engine-lib 4.1.0
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/LICENSE.txt +401 -0
- package/README.md +202 -0
- package/dist/adapters/control-adapter.d.ts +3 -0
- package/dist/adapters/control-adapter.d.ts.map +1 -0
- package/dist/adapters/control-adapter.js +17 -0
- package/dist/adapters/encounter-datetime-adapter.d.ts +3 -0
- package/dist/adapters/encounter-datetime-adapter.d.ts.map +1 -0
- package/dist/adapters/encounter-datetime-adapter.js +26 -0
- package/dist/adapters/encounter-diagnosis-adapter.d.ts +10 -0
- package/dist/adapters/encounter-diagnosis-adapter.d.ts.map +1 -0
- package/dist/adapters/encounter-diagnosis-adapter.js +89 -0
- package/dist/adapters/encounter-diagnosis-adapter.test.js +217 -0
- package/dist/adapters/encounter-location-adapter.d.ts +3 -0
- package/dist/adapters/encounter-location-adapter.d.ts.map +1 -0
- package/dist/adapters/encounter-location-adapter.js +25 -0
- package/dist/adapters/encounter-provider-adapter.d.ts +3 -0
- package/dist/adapters/encounter-provider-adapter.d.ts.map +1 -0
- package/dist/adapters/encounter-provider-adapter.js +34 -0
- package/dist/adapters/encounter-role-adapter.d.ts +3 -0
- package/dist/adapters/encounter-role-adapter.d.ts.map +1 -0
- package/dist/adapters/encounter-role-adapter.js +40 -0
- package/dist/adapters/inline-date-adapter.d.ts +3 -0
- package/dist/adapters/inline-date-adapter.d.ts.map +1 -0
- package/dist/adapters/inline-date-adapter.js +56 -0
- package/dist/adapters/obs-adapter.d.ts +29 -0
- package/dist/adapters/obs-adapter.d.ts.map +1 -0
- package/dist/adapters/obs-adapter.js +284 -0
- package/dist/adapters/obs-adapter.test.js +1443 -0
- package/dist/adapters/obs-comment-adapter.d.ts +4 -0
- package/dist/adapters/obs-comment-adapter.d.ts.map +1 -0
- package/dist/adapters/obs-comment-adapter.js +52 -0
- package/dist/adapters/orders-adapter.d.ts +4 -0
- package/dist/adapters/orders-adapter.d.ts.map +1 -0
- package/dist/adapters/orders-adapter.js +64 -0
- package/dist/adapters/patient-identifier-adapter.d.ts +3 -0
- package/dist/adapters/patient-identifier-adapter.d.ts.map +1 -0
- package/dist/adapters/patient-identifier-adapter.js +40 -0
- package/dist/adapters/person-attribute-adapter.d.ts +3 -0
- package/dist/adapters/person-attribute-adapter.d.ts.map +1 -0
- package/dist/adapters/person-attribute-adapter.js +39 -0
- package/dist/adapters/person-attribute-adapter.test.js +146 -0
- package/dist/adapters/program-state-adapter.d.ts +3 -0
- package/dist/adapters/program-state-adapter.d.ts.map +1 -0
- package/dist/adapters/program-state-adapter.js +41 -0
- package/dist/adapters/program-state-adapter.test.js +411 -0
- package/dist/api/index.d.ts +27 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +170 -0
- package/dist/components/error/error-modal.component.d.ts +7 -0
- package/dist/components/error/error-modal.component.d.ts.map +1 -0
- package/dist/components/error/error-modal.component.js +31 -0
- package/dist/components/error/error.scss +4 -0
- package/dist/components/extension/extension-parcel.component.d.ts +5 -0
- package/dist/components/extension/extension-parcel.component.d.ts.map +1 -0
- package/dist/components/extension/extension-parcel.component.js +35 -0
- package/dist/components/field-label/field-label.component.d.ts +12 -0
- package/dist/components/field-label/field-label.component.d.ts.map +1 -0
- package/dist/components/field-label/field-label.component.js +33 -0
- package/dist/components/field-label/field-label.scss +15 -0
- package/dist/components/group/obs-group.component.d.ts +5 -0
- package/dist/components/group/obs-group.component.d.ts.map +1 -0
- package/dist/components/group/obs-group.component.js +48 -0
- package/dist/components/group/obs-group.scss +16 -0
- package/dist/components/inputs/content-switcher/content-switcher.component.d.ts +5 -0
- package/dist/components/inputs/content-switcher/content-switcher.component.d.ts.map +1 -0
- package/dist/components/inputs/content-switcher/content-switcher.component.js +70 -0
- package/dist/components/inputs/content-switcher/content-switcher.scss +55 -0
- package/dist/components/inputs/date/date.component.d.ts +5 -0
- package/dist/components/inputs/date/date.component.d.ts.map +1 -0
- package/dist/components/inputs/date/date.component.js +125 -0
- package/dist/components/inputs/date/date.scss +37 -0
- package/dist/components/inputs/date/date.test.js +85 -0
- package/dist/components/inputs/file/file-thumbnail.component.d.ts +10 -0
- package/dist/components/inputs/file/file-thumbnail.component.d.ts.map +1 -0
- package/dist/components/inputs/file/file-thumbnail.component.js +51 -0
- package/dist/components/inputs/file/file-thumbnail.scss +42 -0
- package/dist/components/inputs/file/file.component.d.ts +5 -0
- package/dist/components/inputs/file/file.component.d.ts.map +1 -0
- package/dist/components/inputs/file/file.component.js +90 -0
- package/dist/components/inputs/file/file.scss +21 -0
- package/dist/components/inputs/fixed-value/fixed-value.component.d.ts +5 -0
- package/dist/components/inputs/fixed-value/fixed-value.component.d.ts.map +1 -0
- package/dist/components/inputs/fixed-value/fixed-value.component.js +14 -0
- package/dist/components/inputs/markdown/markdown-wrapper.component.d.ts +6 -0
- package/dist/components/inputs/markdown/markdown-wrapper.component.d.ts.map +1 -0
- package/dist/components/inputs/markdown/markdown-wrapper.component.js +20 -0
- package/dist/components/inputs/markdown/markdown.component.d.ts +5 -0
- package/dist/components/inputs/markdown/markdown.component.d.ts.map +1 -0
- package/dist/components/inputs/markdown/markdown.component.js +26 -0
- package/dist/components/inputs/multi-select/multi-select.component.d.ts +5 -0
- package/dist/components/inputs/multi-select/multi-select.component.d.ts.map +1 -0
- package/dist/components/inputs/multi-select/multi-select.component.js +134 -0
- package/dist/components/inputs/multi-select/multi-select.scss +25 -0
- package/dist/components/inputs/multi-select/multi-select.test.js +106 -0
- package/dist/components/inputs/number/number.component.d.ts +5 -0
- package/dist/components/inputs/number/number.component.d.ts.map +1 -0
- package/dist/components/inputs/number/number.component.js +77 -0
- package/dist/components/inputs/number/number.scss +15 -0
- package/dist/components/inputs/number/number.test.js +98 -0
- package/dist/components/inputs/radio/radio.component.d.ts +5 -0
- package/dist/components/inputs/radio/radio.component.d.ts.map +1 -0
- package/dist/components/inputs/radio/radio.component.js +69 -0
- package/dist/components/inputs/radio/radio.scss +36 -0
- package/dist/components/inputs/radio/radio.test.js +190 -0
- package/dist/components/inputs/select/dropdown.component.d.ts +5 -0
- package/dist/components/inputs/select/dropdown.component.d.ts.map +1 -0
- package/dist/components/inputs/select/dropdown.component.js +82 -0
- package/dist/components/inputs/select/dropdown.scss +11 -0
- package/dist/components/inputs/select/dropdown.test.js +157 -0
- package/dist/components/inputs/text/text.component.d.ts +5 -0
- package/dist/components/inputs/text/text.component.d.ts.map +1 -0
- package/dist/components/inputs/text/text.component.js +62 -0
- package/dist/components/inputs/text/text.scss +15 -0
- package/dist/components/inputs/text/text.test.js +184 -0
- package/dist/components/inputs/text-area/text-area.component.d.ts +5 -0
- package/dist/components/inputs/text-area/text-area.component.d.ts.map +1 -0
- package/dist/components/inputs/text-area/text-area.component.js +60 -0
- package/dist/components/inputs/text-area/text-area.scss +11 -0
- package/dist/components/inputs/toggle/toggle.component.d.ts +5 -0
- package/dist/components/inputs/toggle/toggle.component.d.ts.map +1 -0
- package/dist/components/inputs/toggle/toggle.component.js +57 -0
- package/dist/components/inputs/toggle/toggle.scss +12 -0
- package/dist/components/inputs/ui-select-extended/ui-select-extended.component.d.ts +5 -0
- package/dist/components/inputs/ui-select-extended/ui-select-extended.component.d.ts.map +1 -0
- package/dist/components/inputs/ui-select-extended/ui-select-extended.component.js +203 -0
- package/dist/components/inputs/ui-select-extended/ui-select-extended.scss +19 -0
- package/dist/components/inputs/ui-select-extended/ui-select-extended.test.js +250 -0
- package/dist/components/inputs/unspecified/unspecified.component.d.ts +11 -0
- package/dist/components/inputs/unspecified/unspecified.component.d.ts.map +1 -0
- package/dist/components/inputs/unspecified/unspecified.component.js +65 -0
- package/dist/components/inputs/unspecified/unspecified.scss +7 -0
- package/dist/components/inputs/unspecified/unspecified.test.js +152 -0
- package/dist/components/inputs/workspace-launcher/workspace-launcher.component.d.ts +5 -0
- package/dist/components/inputs/workspace-launcher/workspace-launcher.component.d.ts.map +1 -0
- package/dist/components/inputs/workspace-launcher/workspace-launcher.component.js +64 -0
- package/dist/components/inputs/workspace-launcher/workspace-launcher.scss +21 -0
- package/dist/components/inputs/workspace-launcher/workspace-launcher.test.js +174 -0
- package/dist/components/label/label.component.d.ts +8 -0
- package/dist/components/label/label.component.d.ts.map +1 -0
- package/dist/components/label/label.component.js +15 -0
- package/dist/components/label/label.scss +15 -0
- package/dist/components/loaders/loader.component.d.ts +4 -0
- package/dist/components/loaders/loader.component.d.ts.map +1 -0
- package/dist/components/loaders/loader.component.js +14 -0
- package/dist/components/loaders/loader.scss +20 -0
- package/dist/components/patient-banner/patient-banner.component.d.ts +7 -0
- package/dist/components/patient-banner/patient-banner.component.d.ts.map +1 -0
- package/dist/components/patient-banner/patient-banner.component.js +16 -0
- package/dist/components/patient-banner/patient-banner.scss +12 -0
- package/dist/components/previous-value-review/previous-value-review.component.d.ts +12 -0
- package/dist/components/previous-value-review/previous-value-review.component.d.ts.map +1 -0
- package/dist/components/previous-value-review/previous-value-review.component.js +29 -0
- package/dist/components/previous-value-review/previous-value-review.scss +36 -0
- package/dist/components/processor-factory/form-processor-factory.component.d.ts +10 -0
- package/dist/components/processor-factory/form-processor-factory.component.d.ts.map +1 -0
- package/dist/components/processor-factory/form-processor-factory.component.js +114 -0
- package/dist/components/renderer/custom-hooks-renderer.component.d.ts +13 -0
- package/dist/components/renderer/custom-hooks-renderer.component.d.ts.map +1 -0
- package/dist/components/renderer/custom-hooks-renderer.component.js +13 -0
- package/dist/components/renderer/field/fieldLogic.d.ts +16 -0
- package/dist/components/renderer/field/fieldLogic.d.ts.map +1 -0
- package/dist/components/renderer/field/fieldLogic.js +238 -0
- package/dist/components/renderer/field/fieldLogic.test.js +140 -0
- package/dist/components/renderer/field/fieldRenderUtils.d.ts +9 -0
- package/dist/components/renderer/field/fieldRenderUtils.d.ts.map +1 -0
- package/dist/components/renderer/field/fieldRenderUtils.js +8 -0
- package/dist/components/renderer/field/fieldRenderUtils.test.js +51 -0
- package/dist/components/renderer/field/form-field-renderer.component.d.ts +19 -0
- package/dist/components/renderer/field/form-field-renderer.component.d.ts.map +1 -0
- package/dist/components/renderer/field/form-field-renderer.component.js +214 -0
- package/dist/components/renderer/field/form-field-renderer.scss +5 -0
- package/dist/components/renderer/form/form-renderer.component.d.ts +10 -0
- package/dist/components/renderer/form/form-renderer.component.d.ts.map +1 -0
- package/dist/components/renderer/form/form-renderer.component.js +102 -0
- package/dist/components/renderer/form/state.d.ts +41 -0
- package/dist/components/renderer/form/state.d.ts.map +1 -0
- package/dist/components/renderer/form/state.js +69 -0
- package/dist/components/renderer/page/page.renderer.component.d.ts +9 -0
- package/dist/components/renderer/page/page.renderer.component.d.ts.map +1 -0
- package/dist/components/renderer/page/page.renderer.component.js +85 -0
- package/dist/components/renderer/page/page.renderer.scss +74 -0
- package/dist/components/renderer/section/section-renderer.component.d.ts +6 -0
- package/dist/components/renderer/section/section-renderer.component.d.ts.map +1 -0
- package/dist/components/renderer/section/section-renderer.component.js +20 -0
- package/dist/components/renderer/section/section-renderer.scss +19 -0
- package/dist/components/repeat/helpers.d.ts +6 -0
- package/dist/components/repeat/helpers.d.ts.map +1 -0
- package/dist/components/repeat/helpers.js +64 -0
- package/dist/components/repeat/helpers.test.js +25 -0
- package/dist/components/repeat/repeat-controls.component.d.ts +12 -0
- package/dist/components/repeat/repeat-controls.component.d.ts.map +1 -0
- package/dist/components/repeat/repeat-controls.component.js +22 -0
- package/dist/components/repeat/repeat-controls.scss +7 -0
- package/dist/components/repeat/repeat.component.d.ts +5 -0
- package/dist/components/repeat/repeat.component.d.ts.map +1 -0
- package/dist/components/repeat/repeat.component.js +185 -0
- package/dist/components/repeat/repeat.scss +30 -0
- package/dist/components/repeat/repeat.test.js +25 -0
- package/dist/components/sidebar/page-observer.d.ts +20 -0
- package/dist/components/sidebar/page-observer.d.ts.map +1 -0
- package/dist/components/sidebar/page-observer.js +60 -0
- package/dist/components/sidebar/sidebar.component.d.ts +14 -0
- package/dist/components/sidebar/sidebar.component.d.ts.map +1 -0
- package/dist/components/sidebar/sidebar.component.js +77 -0
- package/dist/components/sidebar/sidebar.scss +114 -0
- package/dist/components/sidebar/useCurrentActivePage.d.ts +34 -0
- package/dist/components/sidebar/useCurrentActivePage.d.ts.map +1 -0
- package/dist/components/sidebar/useCurrentActivePage.js +114 -0
- package/dist/components/sidebar/useCurrentActivePage.test.js +208 -0
- package/dist/components/sidebar/usePageObserver.d.ts +11 -0
- package/dist/components/sidebar/usePageObserver.d.ts.map +1 -0
- package/dist/components/sidebar/usePageObserver.js +42 -0
- package/dist/components/value/value.component.d.ts +6 -0
- package/dist/components/value/value.component.d.ts.map +1 -0
- package/dist/components/value/value.component.js +24 -0
- package/dist/components/value/value.scss +17 -0
- package/dist/components/value/view/field-value-view.component.d.ts +10 -0
- package/dist/components/value/view/field-value-view.component.d.ts.map +1 -0
- package/dist/components/value/view/field-value-view.component.js +29 -0
- package/dist/components/value/view/field-value-view.scss +31 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +13 -0
- package/dist/datasources/concept-data-source.d.ts +6 -0
- package/dist/datasources/concept-data-source.d.ts.map +1 -0
- package/dist/datasources/concept-data-source.js +35 -0
- package/dist/datasources/data-source.d.ts +10 -0
- package/dist/datasources/data-source.d.ts.map +1 -0
- package/dist/datasources/data-source.js +41 -0
- package/dist/datasources/encounter-role-datasource.d.ts +6 -0
- package/dist/datasources/encounter-role-datasource.d.ts.map +1 -0
- package/dist/datasources/encounter-role-datasource.js +13 -0
- package/dist/datasources/historical-data-source.d.ts +6 -0
- package/dist/datasources/historical-data-source.d.ts.map +1 -0
- package/dist/datasources/historical-data-source.js +24 -0
- package/dist/datasources/location-data-source.d.ts +6 -0
- package/dist/datasources/location-data-source.d.ts.map +1 -0
- package/dist/datasources/location-data-source.js +24 -0
- package/dist/datasources/provider-datasource.d.ts +6 -0
- package/dist/datasources/provider-datasource.d.ts.map +1 -0
- package/dist/datasources/provider-datasource.js +13 -0
- package/dist/datasources/select-concept-answers-datasource.d.ts +9 -0
- package/dist/datasources/select-concept-answers-datasource.d.ts.map +1 -0
- package/dist/datasources/select-concept-answers-datasource.js +19 -0
- package/dist/declarations.d.js +0 -0
- package/dist/external-function-context.d.ts +7 -0
- package/dist/external-function-context.d.ts.map +1 -0
- package/dist/external-function-context.js +2 -0
- package/dist/form-engine.component.d.ts +23 -0
- package/dist/form-engine.component.d.ts.map +1 -0
- package/dist/form-engine.component.js +174 -0
- package/dist/form-engine.scss +148 -0
- package/dist/form-engine.test.js +1253 -0
- package/dist/globals.d.ts +3 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +2 -0
- package/dist/hooks/useConcepts.d.ts +23 -0
- package/dist/hooks/useConcepts.d.ts.map +1 -0
- package/dist/hooks/useConcepts.js +31 -0
- package/dist/hooks/useDataSourceDependentValue.d.ts +4 -0
- package/dist/hooks/useDataSourceDependentValue.d.ts.map +1 -0
- package/dist/hooks/useDataSourceDependentValue.js +14 -0
- package/dist/hooks/useEncounter.d.ts +7 -0
- package/dist/hooks/useEncounter.d.ts.map +1 -0
- package/dist/hooks/useEncounter.js +38 -0
- package/dist/hooks/useEncounterRole.d.ts +7 -0
- package/dist/hooks/useEncounterRole.d.ts.map +1 -0
- package/dist/hooks/useEncounterRole.js +18 -0
- package/dist/hooks/useEvaluateFormFieldExpressions.d.ts +7 -0
- package/dist/hooks/useEvaluateFormFieldExpressions.d.ts.map +1 -0
- package/dist/hooks/useEvaluateFormFieldExpressions.js +112 -0
- package/dist/hooks/useExternalFormAction.d.ts +43 -0
- package/dist/hooks/useExternalFormAction.d.ts.map +1 -0
- package/dist/hooks/useExternalFormAction.js +71 -0
- package/dist/hooks/useFormCollapse.d.ts +6 -0
- package/dist/hooks/useFormCollapse.d.ts.map +1 -0
- package/dist/hooks/useFormCollapse.js +35 -0
- package/dist/hooks/useFormFieldValidators.d.ts +3 -0
- package/dist/hooks/useFormFieldValidators.d.ts.map +1 -0
- package/dist/hooks/useFormFieldValidators.js +20 -0
- package/dist/hooks/useFormFieldValueAdapters.d.ts +3 -0
- package/dist/hooks/useFormFieldValueAdapters.d.ts.map +1 -0
- package/dist/hooks/useFormFieldValueAdapters.js +21 -0
- package/dist/hooks/useFormFields.d.ts +6 -0
- package/dist/hooks/useFormFields.d.ts.map +1 -0
- package/dist/hooks/useFormFields.js +62 -0
- package/dist/hooks/useFormFieldsMeta.d.ts +4 -0
- package/dist/hooks/useFormFieldsMeta.d.ts.map +1 -0
- package/dist/hooks/useFormFieldsMeta.js +42 -0
- package/dist/hooks/useFormJson.d.ts +19 -0
- package/dist/hooks/useFormJson.d.ts.map +1 -0
- package/dist/hooks/useFormJson.js +198 -0
- package/dist/hooks/useFormJson.test.js +194 -0
- package/dist/hooks/useFormStateHelpers.d.ts +15 -0
- package/dist/hooks/useFormStateHelpers.d.ts.map +1 -0
- package/dist/hooks/useFormStateHelpers.js +83 -0
- package/dist/hooks/useFormWorkspaceSize.d.ts +7 -0
- package/dist/hooks/useFormWorkspaceSize.d.ts.map +1 -0
- package/dist/hooks/useFormWorkspaceSize.js +46 -0
- package/dist/hooks/useFormWorkspaceSize.test.js +141 -0
- package/dist/hooks/useInitialValues.d.ts +9 -0
- package/dist/hooks/useInitialValues.d.ts.map +1 -0
- package/dist/hooks/useInitialValues.js +29 -0
- package/dist/hooks/useInitialValues.test.js +78 -0
- package/dist/hooks/usePatientData.d.ts +6 -0
- package/dist/hooks/usePatientData.d.ts.map +1 -0
- package/dist/hooks/usePatientData.js +30 -0
- package/dist/hooks/usePatientPrograms.d.ts +7 -0
- package/dist/hooks/usePatientPrograms.d.ts.map +1 -0
- package/dist/hooks/usePatientPrograms.js +22 -0
- package/dist/hooks/usePostSubmissionActions.d.ts +13 -0
- package/dist/hooks/usePostSubmissionActions.d.ts.map +1 -0
- package/dist/hooks/usePostSubmissionActions.js +23 -0
- package/dist/hooks/usePostSubmissionActions.test.js +55 -0
- package/dist/hooks/useProcessorDependencies.d.ts +8 -0
- package/dist/hooks/useProcessorDependencies.d.ts.map +1 -0
- package/dist/hooks/useProcessorDependencies.js +33 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +25 -0
- package/dist/post-submission-actions/mark-patient-deceased-action.d.ts +4 -0
- package/dist/post-submission-actions/mark-patient-deceased-action.d.ts.map +1 -0
- package/dist/post-submission-actions/mark-patient-deceased-action.js +53 -0
- package/dist/post-submission-actions/program-enrollment-action.d.ts +4 -0
- package/dist/post-submission-actions/program-enrollment-action.d.ts.map +1 -0
- package/dist/post-submission-actions/program-enrollment-action.js +105 -0
- package/dist/processors/encounter/encounter-form-processor.d.ts +26 -0
- package/dist/processors/encounter/encounter-form-processor.d.ts.map +1 -0
- package/dist/processors/encounter/encounter-form-processor.js +376 -0
- package/dist/processors/encounter/encounter-form-processor.test.js +207 -0
- package/dist/processors/encounter/encounter-processor-helper.d.ts +19 -0
- package/dist/processors/encounter/encounter-processor-helper.d.ts.map +1 -0
- package/dist/processors/encounter/encounter-processor-helper.js +293 -0
- package/dist/processors/form-processor.d.ts +25 -0
- package/dist/processors/form-processor.d.ts.map +1 -0
- package/dist/processors/form-processor.js +26 -0
- package/dist/provider/form-factory-helper.d.ts +8 -0
- package/dist/provider/form-factory-helper.d.ts.map +1 -0
- package/dist/provider/form-factory-helper.js +73 -0
- package/dist/provider/form-factory-provider.d.ts +48 -0
- package/dist/provider/form-factory-provider.d.ts.map +1 -0
- package/dist/provider/form-factory-provider.js +136 -0
- package/dist/provider/form-provider.d.ts +26 -0
- package/dist/provider/form-provider.d.ts.map +1 -0
- package/dist/provider/form-provider.js +17 -0
- package/dist/registry/inbuilt-components/InbuiltPostSubmissionActions.d.ts +4 -0
- package/dist/registry/inbuilt-components/InbuiltPostSubmissionActions.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/InbuiltPostSubmissionActions.js +10 -0
- package/dist/registry/inbuilt-components/control-templates.d.ts +4 -0
- package/dist/registry/inbuilt-components/control-templates.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/control-templates.js +54 -0
- package/dist/registry/inbuilt-components/inbuiltControls.d.ts +7 -0
- package/dist/registry/inbuilt-components/inbuiltControls.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/inbuiltControls.js +94 -0
- package/dist/registry/inbuilt-components/inbuiltDataSources.d.ts +8 -0
- package/dist/registry/inbuilt-components/inbuiltDataSources.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/inbuiltDataSources.js +36 -0
- package/dist/registry/inbuilt-components/inbuiltFieldValueAdapters.d.ts +4 -0
- package/dist/registry/inbuilt-components/inbuiltFieldValueAdapters.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/inbuiltFieldValueAdapters.js +71 -0
- package/dist/registry/inbuilt-components/inbuiltTransformers.d.ts +4 -0
- package/dist/registry/inbuilt-components/inbuiltTransformers.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/inbuiltTransformers.js +7 -0
- package/dist/registry/inbuilt-components/inbuiltValidators.d.ts +7 -0
- package/dist/registry/inbuilt-components/inbuiltValidators.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/inbuiltValidators.js +29 -0
- package/dist/registry/inbuilt-components/template-component-map.d.ts +5 -0
- package/dist/registry/inbuilt-components/template-component-map.d.ts.map +1 -0
- package/dist/registry/inbuilt-components/template-component-map.js +27 -0
- package/dist/registry/registry.d.ts +61 -0
- package/dist/registry/registry.d.ts.map +1 -0
- package/dist/registry/registry.js +184 -0
- package/dist/registry/registry.test.js +17 -0
- package/dist/setup-tests.js +30 -0
- package/dist/transformers/default-schema-transformer.d.ts +4 -0
- package/dist/transformers/default-schema-transformer.d.ts.map +1 -0
- package/dist/transformers/default-schema-transformer.js +308 -0
- package/dist/transformers/default-schema-transformer.test.js +319 -0
- package/dist/types/domain.d.ts +219 -0
- package/dist/types/domain.d.ts.map +1 -0
- package/dist/types/domain.js +1 -0
- package/dist/types/index.d.ts +126 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/schema.d.ts +243 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +1 -0
- package/dist/typings.d.js +1 -0
- package/dist/utils/boolean-utils.d.ts +13 -0
- package/dist/utils/boolean-utils.d.ts.map +1 -0
- package/dist/utils/boolean-utils.js +22 -0
- package/dist/utils/common-expression-helpers.d.ts +261 -0
- package/dist/utils/common-expression-helpers.d.ts.map +1 -0
- package/dist/utils/common-expression-helpers.js +538 -0
- package/dist/utils/common-expression-helpers.test.js +461 -0
- package/dist/utils/common-utils.d.ts +51 -0
- package/dist/utils/common-utils.d.ts.map +1 -0
- package/dist/utils/common-utils.js +102 -0
- package/dist/utils/common-utils.test.js +134 -0
- package/dist/utils/error-utils.d.ts +11 -0
- package/dist/utils/error-utils.d.ts.map +1 -0
- package/dist/utils/error-utils.js +34 -0
- package/dist/utils/expression-runner.d.ts +25 -0
- package/dist/utils/expression-runner.d.ts.map +1 -0
- package/dist/utils/expression-runner.js +104 -0
- package/dist/utils/expression-runner.test.js +362 -0
- package/dist/utils/form-helper.d.ts +37 -0
- package/dist/utils/form-helper.d.ts.map +1 -0
- package/dist/utils/form-helper.js +239 -0
- package/dist/utils/form-helper.test.js +638 -0
- package/dist/utils/form-page-utils.d.ts +3 -0
- package/dist/utils/form-page-utils.d.ts.map +1 -0
- package/dist/utils/form-page-utils.js +10 -0
- package/dist/utils/forms-loader.d.ts +45 -0
- package/dist/utils/forms-loader.d.ts.map +1 -0
- package/dist/utils/forms-loader.js +246 -0
- package/dist/utils/forms-loader.test.js +333 -0
- package/dist/utils/post-submission-action-helper.d.ts +2 -0
- package/dist/utils/post-submission-action-helper.d.ts.map +1 -0
- package/dist/utils/post-submission-action-helper.js +57 -0
- package/dist/utils/test-utils.js +66 -0
- package/dist/utils/zscore-service.d.ts +6 -0
- package/dist/utils/zscore-service.d.ts.map +1 -0
- package/dist/utils/zscore-service.js +54 -0
- package/dist/validators/conditional-answered-validator.d.ts +3 -0
- package/dist/validators/conditional-answered-validator.d.ts.map +1 -0
- package/dist/validators/conditional-answered-validator.js +18 -0
- package/dist/validators/conditional-answered-validator.test.js +63 -0
- package/dist/validators/date-validator.d.ts +3 -0
- package/dist/validators/date-validator.d.ts.map +1 -0
- package/dist/validators/date-validator.js +21 -0
- package/dist/validators/date-validator.test.js +53 -0
- package/dist/validators/default-value-validator.d.ts +3 -0
- package/dist/validators/default-value-validator.d.ts.map +1 -0
- package/dist/validators/default-value-validator.js +46 -0
- package/dist/validators/default-value-validator.test.js +95 -0
- package/dist/validators/form-validator.d.ts +9 -0
- package/dist/validators/form-validator.d.ts.map +1 -0
- package/dist/validators/form-validator.js +82 -0
- package/dist/validators/form-validator.test.js +158 -0
- package/dist/validators/js-expression-validator.d.ts +3 -0
- package/dist/validators/js-expression-validator.d.ts.map +1 -0
- package/dist/validators/js-expression-validator.js +25 -0
- package/dist/validators/js-expression-validator.test.js +115 -0
- package/dist/validators/schema.d.ts +1 -0
- package/dist/validators/schema.d.ts.map +1 -0
- package/dist/validators/schema.js +32 -0
- package/dist/zscore/bfa_boys_5_above.json +2522 -0
- package/dist/zscore/bfa_girls_5_above.json +2522 -0
- package/dist/zscore/hfa_boys_5_above.json +2186 -0
- package/dist/zscore/hfa_boys_below5.json +22286 -0
- package/dist/zscore/hfa_girls_5_above.json +2186 -0
- package/dist/zscore/hfa_girls_below5.json +22286 -0
- package/dist/zscore/wfl_boys_below5.json +7814 -0
- package/dist/zscore/wfl_girls_below5.json +7814 -0
- package/dist/zscore-tests/bmi-age.test.js +84 -0
- package/dist/zscore-tests/height-age.test.js +88 -0
- package/dist/zscore-tests/weight-height.test.js +82 -0
- package/package.json +105 -0
- package/src/adapters/control-adapter.ts +29 -0
- package/src/adapters/encounter-datetime-adapter.ts +38 -0
- package/src/adapters/encounter-diagnosis-adapter.ts +121 -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 +59 -0
- package/src/adapters/obs-adapter.ts +349 -0
- package/src/adapters/obs-comment-adapter.ts +61 -0
- package/src/adapters/orders-adapter.ts +82 -0
- package/src/adapters/patient-identifier-adapter.ts +46 -0
- package/src/adapters/person-attribute-adapter.ts +45 -0
- package/src/adapters/program-state-adapter.ts +57 -0
- package/src/api/index.ts +224 -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 +55 -0
- package/src/components/field-label/field-label.scss +15 -0
- package/src/components/group/obs-group.component.tsx +59 -0
- package/src/components/group/obs-group.scss +16 -0
- package/src/components/inputs/content-switcher/content-switcher.component.tsx +81 -0
- package/src/components/inputs/content-switcher/content-switcher.scss +55 -0
- package/src/components/inputs/date/date.component.tsx +141 -0
- package/src/components/inputs/date/date.scss +37 -0
- package/src/components/inputs/file/file-thumbnail.component.tsx +55 -0
- package/src/components/inputs/file/file-thumbnail.scss +42 -0
- package/src/components/inputs/file/file.component.tsx +98 -0
- package/src/components/inputs/file/file.scss +21 -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 +24 -0
- package/src/components/inputs/multi-select/multi-select.component.tsx +152 -0
- package/src/components/inputs/multi-select/multi-select.scss +25 -0
- package/src/components/inputs/number/number.component.tsx +85 -0
- package/src/components/inputs/number/number.scss +15 -0
- package/src/components/inputs/radio/radio.component.tsx +81 -0
- package/src/components/inputs/radio/radio.scss +36 -0
- package/src/components/inputs/select/dropdown.component.tsx +86 -0
- package/src/components/inputs/select/dropdown.scss +11 -0
- package/src/components/inputs/text/text.component.tsx +67 -0
- package/src/components/inputs/text/text.scss +15 -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/ui-select-extended/ui-select-extended.component.tsx +208 -0
- package/src/components/inputs/ui-select-extended/ui-select-extended.scss +19 -0
- package/src/components/inputs/unspecified/unspecified.component.tsx +84 -0
- package/src/components/inputs/unspecified/unspecified.scss +7 -0
- package/src/components/inputs/workspace-launcher/workspace-launcher.component.tsx +80 -0
- package/src/components/inputs/workspace-launcher/workspace-launcher.scss +21 -0
- package/src/components/label/label.component.tsx +20 -0
- package/src/components/label/label.scss +15 -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 +128 -0
- package/src/components/renderer/custom-hooks-renderer.component.tsx +30 -0
- package/src/components/renderer/field/fieldLogic.ts +314 -0
- package/src/components/renderer/field/fieldRenderUtils.ts +16 -0
- package/src/components/renderer/field/form-field-renderer.component.tsx +291 -0
- package/src/components/renderer/field/form-field-renderer.scss +5 -0
- package/src/components/renderer/form/form-renderer.component.tsx +123 -0
- package/src/components/renderer/form/state.ts +59 -0
- package/src/components/renderer/page/page.renderer.component.tsx +120 -0
- package/src/components/renderer/page/page.renderer.scss +74 -0
- package/src/components/renderer/section/section-renderer.component.tsx +25 -0
- package/src/components/renderer/section/section-renderer.scss +19 -0
- package/src/components/repeat/helpers.ts +77 -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 +206 -0
- package/src/components/repeat/repeat.scss +30 -0
- package/src/components/sidebar/page-observer.ts +58 -0
- package/src/components/sidebar/sidebar.component.tsx +121 -0
- package/src/components/sidebar/sidebar.scss +114 -0
- package/src/components/sidebar/useCurrentActivePage.ts +137 -0
- package/src/components/sidebar/usePageObserver.ts +45 -0
- package/src/components/value/value.component.tsx +30 -0
- package/src/components/value/value.scss +17 -0
- package/src/components/value/view/field-value-view.component.tsx +36 -0
- package/src/components/value/view/field-value-view.scss +31 -0
- package/src/constants.ts +14 -0
- package/src/datasources/concept-data-source.ts +42 -0
- package/src/datasources/data-source.ts +34 -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 +25 -0
- package/src/declarations.d.ts +2 -0
- package/src/external-function-context.tsx +8 -0
- package/src/form-engine.component.tsx +222 -0
- package/src/form-engine.scss +148 -0
- package/src/globals.ts +2 -0
- package/src/hooks/useConcepts.ts +58 -0
- package/src/hooks/useDataSourceDependentValue.ts +16 -0
- package/src/hooks/useEncounter.ts +40 -0
- package/src/hooks/useEncounterRole.ts +15 -0
- package/src/hooks/useEvaluateFormFieldExpressions.ts +152 -0
- package/src/hooks/useExternalFormAction.ts +94 -0
- package/src/hooks/useFormCollapse.ts +36 -0
- package/src/hooks/useFormFieldValidators.ts +22 -0
- package/src/hooks/useFormFieldValueAdapters.ts +23 -0
- package/src/hooks/useFormFields.ts +65 -0
- package/src/hooks/useFormFieldsMeta.ts +48 -0
- package/src/hooks/useFormJson.ts +257 -0
- package/src/hooks/useFormStateHelpers.ts +72 -0
- package/src/hooks/useFormWorkspaceSize.ts +52 -0
- package/src/hooks/useInitialValues.ts +39 -0
- package/src/hooks/usePatientData.ts +32 -0
- package/src/hooks/usePatientPrograms.ts +38 -0
- package/src/hooks/usePostSubmissionActions.ts +31 -0
- package/src/hooks/useProcessorDependencies.ts +42 -0
- package/src/index.ts +11 -0
- package/src/lifecycle.ts +32 -0
- package/src/post-submission-actions/mark-patient-deceased-action.ts +68 -0
- package/src/post-submission-actions/program-enrollment-action.ts +137 -0
- package/src/processors/encounter/encounter-form-processor.ts +445 -0
- package/src/processors/encounter/encounter-processor-helper.ts +387 -0
- package/src/processors/form-processor.ts +40 -0
- package/src/provider/form-factory-helper.ts +106 -0
- package/src/provider/form-factory-provider.tsx +211 -0
- package/src/provider/form-provider.tsx +39 -0
- package/src/registry/inbuilt-components/InbuiltPostSubmissionActions.ts +13 -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 +74 -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.ts +290 -0
- package/src/transformers/default-schema-transformer.ts +340 -0
- package/src/types/domain.ts +237 -0
- package/src/types/index.ts +153 -0
- package/src/types/schema.ts +259 -0
- package/src/typings.d.ts +9 -0
- package/src/utils/boolean-utils.ts +25 -0
- package/src/utils/common-expression-helpers.ts +636 -0
- package/src/utils/common-utils.ts +108 -0
- package/src/utils/error-utils.ts +37 -0
- package/src/utils/expression-runner.ts +172 -0
- package/src/utils/form-helper.ts +283 -0
- package/src/utils/form-page-utils.ts +13 -0
- package/src/utils/forms-loader.ts +306 -0
- package/src/utils/post-submission-action-helper.ts +71 -0
- package/src/utils/zscore-service.ts +59 -0
- package/src/validators/conditional-answered-validator.ts +17 -0
- package/src/validators/date-validator.ts +19 -0
- package/src/validators/default-value-validator.ts +36 -0
- package/src/validators/form-validator.ts +95 -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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function evaluatePostSubmissionExpression(expression, encounters) {
|
|
2
|
+
const encounter = encounters[0];
|
|
3
|
+
const regx = /(?:\w+|'(?:\\'|[^'\n])*')/g;
|
|
4
|
+
let match;
|
|
5
|
+
const fieldIds = new Set();
|
|
6
|
+
try {
|
|
7
|
+
while(match = regx.exec(expression)){
|
|
8
|
+
const value = match[0].replace(/\\'/g, "'"); // Replace escaped single quotes
|
|
9
|
+
const isBoolean = /^(true|false)$/i.test(value);
|
|
10
|
+
const isNumber = /^-?\d+$/.test(value);
|
|
11
|
+
const isFloat = /^-?\d+\.\d+$/.test(value);
|
|
12
|
+
if (!(value.startsWith("'") && value.endsWith("'")) && typeof value === 'string' && !isBoolean && !isNumber && !isFloat) {
|
|
13
|
+
fieldIds.add(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let fieldToValueMap = {};
|
|
17
|
+
let replacedExpression;
|
|
18
|
+
if (fieldIds.size) {
|
|
19
|
+
fieldToValueMap = getFieldValues(fieldIds, encounter);
|
|
20
|
+
}
|
|
21
|
+
if (Object.keys(fieldToValueMap).length) {
|
|
22
|
+
replacedExpression = expression.replace(/(\w+)/g, (match)=>{
|
|
23
|
+
return Object.prototype.hasOwnProperty.call(fieldToValueMap, match) ? fieldToValueMap[match] : match;
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
replacedExpression = expression;
|
|
27
|
+
}
|
|
28
|
+
return eval(replacedExpression);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error('Error evaluating expression');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function getFieldValues(fieldIds, encounter) {
|
|
34
|
+
const result = {};
|
|
35
|
+
fieldIds.forEach((fieldId)=>{
|
|
36
|
+
let value = encounter.obs?.find((item)=>item.formFieldPath.includes(fieldId))?.value;
|
|
37
|
+
if (typeof value === 'object') {
|
|
38
|
+
value = value.uuid;
|
|
39
|
+
}
|
|
40
|
+
if (value) {
|
|
41
|
+
value = formatValue(value);
|
|
42
|
+
}
|
|
43
|
+
result[fieldId] = value;
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//This function wraps string values in single quotes which Javascript will evaluate
|
|
48
|
+
function formatValue(value) {
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
if (value.length >= 2 && value[0] === "'" && value[value.length - 1] === "'") {
|
|
51
|
+
return value;
|
|
52
|
+
} else {
|
|
53
|
+
return `'${value}'`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export async function findNumberInput(screen, name) {
|
|
2
|
+
return await screen.findByRole('spinbutton', {
|
|
3
|
+
name
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
export async function findTextOrDateInput(screen, name) {
|
|
7
|
+
return await screen.findByRole('textbox', {
|
|
8
|
+
name
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export async function findRadioGroupInput(screen, name) {
|
|
12
|
+
return await screen.findByRole('group', {
|
|
13
|
+
name
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export async function findRadioGroupMember(screen, name) {
|
|
17
|
+
return await screen.findByRole('radio', {
|
|
18
|
+
name
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export async function findCheckboxGroup(screen, name) {
|
|
22
|
+
return await screen.findByRole('group', {
|
|
23
|
+
name: new RegExp(name, 'i')
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export async function findCheckboxSearchable(screen, nameSubstring) {
|
|
27
|
+
return await screen.findByRole('combobox', {
|
|
28
|
+
name: new RegExp(nameSubstring, 'i')
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export async function findSelectInput(screen, name) {
|
|
32
|
+
return await screen.findByRole('combobox', {
|
|
33
|
+
name
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export async function findAllRadioGroupInputs(screen, name) {
|
|
37
|
+
return await screen.queryAllByRole('group', {
|
|
38
|
+
name
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function findAllRadioGroupMembers(screen, name) {
|
|
42
|
+
return await screen.queryAllByRole('radio', {
|
|
43
|
+
name
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export async function findAllTextOrDateInputs(screen, name) {
|
|
47
|
+
return await screen.queryAllByRole('textbox', {
|
|
48
|
+
name
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const fieldTypeToGetterMap = {
|
|
52
|
+
text: findTextOrDateInput,
|
|
53
|
+
date: findTextOrDateInput,
|
|
54
|
+
number: findNumberInput,
|
|
55
|
+
radio: findRadioGroupInput,
|
|
56
|
+
'radio-group': findRadioGroupInput,
|
|
57
|
+
'radio-item': findRadioGroupMember,
|
|
58
|
+
textarea: findTextOrDateInput,
|
|
59
|
+
checkbox: findCheckboxGroup,
|
|
60
|
+
'checkbox-searchable': findCheckboxSearchable,
|
|
61
|
+
select: findSelectInput
|
|
62
|
+
};
|
|
63
|
+
export async function assertFormHasAllFields(screen, fields) {
|
|
64
|
+
const fieldsInDom = await Promise.all(fields.map(({ fieldName, fieldType })=>fieldTypeToGetterMap[fieldType](screen, fieldName)));
|
|
65
|
+
await Promise.all(fieldsInDom.map((field)=>expect(field).toBeInTheDocument()));
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zscore-service.d.ts","sourceRoot":"","sources":["../../src/utils/zscore-service.ts"],"names":[],"mappings":"AAWA,wBAAgB,qBAAqB,CAAC,MAAM,KAAA,EAAE,SAAS,KAAA,EAAE,OAAO,KAAA;;;;EAgC/D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import filter from "lodash/filter";
|
|
2
|
+
import bfaMale5Above from "../zscore/bfa_boys_5_above.json";
|
|
3
|
+
import wflMaleBelow5 from "../zscore/wfl_boys_below5.json";
|
|
4
|
+
import hfaMale5Above from "../zscore/hfa_boys_5_above.json";
|
|
5
|
+
import hfaMaleBelow5 from "../zscore/hfa_boys_below5.json";
|
|
6
|
+
import bfaFemale5Above from "../zscore/bfa_girls_5_above.json";
|
|
7
|
+
import wflFemaleBelow5 from "../zscore/wfl_girls_below5.json";
|
|
8
|
+
import hfaFemale5Above from "../zscore/hfa_girls_5_above.json";
|
|
9
|
+
import hfaFemaleBelow5 from "../zscore/hfa_girls_below5.json";
|
|
10
|
+
import dayjs from "dayjs";
|
|
11
|
+
export function getZRefByGenderAndAge(gender, birthDate, refdate) {
|
|
12
|
+
const scoreRefModel = {
|
|
13
|
+
weightForHeightRef: null,
|
|
14
|
+
heightForAgeRef: null,
|
|
15
|
+
bmiForAgeRef: null
|
|
16
|
+
};
|
|
17
|
+
const age = getAge(birthDate, refdate, 'years');
|
|
18
|
+
const ageInMonths = getAge(birthDate, refdate, 'months');
|
|
19
|
+
const ageInDays = getAge(birthDate, refdate, 'days');
|
|
20
|
+
if (gender === 'F') {
|
|
21
|
+
if (age < 5) {
|
|
22
|
+
scoreRefModel.weightForHeightRef = wflFemaleBelow5;
|
|
23
|
+
scoreRefModel.heightForAgeRef = getScoreReference(hfaFemaleBelow5, 'Day', ageInDays);
|
|
24
|
+
}
|
|
25
|
+
if (age >= 5 && age < 18) {
|
|
26
|
+
scoreRefModel.bmiForAgeRef = getScoreReference(bfaFemale5Above, 'Month', ageInMonths);
|
|
27
|
+
scoreRefModel.heightForAgeRef = getScoreReference(hfaFemale5Above, 'Month', ageInMonths);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (gender === 'M') {
|
|
31
|
+
if (age < 5) {
|
|
32
|
+
scoreRefModel.weightForHeightRef = wflMaleBelow5;
|
|
33
|
+
scoreRefModel.heightForAgeRef = getScoreReference(hfaMaleBelow5, 'Day', ageInDays);
|
|
34
|
+
}
|
|
35
|
+
if (age >= 5 && age < 18) {
|
|
36
|
+
scoreRefModel.bmiForAgeRef = getScoreReference(bfaMale5Above, 'Month', ageInMonths);
|
|
37
|
+
scoreRefModel.heightForAgeRef = getScoreReference(hfaMale5Above, 'Month', ageInMonths);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return scoreRefModel;
|
|
41
|
+
}
|
|
42
|
+
function getScoreReference(refData, searchKey, searchValue) {
|
|
43
|
+
return filter(refData, (refObject)=>{
|
|
44
|
+
return refObject[searchKey] === searchValue;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function getAge(birthdate, refDate, ageIn) {
|
|
48
|
+
if (birthdate && refDate && ageIn) {
|
|
49
|
+
const todayMoment = dayjs(refDate);
|
|
50
|
+
const birthDateMoment = dayjs(birthdate);
|
|
51
|
+
return todayMoment.diff(birthDateMoment, ageIn);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-answered-validator.d.ts","sourceRoot":"","sources":["../../src/validators/conditional-answered-validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,UAAU,CAAC;AAEnE,eAAO,MAAM,4BAA4B,EAAE,kBAa1C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isEmpty } from "./form-validator.js";
|
|
2
|
+
export const conditionalAnsweredValidator = {
|
|
3
|
+
validate: function(field, value, config) {
|
|
4
|
+
const { referenceQuestionId, referenceQuestionAnswers, values, formFields, message } = config;
|
|
5
|
+
const referencedField = formFields.find((field)=>field.id === referenceQuestionId);
|
|
6
|
+
const referencedFieldValue = values[referencedField.id];
|
|
7
|
+
if (!isEmpty(value) && !referenceQuestionAnswers.includes(referencedFieldValue)) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
resultType: 'error',
|
|
11
|
+
errCode: 'invalid.valueSelected',
|
|
12
|
+
message: message
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { conditionalAnsweredValidator } from "./conditional-answered-validator.js";
|
|
2
|
+
import { isEmpty } from "./form-validator.js";
|
|
3
|
+
jest.mock('../validators/form-validator', ()=>({
|
|
4
|
+
isEmpty: jest.fn()
|
|
5
|
+
}));
|
|
6
|
+
describe('conditionalAnsweredValidator', ()=>{
|
|
7
|
+
let field;
|
|
8
|
+
let value;
|
|
9
|
+
let config;
|
|
10
|
+
beforeEach(()=>{
|
|
11
|
+
field = {
|
|
12
|
+
label: 'Test Field',
|
|
13
|
+
type: 'obs',
|
|
14
|
+
questionOptions: {
|
|
15
|
+
rendering: 'repeating',
|
|
16
|
+
concept: 'j8b6705b-b6d8-4eju-8f37-0b14f5347569'
|
|
17
|
+
},
|
|
18
|
+
id: 'testFieldId'
|
|
19
|
+
};
|
|
20
|
+
config = {
|
|
21
|
+
referenceQuestionId: 'referenceQuestionId',
|
|
22
|
+
referenceQuestionAnswers: [
|
|
23
|
+
'answer1',
|
|
24
|
+
'answer2'
|
|
25
|
+
],
|
|
26
|
+
values: {
|
|
27
|
+
referenceQuestionId: 'answer1'
|
|
28
|
+
},
|
|
29
|
+
formFields: [
|
|
30
|
+
{
|
|
31
|
+
id: 'referenceQuestionId'
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
message: 'Invalid value selected'
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
it('should return no error if value is empty', ()=>{
|
|
38
|
+
isEmpty.mockReturnValue(true);
|
|
39
|
+
value = '';
|
|
40
|
+
const result = conditionalAnsweredValidator.validate(field, value, config);
|
|
41
|
+
expect(result).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
it('should return no error if value is not empty and reference question answer is included', ()=>{
|
|
44
|
+
isEmpty.mockReturnValue(false);
|
|
45
|
+
value = 'some value';
|
|
46
|
+
config.values.referenceQuestionId = 'answer1';
|
|
47
|
+
const result = conditionalAnsweredValidator.validate(field, value, config);
|
|
48
|
+
expect(result).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
it('should return an error if value is not empty and reference question answer is not included', ()=>{
|
|
51
|
+
isEmpty.mockReturnValue(false);
|
|
52
|
+
value = 'some value';
|
|
53
|
+
config.values.referenceQuestionId = 'answer3';
|
|
54
|
+
const result = conditionalAnsweredValidator.validate(field, value, config);
|
|
55
|
+
expect(result).toEqual([
|
|
56
|
+
{
|
|
57
|
+
resultType: 'error',
|
|
58
|
+
errCode: 'invalid.valueSelected',
|
|
59
|
+
message: 'Invalid value selected'
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-validator.d.ts","sourceRoot":"","sources":["../../src/validators/date-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,UAAU,CAAC;AAInE,eAAO,MAAM,aAAa,EAAE,kBAc3B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isTrue } from "../utils/boolean-utils.js";
|
|
2
|
+
import { FieldValidator } from "./form-validator.js";
|
|
3
|
+
export const DateValidator = {
|
|
4
|
+
validate: (field, value, config)=>{
|
|
5
|
+
const now = new Date();
|
|
6
|
+
const errors = !value ? FieldValidator.validate(field, value) : [];
|
|
7
|
+
if (errors.length) {
|
|
8
|
+
return errors;
|
|
9
|
+
}
|
|
10
|
+
if (value && !isTrue(config?.allowFutureDates)) {
|
|
11
|
+
return value.getTime && value.getTime() > now.getTime() ? [
|
|
12
|
+
{
|
|
13
|
+
resultType: 'error',
|
|
14
|
+
errCode: 'value.invalid',
|
|
15
|
+
message: 'Future dates not allowed'
|
|
16
|
+
}
|
|
17
|
+
] : [];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DateValidator } from "./date-validator.js";
|
|
2
|
+
describe('DateValidator - validate', ()=>{
|
|
3
|
+
const field = {
|
|
4
|
+
label: 'HTS Date',
|
|
5
|
+
type: 'obs',
|
|
6
|
+
questionOptions: {
|
|
7
|
+
rendering: 'date',
|
|
8
|
+
concept: 'j8b6705b-b6d8-4eju-8f37-0b14f5347569'
|
|
9
|
+
},
|
|
10
|
+
isRequired: true,
|
|
11
|
+
required: true,
|
|
12
|
+
validators: [
|
|
13
|
+
{
|
|
14
|
+
type: 'date',
|
|
15
|
+
allowFutureDates: 'false'
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
meta: {},
|
|
19
|
+
id: 'hts-date'
|
|
20
|
+
};
|
|
21
|
+
it('should reject if an empty date is provided for a required field', ()=>{
|
|
22
|
+
// setup and replay
|
|
23
|
+
const errors = DateValidator.validate(field, null, field.validators[0]);
|
|
24
|
+
// verify
|
|
25
|
+
expect(errors).toEqual([
|
|
26
|
+
{
|
|
27
|
+
errCode: 'field.required',
|
|
28
|
+
message: 'Field is mandatory',
|
|
29
|
+
resultType: 'error'
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
it('should by default reject future dates', ()=>{
|
|
34
|
+
// setup and replay
|
|
35
|
+
const errors = DateValidator.validate(field, new Date('December 17, 2032 03:24:00'), null);
|
|
36
|
+
// verify
|
|
37
|
+
expect(errors).toEqual([
|
|
38
|
+
{
|
|
39
|
+
errCode: 'value.invalid',
|
|
40
|
+
message: 'Future dates not allowed',
|
|
41
|
+
resultType: 'error'
|
|
42
|
+
}
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
it('should accept future dates for fields supporting them', ()=>{
|
|
46
|
+
// setup and replay
|
|
47
|
+
const errors = DateValidator.validate(field, new Date('December 17, 2032 03:24:00'), {
|
|
48
|
+
allowFutureDates: true
|
|
49
|
+
});
|
|
50
|
+
// verify
|
|
51
|
+
expect(errors).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-value-validator.d.ts","sourceRoot":"","sources":["../../src/validators/default-value-validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,UAAU,CAAC;AAInE,eAAO,MAAM,qBAAqB,EAAE,kBA8BnC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { codedTypes } from "../constants.js";
|
|
3
|
+
import { isEmpty } from "./form-validator.js";
|
|
4
|
+
export const DefaultValueValidator = {
|
|
5
|
+
validate: (field, value)=>{
|
|
6
|
+
if (!isEmpty(value) && codedTypes.includes(field.questionOptions.rendering)) {
|
|
7
|
+
const valuesArray = Array.isArray(value) ? value : [
|
|
8
|
+
value
|
|
9
|
+
];
|
|
10
|
+
// check whether value exists in answers
|
|
11
|
+
if (!valuesArray.every((val)=>field.questionOptions.answers?.find((answer)=>answer.concept === val || answer.value === val))) {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
resultType: 'error',
|
|
15
|
+
errCode: 'invalid.defaultValue',
|
|
16
|
+
message: 'Value not found in coded answers list'
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!isEmpty(value) && field.questionOptions.rendering == 'date') {
|
|
22
|
+
// Check if value is a valid date value
|
|
23
|
+
if (!dayjs(value).isValid()) {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
resultType: 'error',
|
|
27
|
+
errCode: 'invalid.defaultValue',
|
|
28
|
+
message: `Invalid date value: '${value}'`
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!isEmpty(value) && field.questionOptions.rendering == 'number') {
|
|
34
|
+
if (isNaN(value)) {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
resultType: 'error',
|
|
38
|
+
errCode: 'invalid.defaultValue',
|
|
39
|
+
message: `Invalid numerical value: '${value}'`
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DefaultValueValidator } from "./default-value-validator.js";
|
|
2
|
+
describe('DefaultValueValidator - validate', ()=>{
|
|
3
|
+
// setup
|
|
4
|
+
const codedField = {
|
|
5
|
+
label: 'Past enrolled patient programs',
|
|
6
|
+
type: 'obs',
|
|
7
|
+
questionOptions: {
|
|
8
|
+
rendering: 'checkbox',
|
|
9
|
+
concept: '3hbkj9-b6d8-4eju-8f37-0b14f5347jv9',
|
|
10
|
+
answers: [
|
|
11
|
+
{
|
|
12
|
+
label: 'Oncology Screening and Diagnosis Program',
|
|
13
|
+
concept: '105e7ad6-c1fd-11eb-8529-0242ac130ju9'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: 'Fight Malaria Initiative',
|
|
17
|
+
concept: '305e7ad6-c1fd-11eb-8529-0242ac130003'
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
id: 'past-patient-programs'
|
|
22
|
+
};
|
|
23
|
+
const dateField = {
|
|
24
|
+
label: 'HTS Date',
|
|
25
|
+
type: 'obs',
|
|
26
|
+
questionOptions: {
|
|
27
|
+
rendering: 'date',
|
|
28
|
+
concept: 'j8b6705b-b6d8-4eju-8f37-0b14f5347569'
|
|
29
|
+
},
|
|
30
|
+
id: 'hts-date'
|
|
31
|
+
};
|
|
32
|
+
const numericField = {
|
|
33
|
+
label: 'Temperature',
|
|
34
|
+
type: 'obs',
|
|
35
|
+
questionOptions: {
|
|
36
|
+
rendering: 'number',
|
|
37
|
+
concept: '2c43u05b-b6d8-4eju-8f37-0b14f5347560'
|
|
38
|
+
},
|
|
39
|
+
id: 'temperature'
|
|
40
|
+
};
|
|
41
|
+
it('should accept valid values for coded types', ()=>{
|
|
42
|
+
// setup and replay
|
|
43
|
+
const errors = DefaultValueValidator.validate(codedField, '105e7ad6-c1fd-11eb-8529-0242ac130ju9');
|
|
44
|
+
// verify
|
|
45
|
+
expect(errors).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
it('should reject invalid values for coded types', ()=>{
|
|
48
|
+
// setup and replay
|
|
49
|
+
const errors = DefaultValueValidator.validate(codedField, 'some none existing value');
|
|
50
|
+
// verify
|
|
51
|
+
expect(errors).toEqual([
|
|
52
|
+
{
|
|
53
|
+
errCode: 'invalid.defaultValue',
|
|
54
|
+
message: 'Value not found in coded answers list',
|
|
55
|
+
resultType: 'error'
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
it('should accept valid date values', ()=>{
|
|
60
|
+
// setup and replay
|
|
61
|
+
const errors = DefaultValueValidator.validate(dateField, '2020-01-20');
|
|
62
|
+
// verify
|
|
63
|
+
expect(errors).toEqual([]);
|
|
64
|
+
});
|
|
65
|
+
it('should reject invalid date values', ()=>{
|
|
66
|
+
// setup and replay
|
|
67
|
+
const errors = DefaultValueValidator.validate(dateField, 'test date');
|
|
68
|
+
// verify
|
|
69
|
+
expect(errors).toEqual([
|
|
70
|
+
{
|
|
71
|
+
errCode: 'invalid.defaultValue',
|
|
72
|
+
message: `Invalid date value: 'test date'`,
|
|
73
|
+
resultType: 'error'
|
|
74
|
+
}
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
it('should accept valid numeric values', ()=>{
|
|
78
|
+
// setup and replay
|
|
79
|
+
const errors = DefaultValueValidator.validate(numericField, '500.5');
|
|
80
|
+
// verify
|
|
81
|
+
expect(errors).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
it('should reject invalid numeric values', ()=>{
|
|
84
|
+
// setup and replay
|
|
85
|
+
const errors = DefaultValueValidator.validate(numericField, '500.5hds');
|
|
86
|
+
// verify
|
|
87
|
+
expect(errors).toEqual([
|
|
88
|
+
{
|
|
89
|
+
errCode: 'invalid.defaultValue',
|
|
90
|
+
message: `Invalid numerical value: '500.5hds'`,
|
|
91
|
+
resultType: 'error'
|
|
92
|
+
}
|
|
93
|
+
]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type FormFieldValidator } from '../types';
|
|
2
|
+
export declare const fieldRequiredErrCode = "field.required";
|
|
3
|
+
export declare const fieldOutOfBoundErrCode = "field.outOfBound";
|
|
4
|
+
export declare const FieldValidator: FormFieldValidator;
|
|
5
|
+
export declare function numberInputRangeValidator(min: number, max: number, inputValue: number): any[] | [{}];
|
|
6
|
+
export declare function isEmpty(value: any): boolean;
|
|
7
|
+
export declare function textInputLengthValidator(minLength: string, maxLength: string, inputLength: number): any[] | [{}];
|
|
8
|
+
export declare function addError(errorCode: string, message: string): [{}];
|
|
9
|
+
//# sourceMappingURL=form-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-validator.d.ts","sourceRoot":"","sources":["../../src/validators/form-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,UAAU,CAAC;AACnE,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD,eAAO,MAAM,cAAc,EAAE,kBAgC5B,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAUrF;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAW3C;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,gBAqBjG;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,CAQjE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const fieldRequiredErrCode = 'field.required';
|
|
2
|
+
export const fieldOutOfBoundErrCode = 'field.outOfBound';
|
|
3
|
+
export const FieldValidator = {
|
|
4
|
+
validate: (field, value)=>{
|
|
5
|
+
if (field.meta?.submission?.unspecified) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
if (isEmpty(value) && field.isRequired) {
|
|
9
|
+
if (typeof field.required === 'object' && field.required.type === 'conditionalRequired' && field.isRequired) {
|
|
10
|
+
return addError(fieldRequiredErrCode, field.required.message ?? 'Field is mandatory');
|
|
11
|
+
} else if (field.isRequired) {
|
|
12
|
+
return addError(fieldRequiredErrCode, 'Field is mandatory');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (field.questionOptions.rendering === 'text') {
|
|
16
|
+
const minLength = field.questionOptions.minLength;
|
|
17
|
+
const maxLength = field.questionOptions.maxLength;
|
|
18
|
+
return textInputLengthValidator(minLength, maxLength, value?.length) ?? [];
|
|
19
|
+
}
|
|
20
|
+
if (field.questionOptions.rendering === 'number') {
|
|
21
|
+
const min = Number(field.questionOptions.min);
|
|
22
|
+
const max = Number(field.questionOptions.max);
|
|
23
|
+
const disallowDecimals = field.questionOptions.disallowDecimals || field.meta?.concept?.allowDecimal;
|
|
24
|
+
if (isEmpty(value)) return [];
|
|
25
|
+
if (disallowDecimals && !Number.isInteger(value)) {
|
|
26
|
+
return addError(fieldOutOfBoundErrCode, 'Decimal values are not allowed for this field');
|
|
27
|
+
}
|
|
28
|
+
if (!Number.isNaN(min) || !Number.isNaN(max)) {
|
|
29
|
+
return numberInputRangeValidator(min, max, value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export function numberInputRangeValidator(min, max, inputValue) {
|
|
36
|
+
if (!Number.isNaN(min) && inputValue < min) {
|
|
37
|
+
return addError(fieldOutOfBoundErrCode, `Value must be greater than ${min}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isNaN(max) && inputValue > max) {
|
|
40
|
+
return addError(fieldOutOfBoundErrCode, `Value must be lower than ${max}`);
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
export function isEmpty(value) {
|
|
45
|
+
if (value === undefined || value === null || value === '') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value == 'string' && !value?.trim()) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value) && !value.length) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
export function textInputLengthValidator(minLength, maxLength, inputLength) {
|
|
57
|
+
const minLen = Number(minLength);
|
|
58
|
+
const maxLen = Number(maxLength);
|
|
59
|
+
if (typeof inputLength === 'number' && !Number.isNaN(inputLength)) {
|
|
60
|
+
if (minLen && maxLen && inputLength >= minLen && inputLength <= maxLen) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
if (minLen && inputLength < minLen) {
|
|
64
|
+
return addError(fieldOutOfBoundErrCode, `Length should be at least ${minLen} characters`);
|
|
65
|
+
}
|
|
66
|
+
if (maxLen && inputLength > maxLen) {
|
|
67
|
+
return addError(fieldOutOfBoundErrCode, `Length should not exceed ${maxLen} characters`);
|
|
68
|
+
}
|
|
69
|
+
if (maxLen && minLen && inputLength < minLen && inputLength > maxLen) {
|
|
70
|
+
return addError(fieldOutOfBoundErrCode, `Length should be between ${minLen} and ${maxLen} characters`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function addError(errorCode, message) {
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
resultType: 'error',
|
|
78
|
+
errCode: errorCode,
|
|
79
|
+
message: message
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
}
|