Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(update RAI withdraw behavior): Update RAI withdraw behavior to accommodate Medicaid specific biz logic #357

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/packages/shared-utils/package-actions/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const arIssueRai: ActionRule = {
action: Action.ISSUE_RAI,
check: (checker, user) =>
checker.isInActivePendingStatus &&
(!checker.hasLatestRai || checker.hasRequestedRai) &&
(!checker.hasLatestRai || checker.hasCompletedRai) &&
isCmsWriteUser(user),
};

Expand Down
10 changes: 6 additions & 4 deletions src/packages/shared-utils/packageCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ export const PackageCheck = ({
checkStatus(seatoolStatus, authorizedStatuses),
};
const raiChecks = {
/** Latest RAI is requested and status is Pending-RAI **/
hasRequestedRai: !!raiRequestedDate && !raiReceivedDate && !raiWithdrawnDate,
/** Latest RAI is not null **/
/** There is an RAI and it does not have a response **/
hasRequestedRai: !!raiRequestedDate && !raiReceivedDate,
/** There is an RAI **/
hasLatestRai: !!raiRequestedDate,
/** Latest RAI has been responded to **/
/** There is an RAI, it has a response, and it has not been withdrawn **/
hasRaiResponse: !!raiRequestedDate && !!raiReceivedDate && !raiWithdrawnDate,
/** Latest RAI has a response and/or has been withdrawn **/
hasCompletedRai: !!raiRequestedDate && !!raiReceivedDate,
/** RAI Withdraw has been enabled **/
hasEnabledRaiWithdraw: raiWithdrawEnabled,
};
Expand Down
68 changes: 48 additions & 20 deletions src/services/api/handlers/packageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,55 @@ export async function withdrawRai(body: RaiWithdraw, document: any) {
const transaction = new sql.Transaction(pool);
try {
await transaction.begin();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is obviously a lot of refactor opportunity here...
I went with the verbose approach, and didn't bother condensing anything, as the api actions in general are soon to be refactored.

// Issue RAI
const query1 = `
UPDATE SEA.dbo.RAI
SET RAI_WITHDRAWN_DATE = DATEADD(s, CONVERT(int, LEFT('${today}', 10)), CAST('19700101' AS DATETIME))
// How we withdraw an RAI Response varies based on authority or not
// Medicaid is handled differently from the rest.
if (body.authority == "MEDICAID") {
// Set Received Date to null
await transaction.request().query(`
UPDATE SEA.dbo.RAI
SET
RAI_RECEIVED_DATE = NULL,
RAI_WITHDRAWN_DATE = DATEADD(s, CONVERT(int, LEFT('${today}', 10)), CAST('19700101' AS DATETIME))
WHERE ID_Number = '${result.data.id}' AND RAI_REQUESTED_DATE = DATEADD(s, CONVERT(int, LEFT('${raiToWithdraw}', 10)), CAST('19700101' AS DATETIME))
`;
const result1 = await transaction.request().query(query1);
console.log(result1);

// Update Status
const query2 = `
UPDATE SEA.dbo.State_Plan
SET
SPW_Status_ID = (SELECT SPW_Status_ID FROM SEA.dbo.SPW_Status WHERE SPW_Status_DESC = '${SEATOOL_STATUS.PENDING}'),
Status_Date = dateadd(s, convert(int, left(${today}, 10)), cast('19700101' as datetime))
WHERE ID_Number = '${result.data.id}'
`;
const result2 = await transaction.request().query(query2);
console.log(result2);
`);
// Set Status to Pending - RAI
await transaction.request().query(`
UPDATE SEA.dbo.State_Plan
SET
SPW_Status_ID = (SELECT SPW_Status_ID FROM SEA.dbo.SPW_Status WHERE SPW_Status_DESC = '${SEATOOL_STATUS.PENDING_RAI}'),
Status_Date = dateadd(s, convert(int, left(${today}, 10)), cast('19700101' as datetime))
WHERE ID_Number = '${result.data.id}'
`);
} else {
// Set Withdrawn_Date on the existing RAI
await transaction.request().query(`
UPDATE SEA.dbo.RAI
SET
RAI_WITHDRAWN_DATE = DATEADD(s, CONVERT(int, LEFT('${today}', 10)), CAST('19700101' AS DATETIME))
WHERE ID_Number = '${result.data.id}' AND RAI_REQUESTED_DATE = DATEADD(s, CONVERT(int, LEFT('${raiToWithdraw}', 10)), CAST('19700101' AS DATETIME))
`);
// Set Status to Pending
await transaction.request().query(`
UPDATE SEA.dbo.State_Plan
SET
SPW_Status_ID = (SELECT SPW_Status_ID FROM SEA.dbo.SPW_Status WHERE SPW_Status_DESC = '${SEATOOL_STATUS.PENDING}'),
Status_Date = dateadd(s, convert(int, left(${today}, 10)), cast('19700101' as datetime))
WHERE ID_Number = '${result.data.id}'
`);
}

// Set a detailed message in the Status Memo
const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(result.data.id, "RAI Response Withdrawn"));
.query(
buildStatusMemoQuery(
result.data.id,
`"RAI Response Withdrawn. Response was received ${document.raiReceivedDate.slice(
0,
10
)} and withdrawn ${new Date(today).toISOString().slice(0, 10)}`
)
);
console.log(statusMemoUpdate);

// write to kafka here
Expand Down Expand Up @@ -190,7 +216,9 @@ export async function respondToRai(body: RaiResponse, document: any) {
// Issue RAI
const query1 = `
UPDATE SEA.dbo.RAI
SET RAI_RECEIVED_DATE = DATEADD(s, CONVERT(int, LEFT('${today}', 10)), CAST('19700101' AS DATETIME))
SET
RAI_RECEIVED_DATE = DATEADD(s, CONVERT(int, LEFT('${today}', 10)), CAST('19700101' AS DATETIME)),
RAI_WITHDRAWN_DATE = NULL
WHERE ID_Number = '${body.id}' AND RAI_REQUESTED_DATE = DATEADD(s, CONVERT(int, LEFT('${raiToRespondTo}', 10)), CAST('19700101' AS DATETIME))
`;
const result1 = await transaction.request().query(query1);
Expand Down
Loading