Skip to content

Instantly share code, notes, and snippets.

@samuelmale
Created April 25, 2024 12:44
Show Gist options
  • Select an option

  • Save samuelmale/e800f1dfaafdb2fc36b86fe120e77516 to your computer and use it in GitHub Desktop.

Select an option

Save samuelmale/e800f1dfaafdb2fc36b86fe120e77516 to your computer and use it in GitHub Desktop.
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