Skip to content

Commit

Permalink
Fix for sped program eligibility rule
Browse files Browse the repository at this point in the history
  • Loading branch information
SodhiA1 committed Jan 16, 2025
1 parent cf2bcab commit dcd5925
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public FteCalculationResult processFteCalculator(StudentRuleData studentRuleData
String collectionType = student.getSdcSchoolCollection().getCollectionEntity().getCollectionTypeCode();
String facilityType = studentRuleData.getSchool().getFacilityTypeCode();
var onlineFacilityCodes = Arrays.asList(FacilityTypeCodes.DISTONLINE.getCode(), FacilityTypeCodes.DIST_LEARN.getCode());
var historicalStudents = validationRulesService.getStudentInHistoricalCollectionWithInSameDistrict(studentRuleData, "1");
var historicalStudentsWithinSameDistrict = validationRulesService.findStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1");

for (int i = 0; i < fteCalculators.size() - 1; i++) {
FteCalculator currentCalculator = fteCalculators.get(i);
Expand All @@ -41,7 +42,10 @@ public FteCalculationResult processFteCalculator(StudentRuleData studentRuleData
}
var fteResult = fteCalculators.get(0).calculateFte(studentRuleData);
if(student.getFte() != null && collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode()) && onlineFacilityCodes.contains(facilityType) &&
(historicalStudents.isEmpty() || historicalStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)) && student.getFte().compareTo(BigDecimal.ZERO) == 0) {
(historicalStudentsWithinSameDistrict.isEmpty() || historicalIndyStudents.isEmpty()
|| historicalStudentsWithinSameDistrict.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)
|| historicalIndyStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0))
&& student.getFte().compareTo(BigDecimal.ZERO) == 0) {
log.debug("ProgramEligibilityBaseRule - SpecialEducationProgramsRule: CollectionTypeCodes - {}, facilityType - {}, for sdcSchoolCollectionStudentID :: {}", collectionType, facilityType, studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
studentRuleData.getSdcSchoolCollectionStudentEntity().setSpecialEducationNonEligReasonCode(ProgramEligibilityIssueCode.FEB_ONLINE_WITH_HISTORICAL_FUNDING.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,35 @@ NOT IN (SELECT saga.sdcSchoolCollectionStudentID FROM SdcSagaEntity saga WHERE s
""")
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameDistrict(UUID districtID, List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);

@Query(value="""
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS, SdcDistrictCollectionEntity SDC
WHERE SDC.districtID = :districtID
AND C.collectionID = SDC.collectionEntity.collectionID
AND C.collectionID = SSC.collectionEntity.collectionID
AND SDC.sdcDistrictCollectionID = SSC.sdcDistrictCollectionID
AND SSC.sdcSchoolCollectionID = SSCS.sdcSchoolCollection.sdcSchoolCollectionID
AND SSCS.assignedStudentId in :assignedStudentIDs
AND C.collectionID != :collectionID
AND SSCS.sdcSchoolCollectionStudentStatusCode != 'DELETED'
AND C.collectionID IN
(SELECT CE.collectionID FROM CollectionEntity CE WHERE CE.collectionStatusCode = 'COMPLETED' AND CE.snapshotDate < :snapshotDate ORDER BY CE.snapshotDate DESC LIMIT :noOfCollections)
""")
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscal(UUID districtID, List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);

@Query(value="""
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS
WHERE C.collectionID = SSC.collectionEntity.collectionID
AND SSC.sdcSchoolCollectionID = SSCS.sdcSchoolCollection.sdcSchoolCollectionID
AND SSCS.assignedStudentId in :assignedStudentIDs
AND C.collectionID != :collectionID
AND SSCS.sdcSchoolCollectionStudentStatusCode != 'DELETED'
AND SSC.sdcDistrictCollectionID IS null
AND C.collectionID IN
(SELECT CE.collectionID FROM CollectionEntity CE WHERE CE.collectionStatusCode = 'COMPLETED' AND CE.snapshotDate < :snapshotDate ORDER BY CE.snapshotDate DESC LIMIT :noOfCollections)
""")
List<SdcSchoolCollectionStudentEntity> findIndyStudentInCurrentFiscal(List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);



@Query(value="""
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculatorUtils;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.*;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity;
import ca.bc.gov.educ.studentdatacollection.api.rules.ProgramEligibilityBaseRule;
import ca.bc.gov.educ.studentdatacollection.api.service.v1.ValidationRulesService;
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
Expand All @@ -15,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

@Component
@Slf4j
Expand Down Expand Up @@ -53,7 +55,8 @@ public List<ProgramEligibilityIssueCode> executeValidation(StudentRuleData stude
Boolean isGA = SchoolGradeCodes.GRADUATED_ADULT.getCode().equals(student.getEnrolledGradeCode());
String collectionType = student.getSdcSchoolCollection().getCollectionEntity().getCollectionTypeCode();
String facilityType = studentRuleData.getSchool().getFacilityTypeCode();
var historicalStudents = validationRulesService.getStudentInHistoricalCollectionWithInSameDistrict(studentRuleData, "1");
var historicalStudentsWithinSameDistrict = validationRulesService.findStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1");

if (StringUtils.isEmpty(student.getSpecialEducationCategoryCode()) || !activeSpecialEdPrograms.contains(student.getSpecialEducationCategoryCode())) {
log.debug("ProgramEligibilityBaseRule - SpecialEducationProgramsRule: Sped code value - {} for sdcSchoolCollectionStudentID :: {}", student.getSpecialEducationCategoryCode(), studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
Expand All @@ -67,7 +70,10 @@ public List<ProgramEligibilityIssueCode> executeValidation(StudentRuleData stude
log.debug("ProgramEligibilityBaseRule - SpecialEducationProgramsRule: SchoolCategoryCode - {}, SchoolFundingCode - {}, for sdcSchoolCollectionStudentID :: {}", studentRuleData.getSchool().getSchoolCategoryCode(), student.getSchoolFundingCode(), studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
errors.add(ProgramEligibilityIssueCode.INDP_FIRST_NATION_SPED);
} else if(student.getFte() != null && collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode()) && onlineFacilityCodes.contains(facilityType) &&
(historicalStudents.isEmpty() || historicalStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)) && student.getFte().compareTo(BigDecimal.ZERO) == 0) {
(historicalStudentsWithinSameDistrict.isEmpty() || historicalIndyStudents.isEmpty()
|| historicalStudentsWithinSameDistrict.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)
|| historicalIndyStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0))
&& student.getFte().compareTo(BigDecimal.ZERO) == 0) {
log.debug("ProgramEligibilityBaseRule - SpecialEducationProgramsRule: CollectionTypeCodes - {}, facilityType - {}, for sdcSchoolCollectionStudentID :: {}", collectionType, facilityType, studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
errors.add(ProgramEligibilityIssueCode.FEB_ONLINE_WITH_HISTORICAL_FUNDING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWi
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameDistrict(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
}

public List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscal(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
setupMergedStudentIdValues(studentRuleData);
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();
return sdcSchoolStudentRepository.findStudentInCurrentFiscal(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
}

public List<SdcSchoolCollectionStudentEntity> findIndyStudentInCurrentFiscal(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
setupMergedStudentIdValues(studentRuleData);
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();
return sdcSchoolStudentRepository.findIndyStudentInCurrentFiscal(studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
}

public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionInAllDistrict(StudentRuleData studentRuleData) {
setupMergedStudentIdValues(studentRuleData);
String noOfCollectionsForLookup = "3";
Expand Down

0 comments on commit dcd5925

Please sign in to comment.