-
Notifications
You must be signed in to change notification settings - Fork 14
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
#3738 - SIMS to SFAS Part 2 #3829
Merged
Merged
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5a4682c
add environment variable
dheepak-aot 242842d
add environment variable
dheepak-aot bb28292
Service to get all student updates
dheepak-aot 1010479
sims to sfas integration and processing service
dheepak-aot b9a7c6c
Merge branch 'main' into feature/#3738-sims-to-sfas-part-2
dheepak-aot 9f83610
Create SIMSToSFAS students
dheepak-aot a6af2e0
SIMS to SFAS file lines.
dheepak-aot b489a3e
SIMS to SFAS file lines.
dheepak-aot 3c1e503
Added service methods
dheepak-aot 415733c
Added integration Service
dheepak-aot 67180cf
Sonar fixes
dheepak-aot f47fcda
Mapping fixes
dheepak-aot f98a21a
Mapping fixes
dheepak-aot 0b188be
improved the process summary logs
dheepak-aot 461b8e8
added comments
dheepak-aot 41adde9
added comments
dheepak-aot 8537234
Merge branch 'main' into feature/#3738-sims-to-sfas-part-2
dheepak-aot ad59a2a
adding footer
dheepak-aot d571036
review comments
dheepak-aot 9b0260d
review comments
dheepak-aot 7d93f44
review comments
dheepak-aot 7e87caf
review comments
dheepak-aot de56e8c
review comments
dheepak-aot 1be8d1e
review comments
dheepak-aot 4410574
review comments
dheepak-aot ae5d9bd
review comments
dheepak-aot 05ec2a2
review comments
dheepak-aot 38cd034
review comments
dheepak-aot c59841f
review comments
dheepak-aot 8f8d1b4
review comments
dheepak-aot 288012f
review comments
dheepak-aot e57356c
review comments
dheepak-aot f30b2b9
review comments
dheepak-aot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,8 @@ export enum FullTimeAwardTypes { | |
BGPD = "BGPD", | ||
SBSD = "SBSD", | ||
} | ||
|
||
export enum YNFlag { | ||
Y = "Y", | ||
N = "N", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
sources/packages/backend/libs/integrations/src/services/sfas/sims-to-sfas.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Student } from "@sims/sims-db"; | ||
|
||
export type StudentDetail = Student & { | ||
cslfOverawardTotal?: string; | ||
bcslOverawardTotal?: string; | ||
}; |
175 changes: 175 additions & 0 deletions
175
sources/packages/backend/libs/integrations/src/services/sfas/sims-to-sfas.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { StudentDetail } from "./sims-to-sfas.model"; | ||
import { | ||
BC_STUDENT_LOAN_AWARD_CODE, | ||
CANADA_STUDENT_LOAN_FULL_TIME_AWARD_CODE, | ||
} from "@sims/services/constants"; | ||
import { | ||
Application, | ||
ApplicationStatus, | ||
mapFromRawAndEntities, | ||
SFASBridgeLog, | ||
Student, | ||
} from "@sims/sims-db"; | ||
import { Brackets, Repository } from "typeorm"; | ||
|
||
/** | ||
* SIMS to SFAS services. | ||
*/ | ||
@Injectable() | ||
export class SIMSToSFASService { | ||
constructor( | ||
@InjectRepository(Student) | ||
private readonly studentRepo: Repository<Student>, | ||
@InjectRepository(Application) | ||
private readonly applicationRepo: Repository<Application>, | ||
@InjectRepository(SFASBridgeLog) | ||
private readonly sfasBridgeLogRepo: Repository<SFASBridgeLog>, | ||
) {} | ||
|
||
/** | ||
* Get the latest bridge file log date. | ||
* When there is no log, null will be returned. | ||
* @returns latest bridge file log date. | ||
*/ | ||
async getLatestBridgeFileLogDate(): Promise<Date | null> { | ||
const [latestBridgeFileLog] = await this.sfasBridgeLogRepo.find({ | ||
select: { id: true, referenceDate: true }, | ||
order: { referenceDate: "DESC" }, | ||
take: 1, | ||
}); | ||
return latestBridgeFileLog ? latestBridgeFileLog.referenceDate : null; | ||
} | ||
|
||
/** | ||
* Log the details of bridge file that was sent to SFAS. | ||
* @param referenceDate date when the bridge file data was extracted. | ||
* @param fileName bridge file name. | ||
*/ | ||
async logBridgeFileDetails( | ||
referenceDate: Date, | ||
fileName: string, | ||
): Promise<void> { | ||
await this.sfasBridgeLogRepo.insert({ | ||
referenceDate, | ||
generatedFileName: fileName, | ||
}); | ||
} | ||
|
||
/** | ||
* Get all student ids of students who have one or more updates | ||
* between the given period. | ||
* The updates can be one or more of the following: | ||
* - Student or User data | ||
* - SIN validation data | ||
* - CAS supplier data | ||
* - Overawards data | ||
* @param modifiedSince the date after which the student data was updated. | ||
* @param modifiedUntil the date until which the student data was updated. | ||
*/ | ||
async getAllStudentsWithUpdates( | ||
modifiedSince: Date, | ||
modifiedUntil: Date, | ||
): Promise<number[]> { | ||
const applicationsWithStudentUpdates = await this.applicationRepo | ||
.createQueryBuilder("application") | ||
.select(["application.id", "student.id"]) | ||
.distinctOn(["student.id"]) | ||
.innerJoin("application.student", "student") | ||
.innerJoin("student.user", "user") | ||
.innerJoin("student.sinValidation", "sinValidation") | ||
.innerJoin("student.casSupplier", "casSupplier") | ||
.leftJoin("student.overawards", "overaward") | ||
.where("application.applicationStatus != :overwritten") | ||
.andWhere("application.currentAssessment is not null") | ||
// Check if the student data was updated in the given period. | ||
.andWhere( | ||
new Brackets((qb) => { | ||
qb.where( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
"student.updatedAt > :modifiedSince AND student.updatedAt <= :modifiedUntil", | ||
) | ||
.orWhere( | ||
"user.updatedAt > :modifiedSince AND user.updatedAt <= :modifiedUntil", | ||
) | ||
.orWhere( | ||
"sinValidation.updatedAt > :modifiedSince AND sinValidation.updatedAt <= :modifiedUntil", | ||
) | ||
.orWhere( | ||
"casSupplier.updatedAt > :modifiedSince AND casSupplier.updatedAt <= :modifiedUntil", | ||
) | ||
.orWhere( | ||
"overaward.updatedAt > :modifiedSince AND overaward.updatedAt <= :modifiedUntil", | ||
); | ||
}), | ||
) | ||
.setParameters({ | ||
overwritten: ApplicationStatus.Overwritten, | ||
modifiedSince, | ||
modifiedUntil, | ||
}) | ||
.getMany(); | ||
// Extract the student ids from the applications. | ||
const modifiedStudentIds = applicationsWithStudentUpdates.map( | ||
(application) => application.student.id, | ||
); | ||
|
||
return modifiedStudentIds; | ||
} | ||
|
||
/** | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Get student details of students who have one or more updates. | ||
* @param studentIds student ids. | ||
* @returns student details. | ||
*/ | ||
async getStudentRecordsByStudentIds( | ||
studentIds: number[], | ||
): Promise<StudentDetail[]> { | ||
const queryResult = await this.studentRepo | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.createQueryBuilder("student") | ||
.select([ | ||
"student.id", | ||
"student.birthDate", | ||
"student.disabilityStatus", | ||
"student.disabilityStatusEffectiveDate", | ||
"user.firstName", | ||
"user.lastName", | ||
"sinValidation.sin", | ||
"casSupplier.supplierNumber", | ||
"casSupplier.supplierAddress", | ||
]) | ||
.addSelect("SUM(cslfOveraward.overawardValue)", "cslfOverawardTotal") | ||
.addSelect("SUM(bcslOveraward.overawardValue)", "bcslOverawardTotal") | ||
.innerJoin("student.user", "user") | ||
.innerJoin("student.sinValidation", "sinValidation") | ||
.innerJoin("student.casSupplier", "casSupplier") | ||
.leftJoin( | ||
"student.overawards", | ||
"cslfOveraward", | ||
"cslfOveraward.disbursementValueCode = :cslfAwardCode", | ||
) | ||
.leftJoin( | ||
"student.overawards", | ||
"bcslOveraward", | ||
"bcslOveraward.disbursementValueCode = :bcslAwardCode", | ||
) | ||
.groupBy("student.id") | ||
.addGroupBy("user.id") | ||
.addGroupBy("sinValidation.id") | ||
.addGroupBy("casSupplier.id") | ||
.where("student.id IN (:...studentIds)") | ||
.setParameters({ | ||
cslfAwardCode: CANADA_STUDENT_LOAN_FULL_TIME_AWARD_CODE, | ||
bcslAwardCode: BC_STUDENT_LOAN_AWARD_CODE, | ||
studentIds, | ||
}) | ||
.getRawAndEntities(); | ||
|
||
return mapFromRawAndEntities<StudentDetail>( | ||
queryResult, | ||
"cslfOverawardTotal", | ||
"bcslOverawardTotal", | ||
); | ||
} | ||
// TODO: SIMS to SFAS - Add methods to extract application and restriction data. | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add a period at the end??