Skip to content

Commit 498793c

Browse files
Merge pull request #1646 from bcgov/feature/EDX-3193
fix dist dup checks (rules) to account for auth ID schools having district ID
2 parents 02c65e3 + af40947 commit 498793c

File tree

12 files changed

+127
-53
lines changed

12 files changed

+127
-53
lines changed

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtils.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,31 @@ public boolean studentPreviouslyReportedInDistrict(StudentRuleData studentRuleDa
8585

8686
long countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn = 0;
8787
var isSpringCollection = isSpringCollection(studentRuleData);
88+
89+
List<SchoolTombstone> allSchools = this.restUtils.getAllSchoolTombstones();
90+
List<UUID> publicSchoolIDsWithSameDistrictID = allSchools.stream()
91+
.filter(s -> s.getIndependentAuthorityId() == null && s.getDistrictId().equals(studentRuleData.getSchool().getDistrictId()))
92+
.map(s -> UUID.fromString(s.getSchoolId()))
93+
.toList();
94+
8895
log.debug("StudentPreviouslyReportedInDistrict: isSpringCollection: " + isSpringCollection + " :: isPublicOnlineOrContEdSchool: " + isPublicOnlineOrContEdSchool + " :: isStudentInDistrictFundedGrade: " + isStudentInDistrictFundedGrade + " :: districtId: " + StringUtils.isNotBlank(school.getDistrictId()));
89-
if(isSpringCollection && isPublicOnlineOrContEdSchool && isStudentInDistrictFundedGrade && StringUtils.isNotBlank(school.getDistrictId())) {
96+
if(isSpringCollection && isPublicOnlineOrContEdSchool && isStudentInDistrictFundedGrade && StringUtils.isNotBlank(school.getDistrictId()) && StringUtils.isBlank(school.getIndependentAuthorityId())) {
9097
var currentSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate();
9198
var fiscalSnapshotDate = getFiscalDateFromCurrentSnapshot(currentSnapshotDate);
9299
log.debug("StudentPreviouslyReportedInDistrict springCollection: fiscalSnapshotDate: " + fiscalSnapshotDate + " :: currentSnapshotDate: " + currentSnapshotDate + " :: assignedStudentId: " + assignedStudentId);
93-
var previousSeptemberCollections = sdcSchoolCollectionRepository.findSeptemberCollectionsForDistrictForFiscalYearToCurrentCollection(UUID.fromString(school.getDistrictId()), fiscalSnapshotDate, currentSnapshotDate);
100+
101+
var previousSeptemberCollections = sdcSchoolCollectionRepository.findSeptemberCollectionsForSchoolsForFiscalYearToCurrentCollection(publicSchoolIDsWithSameDistrictID, fiscalSnapshotDate, currentSnapshotDate);
94102
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschool(studentRuleData.getHistoricStudentIds(), previousSeptemberCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
95103
log.debug("StudentPreviouslyReportedInDistrict: springCollection student count :: " + countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn);
96104
}
97105
var isMayCollection = isMayCollection(studentRuleData);
98106
log.debug("StudentPreviouslyReportedInDistrict: isMayCollection: " + isMayCollection + " :: isPublicOnlineOrContEdSchool: " + isPublicOnlineOrContEdSchool + " :: isStudentInDistrictFundedGrade: " + isStudentInDistrictFundedGrade + " :: districtId: " + StringUtils.isNotBlank(school.getDistrictId()));
99-
if(isMayCollection && isPublicOnlineOrContEdSchool && isStudentInDistrictFundedGrade && StringUtils.isNotBlank(school.getDistrictId())) {
107+
if(isMayCollection && isPublicOnlineOrContEdSchool && isStudentInDistrictFundedGrade && StringUtils.isNotBlank(school.getDistrictId()) && StringUtils.isBlank(school.getIndependentAuthorityId())) {
100108
var currentSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate();
101109
var fiscalSnapshotDate = getFiscalDateFromCurrentSnapshot(currentSnapshotDate);
102110
log.debug("StudentPreviouslyReportedInDistrict mayCollection: fiscalSnapshotDate: " + fiscalSnapshotDate + " :: currentSnapshotDate: " + currentSnapshotDate + " :: assignedStudentId: " + assignedStudentId);
103-
var previousSeptemberCollections = sdcSchoolCollectionRepository.findFebruaryCollectionsForDistrictForFiscalYearToCurrentCollection(UUID.fromString(school.getDistrictId()), fiscalSnapshotDate, currentSnapshotDate);
104-
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschoolWithNonZeroFTE(studentRuleData.getHistoricStudentIds(), previousSeptemberCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
111+
var previousFebruaryCollections = sdcSchoolCollectionRepository.findFebruaryCollectionsForSchoolsForFiscalYearToCurrentCollection(publicSchoolIDsWithSameDistrictID, fiscalSnapshotDate, currentSnapshotDate);
112+
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschoolWithNonZeroFTE(studentRuleData.getHistoricStudentIds(), previousFebruaryCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
105113
log.debug("StudentPreviouslyReportedInDistrict: mayCollection student count :: " + countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn);
106114
}
107115

@@ -125,15 +133,20 @@ public boolean studentPreviouslyReportedInIndependentAuthority(StudentRuleData s
125133

126134
long countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn = 0;
127135

128-
if(isSpringCollection(studentRuleData) && isIndependentOnlineSchool && isStudentInDistrictFundedGrade && (StringUtils.isNotBlank(school.getIndependentAuthorityId()))) {
129-
var schoolIDs = restUtils.getSchoolIDsByIndependentAuthorityID(school.getIndependentAuthorityId());
130-
if (schoolIDs.isPresent()) {
131-
var currentSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate();
132-
var fiscalSnapshotDate = getFiscalDateFromCurrentSnapshot(currentSnapshotDate);
133-
//Check both Sep & Feb
134-
var previousCollections = sdcSchoolCollectionRepository.findAllCollectionsForSchoolsForFiscalYearToCurrentCollection(schoolIDs.get(), fiscalSnapshotDate, currentSnapshotDate);
135-
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschoolWithNonZeroFTE(studentRuleData.getHistoricStudentIds(), previousCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
136-
}
136+
var schoolIDs = restUtils.getSchoolIDsByIndependentAuthorityID(school.getIndependentAuthorityId());
137+
138+
if(isSpringCollection(studentRuleData) && isIndependentOnlineSchool && isStudentInDistrictFundedGrade && (StringUtils.isNotBlank(school.getIndependentAuthorityId())) && schoolIDs.isPresent()) {
139+
var currentSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate();
140+
var fiscalSnapshotDate = getFiscalDateFromCurrentSnapshot(currentSnapshotDate);
141+
var previousCollections = sdcSchoolCollectionRepository.findSeptemberCollectionsForSchoolsForFiscalYearToCurrentCollection(schoolIDs.get(), fiscalSnapshotDate, currentSnapshotDate);
142+
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschool(studentRuleData.getHistoricStudentIds(), previousCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
143+
}
144+
145+
if(isMayCollection(studentRuleData) && isIndependentOnlineSchool && isStudentInDistrictFundedGrade && (StringUtils.isNotBlank(school.getIndependentAuthorityId())) && schoolIDs.isPresent()) {
146+
var currentSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate();
147+
var fiscalSnapshotDate = getFiscalDateFromCurrentSnapshot(currentSnapshotDate);
148+
var previousCollections = sdcSchoolCollectionRepository.findFebruaryCollectionsForSchoolsForFiscalYearToCurrentCollection(schoolIDs.get(), fiscalSnapshotDate, currentSnapshotDate);
149+
countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn += sdcSchoolCollectionStudentRepository.countAllByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInExcludingHomeschoolWithNonZeroFTE(studentRuleData.getHistoricStudentIds(), previousCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList());
137150
}
138151

139152
return countAllByAssignedStudentIdAndSdcSchoolCollectionSdcSchoolCollectionIDIn > 0;
@@ -279,7 +292,7 @@ public boolean includedInCollectionThisSchoolYearForAuthWithNonZeroFteWithSchool
279292
.filter(school -> school.getIndependentAuthorityId() != null && school.getIndependentAuthorityId().equals(studentRuleData.getSchool().getIndependentAuthorityId()))
280293
.map(school -> UUID.fromString(school.getSchoolId()))
281294
.toList();
282-
List<SdcSchoolCollectionStudentEntity> historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalWithInSameAuthority(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), "3");
295+
List<SdcSchoolCollectionStudentEntity> historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalWithInSameSchool(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), "3");
283296

284297
for (SdcSchoolCollectionStudentEntity studentEntity : historicalCollections) {
285298
String schoolId = studentEntity.getSdcSchoolCollection().getSchoolID().toString();
@@ -300,7 +313,7 @@ public boolean includedInCollectionThisSchoolYearForAuthWithNonZeroFteWithSchool
300313
.filter(school -> school.getIndependentAuthorityId() != null && school.getIndependentAuthorityId().equals(studentRuleData.getSchool().getIndependentAuthorityId()))
301314
.map(school -> UUID.fromString(school.getSchoolId()))
302315
.toList();
303-
List<SdcSchoolCollectionStudentEntity> historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalWithInSameAuthority(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), "3");
316+
List<SdcSchoolCollectionStudentEntity> historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalWithInSameSchool(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), "3");
304317

305318
for (SdcSchoolCollectionStudentEntity studentEntity : historicalCollections) {
306319
String schoolId = studentEntity.getSdcSchoolCollection().getSchoolID().toString();

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/StudentValidationIssueTypeCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public enum StudentValidationIssueTypeCode {
101101
REFUGEE_IS_ADULT("REFUGEEISADULT", "Adults are not eligible for February newcomer refugee funding.", FUNDING_WARNING),
102102
SUMMER_PUBLIC_SCHOOL_GRADE_ERROR("SUMMERPUBLICSCHOOLGRADEERROR","8/9 cross enrolment students must be in grades 8 or 9", ERROR),
103103
SUMMER_STUDENT_ALREADY_REPORTED_DISTRICT_ERROR("SUMMERSTUDENTREPORTEDINDISTRICTERROR","The student has already been reported by the district during the current school year.", ERROR),
104-
SUMMER_STUDENT_ALREADY_REPORTED_AUTHORITY_ERROR("SUMMERSTUDENTREPORTEDINDISTRICTERROR","The student has already been reported by the authority during the current school year.", ERROR),
104+
SUMMER_STUDENT_ALREADY_REPORTED_AUTHORITY_ERROR("SUMMERSTUDENTREPORTEDINAUTHORITYERROR","The student has already been reported by the authority during the current school year.", ERROR),
105105
SUMMER_STUDENT_REPORTED_NOT_IN_DISTRICT_ERROR("SUMMERSTUDENTREPORTEDNOTINDISTRICTERROR","Student was not reported in Grade 8 or 9 this school year and cannot be reported in 8/9 cross enrolment in this collection.", FUNDING_WARNING),
106106
SUMMER_ADULT_STUDENT_ERROR("SUMMERADULTSTUDENTERROR","Adult students cannot be reported in 8/9 cross enrolment", ERROR),
107107
SUMMER_FUNDING_CODE_ERROR("SUMMERFUNDINGCODEERROR","Out of Province/International students cannot be reported in Summer collection", ERROR),

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/ZeroFteReasonCodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public enum ZeroFteReasonCodes {
1414
NUM_COURSES("NUMCOURSE", "Student does not have any courses reported."),
1515
INACTIVE("INACTIVE", "The student has not been reported as \"active\" in a new course in the last two years."),
1616
NOMINAL_ROLL_ELIGIBLE("NOMROLL", "The student is Nominal Roll eligible and is federally funded."),
17+
DISTRICT_DUPLICATE_FUNDING("DISTDUP", "The district has already received funding for the student this year."),
1718
IND_AUTH_DUPLICATE_FUNDING("AUTHDUP", "The authority has already received funding for the student this year."),
1819
GRADUATED_ADULT_IND_AUTH("INDYADULT", "The student is graduated adult reported by an independent school."),
19-
DISTRICT_DUPLICATE_FUNDING("DISTDUP", "The district has already received funding for the student this year."),
2020
NO_ONLINE_LEARNING("NOONLINE", "None of student's educational program was delivered through online learning this year."),
2121
NOT_REPORTED("NOREPORT", "Student was not reported in Grade 8 or 9 outside of district this school year."),
2222
ZERO_COURSES("ZEROCRS", "The student was reported with zero courses and in a secondary grade or adult grade level."),

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.time.LocalDate;
1717
import java.util.List;
18-
import java.util.Map;
1918
import java.util.UUID;
2019

2120
@Repository
@@ -1135,23 +1134,7 @@ NOT IN (SELECT saga.sdcSchoolCollectionStudentID FROM SdcSagaEntity saga WHERE s
11351134
AND C.collectionID IN
11361135
(SELECT CE.collectionID FROM CollectionEntity CE WHERE CE.collectionStatusCode = 'COMPLETED' ORDER BY CE.snapshotDate DESC LIMIT :noOfCollections)
11371136
""")
1138-
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameAuthority(List<UUID> schoolIDs, List<UUID> assignedStudentIDs, String noOfCollections);
1139-
1140-
@Query(value="""
1141-
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS, SdcDistrictCollectionEntity SDC
1142-
WHERE SDC.districtID = :districtID
1143-
AND C.collectionID = SDC.collectionEntity.collectionID
1144-
AND C.collectionID = SSC.collectionEntity.collectionID
1145-
AND SDC.sdcDistrictCollectionID = SSC.sdcDistrictCollectionID
1146-
AND SSC.sdcSchoolCollectionID = SSCS.sdcSchoolCollection.sdcSchoolCollectionID
1147-
AND SSCS.assignedStudentId in :assignedStudentIDs
1148-
AND C.collectionID != :collectionID
1149-
AND SSCS.fte > 0
1150-
AND SSCS.sdcSchoolCollectionStudentStatusCode != 'DELETED'
1151-
AND C.collectionID IN
1152-
(SELECT CE.collectionID FROM CollectionEntity CE WHERE CE.collectionStatusCode = 'COMPLETED' AND CE.snapshotDate < :snapshotDate ORDER BY CE.snapshotDate DESC LIMIT :noOfCollections)
1153-
""")
1154-
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameDistrict(UUID districtID, List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);
1137+
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameSchool(List<UUID> schoolIDs, List<UUID> assignedStudentIDs, String noOfCollections);
11551138

11561139
@Query(value="""
11571140
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/ValidationRulesService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ public void setGraduationStatus(SdcSchoolCollectionStudentEntity student){
213213

214214
public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWithInSameDistrict(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
215215
setupMergedStudentIdValues(studentRuleData);
216-
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();
217-
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameDistrict(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
216+
List<SchoolTombstone> allSchools = this.restUtils.getAllSchoolTombstones();
217+
List<UUID> publicSchoolIDsWithSameDistrictID = allSchools.stream()
218+
.filter(school -> school.getIndependentAuthorityId() == null && school.getDistrictId().equals(studentRuleData.getSchool().getDistrictId()))
219+
.map(school -> UUID.fromString(school.getSchoolId()))
220+
.toList();
221+
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameSchool(publicSchoolIDsWithSameDistrictID, studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup);
218222
}
219223

220224
public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWithInSameAuthority(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
@@ -224,7 +228,7 @@ public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWi
224228
.filter(school -> school.getIndependentAuthorityId() != null && school.getIndependentAuthorityId().equals(studentRuleData.getSchool().getIndependentAuthorityId()))
225229
.map(school -> UUID.fromString(school.getSchoolId()))
226230
.toList();
227-
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameAuthority(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup);
231+
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameSchool(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup);
228232
}
229233

230234
public List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscal(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {

0 commit comments

Comments
 (0)