Skip to content

Commit

Permalink
modify form template based on ld flag for ILOS
Browse files Browse the repository at this point in the history
  • Loading branch information
karla-vm committed May 22, 2024
1 parent df18208 commit 4ae3940
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion services/app-api/handlers/reports/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ export const createReport = handler(async (event, _context) => {
const isProgramPCCM =
unvalidatedMetadata?.programIsPCCM?.[0]?.value === "Yes";

const ilosAvailable = unvalidatedMetadata?.ilosAvailable;

try {
({ formTemplate, formTemplateVersion } = await getOrCreateFormTemplate(
reportBucket,
reportType,
isProgramPCCM
isProgramPCCM,
ilosAvailable
));
} catch (err) {
logger.error(err, "Error getting or creating template");
Expand Down
25 changes: 23 additions & 2 deletions services/app-api/utils/formTemplates/formTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ export const formTemplateForReportType = (reportType: ReportType) => {
export async function getOrCreateFormTemplate(
reportBucket: string,
reportType: ReportType,
isProgramPCCM: boolean
isProgramPCCM: boolean,
ilosAvailable?: boolean
) {
let currentFormTemplate = formTemplateForReportType(reportType);
if (isProgramPCCM) {
currentFormTemplate = generatePCCMTemplate(currentFormTemplate);
}
if (!ilosAvailable) {
currentFormTemplate = generateTemplateWithoutIlos(currentFormTemplate);
}
const stringifiedTemplate = JSON.stringify(currentFormTemplate);

const currentTemplateHash = createHash("md5")
.update(stringifiedTemplate)
.digest("hex");
Expand Down Expand Up @@ -323,3 +326,21 @@ const makePCCMTemplateModifications = (reportTemplate: ReportJson) => {
}
programTypeQuestion.props!.disabled = true;
};

const generateTemplateWithoutIlos = (originalReportTemplate: any) => {
const reportTemplate = structuredClone(originalReportTemplate);

// remove ILOS sections from template
reportTemplate.routes = reportTemplate.routes.map((route: ReportRoute) => {
if (
route.path === "/mcpar/program-information" ||
route.path === "/mcpar/plan-level-indicators"
) {
const updatedChildren = route.children?.slice(0, -1);
route.children = updatedChildren;
}
return route;
});

return reportTemplate;
};
1 change: 1 addition & 0 deletions services/app-api/utils/types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface MCPARReportMetadata extends ReportMetadata {
dueDate: number;
combinedData: boolean;
programIsPCCM: Choice[];
ilosAvailable?: boolean;
}

export enum ReportType {
Expand Down
5 changes: 5 additions & 0 deletions services/ui-src/src/components/modals/AddEditReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const AddEditReportModal = ({
const { copyEligibleReportsByState } = useStore();

const [submitting, setSubmitting] = useState<boolean>(false);

// LaunchDarkly
const yoyCopyFlag = useFlags()?.yoyCopy;
const ilos = useFlags()?.ilos;

// get correct form
const modalFormJsonMap: any = {
Expand Down Expand Up @@ -90,6 +93,7 @@ export const AddEditReportModal = ({
formData["reportingPeriodEndDate"]
);
const programIsPCCM = formData["programIsPCCM"];
const ilosAvailable = ilos;

return {
metadata: {
Expand All @@ -101,6 +105,7 @@ export const AddEditReportModal = ({
lastAlteredBy: full_name,
copyFieldDataSourceId: copyFieldDataSourceId?.value,
programIsPCCM,
ilosAvailable,
locked: false,
submissionCount: 0,
previousRevisions: [],
Expand Down
1 change: 1 addition & 0 deletions services/ui-src/src/types/reportContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ReportMetadataShape extends ReportKeys {
fieldDataId: string;
copyFieldDataSourceId?: string;
programIsPCCM?: Choice[];
ilosAvailable?: boolean;
previousRevisions: string[];
}

Expand Down

0 comments on commit 4ae3940

Please sign in to comment.