Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
SodhiA1 committed Jan 16, 2025
1 parent dcd5925 commit bfcbb0d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.CollectionTypeCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ProgramEligibilityIssueCode;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes;
import ca.bc.gov.educ.studentdatacollection.api.service.v1.ValidationRulesService;
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.FteCalculationResult;
Expand Down Expand Up @@ -32,19 +33,19 @@ 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 historicalStudentsWithinSameDistrict = validationRulesService.findStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1", studentRuleData.getSchool().getIndependentAuthorityId());

for (int i = 0; i < fteCalculators.size() - 1; i++) {
FteCalculator currentCalculator = fteCalculators.get(i);
FteCalculator nextCalculator = fteCalculators.get(i + 1);
currentCalculator.setNext(nextCalculator);
}
var fteResult = fteCalculators.get(0).calculateFte(studentRuleData);
if(student.getFte() != null && collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode()) && onlineFacilityCodes.contains(facilityType) &&
(historicalStudentsWithinSameDistrict.isEmpty() || historicalIndyStudents.isEmpty()
|| historicalStudentsWithinSameDistrict.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)
|| historicalIndyStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0))
if(SchoolCategoryCodes.INDEPENDENTS.contains(studentRuleData.getSchool().getSchoolCategoryCode())
&& student.getFte() != null
&& collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode()) && onlineFacilityCodes.contains(facilityType)
&& (historicalIndyStudents.isEmpty()
|| 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,21 +1143,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ 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 historicalStudentsWithinSameDistrict = validationRulesService.findStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1");
var historicalIndyStudents = validationRulesService.findIndyStudentInCurrentFiscal(studentRuleData, "1", studentRuleData.getSchool().getIndependentAuthorityId());

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 @@ -69,9 +68,10 @@ public List<ProgramEligibilityIssueCode> executeValidation(StudentRuleData stude
&& SchoolFundingCodes.STATUS_FIRST_NATION.getCode().equals(student.getSchoolFundingCode())) {
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) &&
(historicalStudentsWithinSameDistrict.isEmpty() || historicalIndyStudents.isEmpty()
|| historicalStudentsWithinSameDistrict.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) == 0)
} else if(SchoolCategoryCodes.INDEPENDENTS.contains(studentRuleData.getSchool().getSchoolCategoryCode())
&& student.getFte() != null && collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode())
&& onlineFacilityCodes.contains(facilityType) &&
(historicalIndyStudents.isEmpty()
|| 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,15 @@ 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> findIndyStudentInCurrentFiscal(StudentRuleData studentRuleData, String noOfCollectionsForLookup, String independentAuthorityId) {
if(independentAuthorityId != null) {
setupMergedStudentIdValues(studentRuleData);
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();
var studentsInIndyInSept = sdcSchoolStudentRepository.findIndyStudentInCurrentFiscal(studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
var schoolIDs = restUtils.getSchoolIDsByIndependentAuthorityID(independentAuthorityId);
return schoolIDs.map(uuids -> studentsInIndyInSept.stream().filter(student -> uuids.contains(student.getSdcSchoolCollection().getSchoolID())).toList()).orElse(Collections.emptyList());
}
return Collections.emptyList();
}

public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionInAllDistrict(StudentRuleData studentRuleData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -858,12 +859,15 @@ void testSpecialEdEligibilityInFebCollection() {
mockCollection.setCloseDate(LocalDateTime.now().plusDays(2));
CollectionEntity collection = collectionRepository.save(mockCollection);

var mockAuth = createMockAuthority();
SchoolTombstone school = createMockSchool();
District district = createMockDistrict();
school.setDistrictId(district.getDistrictId());
school.setIndependentAuthorityId(mockAuth.getIndependentAuthorityId());
UUID schoolId = UUID.fromString(school.getSchoolId());
doReturn(Optional.of(school)).when(restUtils).getSchoolBySchoolID(schoolId.toString());
createHistoricalCollectionWithStudent(CollectionTypeCodes.SEPTEMBER.getTypeCode(), LocalDateTime.of(LocalDate.parse((LocalDate.now().getYear() - 1) + "-09-30"), LocalTime.MIDNIGHT), assignedStudentID, UUID.fromString(district.getDistrictId()), schoolId, new BigDecimal(0));
when(restUtils.getSchoolIDsByIndependentAuthorityID(anyString())).thenReturn(Optional.of(Collections.singletonList(schoolId)));
createHistoricalCollectionWithStudent(CollectionTypeCodes.SEPTEMBER.getTypeCode(), LocalDateTime.of(LocalDate.parse((LocalDate.now().getYear() - 1) + "-09-30"), LocalTime.MIDNIGHT), assignedStudentID, null, schoolId, new BigDecimal(0));

SdcDistrictCollectionEntity sdcDistrictCollection = createMockSdcDistrictCollectionEntity(collection, UUID.fromString(district.getDistrictId()));
sdcDistrictCollectionRepository.save(sdcDistrictCollection);
Expand All @@ -876,8 +880,9 @@ void testSpecialEdEligibilityInFebCollection() {
entity.setAssignedStudentId(assignedStudentID);
entity.setEnrolledGradeCode("08");
entity.setFte(BigDecimal.ZERO);
entity.setSchoolFundingCode(null);

school.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode());
school.setSchoolCategoryCode(SchoolCategoryCodes.INDEPEND.getCode());
school.setFacilityTypeCode(FacilityTypeCodes.DIST_LEARN.getCode());

PenMatchResult penMatchResult = getPenMatchResult();
Expand Down Expand Up @@ -950,12 +955,14 @@ private void createHistoricalCollectionWithStudent(String collectionTypeCode, Lo
collection.setSnapshotDate(LocalDate.from(collectionCloseDate.minusDays(10)));
collection.setCollectionStatusCode("COMPLETED");
collectionRepository.save(collection);

SdcDistrictCollectionEntity sdcDistrictCollection = createMockSdcDistrictCollectionEntity(collection, districtID);
sdcDistrictCollectionRepository.save(sdcDistrictCollection);
SdcDistrictCollectionEntity sdcDistrictCollection = null;
if(districtID != null) {
sdcDistrictCollection = createMockSdcDistrictCollectionEntity(collection, districtID);
sdcDistrictCollectionRepository.save(sdcDistrictCollection);
}

var sdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(collection, schoolID);
sdcSchoolCollectionEntity.setSdcDistrictCollectionID(sdcDistrictCollection.getSdcDistrictCollectionID());
sdcSchoolCollectionEntity.setSdcDistrictCollectionID(sdcDistrictCollection != null ? sdcDistrictCollection.getSdcDistrictCollectionID() : null);
sdcSchoolCollectionRepository.save(sdcSchoolCollectionEntity);
val entity = this.createMockSchoolStudentEntity(sdcSchoolCollectionEntity);
entity.setAssignedStudentId(assignedStudentID);
Expand Down

0 comments on commit bfcbb0d

Please sign in to comment.