From b3bdd8d0b985198b42fe073df3f5cefd180be896 Mon Sep 17 00:00:00 2001 From: samuelmale Date: Thu, 16 May 2024 22:49:32 +0300 Subject: [PATCH 1/2] Hide empty repeating groups --- .vscode/settings.json | 3 +++ src/components/encounter/encounter-form-manager.ts | 6 ++---- .../encounter/encounter-form.component.tsx | 12 ++++++------ src/components/repeat/repeat.component.tsx | 9 ++++++++- src/registry/registry.ts | 4 ++-- 5 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..327b4b2cc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["fhir", "Openmrs"] +} diff --git a/src/components/encounter/encounter-form-manager.ts b/src/components/encounter/encounter-form-manager.ts index 061745ff7..d25843dac 100644 --- a/src/components/encounter/encounter-form-manager.ts +++ b/src/components/encounter/encounter-form-manager.ts @@ -104,7 +104,7 @@ export class EncounterFormManager { function prepareObs(obsForSubmission: OpenmrsObs[], fields: FormField[]) { fields - .filter((field) => hasSubmitableObs(field)) + .filter((field) => hasSubmittableObs(field)) .forEach((field) => { if ((field.isHidden || field.isParentHidden) && field.meta.previousValue) { const valuesArray = Array.isArray(field.meta.previousValue) @@ -160,12 +160,10 @@ function addObsToList(obsList: Array>, obs: Partial = ({ ? [{ type: 'default' }, ...field.validators] : [{ type: 'default' }]; // handle validation - const basevalidatorConfig = { + const baseValidatorConfig = { expressionContext: { patient, mode: sessionMode }, values: { ...values, [fieldName]: value }, fields, @@ -519,13 +519,13 @@ const EncounterForm: React.FC = ({ const warnings = []; if (!isUnspecified) { for (let validatorConfig of validators) { - const errorsAndWarinings = - formFieldValidators[validatorConfig.type].validate(field, value, { - ...basevalidatorConfig, + const errorsAndWarnings = + formFieldValidators[validatorConfig.type]?.validate(field, value, { + ...baseValidatorConfig, ...validatorConfig, }) || []; - errors.push(...errorsAndWarinings.filter((error) => error.resultType == 'error')); - warnings.push(...errorsAndWarinings.filter((error) => error.resultType == 'warning')); + errors.push(...errorsAndWarnings.filter((error) => error.resultType == 'error')); + warnings.push(...errorsAndWarnings.filter((error) => error.resultType == 'warning')); } } setErrors?.(errors); diff --git a/src/components/repeat/repeat.component.tsx b/src/components/repeat/repeat.component.tsx index 85177baa4..7bb8b94ec 100644 --- a/src/components/repeat/repeat.component.tsx +++ b/src/components/repeat/repeat.component.tsx @@ -136,7 +136,7 @@ const Repeat: React.FC = ({ question, onChange, handler }) => { : null; }, [rows, fieldComponent]); - if (question.isHidden || !nodes) { + if (question.isHidden || !nodes || !hasVisibleField(question)) { return null; } return isGrouped ? ( @@ -150,6 +150,13 @@ const Repeat: React.FC = ({ question, onChange, handler }) => { ); }; +function hasVisibleField(field: FormField) { + if (field.questions?.length) { + return field.questions?.some((child) => !child.isHidden); + } + return !field.isHidden; +} + function getQuestionWithSupportedRendering(question: FormField) { return { ...question, diff --git a/src/registry/registry.ts b/src/registry/registry.ts index 71b10c4a2..25b9e08c3 100644 --- a/src/registry/registry.ts +++ b/src/registry/registry.ts @@ -94,7 +94,7 @@ export function registerExpressionHelper(name: string, fn: Function) { getFormsStore().expressionHelpers[name] = fn; } -export function registereformSchemaTransformers(registration: ComponentRegistration) { +export function registerFormSchemaTransformers(registration: ComponentRegistration) { const store = getFormsStore(); const existingIndex = store.formSchemaTransformers.findIndex((reg) => reg.name === registration.name); @@ -109,7 +109,7 @@ export function registereformSchemaTransformers(registration: ComponentRegistrat // Getters /** - * A convinience function that returns the appropriate control for a given rendering type. + * A convenience function that returns the appropriate control for a given rendering type. */ export async function getRegisteredControl(renderType: string) { if (registryCache.controls[renderType]) { From f3c9d7bc85c6e0ce3218ed66f7c726120be5a5e3 Mon Sep 17 00:00:00 2001 From: samuelmale Date: Thu, 16 May 2024 23:16:33 +0300 Subject: [PATCH 2/2] Remove vscode related file --- .gitignore | 3 +++ .vscode/settings.json | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 0a891c4a0..df836f391 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,6 @@ typings/ !.yarn/releases !.yarn/sdks !.yarn/versions + +# vscode +.vscode/* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 327b4b2cc..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "cSpell.words": ["fhir", "Openmrs"] -}