Skip to content

Commit

Permalink
feat(update RAI withdraw behavior): Update RAI withdraw behavior to a…
Browse files Browse the repository at this point in the history
…ccommodate Medicaid specific biz logic (#357)

* change rai behavior for medicaid

* Update rule for issue rai

* Set withdrawn date for medicaid and adjust rules, per AC.

* Correct issue rai behavior for medicaid

* fix timestamps

* hide issue rai for chip when rai withdraw is enabled
  • Loading branch information
mdial89f authored Feb 8, 2024
1 parent 666adf5 commit 4523f31
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 29 deletions.
14 changes: 13 additions & 1 deletion src/packages/shared-utils/package-actions/rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Action,
ActionRule,
PlanType,
SEATOOL_STATUS,
finalDispositionStatuses,
} from "../../shared-types";
Expand All @@ -10,7 +11,18 @@ const arIssueRai: ActionRule = {
action: Action.ISSUE_RAI,
check: (checker, user) =>
checker.isInActivePendingStatus &&
(!checker.hasLatestRai || checker.hasRequestedRai) &&
(
// Doesn't have any RAIs
!checker.hasLatestRai ||
(
// The latest RAI is complete
checker.hasCompletedRai &&
// The package is not a medicaid spa (med spas only get 1 rai)
!checker.planTypeIs([PlanType.MED_SPA]) &&
// The package does not have RAI Response Withdraw enabled
!checker.hasEnabledRaiWithdraw
)
) &&
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
76 changes: 53 additions & 23 deletions src/services/api/handlers/packageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { produceMessage } from "../libs/kafka";
import { response } from "../libs/handler";
import { SEATOOL_STATUS } from "shared-types/statusHelper";
import { seaToolFriendlyTimestamp } from "shared-utils";
import { formatSeatoolDate, seaToolFriendlyTimestamp } from "shared-utils";
import { buildStatusMemoQuery } from "../libs/statusMemo";

const TOPIC_NAME = process.env.topicName as string;
Expand Down Expand Up @@ -119,29 +119,57 @@ export async function withdrawRai(body: RaiWithdraw, document: any) {
const transaction = new sql.Transaction(pool);
try {
await transaction.begin();
// 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);
`);
// 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}'
`);
}

// 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);

const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(result.data.id, "RAI Response Withdrawn"));
// Set a detailed message in the Status Memo
const statusMemoUpdate = await transaction.request().query(
buildStatusMemoQuery(
result.data.id,
`RAI Response Withdrawn. Response was received ${formatSeatoolDate(
document.raiReceivedDate
)} and withdrawn ${new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
year: "numeric",
month: "2-digit",
day: "2-digit",
})}`
)
);
console.log(statusMemoUpdate);

// write to kafka here
Expand Down Expand Up @@ -190,7 +218,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
5 changes: 4 additions & 1 deletion src/services/api/libs/statusMemo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export function buildStatusMemoQuery(id: string, msg: string) {
const printable = new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
});
return `
UPDATE SEA.dbo.State_Plan
SET
Status_Memo = '- OneMAC Activity: ' + FORMAT(DATEADD(SECOND, CAST('${Date.now()}' AS BIGINT) / 1000, '1970-01-01'), 'MM/dd/yyyy HH:mm') + ' - ' + '${msg} ' + '\r' + CAST(ISNULL(Status_Memo, '') AS VARCHAR(MAX))
Status_Memo = '- OneMAC Activity: ${printable} - ${msg} \r' + CAST(ISNULL(Status_Memo, '') AS VARCHAR(MAX))
WHERE ID_Number = '${id}'
`;
}

0 comments on commit 4523f31

Please sign in to comment.