Created
April 25, 2024 12:44
-
-
Save samuelmale/e800f1dfaafdb2fc36b86fe120e77516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { FormField, FormSchemaTransformer, FormSchema } from '../types'; | |
| export const AngularFormEngineSchemaTransformer: FormSchemaTransformer = { | |
| transform: (form: FormSchema) => { | |
| form.pages.forEach((page) => { | |
| if (page.sections) { | |
| page.sections.forEach((section) => { | |
| section?.questions.forEach((question) => handleQuestion(question)); | |
| }); | |
| } | |
| }); | |
| return form; | |
| }, | |
| }; | |
| function handleQuestion(question: FormField) { | |
| try { | |
| transformByType(question); | |
| transformByRendering(question); | |
| if (question?.questions?.length) { | |
| question.questions.forEach((question) => handleQuestion(question)); | |
| } | |
| } catch (error) { | |
| console.error(error); | |
| } | |
| } | |
| function transformByType(question: FormField) { | |
| switch (question.type) { | |
| case 'encounterProvider': | |
| question.questionOptions.rendering = 'encounter-provider'; | |
| break; | |
| case 'encounterLocation': | |
| question.questionOptions.rendering = 'encounter-location'; | |
| break; | |
| } | |
| } | |
| function transformByRendering(question: FormField) { | |
| switch (question.questionOptions.rendering as any) { | |
| case 'multiCheckbox': | |
| question.questionOptions.rendering = 'checkbox'; | |
| break; | |
| case 'numeric': | |
| question.questionOptions.rendering = 'number'; | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment