Skip to content

Commit

Permalink
CMDCT-4224: adding more validation and tests, cleaning up mock report…
Browse files Browse the repository at this point in the history
… data file
  • Loading branch information
angelaco11 committed Jan 17, 2025
1 parent 92baa65 commit 71c2caa
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1,102 deletions.
12 changes: 10 additions & 2 deletions services/app-api/forms/qms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ export const qmsReportTemplate: ReportTemplate = {
type: ElementType.Radio,
label: "Which quality measure will be reported?",
value: [
{ label: "{Measure name version 1}", value: "measure-1" },
{ label: "{Measure name version 2}", value: "measure-2" },
{
label: "{Measure name version 1}",
value: "measure-1",
checkedChildren: [],
},
{
label: "{Measure name version 2}",
value: "measure-2",
checkedChildren: [],
},
],
},
],
Expand Down
5 changes: 4 additions & 1 deletion services/app-api/types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ export type TextboxTemplate = {
type: ElementType.Textbox;
label: string;
helperText?: string;
answer?: string;
};

export type DateTemplate = {
type: ElementType.Date;
label: string;
helperText: string;
answer?: string;
};

export type AccordionTemplate = {
Expand All @@ -238,6 +240,7 @@ export type RadioTemplate = {
label: string;
helperText?: string;
value: ChoiceTemplate[];
answer?: string;
};

export type ButtonLinkTemplate = {
Expand All @@ -250,7 +253,7 @@ export type ChoiceTemplate = {
label: string;
value: string;
checked?: boolean;
checkedChildren?: PageElement[];
checkedChildren: PageElement[];
};

export type MeasureTableTemplate = {
Expand Down
107 changes: 61 additions & 46 deletions services/app-api/utils/reportValidation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { array, boolean, lazy, mixed, number, object, string } from "yup";
import {
array,
boolean,
lazy,
mixed,
number,
object,
Schema,
string,
} from "yup";
import {
ReportStatus,
ReportType,
Expand Down Expand Up @@ -29,12 +38,14 @@ const textboxTemplateSchema = object().shape({
type: string().required(ElementType.Textbox),
label: string().required(),
helperText: string().notRequired(),
answer: string().notRequired(),
});

const dateTemplateSchema = object().shape({
type: string().required(ElementType.Date),
label: string().required(),
helperText: string().required(),
answer: string().notRequired(),
});

const accordionTemplateSchema = object().shape({
Expand All @@ -50,6 +61,40 @@ const resultRowButtonTemplateSchema = object().shape({
to: string().required(),
});

const pageElementSchema = lazy((value: PageElement): Schema<any> => {
if (!value.type) {
throw new Error();
}
switch (value.type) {
case ElementType.Header:
return headerTemplateSchema;
case ElementType.SubHeader:
return subHeaderTemplateSchema;
case ElementType.Paragraph:
return paragraphTemplateSchema;
case ElementType.Textbox:
return textboxTemplateSchema;
case ElementType.Date:
return dateTemplateSchema;
case ElementType.Accordion:
return accordionTemplateSchema;
case ElementType.ResultRowButton:
return resultRowButtonTemplateSchema;
case ElementType.Radio:
return radioTemplateSchema;
case ElementType.ButtonLink:
return buttonLinkTemplateSchema;
case ElementType.MeasureTable:
return measureTableTemplateSchema;
case ElementType.QualityMeasureTable:
return qualityMeasureTableTemplateSchema;
case ElementType.StatusTable:
return statusTableTemplateSchema;
default:
return mixed().notRequired(); // Fallback, although it should never be hit
}
});

const radioTemplateSchema = object().shape({
type: string().required(ElementType.Radio),
label: string().required(),
Expand All @@ -59,9 +104,10 @@ const radioTemplateSchema = object().shape({
label: string().required(),
value: string().required(),
checked: boolean().notRequired(),
checkedChildren: array().notRequired(), // TODO: add PageElement array
checkedChildren: lazy(() => array().of(pageElementSchema).notRequired()),
})
),
answer: string().notRequired(),
});

const buttonLinkTemplateSchema = object().shape({
Expand All @@ -87,40 +133,6 @@ const statusTableTemplateSchema = object().shape({
to: string().required(),
});

const pageElementSchema = lazy((value: PageElement) => {
if (!value.type) {
throw new Error();
}
switch (value.type) {
case ElementType.Header:
return headerTemplateSchema;
case ElementType.SubHeader:
return subHeaderTemplateSchema;
case ElementType.Paragraph:
return paragraphTemplateSchema;
case ElementType.Textbox:
return textboxTemplateSchema;
case ElementType.Date:
return dateTemplateSchema;
case ElementType.Accordion:
return accordionTemplateSchema;
case ElementType.ResultRowButton:
return resultRowButtonTemplateSchema;
case ElementType.Radio:
return radioTemplateSchema;
case ElementType.ButtonLink:
return buttonLinkTemplateSchema;
case ElementType.MeasureTable:
return measureTableTemplateSchema;
case ElementType.QualityMeasureTable:
return qualityMeasureTableTemplateSchema;
case ElementType.StatusTable:
return statusTableTemplateSchema;
default:
return mixed().notRequired(); // Fallback, although it should never be hit
}
});

const parentPageTemplateSchema = object().shape({
id: string().required(),
childPageIds: array().of(string()).required(),
Expand All @@ -145,17 +157,20 @@ const measurePageTemplateSchema = formPageTemplateSchema.shape({
substitutable: boolean().notRequired(),
});

const measureOptionsArraySchema = array().of(
object().shape({
cmit: number().required(),
required: boolean().required(),
stratified: boolean().required(),
measureTemplate: mixed()
.oneOf(Object.values(MeasureTemplateName))
.required(),
})
);

const measureLookupSchema = object().shape({
defaultMeasures: array().of(
object().shape({
cmit: number().required(),
required: boolean().required(),
stratified: boolean().required(),
measureTemplate: mixed()
.oneOf(Object.values(MeasureTemplateName))
.required(),
})
),
defaultMeasures: measureOptionsArraySchema,
// TODO: Add option groups
});

/**
Expand Down
Loading

0 comments on commit 71c2caa

Please sign in to comment.