From aed3e647badefedef9527012457d7d2ad2e09670 Mon Sep 17 00:00:00 2001 From: gitcliff Date: Mon, 22 Apr 2024 15:29:25 +0300 Subject: [PATCH] 03-2167:adding concept to the meta object --- src/api/OHRIFormField.ts | 32 +++++++++++++++++++ src/api/types.ts | 5 ++- .../ohri-encounter-form.component.tsx | 8 ++--- .../ohri-content-switcher.test.tsx | 2 +- .../inputs/date/ohri-date.component.tsx | 1 - src/components/inputs/file/file.component.tsx | 1 - .../ohri-encounter-location.component.tsx | 2 +- .../inputs/radio/ohri-radio.component.tsx | 2 -- .../inputs/select/ohri-dropdown.component.tsx | 1 - .../inputs/select/ohri-dropdown.test.tsx | 5 ++- .../text-area/ohri-text-area.component.tsx | 1 - .../inputs/text/ohri-text.component.tsx | 2 -- .../inputs/toggle/ohri-toggle.component.tsx | 1 - .../inputs/tooltip/ohri-tooltip.tsx | 2 +- .../ui-select-extended.test.tsx | 2 +- src/components/repeat/helpers.ts | 2 +- .../repeat/ohri-repeat.component.tsx | 3 +- src/components/section/helpers.ts | 2 +- .../section/ohri-form-section.component.tsx | 3 +- src/hooks/useFormFieldHandlers.tsx | 7 ++-- src/hooks/useFormFieldValidators.ts | 9 +++--- src/hooks/useInitialValues.test.ts | 3 +- src/hooks/useInitialValues.ts | 3 +- src/ohri-form-context.tsx | 3 +- src/submission-handlers/base-handlers.test.ts | 2 +- src/submission-handlers/base-handlers.ts | 3 +- .../encounterDatetimeHandler.ts | 3 +- .../encounterLocationHandler.ts | 3 +- .../encounterProviderHandler.ts | 3 +- .../angular-fe-schema-transformer.ts | 3 +- src/utils/common-expression-helpers.ts | 2 +- src/utils/common-utils.ts | 3 +- src/utils/expression-parser.test.ts | 8 ++--- src/utils/expression-parser.ts | 2 +- src/utils/expression-runner.test.ts | 8 ++--- src/utils/expression-runner.ts | 3 +- src/utils/forms-loader.ts | 2 +- src/utils/ohri-form-helper.ts | 3 +- .../default-value-validator.test.ts | 2 +- src/validators/default-value-validator.ts | 5 +-- src/validators/ohri-date-validator.test.ts | 2 +- src/validators/ohri-date-validator.ts | 3 +- src/validators/ohri-form-validator.test.ts | 2 +- src/validators/ohri-form-validator.ts | 3 +- .../ohri-js-expression-validator.test.ts | 4 +-- .../ohri-js-expression-validator.ts | 9 +++--- 46 files changed, 112 insertions(+), 68 deletions(-) create mode 100644 src/api/OHRIFormField.ts diff --git a/src/api/OHRIFormField.ts b/src/api/OHRIFormField.ts new file mode 100644 index 000000000..1ca38f3e4 --- /dev/null +++ b/src/api/OHRIFormField.ts @@ -0,0 +1,32 @@ +import { OpenmrsResource } from '@openmrs/esm-framework'; +import { OHRIFormQuestionOptions, HideProps } from './types'; + +export interface OHRIFormField { + label: string; + type: string; + questionOptions: OHRIFormQuestionOptions; + id: string; + uuid?: string; + groupId?: string; + questions?: Array; + value?: any; + hide?: HideProps; + isHidden?: boolean; + isParentHidden?: boolean; + fieldDependants?: Set; + pageDependants?: Set; + sectionDependants?: Set; + required?: boolean; + unspecified?: boolean; + disabled?: boolean; + readonly?: string | boolean; + inlineRendering?: 'single-line' | 'multiline' | 'automatic'; + validators?: Array>; + behaviours?: Array>; + questionInfo?: string; + constrainMaxWidth?: boolean; + meta?: { + concept?: OpenmrsResource; + [anythingElse: string]: any; + }; +} diff --git a/src/api/types.ts b/src/api/types.ts index 465705fd1..71024fbd4 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -118,7 +118,10 @@ export interface OHRIFormField { behaviours?: Array>; questionInfo?: string; constrainMaxWidth?: boolean; - meta?:{ concept? : OpenmrsResource}; + meta?: { + concept? : OpenmrsResource, + [anythingElse: string]: any; + }; } export interface previousValue { diff --git a/src/components/encounter/ohri-encounter-form.component.tsx b/src/components/encounter/ohri-encounter-form.component.tsx index b95e384e3..f11132fc3 100644 --- a/src/components/encounter/ohri-encounter-form.component.tsx +++ b/src/components/encounter/ohri-encounter-form.component.tsx @@ -2,7 +2,6 @@ import React, { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useSt import { SessionLocation, showToast, useLayoutType, Visit } from '@openmrs/esm-framework'; import { ConceptFalse, ConceptTrue } from '../../constants'; import { - OHRIFormField, OHRIFormPage as OHRIFormPageProps, OHRIFormSchema, OpenmrsEncounter, @@ -10,6 +9,7 @@ import { ValidationResult, RepeatObsGroupCounter, } from '../../api/types'; +import { OHRIFormField } from '../../api/OHRIFormField'; import OHRIFormPage from '../page/ohri-form-page'; import { OHRIFormContext } from '../../ohri-form-context'; import { @@ -263,9 +263,9 @@ export const OHRIEncounterForm: React.FC = ({ const matchingConcept = findConceptByReference(field.questionOptions.concept, concepts); field.questionOptions.concept = matchingConcept ? matchingConcept.uuid : field.questionOptions.concept; field.label = field.label ? field.label : matchingConcept?.display; - field.meta ={ - concept: matchingConcept - } + field.meta = { + concept: matchingConcept, + }; if (field.questionOptions.answers) { field.questionOptions.answers = field.questionOptions.answers.map((answer) => { const matchingAnswerConcept = findConceptByReference(answer.concept, concepts); diff --git a/src/components/inputs/content-switcher/ohri-content-switcher.test.tsx b/src/components/inputs/content-switcher/ohri-content-switcher.test.tsx index bd2de0a39..cba78b949 100644 --- a/src/components/inputs/content-switcher/ohri-content-switcher.test.tsx +++ b/src/components/inputs/content-switcher/ohri-content-switcher.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { render, fireEvent, screen, cleanup, act, waitFor } from '@testing-library/react'; import { Form, Formik } from 'formik'; import { EncounterContext, OHRIFormContext } from '../../../ohri-form-context'; -import { OHRIFormField } from '../../../api/types'; +import { OHRIFormField } from '../../../api/OHRIFormField'; import { ObsSubmissionHandler } from '../../../submission-handlers/base-handlers'; import { OHRIContentSwitcher } from './ohri-content-switcher.component'; diff --git a/src/components/inputs/date/ohri-date.component.tsx b/src/components/inputs/date/ohri-date.component.tsx index e966369ee..7f154f099 100644 --- a/src/components/inputs/date/ohri-date.component.tsx +++ b/src/components/inputs/date/ohri-date.component.tsx @@ -22,7 +22,6 @@ const OHRIDate: React.FC = ({ question, onChange, handler, p const isFieldRequiredError = useMemo(() => errors[0]?.errCode == fieldRequiredErrCode, [errors]); const [previousValueForReview, setPreviousValueForReview] = useState(null); const [time, setTime] = useState(''); - useEffect(() => { if (question['submission']) { question['submission'].errors && setErrors(question['submission'].errors); diff --git a/src/components/inputs/file/file.component.tsx b/src/components/inputs/file/file.component.tsx index 73adb80a3..3ddcffc0d 100644 --- a/src/components/inputs/file/file.component.tsx +++ b/src/components/inputs/file/file.component.tsx @@ -22,7 +22,6 @@ const File: React.FC = ({ question, onChange, handler }) => { const [selectedFiles, setSelectedFiles] = useState(null); // Add state for selected files const [imagePreview, setImagePreview] = useState(null); const [uploadMode, setUploadMode] = useState(''); - useEffect(() => { if (encounterContext.sessionMode === 'edit') { setUploadMode('edit'); diff --git a/src/components/inputs/location/ohri-encounter-location.component.tsx b/src/components/inputs/location/ohri-encounter-location.component.tsx index feb7023f5..8223b86c1 100644 --- a/src/components/inputs/location/ohri-encounter-location.component.tsx +++ b/src/components/inputs/location/ohri-encounter-location.component.tsx @@ -5,7 +5,7 @@ import { createErrorHandler } from '@openmrs/esm-framework'; import { isInlineView } from '../../../utils/ohri-form-helper'; import { getAllLocations, getLocationsByTag } from '../../../api/api'; import { isTrue } from '../../../utils/boolean-utils'; -import { OHRIFormField } from '../../../api/types'; +import { OHRIFormField } from '../../../api/OHRIFormField'; import { OHRIFormContext } from '../../../ohri-form-context'; import { OHRIFieldValueView } from '../../value/view/ohri-field-value-view.component'; import styles from './ohri-encounter-location.scss'; diff --git a/src/components/inputs/radio/ohri-radio.component.tsx b/src/components/inputs/radio/ohri-radio.component.tsx index 6f35d6442..a2f7b0501 100644 --- a/src/components/inputs/radio/ohri-radio.component.tsx +++ b/src/components/inputs/radio/ohri-radio.component.tsx @@ -15,8 +15,6 @@ const OHRIRadio: React.FC = ({ question, onChange, handler, const [errors, setErrors] = useState([]); const isFieldRequiredError = useMemo(() => errors[0]?.errCode == fieldRequiredErrCode, [errors]); const [warnings, setWarnings] = useState([]); - - useEffect(() => { if (question['submission']) { question['submission'].errors && setErrors(question['submission'].errors); diff --git a/src/components/inputs/select/ohri-dropdown.component.tsx b/src/components/inputs/select/ohri-dropdown.component.tsx index f89a574e1..22e973465 100644 --- a/src/components/inputs/select/ohri-dropdown.component.tsx +++ b/src/components/inputs/select/ohri-dropdown.component.tsx @@ -16,7 +16,6 @@ const OHRIDropdown: React.FC = ({ question, onChange, handle const [errors, setErrors] = useState([]); const isFieldRequiredError = useMemo(() => errors[0]?.errCode == fieldRequiredErrCode, [errors]); const [warnings, setWarnings] = useState([]); - useEffect(() => { if (question['submission']) { question['submission'].errors && setErrors(question['submission'].errors); diff --git a/src/components/inputs/select/ohri-dropdown.test.tsx b/src/components/inputs/select/ohri-dropdown.test.tsx index 1f9ed377a..acfdc7528 100644 --- a/src/components/inputs/select/ohri-dropdown.test.tsx +++ b/src/components/inputs/select/ohri-dropdown.test.tsx @@ -3,7 +3,7 @@ import { render, fireEvent, screen, cleanup, act } from '@testing-library/react' import { Form, Formik } from 'formik'; import { EncounterContext, OHRIFormContext } from '../../../ohri-form-context'; import OHRIDropdown from './ohri-dropdown.component'; -import { OHRIFormField } from '../../../api/types'; +import { OHRIFormField } from '../../../api/OHRIFormField'; import { ObsSubmissionHandler } from '../../../submission-handlers/base-handlers'; const question: OHRIFormField = { @@ -67,8 +67,7 @@ const renderForm = (intialValues) => { isFieldInitializationComplete: true, isSubmitting: false, formFieldHandlers: { obs: ObsSubmissionHandler }, - }} - > + }}> diff --git a/src/components/inputs/text-area/ohri-text-area.component.tsx b/src/components/inputs/text-area/ohri-text-area.component.tsx index 259f1cbc2..ac51f7430 100644 --- a/src/components/inputs/text-area/ohri-text-area.component.tsx +++ b/src/components/inputs/text-area/ohri-text-area.component.tsx @@ -21,7 +21,6 @@ const OHRITextArea: React.FC = ({ const [errors, setErrors] = useState([]); const isFieldRequiredError = useMemo(() => errors[0]?.errCode == fieldRequiredErrCode, [errors]); const [warnings, setWarnings] = useState([]); - useEffect(() => { if (question['submission']) { question['submission'].errors && setErrors(question['submission'].errors); diff --git a/src/components/inputs/text/ohri-text.component.tsx b/src/components/inputs/text/ohri-text.component.tsx index fee2a69b8..e68f8d080 100644 --- a/src/components/inputs/text/ohri-text.component.tsx +++ b/src/components/inputs/text/ohri-text.component.tsx @@ -16,8 +16,6 @@ const OHRIText: React.FC = ({ question, onChange, handler, p const [errors, setErrors] = useState([]); const [warnings, setWarnings] = useState([]); const isFieldRequiredError = useMemo(() => errors[0]?.errCode == fieldRequiredErrCode, [errors]); - - useEffect(() => { if (question['submission']) { question['submission'].errors && setErrors(question['submission'].errors); diff --git a/src/components/inputs/toggle/ohri-toggle.component.tsx b/src/components/inputs/toggle/ohri-toggle.component.tsx index 1388d46d6..9ea5c7744 100644 --- a/src/components/inputs/toggle/ohri-toggle.component.tsx +++ b/src/components/inputs/toggle/ohri-toggle.component.tsx @@ -13,7 +13,6 @@ import { booleanConceptToBoolean } from '../../../utils/common-expression-helper const OHRIToggle: React.FC = ({ question, onChange, handler, previousValue }) => { const [field, meta] = useField(question.id); const { setFieldValue, encounterContext, layoutType, workspaceLayout } = React.useContext(OHRIFormContext); - const handleChange = (value) => { setFieldValue(question.id, value); onChange(question.id, value, null, null); diff --git a/src/components/inputs/tooltip/ohri-tooltip.tsx b/src/components/inputs/tooltip/ohri-tooltip.tsx index 7354c7c49..06b9d3650 100644 --- a/src/components/inputs/tooltip/ohri-tooltip.tsx +++ b/src/components/inputs/tooltip/ohri-tooltip.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Tooltip } from '@carbon/react'; import { Information } from '@carbon/react/icons'; import styles from './ohri-tooltip.scss'; -import { OHRIFormField } from '../../../api/types'; +import { OHRIFormField } from '../../../api/OHRIFormField'; interface OHRITooltipProps { field: OHRIFormField; diff --git a/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx b/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx index 44050f9a7..411237e8f 100644 --- a/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx +++ b/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render, fireEvent, waitFor, act, screen } from '@testing-library/react'; import UISelectExtended from './ui-select-extended'; -import { OHRIFormField } from '../../../api/types'; +import { OHRIFormField } from '../../../api/OHRIFormField'; import { EncounterContext, OHRIFormContext } from '../../../ohri-form-context'; import { Form, Formik } from 'formik'; import { ObsSubmissionHandler } from '../../../submission-handlers/base-handlers'; diff --git a/src/components/repeat/helpers.ts b/src/components/repeat/helpers.ts index c026c57d0..28f57a884 100644 --- a/src/components/repeat/helpers.ts +++ b/src/components/repeat/helpers.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../../api/types'; +import { OHRIFormField } from '../../api/OHRIFormField'; import { cloneDeep } from 'lodash-es'; export function cloneObsGroup(srcField: OHRIFormField, obsGroup: any, idSuffix: number) { diff --git a/src/components/repeat/ohri-repeat.component.tsx b/src/components/repeat/ohri-repeat.component.tsx index dd5425448..3d58e95ab 100644 --- a/src/components/repeat/ohri-repeat.component.tsx +++ b/src/components/repeat/ohri-repeat.component.tsx @@ -4,7 +4,8 @@ import { Add, TrashCan } from '@carbon/react/icons'; import { useFormikContext } from 'formik'; import { useTranslation } from 'react-i18next'; import { OHRIFormContext } from '../../ohri-form-context'; -import { OHRIFormField, OHRIFormFieldProps } from '../../api/types'; +import { OHRIFormFieldProps } from '../../api/types'; +import { OHRIFormField } from '../../api/OHRIFormField'; import { OHRIObsGroup } from '../group/ohri-obs-group.component'; import { evaluateAsyncExpression, evaluateExpression } from '../../utils/expression-runner'; import { isEmpty } from '../../validators/ohri-form-validator'; diff --git a/src/components/section/helpers.ts b/src/components/section/helpers.ts index d7c6c19a4..4e7fcf484 100644 --- a/src/components/section/helpers.ts +++ b/src/components/section/helpers.ts @@ -1,5 +1,5 @@ import { formatDate } from '@openmrs/esm-framework'; -import { OHRIFormField } from '../../api/types'; +import { OHRIFormField } from '../../api/OHRIFormField'; import { getRegisteredControl } from '../../registry/registry'; import { isTrue } from '../../utils/boolean-utils'; diff --git a/src/components/section/ohri-form-section.component.tsx b/src/components/section/ohri-form-section.component.tsx index 1b96add80..4fae5a92b 100644 --- a/src/components/section/ohri-form-section.component.tsx +++ b/src/components/section/ohri-form-section.component.tsx @@ -4,7 +4,8 @@ import { ErrorBoundary } from 'react-error-boundary'; import { ToastNotification } from '@carbon/react'; import { getRegisteredFieldSubmissionHandler } from '../../registry/registry'; import { OHRIUnspecified } from '../inputs/unspecified/ohri-unspecified.component'; -import { OHRIFormField, OHRIFormFieldProps, previousValue, SubmissionHandler } from '../../api/types'; +import { OHRIFormFieldProps, previousValue, SubmissionHandler } from '../../api/types'; +import { OHRIFormField } from '../../api/OHRIFormField'; import styles from './ohri-form-section.scss'; import { formatPreviousValueDisplayText, getFieldControlWithFallback, isUnspecifiedSupported } from './helpers'; import { OHRITooltip } from '../inputs/tooltip/ohri-tooltip'; diff --git a/src/hooks/useFormFieldHandlers.tsx b/src/hooks/useFormFieldHandlers.tsx index cb51ed662..d649746ef 100644 --- a/src/hooks/useFormFieldHandlers.tsx +++ b/src/hooks/useFormFieldHandlers.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react'; -import { OHRIFormField, SubmissionHandler } from '../api/types'; +import { SubmissionHandler } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { getRegisteredFieldSubmissionHandler } from '..'; export function useFormFieldHandlers(fields: OHRIFormField[]) { @@ -7,11 +8,11 @@ export function useFormFieldHandlers(fields: OHRIFormField[]) { useEffect(() => { const supportedTypes = new Set(); - fields.forEach(field => { + fields.forEach((field) => { supportedTypes.add(field.type); }); const supportedTypesArray = Array.from(supportedTypes); - Promise.all(supportedTypesArray.map(type => getRegisteredFieldSubmissionHandler(type))).then(handlers => { + Promise.all(supportedTypesArray.map((type) => getRegisteredFieldSubmissionHandler(type))).then((handlers) => { const typeToHandlersArray = supportedTypesArray.map((type, index) => ({ [type]: handlers[index], })); diff --git a/src/hooks/useFormFieldValidators.ts b/src/hooks/useFormFieldValidators.ts index f91d76816..8d1add555 100644 --- a/src/hooks/useFormFieldValidators.ts +++ b/src/hooks/useFormFieldValidators.ts @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react'; -import { FieldValidator, OHRIFormField } from '../api/types'; +import { FieldValidator } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { getRegisteredValidator } from '../registry/registry'; export function useFormFieldValidators(fields: OHRIFormField[]) { @@ -7,11 +8,11 @@ export function useFormFieldValidators(fields: OHRIFormField[]) { useEffect(() => { const supportedTypes = new Set(['default']); - fields.forEach(field => { - field.validators?.forEach(validator => supportedTypes.add(validator.type)); + fields.forEach((field) => { + field.validators?.forEach((validator) => supportedTypes.add(validator.type)); }); const supportedTypesArray = Array.from(supportedTypes); - Promise.all(supportedTypesArray.map(type => getRegisteredValidator(type))).then(validators => { + Promise.all(supportedTypesArray.map((type) => getRegisteredValidator(type))).then((validators) => { setValidators( Object.assign({}, ...validators.map((validator, index) => ({ [supportedTypesArray[index]]: validator }))), ); diff --git a/src/hooks/useInitialValues.test.ts b/src/hooks/useInitialValues.test.ts index 7c3979c39..32069f2d0 100644 --- a/src/hooks/useInitialValues.test.ts +++ b/src/hooks/useInitialValues.test.ts @@ -2,7 +2,8 @@ import { act, renderHook } from '@testing-library/react'; import { useInitialValues } from './useInitialValues'; import testEncounter from '../../__mocks__/use-initial-values/encounter.mock.json'; import testPatient from '../../__mocks__/use-initial-values/patient.mock.json'; -import { OHRIFormField, OpenmrsEncounter } from '../api/types'; +import { OpenmrsEncounter } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { ObsSubmissionHandler } from '../submission-handlers/base-handlers'; const obsGroupMembers: Array = [ diff --git a/src/hooks/useInitialValues.ts b/src/hooks/useInitialValues.ts index 5f93ece09..8fcc86bce 100644 --- a/src/hooks/useInitialValues.ts +++ b/src/hooks/useInitialValues.ts @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import { EncounterContext, inferInitialValueFromDefaultFieldValue, isEmpty } from '..'; -import { OHRIFormField, OpenmrsEncounter, SubmissionHandler } from '../api/types'; +import { OpenmrsEncounter, SubmissionHandler } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { evaluateAsyncExpression } from '../utils/expression-runner'; import { cloneObsGroup } from '../components/repeat/helpers'; import { assignedObsIds } from '../submission-handlers/base-handlers'; diff --git a/src/ohri-form-context.tsx b/src/ohri-form-context.tsx index bb7f23f16..a6c7ad538 100644 --- a/src/ohri-form-context.tsx +++ b/src/ohri-form-context.tsx @@ -1,6 +1,7 @@ import { LayoutType } from '@openmrs/esm-framework'; import React from 'react'; -import { RepeatObsGroupCounter, OHRIFormField, OpenmrsEncounter, SessionMode, SubmissionHandler } from './api/types'; +import { RepeatObsGroupCounter, OpenmrsEncounter, SessionMode, SubmissionHandler } from './api/types'; +import { OHRIFormField } from './api/OHRIFormField'; type OHRIFormContextProps = { values: Record; diff --git a/src/submission-handlers/base-handlers.test.ts b/src/submission-handlers/base-handlers.test.ts index 376c1b0e2..259c8b7d7 100644 --- a/src/submission-handlers/base-handlers.test.ts +++ b/src/submission-handlers/base-handlers.test.ts @@ -1,6 +1,6 @@ import { Observable } from 'rxjs'; import { EncounterContext } from '../ohri-form-context'; -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { findObsByFormField, ObsSubmissionHandler } from './base-handlers'; const encounterContext: EncounterContext = { diff --git a/src/submission-handlers/base-handlers.ts b/src/submission-handlers/base-handlers.ts index dd1d3eb2b..fac78dc8e 100644 --- a/src/submission-handlers/base-handlers.ts +++ b/src/submission-handlers/base-handlers.ts @@ -2,7 +2,8 @@ import dayjs from 'dayjs'; import { getConcept, getAttachmentByUuid } from '../api/api'; import { ConceptTrue } from '../constants'; import { EncounterContext } from '../ohri-form-context'; -import { OHRIFormField, OpenmrsEncounter, OpenmrsObs, SubmissionHandler } from '../api/types'; +import { OpenmrsEncounter, OpenmrsObs, SubmissionHandler } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { parseToLocalDateTime } from '../utils/ohri-form-helper'; import { flattenObsList, hasRendering } from '../utils/common-utils'; diff --git a/src/submission-handlers/encounterDatetimeHandler.ts b/src/submission-handlers/encounterDatetimeHandler.ts index 81e2cdac0..c46e7b3b8 100644 --- a/src/submission-handlers/encounterDatetimeHandler.ts +++ b/src/submission-handlers/encounterDatetimeHandler.ts @@ -1,5 +1,6 @@ import { SubmissionHandler } from '..'; -import { OpenmrsEncounter, OHRIFormField } from '../api/types'; +import { OpenmrsEncounter } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { EncounterContext } from '../ohri-form-context'; export const EncounterDatetimeHandler: SubmissionHandler = { diff --git a/src/submission-handlers/encounterLocationHandler.ts b/src/submission-handlers/encounterLocationHandler.ts index acaa5cc3e..8318d5201 100644 --- a/src/submission-handlers/encounterLocationHandler.ts +++ b/src/submission-handlers/encounterLocationHandler.ts @@ -1,7 +1,8 @@ import { map } from 'rxjs/operators'; import { SubmissionHandler } from '..'; import { getAllLocations } from '../api/api'; -import { OpenmrsEncounter, OHRIFormField } from '../api/types'; +import { OpenmrsEncounter } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { EncounterContext } from '../ohri-form-context'; export const EncounterLocationSubmissionHandler: SubmissionHandler = { diff --git a/src/submission-handlers/encounterProviderHandler.ts b/src/submission-handlers/encounterProviderHandler.ts index 7c0e9d346..3a7c28b5c 100644 --- a/src/submission-handlers/encounterProviderHandler.ts +++ b/src/submission-handlers/encounterProviderHandler.ts @@ -1,5 +1,6 @@ import { SubmissionHandler } from '..'; -import { OpenmrsEncounter, OHRIFormField } from '../api/types'; +import { OpenmrsEncounter } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { EncounterContext } from '../ohri-form-context'; export const EncounterProviderHandler: SubmissionHandler = { diff --git a/src/transformers/angular-fe-schema-transformer.ts b/src/transformers/angular-fe-schema-transformer.ts index fbd16878a..66c0b5521 100644 --- a/src/transformers/angular-fe-schema-transformer.ts +++ b/src/transformers/angular-fe-schema-transformer.ts @@ -1,4 +1,5 @@ -import { FormSchemaTransformer, OHRIFormField, OHRIFormSchema } from '../api/types'; +import { FormSchemaTransformer, OHRIFormSchema } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; export const AngularFormEngineSchemaTransformer: FormSchemaTransformer = { transform: (form: OHRIFormSchema) => { diff --git a/src/utils/common-expression-helpers.ts b/src/utils/common-expression-helpers.ts index f136fa116..9539bb8a8 100644 --- a/src/utils/common-expression-helpers.ts +++ b/src/utils/common-expression-helpers.ts @@ -6,7 +6,7 @@ import filter from 'lodash/filter'; import first from 'lodash/first'; import forEach from 'lodash/forEach'; import last from 'lodash/last'; -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { FormNode } from './expression-runner'; import { isEmpty as isValueEmpty } from '../validators/ohri-form-validator'; import * as apiFunctions from '../api/api'; diff --git a/src/utils/common-utils.ts b/src/utils/common-utils.ts index 176d7cbf5..b9e0a4389 100644 --- a/src/utils/common-utils.ts +++ b/src/utils/common-utils.ts @@ -1,4 +1,5 @@ -import { OHRIFormField, OpenmrsObs, RenderType, AttachmentResponse, Attachment } from '../api/types'; +import { OpenmrsObs, RenderType, AttachmentResponse, Attachment } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { formatDate } from '@openmrs/esm-framework'; export function flattenObsList(obsList: OpenmrsObs[]): OpenmrsObs[] { diff --git a/src/utils/expression-parser.test.ts b/src/utils/expression-parser.test.ts index c12a5956e..b0b123437 100644 --- a/src/utils/expression-parser.test.ts +++ b/src/utils/expression-parser.test.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { ConceptFalse } from '../constants'; import { findAndRegisterReferencedFields, @@ -201,7 +201,7 @@ describe('findAndRegisterReferencedFields', () => { it('should register field dependants', () => { // setup const expression = "linkedToCare == 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3' && !isEmpty(htsProviderRemarks)"; - const patientIdentificationNumberField = testFields.find(f => f.id === 'patientIdentificationNumber'); + const patientIdentificationNumberField = testFields.find((f) => f.id === 'patientIdentificationNumber'); // replay findAndRegisterReferencedFields( @@ -211,8 +211,8 @@ describe('findAndRegisterReferencedFields', () => { ); // verify - const linkedToCare = testFields.find(f => f.id === 'linkedToCare'); - const htsProviderRemarks = testFields.find(f => f.id === 'htsProviderRemarks'); + const linkedToCare = testFields.find((f) => f.id === 'linkedToCare'); + const htsProviderRemarks = testFields.find((f) => f.id === 'htsProviderRemarks'); expect(linkedToCare.fieldDependants).toStrictEqual(new Set(['patientIdentificationNumber'])); expect(htsProviderRemarks.fieldDependants).toStrictEqual(new Set(['patientIdentificationNumber'])); }); diff --git a/src/utils/expression-parser.ts b/src/utils/expression-parser.ts index fd396a3dd..9f23653b2 100644 --- a/src/utils/expression-parser.ts +++ b/src/utils/expression-parser.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { ConceptFalse, ConceptTrue } from '../constants'; import { registerDependency } from './common-expression-helpers'; import { FormNode } from './expression-runner'; diff --git a/src/utils/expression-runner.test.ts b/src/utils/expression-runner.test.ts index 12e9c5470..c01ba0462 100644 --- a/src/utils/expression-runner.test.ts +++ b/src/utils/expression-runner.test.ts @@ -1,5 +1,5 @@ import { registerExpressionHelper } from '..'; -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { CommonExpressionHelpers } from './common-expression-helpers'; import { checkReferenceToResolvedFragment, evaluateExpression, ExpressionContext } from './expression-runner'; @@ -99,7 +99,7 @@ describe('Common expression runner - evaluateExpression', () => { referredToPreventionServices: [], bodyTemperature: 0, }; - allFields.forEach(field => { + allFields.forEach((field) => { field.fieldDependants = undefined; }); }); @@ -277,7 +277,7 @@ describe('Common expression runner - checkReferenceToResolvedFragment', () => { describe('Common expression runner - validate helper functions', () => { const allFields = JSON.parse(JSON.stringify(testFields)); - const allFieldsKeys = allFields.map(f => f.id); + const allFieldsKeys = allFields.map((f) => f.id); let valuesMap = { linkedToCare: '', patientIdentificationNumber: '', @@ -301,7 +301,7 @@ describe('Common expression runner - validate helper functions', () => { referredToPreventionServices: [], bodyTemperature: 0, }; - allFields.forEach(field => { + allFields.forEach((field) => { field.fieldDependants = undefined; }); }); diff --git a/src/utils/expression-runner.ts b/src/utils/expression-runner.ts index 2cdc533f8..a3916fb27 100644 --- a/src/utils/expression-runner.ts +++ b/src/utils/expression-runner.ts @@ -1,4 +1,5 @@ -import { OHRIFormField, OHRIFormPage, OHRIFormSection } from '../api/types'; +import { OHRIFormPage, OHRIFormSection } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { getRegisteredExpressionHelpers } from '../registry/registry'; import { CommonExpressionHelpers } from './common-expression-helpers'; import { findAndRegisterReferencedFields, linkReferencedFieldValues, parseExpression } from './expression-parser'; diff --git a/src/utils/forms-loader.ts b/src/utils/forms-loader.ts index 39bd99ea9..265a94ad8 100644 --- a/src/utils/forms-loader.ts +++ b/src/utils/forms-loader.ts @@ -1,5 +1,5 @@ import * as semver from 'semver'; -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; let baseRegistry = {}; export interface FormJsonFile { diff --git a/src/utils/ohri-form-helper.ts b/src/utils/ohri-form-helper.ts index 558e334ee..c8da7460b 100644 --- a/src/utils/ohri-form-helper.ts +++ b/src/utils/ohri-form-helper.ts @@ -2,7 +2,8 @@ import dayjs from 'dayjs'; import { LayoutType } from '@openmrs/esm-framework'; import { ConceptTrue } from '../constants'; import { EncounterContext } from '../ohri-form-context'; -import { OHRIFormField, OHRIFormPage, OHRIFormSection, SessionMode, SubmissionHandler } from '../api/types'; +import { OHRIFormPage, OHRIFormSection, SessionMode, SubmissionHandler } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { OHRIDefaultFieldValueValidator } from '../validators/default-value-validator'; import { isEmpty } from '../validators/ohri-form-validator'; import { isTrue } from './boolean-utils'; diff --git a/src/validators/default-value-validator.test.ts b/src/validators/default-value-validator.test.ts index b155c23db..b9c40c6fa 100644 --- a/src/validators/default-value-validator.test.ts +++ b/src/validators/default-value-validator.test.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { OHRIDefaultFieldValueValidator } from './default-value-validator'; describe('OHRIDefaultFieldValueValidator - validate', () => { diff --git a/src/validators/default-value-validator.ts b/src/validators/default-value-validator.ts index d85bf49f1..23de739dc 100644 --- a/src/validators/default-value-validator.ts +++ b/src/validators/default-value-validator.ts @@ -1,12 +1,13 @@ import dayjs from 'dayjs'; -import { FieldValidator, OHRIFormField } from '../api/types'; +import { FieldValidator } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; export const OHRIDefaultFieldValueValidator: FieldValidator = { validate: (field: OHRIFormField, value: any) => { const codedTypes = ['radio', 'checkbox', 'select', 'content-switcher']; if (codedTypes.includes(field.questionOptions.rendering)) { // check whether value exists in answers - if (!field.questionOptions.answers?.find(answer => answer.concept == value)) { + if (!field.questionOptions.answers?.find((answer) => answer.concept == value)) { return [ { resultType: 'error', errCode: 'invalid.defaultValue', message: 'Value not found in coded answers list' }, ]; diff --git a/src/validators/ohri-date-validator.test.ts b/src/validators/ohri-date-validator.test.ts index 6d15fe916..4f9890f23 100644 --- a/src/validators/ohri-date-validator.test.ts +++ b/src/validators/ohri-date-validator.test.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { OHRIDateValidator } from './ohri-date-validator'; describe('OHRIDateValidator - validate', () => { diff --git a/src/validators/ohri-date-validator.ts b/src/validators/ohri-date-validator.ts index e3bb0f749..bb25878af 100644 --- a/src/validators/ohri-date-validator.ts +++ b/src/validators/ohri-date-validator.ts @@ -1,4 +1,5 @@ -import { FieldValidator, OHRIFormField } from '../api/types'; +import { FieldValidator } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { isTrue } from '../utils/boolean-utils'; import { OHRIFieldValidator } from './ohri-form-validator'; diff --git a/src/validators/ohri-form-validator.test.ts b/src/validators/ohri-form-validator.test.ts index 230dcd811..856d6e21b 100644 --- a/src/validators/ohri-form-validator.test.ts +++ b/src/validators/ohri-form-validator.test.ts @@ -1,4 +1,4 @@ -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { OHRIFieldValidator } from './ohri-form-validator'; describe('OHRIFieldValidator - validate', () => { diff --git a/src/validators/ohri-form-validator.ts b/src/validators/ohri-form-validator.ts index dc2e73133..a5dfd3ef1 100644 --- a/src/validators/ohri-form-validator.ts +++ b/src/validators/ohri-form-validator.ts @@ -1,4 +1,5 @@ -import { FieldValidator, OHRIFormField } from '../api/types'; +import { FieldValidator } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { isTrue } from '../utils/boolean-utils'; export const fieldRequiredErrCode = 'field.required'; diff --git a/src/validators/ohri-js-expression-validator.test.ts b/src/validators/ohri-js-expression-validator.test.ts index 3ac291a4a..bd84fd48c 100644 --- a/src/validators/ohri-js-expression-validator.test.ts +++ b/src/validators/ohri-js-expression-validator.test.ts @@ -1,5 +1,5 @@ import dayjs from 'dayjs'; -import { OHRIFormField } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { ExpressionContext } from '../utils/expression-runner'; import { testFields } from '../utils/expression-runner.test'; import { OHRIJSExpressionValidator } from './ohri-js-expression-validator'; @@ -19,7 +19,7 @@ describe('OHRIJSExpressionValidator - validate', () => { it('should evaluate js expressions', () => { // setup - const field = allFields.find(f => f.id == 'htsProviderRemarks'); + const field = allFields.find((f) => f.id == 'htsProviderRemarks'); const failsWhenExpression = '!isEmpty(myValue) && isEmpty(`referredToPreventionServices`)'; // replay diff --git a/src/validators/ohri-js-expression-validator.ts b/src/validators/ohri-js-expression-validator.ts index b3aaa8e79..6fd80cf25 100644 --- a/src/validators/ohri-js-expression-validator.ts +++ b/src/validators/ohri-js-expression-validator.ts @@ -1,4 +1,5 @@ -import { FieldValidator, OHRIFormField } from '../api/types'; +import { FieldValidator } from '../api/types'; +import { OHRIFormField } from '../api/OHRIFormField'; import { evaluateExpression, ExpressionContext } from '../utils/expression-runner'; interface JSExpressionValidatorConfig { @@ -11,14 +12,14 @@ interface JSExpressionValidatorConfig { } export const OHRIJSExpressionValidator: FieldValidator = { - validate: function(field: OHRIFormField, value: any, config: JSExpressionValidatorConfig) { + validate: function (field: OHRIFormField, value: any, config: JSExpressionValidatorConfig) { const INVALID_VALUE_ERR_CODE = 'value.invalid'; const INVALID_VALUE_ERR_MESSAGE = 'Invalid value'; const FIELD_HAS_WARNINGS_MESSAGE = 'Field has warnings'; config.expressionContext.myValue = value; return Object.keys(config) - .filter(key => key === 'failsWhenExpression' || key === 'warnsWhenExpression') - .flatMap(key => { + .filter((key) => key === 'failsWhenExpression' || key === 'warnsWhenExpression') + .flatMap((key) => { const isErrorValidator = key === 'failsWhenExpression'; return evaluateExpression( config[key],