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

#3594 - Email to Student - 2nd Disbursement has passed, still pending (Part 2) #4303

Conversation

lewischen-aot
Copy link
Collaborator

@lewischen-aot lewischen-aot commented Jan 29, 2025

As the second part of the story, this PR has the following changes

  • Added the new notification generation process in the existing student-application-notifications scheduler.
  • Refactored the current scheduler processor to allow multiple notifications to be handled.
    • Created a "service" to isolate each notification.
    • The processor should trigger all the notifications.
  • Created the query to get the second disbursements where the disbursement dates have passed and the institution has not yet approved the second COE/disbursement. The logic is as follows:
    • First, retrieves disbursements with disbursement dates that have passed today, notifications have not been sent for completed applications, which have two disbursements with the second disbursement being either "Completed" or "Required" for its COE status. Use COUNT(assessment.id) to differentiate 2-disbursements applications from 1-disbursement applications.
    • Then, find the disbursements with "Required" COE status from the above subquery (the disbursement Ids) that are pending.
    • Conditions to send the notification
      • Disbursement should be "pending".
      • COE should be "pending" "required".
      • Only completed application current assessment, not overwritten.
  • Send the notification to the student using the GC Notify Template in the story and mark the assessment Id in the record's meta data to ensure the notification is only sent once.

Screenshot of the notification email
Screenshot 2025-01-28 165147

SQL version of the query as a reference

with disbursement_set as (
select
	max(ds.id) as "id"
from sims.disbursement_schedules ds 
inner join sims.student_assessments sa on sa.id = ds.student_assessment_id 
inner join sims.applications a on a.id = sa.application_id 
and a."application_status" = 'Completed'
and a.is_archived = false
and ds."coe_status" in ['Completed', 'Required']
and ds.disbursement_date < :today
group by sa.id
having count(sa.id) = 2
)
select
	ds.id as "disbursement_id",
	sa.id as "assessment_id",
	ds.disbursement_date,
	ds."disbursement_schedule_status",
        u.id as "user_id",
	u.first_name as "given_names",
	u.last_name as "last_name"
from sims.disbursement_schedules ds 
inner join sims.student_assessments sa on sa.id = ds.student_assessment_id 
inner join sims.applications a on a.id = sa.application_id 
inner join sims.students s on s.id = a.student_id
inner join sims.users u on u.id = s.user_id
where ds.id in (select "id" from disbursement_set)
and ds."coe_status" = 'Required'
and ds."disbursement_schedule_status" = 'Pending';

@lewischen-aot lewischen-aot self-assigned this Jan 29, 2025
@lewischen-aot lewischen-aot marked this pull request as ready for review January 29, 2025 22:00
@lewischen-aot lewischen-aot changed the title #3594 - Email to Student - 2nd Disbursement has passed, still pending #3594 - Email to Student - 2nd Disbursement has passed, still pending (Part 2) Jan 29, 2025
Copy link
Collaborator

@sh16011993 sh16011993 left a comment

Choose a reason for hiding this comment

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

Great work @lewischen-aot 👍 Left a few comments.

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Great work, please take a look at the comments.

* @param processSummary process summary for logging.
*/
async createNotification(processSummary: ProcessSummary): Promise<void> {
const notificationLog = new ProcessSummary();
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines 309 to 310
coeStatus: [COEStatus.completed, COEStatus.required],
disbursementScheduleStatusPending: DisbursementScheduleStatus.Pending,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👍

.innerJoin("assessment.application", "application")
.where(`NOT EXISTS (${notificationExistsQuery})`)
.andWhere("application.applicationStatus = :applicationStatusCompleted")
.andWhere("application.isArchived = false")
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@sh16011993 sh16011993 left a comment

Choose a reason for hiding this comment

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

Great work @lewischen-aot 👍

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes, especially by putting the effort into the SQL query. Please take a look at the remaining comments.

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.36% ( 3887 / 17380 )
Methods: 10.27% ( 226 / 2201 )
Lines: 25.71% ( 3353 / 13044 )
Branches: 14.43% ( 308 / 2135 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.59% ( 589 / 898 )
Methods: 59.63% ( 65 / 109 )
Lines: 68.72% ( 468 / 681 )
Branches: 51.85% ( 56 / 108 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 86.72% ( 1397 / 1611 )
Methods: 83.6% ( 158 / 189 )
Lines: 88.99% ( 1156 / 1299 )
Branches: 67.48% ( 83 / 123 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 68.11% ( 6019 / 8837 )
Methods: 65.84% ( 742 / 1127 )
Lines: 71.94% ( 4712 / 6550 )
Branches: 48.71% ( 565 / 1160 )

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes and looking into the query. Looks good 👍

@lewischen-aot lewischen-aot added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit 1beec0d Jan 31, 2025
21 checks passed
@lewischen-aot lewischen-aot deleted the feature/#3594-email-to-student-2nd-disbursement-has-passed-part-2 branch January 31, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants