Skip to content

Commit

Permalink
Merge pull request #455 from USEPA/feature/update-2022-crf-status
Browse files Browse the repository at this point in the history
Feature/update 2022 crf status
  • Loading branch information
courtneymyers authored Jul 31, 2024
2 parents 4092eac + 02d446b commit 4ff7020
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

# Set environment variables
env:
APP_VERSION: 5.0
APP_VERSION: 5.0.2
CLOUD_SPACE: production
SERVER_BASE_PATH: /csb
FORMIO_BASE_URL: ${{ secrets.FORMIO_BASE_URL }}
Expand Down
4 changes: 2 additions & 2 deletions app/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epa-csb-rebate-forms-app-client",
"version": "5.0.1",
"version": "5.0.2",
"description": "U.S. EPA CSB Rebate Forms Application (client app)",
"homepage": ".",
"license": "CC0-1.0",
Expand Down
16 changes: 10 additions & 6 deletions app/client/src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ export const formioStatusMap = new Map<string, string>()
/**
* BAP internal to external status mapping by year and form type.
*
* NOTE: The "Edits Requested" BAP status is supported in the app, but not
* included in the maps because the BAP status alone can't be used in
* "Edits Requested" scenarios. See `submissionNeedsEdits()` in `utilities.ts`.
* NOTES:
* 1. The "Edits Requested" BAP status is supported in the app, but not included
* in the maps because the BAP status alone can't be used in "Edits Requested"
* scenarios (See `submissionNeedsEdits()` in `utilities.ts`).
* 2. The 2022 CRF status "Reimbursement Needed" is supported in the app, but
* not included in the map because it relies on both the BAP internal status of
* "Branch Director Approved" and the BAP's "Reimbursement_Needed__c" field
* (see `submissionNeedsReimbursement()` in `utilities.ts`).
*/
export const bapStatusMap = {
2022: {
Expand All @@ -93,9 +98,8 @@ export const bapStatusMap = {
.set("Accepted", "Funding Approved"),
crf: new Map<string, string>()
.set("Needs Clarification", "Needs Clarification")
.set("Reimbursement Needed", "Reimbursement Needed")
.set("Branch Director Denied", "Close Out Not Approved")
.set("Branch Director Approved", "Close Out Approved"),
.set("Accepted", "Close Out Approved"),
},
2023: {
frf: new Map<string, string>()
Expand All @@ -108,7 +112,7 @@ export const bapStatusMap = {
.set("Withdrawn", "Withdrawn")
.set("Coordinator Denied", "Funding Denied")
.set("Accepted", "Funding Approved"),
crf: new Map<string, string>(),
crf: new Map<string, string>(), // TODO
},
};

Expand Down
15 changes: 12 additions & 3 deletions app/client/src/routes/submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
useSubmissionsQueries,
useSubmissions,
submissionNeedsEdits,
submissionNeedsReimbursement,
getUserInfo,
} from "@/utilities";
import { Loading, LoadingButtonIcon } from "@/components/loading";
Expand Down Expand Up @@ -724,12 +725,20 @@ function CRF2022Submission(props: { rebate: Rebate }) {

const crfBapInternalStatus = crf.bap?.status || "";
const crfFormioStatus = formioStatusMap.get(crf.formio.state);
const crfBapReimbursementNeeded = crf.bap?.reimbursementNeeded || false;

const crfNeedsReimbursement = submissionNeedsReimbursement({
status: crfBapInternalStatus,
reimbursementNeeded: crfBapReimbursementNeeded,
});

const crfStatus = crfNeedsEdits
? "Edits Requested"
: bapStatusMap["2022"].crf.get(crfBapInternalStatus) ||
crfFormioStatus ||
"";
: crfNeedsReimbursement
? "Reimbursement Needed"
: bapStatusMap["2022"].crf.get(crfBapInternalStatus) ||
crfFormioStatus ||
"";

const crfApproved = crfStatus === "Close Out Approved";

Expand Down
92 changes: 67 additions & 25 deletions app/client/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type BapFormSubmission = {
CSB_Funding_Request_Status__c: string;
CSB_Payment_Request_Status__c: string;
CSB_Closeout_Request_Status__c: string;
Reimbursement_Needed__c: boolean;
attributes: { type: string; url: string };
};
attributes: { type: string; url: string };
Expand Down Expand Up @@ -278,6 +279,7 @@ export type BapSubmission = {
rebateId: string | null; // CSB Rebate ID (6 digits)
reviewItemId: string | null; // CSB Rebate ID with form/version ID (9 digits)
status: string | null;
reimbursementNeeded: boolean;
};

export type Rebate = {
Expand Down Expand Up @@ -372,8 +374,8 @@ export function useHelpdeskAccess() {
return !user
? "pending"
: userRoles.includes("csb_admin") || userRoles.includes("csb_helpdesk")
? "success"
: "failure";
? "success"
: "failure";
}

/** Custom hook to fetch CSB config. */
Expand Down Expand Up @@ -446,8 +448,8 @@ export function useChangeRequestsQuery(rebateYear: RebateYear) {
rebateYear === "2022"
? changeRequest2022Query
: rebateYear === "2023"
? changeRequest2023Query
: changeRequestQuery;
? changeRequest2023Query
: changeRequestQuery;

return useQuery(query);
}
Expand All @@ -461,8 +463,8 @@ export function useChangeRequestsData(rebateYear: RebateYear) {
return rebateYear === "2022"
? queryClient.getQueryData<[]>(["formio/2022/changes"])
: rebateYear === "2023"
? queryClient.getQueryData<FormioChange2023Submission[]>(["formio/2023/changes"]) // prettier-ignore
: undefined;
? queryClient.getQueryData<FormioChange2023Submission[]>(["formio/2023/changes"]) // prettier-ignore
: undefined;
}

/** Custom hook to fetch submissions from the BAP and Formio. */
Expand All @@ -487,10 +489,10 @@ export function useSubmissionsQueries(rebateYear: RebateYear) {
Record_Type_Name__c.startsWith("CSB Funding Request") // prettier-ignore
? "frfs"
: Record_Type_Name__c.startsWith("CSB Payment Request")
? "prfs"
: Record_Type_Name__c.startsWith("CSB Close Out Request")
? "crfs"
: null;
? "prfs"
: Record_Type_Name__c.startsWith("CSB Close Out Request")
? "crfs"
: null;

if (rebateYear && formType) {
object[rebateYear][formType].push(submission);
Expand Down Expand Up @@ -589,8 +591,8 @@ export function useSubmissionsQueries(rebateYear: RebateYear) {
rebateYear === "2022"
? [bapQuery, formioFRF2022Query, formioPRF2022Query, formioCRF2022Query]
: rebateYear === "2023"
? [bapQuery, formioFRF2023Query, formioPRF2023Query, formioCRF2023Query]
: [];
? [bapQuery, formioFRF2023Query, formioPRF2023Query, formioCRF2023Query]
: [];

return useQueries({ queries });
}
Expand All @@ -609,22 +611,22 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
rebateYear === "2022"
? queryClient.getQueryData<FormioFRF2022Submission[]>(["formio/2022/frf-submissions"]) // prettier-ignore
: rebateYear === "2023"
? queryClient.getQueryData<FormioFRF2023Submission[]>(["formio/2023/frf-submissions"]) // prettier-ignore
: undefined;
? queryClient.getQueryData<FormioFRF2023Submission[]>(["formio/2023/frf-submissions"]) // prettier-ignore
: undefined;

const formioPRFSubmissions =
rebateYear === "2022"
? queryClient.getQueryData<FormioPRF2022Submission[]>(["formio/2022/prf-submissions"]) // prettier-ignore
: rebateYear === "2023"
? queryClient.getQueryData<FormioPRF2023Submission[]>(["formio/2023/prf-submissions"]) // prettier-ignore
: undefined;
? queryClient.getQueryData<FormioPRF2023Submission[]>(["formio/2023/prf-submissions"]) // prettier-ignore
: undefined;

const formioCRFSubmissions =
rebateYear === "2022"
? queryClient.getQueryData<FormioCRF2022Submission[]>(["formio/2022/crf-submissions"]) // prettier-ignore
: rebateYear === "2023"
? queryClient.getQueryData<FormioCRF2023Submission[]>(["formio/2023/crf-submissions"]) // prettier-ignore
: undefined;
? queryClient.getQueryData<FormioCRF2023Submission[]>(["formio/2023/crf-submissions"]) // prettier-ignore
: undefined;

const submissions: {
[rebateId: string]: Rebate;
Expand Down Expand Up @@ -657,6 +659,7 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
const rebateId = bapMatch?.Parent_Rebate_ID__c || null;
const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null;
const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Funding_Request_Status__c || null; // prettier-ignore
const reimbursementNeeded = bapMatch?.Parent_CSB_Rebate__r?.Reimbursement_Needed__c || false; // prettier-ignore

/**
* NOTE: If new FRF submissions have been reciently created in Formio and
Expand All @@ -670,7 +673,15 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
rebateYear,
frf: {
formio: { ...formioFRFSubmission },
bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status },
bap: {
modified,
comboKey,
mongoId,
rebateId,
reviewItemId,
status,
reimbursementNeeded,
},
},
prf: { formio: null, bap: null },
crf: { formio: null, bap: null },
Expand All @@ -686,8 +697,8 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
rebateYear === "2022"
? (formioPRFSubmission as FormioPRF2022Submission).data.hidden_bap_rebate_id // prettier-ignore
: rebateYear === "2023"
? (formioPRFSubmission as FormioPRF2023Submission).data._bap_rebate_id
: null;
? (formioPRFSubmission as FormioPRF2023Submission).data._bap_rebate_id
: null;

const bapMatch = bapFormSubmissions[rebateYear].prfs.find((bapPRFSub) => {
return bapPRFSub.Parent_Rebate_ID__c === formioBapRebateId;
Expand All @@ -699,11 +710,20 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
const rebateId = bapMatch?.Parent_Rebate_ID__c || null;
const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null;
const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Payment_Request_Status__c || null; // prettier-ignore
const reimbursementNeeded = bapMatch?.Parent_CSB_Rebate__r?.Reimbursement_Needed__c || false; // prettier-ignore

if (formioBapRebateId && submissions[formioBapRebateId]) {
submissions[formioBapRebateId].prf = {
formio: { ...formioPRFSubmission },
bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status },
bap: {
modified,
comboKey,
mongoId,
rebateId,
reviewItemId,
status,
reimbursementNeeded,
},
};
}
}
Expand All @@ -717,8 +737,8 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
rebateYear === "2022"
? (formioCRFSubmission as FormioCRF2022Submission).data.hidden_bap_rebate_id // prettier-ignore
: rebateYear === "2023"
? (formioCRFSubmission as FormioCRF2023Submission).data._bap_rebate_id
: null;
? (formioCRFSubmission as FormioCRF2023Submission).data._bap_rebate_id
: null;

const bapMatch = bapFormSubmissions[rebateYear].crfs.find((bapCRFSub) => {
return bapCRFSub.Parent_Rebate_ID__c === formioBapRebateId;
Expand All @@ -730,11 +750,20 @@ function useCombinedSubmissions(rebateYear: RebateYear) {
const rebateId = bapMatch?.Parent_Rebate_ID__c || null;
const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null;
const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Closeout_Request_Status__c || null; // prettier-ignore
const reimbursementNeeded = bapMatch?.Parent_CSB_Rebate__r?.Reimbursement_Needed__c || false; // prettier-ignore

if (formioBapRebateId && submissions[formioBapRebateId]) {
submissions[formioBapRebateId].crf = {
formio: { ...formioCRFSubmission },
bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status },
bap: {
modified,
comboKey,
mongoId,
rebateId,
reviewItemId,
status,
reimbursementNeeded,
},
};
}
}
Expand Down Expand Up @@ -856,6 +885,19 @@ export function submissionNeedsEdits(options: {
);
}

/**
* Determines whether a submission needs reimbursement, based on the BAP status
* and reimbursement status.
*/
export function submissionNeedsReimbursement(options: {
status: string;
reimbursementNeeded: boolean;
}) {
const { status, reimbursementNeeded } = options;

return status === "Branch Director Approved" && reimbursementNeeded;
}

/**
* Returns a user’s title and name when provided an email address and a SAM.gov
* entity/record.
Expand Down
4 changes: 2 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epa-csb-rebate-forms-app",
"version": "5.0.1",
"version": "5.0.2",
"description": "U.S. EPA CSB Rebate Forms Application",
"license": "CC0-1.0",
"author": "USEPA (https://www.epa.gov)",
Expand Down
17 changes: 11 additions & 6 deletions app/server/app/utilities/bap.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const { submissionPeriodOpen } = require("../config/formio");
* CSB_Funding_Request_Status__c: string
* CSB_Payment_Request_Status__c: string
* CSB_Closeout_Request_Status__c: string
* Reimbursement_Needed__c: boolean
* }} Parent_CSB_Rebate__r
* @property {{
* type: string
Expand Down Expand Up @@ -517,7 +518,8 @@ async function queryForBapFormSubmissionData(
// Rebate_Program_Year__c,
// Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c,
// Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c,
// Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c
// Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c,
// Parent_CSB_Rebate__r.Reimbursement_Needed__c
// FROM
// Order_Request__c
// WHERE
Expand Down Expand Up @@ -546,6 +548,7 @@ async function queryForBapFormSubmissionData(
"Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c": 1,
"Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c": 1,
"Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c": 1,
"Parent_CSB_Rebate__r.Reimbursement_Needed__c": 1,
},
)
.execute(async (err, records) => ((await err) ? err : records));
Expand Down Expand Up @@ -613,7 +616,8 @@ async function queryForBapFormSubmissionsStatuses(req) {
// Rebate_Program_Year__c,
// Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c,
// Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c,
// Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c
// Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c,
// Parent_CSB_Rebate__r.Reimbursement_Needed__c
// FROM
// Order_Request__c
// WHERE
Expand Down Expand Up @@ -643,6 +647,7 @@ async function queryForBapFormSubmissionsStatuses(req) {
"Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c": 1,
"Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c": 1,
"Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c": 1,
"Parent_CSB_Rebate__r.Reimbursement_Needed__c": 1,
},
)
.sort({ CreatedDate: -1 })
Expand Down Expand Up @@ -1599,10 +1604,10 @@ function checkFormSubmissionPeriodAndBapStatus({
formType === "frf"
? "CSB_Funding_Request_Status__c"
: formType === "prf"
? "CSB_Payment_Request_Status__c"
: formType === "crf"
? "CSB_Closeout_Request_Status__c"
: null;
? "CSB_Payment_Request_Status__c"
: formType === "crf"
? "CSB_Closeout_Request_Status__c"
: null;

return submission?.Parent_CSB_Rebate__r?.[statusField] === "Edits Requested"
? Promise.resolve()
Expand Down
Loading

0 comments on commit 4ff7020

Please sign in to comment.