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

#2001 - Changes to handle PD PPD Part 1 #2115

Merged
merged 11 commits into from
Jul 18, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ export const DUPLICATE_SABC_CODE = "DUPLICATE_SABC_CODE";
* Institution location not valid.
*/
export const INSTITUTION_LOCATION_NOT_VALID = "INSTITUTION_LOCATION_NOT_VALID";

/**
* Request for permanent disability not allowed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The requests are no longer specifically for permanent disability.

*/
export const PD_REQUEST_NOT_ALLOWED = "PD_REQUEST_NOT_ALLOWED";
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe("ApplicationOfferingChangeRequestInstitutionsController(e2e)-getComplet

const searchKeyword = "TestStudent";
const endpoint = `/institutions/location/${collegeFLocation.id}/application-offering-change-request/completed?page=0&pageLimit=10&searchCriteria=${searchKeyword}`;
console.log(endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


// Act/Assert
await request(app.getHttpServer())
.get(endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
UserToken,
} from "../../auth/decorators";
import { StudentUserToken } from "../../auth/userToken.interface";
import { ClientTypeBaseRoute } from "../../types";
import { ApiProcessError, ClientTypeBaseRoute } from "../../types";
import BaseController from "../BaseController";
import { ATBCIntegrationProcessingService } from "@sims/integrations/atbc-integration";
import { PDStatus } from "@sims/sims-db";
import { PD_REQUEST_NOT_ALLOWED } from "../../constants";

@AllowAuthorizedParty(AuthorizedParties.student)
@RequiresStudentAccount()
Expand Down Expand Up @@ -45,18 +47,17 @@ export class ATBCStudentController extends BaseController {
const student = await this.studentService.getStudentById(
studentUserToken.studentId,
);
// Check the PD status in DB. Student should only be allowed to check the PD status once.
// studentPDSentAt is set when student apply for PD status for the first.
// studentPDVerified is null before PD scheduled job update status.
// studentPDVerified is true if PD confirmed by ATBC or is true from sfas_individual table.
// studentPDVerified is false if PD denied by ATBC.
// To apply for a PD, SIN validation must be completed for the student and
// not applied for PD already.
Copy link
Contributor

Choose a reason for hiding this comment

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

@dheepak-aot , can you confirm this? In our grooming, I remember saying that the student can apply for PD multiple times, especially for the PPD

Copy link
Collaborator Author

@dheepak-aot dheepak-aot Jul 17, 2023

Choose a reason for hiding this comment

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

Thanks for bring this up.
I had a quick chat with @JasonCTang on the same and got to know that, as per the current understanding, student requests disability status only once in our application. In case they want to apply again because of something happened to them later after losing their status, they update ATBC directly and ATBC will be updating the student disability status which we read on daily basis through their response API.
I will update this information to the ticket.

Let me know if it is still not clear. We can talk.

Copy link
Contributor

@ann-aot ann-aot Jul 17, 2023

Choose a reason for hiding this comment

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

Thanks @dheepak-aot for the details. Ya, adding it to the ticket will make it easier for future development. Keeping it open for other devs

if (
!student.sinValidation.isValidSIN ||
!!student.studentPDSentAt ||
student.studentPDVerified !== null
student.pdStatus !== PDStatus.NotRequested
) {
throw new UnprocessableEntityException(
"Either the client does not have a validated SIN or the request was already sent to ATBC.",
new ApiProcessError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

"Either SIN validation is not complete or requested for PD already.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that we can have it adjusted to PD/PPD for now.

sh16011993 marked this conversation as resolved.
Show resolved Hide resolved
PD_REQUEST_NOT_ALLOWED,
),
);
}
// This is the only place in application where we call an external application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
saveFakeStudent,
} from "@sims/test-utils";
import { Application, Institution, InstitutionLocation } from "@sims/sims-db";
import { determinePDStatus, getUserFullName } from "../../../../utilities";
import { getUserFullName } from "../../../../utilities";
import { getISODateOnlyString } from "@sims/utilities";
import { saveStudentApplicationForCollegeC } from "./student.institutions.utils";

Expand Down Expand Up @@ -86,7 +86,7 @@ describe("StudentInstitutionsController(e2e)-getStudentProfile", () => {
},
phone: student.contactInfo.phone,
},
pdStatus: determinePDStatus(student),
pdStatus: student.pdStatus,
validSin: student.sinValidation.isValidSIN,
sin: student.sinValidation.sin,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
mockUserLoginInfo,
} from "../../../../testHelpers";
import { saveFakeStudent } from "@sims/test-utils";
import { determinePDStatus, getUserFullName } from "../../../../utilities";
import { getUserFullName } from "../../../../utilities";
import { TestingModule } from "@nestjs/testing";

describe("StudentInstitutionsController(e2e)-getStudentProfile", () => {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("StudentInstitutionsController(e2e)-getStudentProfile", () => {
},
phone: student.contactInfo.phone,
},
pdStatus: determinePDStatus(student),
pdStatus: student.pdStatus,
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

validSin: student.sinValidation.isValidSIN,
sin: student.sinValidation.sin,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
FileOriginType,
NOTE_DESCRIPTION_MAX_LENGTH,
FILE_NAME_MAX_LENGTH,
PDStatus,
} from "@sims/sims-db";
import {
AddressAPIOutDTO,
AddressDetailsAPIInDTO,
} from "../../../route-controllers/models/common.dto";
import { StudentPDStatus } from "../../../types";

export class ContactInformationAPIOutDTO {
address: AddressAPIOutDTO;
Expand Down Expand Up @@ -180,7 +180,7 @@ export class StudentProfileAPIOutDTO {
dateOfBirth: string;
contact: ContactInformationAPIOutDTO;
validSin: boolean;
pdStatus: StudentPDStatus;
pdStatus: PDStatus;
sin: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ApplicationPaginationOptionsAPIInDTO,
PaginatedResultsAPIOutDTO,
} from "../models/pagination.dto";
import { determinePDStatus, getUserFullName } from "../../utilities";
import { getUserFullName } from "../../utilities";
import { getISODateOnlyString } from "@sims/utilities";
import { AddressInfo, Application, Student } from "@sims/sims-db";
import {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class StudentControllerService {
address: transformAddressDetailsForAddressBlockForm(address),
phone: student.contactInfo.phone,
},
pdStatus: determinePDStatus(student),
pdStatus: student.pdStatus,
validSin: student.sinValidation.isValidSIN,
sin: student.sinValidation.sin,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DisbursementOverawardOriginType,
RestrictionNotificationType,
StudentRestriction,
PDStatus,
} from "@sims/sims-db";
import { DataSource, EntityManager } from "typeorm";
import { StudentUserToken } from "../../auth/userToken.interface";
Expand Down Expand Up @@ -69,6 +70,7 @@ export class StudentService extends RecordDataModelService<Student> {
"student.studentPDVerified",
"student.studentPDSentAt",
"student.studentPDUpdateAt",
"student.pdStatus",
"sinValidation.id",
"sinValidation.sin",
"sinValidation.isValidSIN",
Expand Down Expand Up @@ -166,11 +168,14 @@ export class StudentService extends RecordDataModelService<Student> {
student.sinConsent = studentInfo.sinConsent;
try {
// Get PD status from SFAS integration data.
student.studentPDVerified = await this.sfasIndividualService.getPDStatus(
user.lastName,
student.birthDate,
studentSIN,
);
const sfasStudentPDVerified =
await this.sfasIndividualService.getPDStatus(
user.lastName,
student.birthDate,
studentSIN,
);
student.studentPDVerified = sfasStudentPDVerified;
student.pdStatus = this.getPDStatus(sfasStudentPDVerified);
} catch (error) {
this.logger.error("Unable to get SFAS information of student.");
this.logger.error(error);
Expand Down Expand Up @@ -667,4 +672,19 @@ export class StudentService extends RecordDataModelService<Student> {
entityManager,
);
}

/**
* Get student PD status.
* @param pdVerified sfas pdVerified flag.
* @returns PD status.
ann-aot marked this conversation as resolved.
Show resolved Hide resolved
*/
private getPDStatus(pdVerified: boolean): PDStatus {
if (pdVerified) {
return PDStatus.PD;
}
if (pdVerified === false) {
return PDStatus.Declined;
}
return PDStatus.NotRequested;
}
}
1 change: 0 additions & 1 deletion sources/packages/backend/apps/api/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export * from "./formsFlow";
export * from "./institutionAuth";
export * from "./optionItem";
export * from "./apiProcessError";
export * from "./pdStatus";
export * from "./clientTypeBaseRoute";
9 changes: 0 additions & 9 deletions sources/packages/backend/apps/api/src/types/pdStatus.ts

This file was deleted.

21 changes: 0 additions & 21 deletions sources/packages/backend/apps/api/src/utilities/student-utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
import { StudentPDStatus } from "../types/pdStatus";
import { Student } from "@sims/sims-db";

/**
* Determines the permanent disability status from Student Entity.
* @param student
* @returns PDStatus enum
*/
export const determinePDStatus = (student: Student): StudentPDStatus => {
if (student.studentPDVerified) {
return StudentPDStatus.Yes;
}
if (student.studentPDVerified === false) {
return StudentPDStatus.No;
}
if (student.studentPDSentAt) {
return StudentPDStatus.Pending;
}
return StudentPDStatus.NotRequested;
};

export const deliveryMethod = (
deliveredOnline: boolean,
deliveredOnSite: boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { getSQLFileData } from "../utilities/sqlLoader";

export class AddStudentPDStatusCol1689350242512 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData("Create-permanent-disability-status.sql", "Types"),
);
await queryRunner.query(getSQLFileData("Add-col-pd-status.sql", "Student"));
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData("Drop-col-pd-status.sql", "Student"),
);
await queryRunner.query(
getSQLFileData("Drop-permanent-disability-status.sql", "Types"),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ALTER TABLE
sims.students
ADD
COLUMN IF NOT EXISTS pd_status sims.permanent_disability_status;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope that it will not open a can of worms about naming possibilities 😉
I believe that the acronyms for PD/PPD mean

  • PPD: Persistent or Prolonged Disability
  • PD: Permanent Disability
    With the above in mind I believe that instead of permanent_disability_status it should be only disability_status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As per discussion with the dev team, we decided to use disability status instead of permanent disability status and try to change the existing code as much as possible.


COMMENT ON COLUMN sims.students.pd_status IS 'Permanent disability status of the student.';

-- Update the pd_status column based on pd_verified and pd_date_sent for existing data.
UPDATE
sims.students
SET
pd_status = CASE
WHEN pd_verified IS NULL
AND pd_date_sent IS NOT NULL THEN 'Requested'
WHEN pd_verified = true THEN 'PD'
WHEN pd_verified = false THEN 'Declined'
ELSE 'Not requested' :: sims.permanent_disability_status
END;

-- Set not null constraint after updating the column.
ALTER TABLE
sims.students
ALTER COLUMN
pd_status
SET
NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE
sims.students DROP COLUMN pd_status;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TYPE sims.permanent_disability_status AS ENUM (
'Not requested',
'Requested',
'PD',
'PPD',
'Declined'
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TYPE sims.permanent_disability_status;
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ATBCIntegrationProcessingService {
if (response) {
const auditUser = await this.systemUsersService.systemUser();
// Update PD sent date.
await this.studentService.updatePDSentDate(student.id, auditUser);
await this.studentService.updatePDRequested(student.id, auditUser);
ann-aot marked this conversation as resolved.
Show resolved Hide resolved
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable } from "@nestjs/common";
import {
PDStatus,
RecordDataModelService,
SINValidation,
Student,
User,
} from "@sims/sims-db";
import { getUTCNow } from "@sims/utilities";
import { InjectLogger, LoggerService } from "@sims/utilities/logger";
import { DataSource, EntityManager } from "typeorm";
import { DataSource, EntityManager, UpdateResult } from "typeorm";

@Injectable()
export class StudentService extends RecordDataModelService<Student> {
Expand All @@ -32,23 +33,25 @@ export class StudentService extends RecordDataModelService<Student> {
}

/**
* Update the PD Sent Date
* Update the PD status to requested.
* @param studentId student who's PD status is to be updated.
* @param auditUser user who is making the changes.
* @returns Student who's PD sent date is updated.
* @returns update result.
*/
async updatePDSentDate(studentId: number, auditUser: User): Promise<Student> {
// get the Student Object
const studentToUpdate = await this.repo.findOneOrFail({
where: { id: studentId },
});
if (studentToUpdate) {
const now = new Date();
studentToUpdate.studentPDSentAt = now;
studentToUpdate.modifier = auditUser;
studentToUpdate.updatedAt = now;
return this.repo.save(studentToUpdate);
}
async updatePDRequested(
studentId: number,
auditUser: User,
): Promise<UpdateResult> {
const now = new Date();
return this.repo.update(
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

{ id: studentId },
{
studentPDSentAt: now,
modifier: auditUser,
updatedAt: now,
pdStatus: PDStatus.Requested,
},
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ export * from "./queue_configuration.model";
export * from "./student-assessment-status.type";
export * from "./application-offering-change-request-status.type";
export * from "./application-offering-change-request.model";
export * from "./student-pd-status.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Permanent disability status of student.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything is SIMS used to be named using PD as permanent disability which is no longer true with the inclusion of PPD.
I would say that we need to reinforce it for the new things and try to adjust the current ones as possible.
As a suggestion, I would remove the "Permanent" from the comment and name the below enum as DisabilityStatus.

*/
export enum PDStatus {
NotRequested = "Not requested",
Requested = "Requested",
PD = "PD",
PPD = "PPD",
Declined = "Declined",
}
Loading