Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…OLLECTION-API into feature/reportRevisions

# Conflicts:
#	api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/reports/CSVReportService.java
#	api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryReportsControllerTest.java
  • Loading branch information
arcshiftsolutions committed Jan 14, 2025
2 parents d5ab5ae + ae99574 commit 21c0d7c
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ProgramEligibilityIssueCode {
NOT_ENROLLED_SPECIAL_ED("NTENRSPED", "The student was not reported in any inclusive education programs."),
NON_ELIG_SPECIAL_EDUCATION("NELISPED", "Student must be school-aged or a non-graduated adult reported in a grade other than GA."),
FEB_ONLINE_WITH_HISTORICAL_FUNDING("FEBSPEDERR", "Student has already been funded in September collection."),
INDP_FIRST_NATION_SPED("FUND20SPED", "Students reported by Independent School with Funding code 20 are not eligible for Inclusive Education funding."),
INDIGENOUS_ADULT("ISADULTAGE", "Student must be school-aged and self-identify as having Indigenous Ancestry to be eligible for funding for Indigenous Support Programs."),
YEARS_IN_ELL("ELL5ORLESS", "Student must be school-aged and have been reported in ELL for 5 years or less."),
NOT_ENROLLED_ELL("NTENRELL", "The student is not enrolled in the ELL program."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public DownloadableReportResponse getMinistryDownloadableReport(UUID collectionI
case INDY_INCLUSIVE_ED_FUNDING_HEADCOUNTS -> ministryReportsService.generateIndySpecialEducationFundingHeadcounts(collectionID);
case ENROLLED_HEADCOUNTS_AND_FTE_REPORT -> ministryReportsService.generateEnrolledHeadcountsAndFteReport(collectionID);
case INCLUSIVE_EDUCATION_VARIANCES_ALL -> ministryReportsService.generateInclusiveEducationVarianceReport(collectionID);
case ENROLMENT_HEADCOUNTS_AND_FTE_REPORT_FOR_OL_AND_CE_SCHOOLS -> ministryReportsService.generateEnrolmentHeadcountsAndFteReportForCEAndOLSchools(collectionID);
case INDY_FUNDING_REPORT_ALL -> ministryReportsService.generateIndyFundingReport(collectionID, false, false, false);
case INDY_FUNDING_REPORT_FUNDED -> ministryReportsService.generateIndyFundingReport(collectionID, false, false, true);
case ONLINE_INDY_FUNDING_REPORT -> ministryReportsService.generateIndyFundingReport(collectionID, true, false, false);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package ca.bc.gov.educ.studentdatacollection.api.rules.programelegibility.impl;

import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculatorUtils;
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.SchoolGradeCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.*;
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 Down Expand Up @@ -64,6 +61,11 @@ public List<ProgramEligibilityIssueCode> executeValidation(StudentRuleData stude
} else if (Boolean.FALSE.equals(isSchoolAged) && (isGraduated || (isAdult && isGA))) {
log.debug("ProgramEligibilityBaseRule - SpecialEducationProgramsRule: Is school aged - {}, Is non graduated adult - {}, for sdcSchoolCollectionStudentID :: {}", student.getIsSchoolAged(), student.getIsGraduated(), studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
errors.add(ProgramEligibilityIssueCode.NON_ELIG_SPECIAL_EDUCATION);
} else if(SchoolCategoryCodes.INDEPENDENTS.contains(studentRuleData.getSchool().getSchoolCategoryCode())
&& StringUtils.isNotEmpty(student.getSchoolFundingCode())
&& 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(collectionType.equalsIgnoreCase(CollectionTypeCodes.FEBRUARY.getTypeCode()) && onlineFacilityCodes.contains(facilityType) &&
historicalStudents.stream().anyMatch(stu -> stu.getFte().compareTo(BigDecimal.ZERO) > 0 && stu.getSpecialEducationNonEligReasonCode() == null)) {
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 @@ -622,10 +622,10 @@ public DownloadableReportResponse generateOffshoreSchoolsHeadcounts(UUID collect
}
}

private Map<String, SpecialEdHeadcountResult> getLastSeptCollectionSchoolMap(CollectionEntity collection){
var lastSeptCollectionOpt = sdcSchoolCollectionRepository.findLastCollectionByType(CollectionTypeCodes.SEPTEMBER.getTypeCode(), collection.getCollectionID(), collection.getSnapshotDate());
private Map<String, SpecialEdHeadcountResult> getLastSeptCollectionSchoolMap(UUID collectionID){
var lastSeptCollectionOpt = sdcSchoolCollectionRepository.findLastCollectionByType(CollectionTypeCodes.SEPTEMBER.getTypeCode(), collectionID);
if(lastSeptCollectionOpt.isEmpty()) {
throw new EntityNotFoundException(CollectionEntity.class, COLLECTION_ID, collection.getCollectionID().toString());
throw new EntityNotFoundException(CollectionEntity.class, COLLECTION_ID, collectionID.toString());
}
List<SpecialEdHeadcountResult> lastSeptCollectionRawData = sdcSchoolCollectionStudentRepository.getSpecialEdHeadcountsByCollectionId(lastSeptCollectionOpt.get().getCollectionID());
return lastSeptCollectionRawData.stream().collect(Collectors.toMap(SpecialEdHeadcountResult::getSchoolID, item -> item));
Expand Down Expand Up @@ -967,7 +967,7 @@ public DownloadableReportResponse generateInclusiveEducationVarianceReport(UUID
SdcDistrictCollectionEntity septCollection = sdcDistrictCollectionRepository.findLastSdcDistrictCollectionByCollectionTypeBefore(CollectionTypeCodes.SEPTEMBER.getTypeCode(), districtID, febCollection.getCollectionEntity().getSnapshotDate())
.orElseThrow(() -> new RuntimeException("No previous September sdc district collection found relative to the February collection."));

var febCollectionRawData = sdcSchoolCollectionStudentRepository.getSpecialEdHeadcountsSimpleFebruaryBySdcDistrictCollectionId(febCollection.getSdcDistrictCollectionID());
var febCollectionRawData = sdcSchoolCollectionStudentRepository.getSpecialEdHeadcountsSimpleBySdcDistrictCollectionId(febCollection.getSdcDistrictCollectionID());
var septCollectionRawData = sdcSchoolCollectionStudentRepository.getSpecialEdHeadcountsSimpleBySdcDistrictCollectionId(septCollection.getSdcDistrictCollectionID());

var district = restUtils.getDistrictByDistrictID(districtID.toString()).orElseThrow(() -> new EntityNotFoundException(District.class, DISTRICT_ID, districtID.toString()));
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public DownloadableReportResponse generateEnrolmentHeadcountsAndFteReportForCEAn
}

List<EnrolmentHeadcountFteResult> results = sdcSchoolCollectionStudentRepository.getEnrolmentHeadcountsAndFteWithRefugeeByCollectionId(collectionID);
var mappedSeptData = getEnrolmentHeadcountFteResultForLastSeptCollection(collection);
var mappedSeptData = getEnrolmentHeadcountFteResultForLastSeptCollection(collectionID);

List<String> headers = Arrays.stream(CEAndOLEnrolmentAndFteHeader.values()).map(CEAndOLEnrolmentAndFteHeader::getCode).toList();
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
Expand Down Expand Up @@ -1136,10 +1136,10 @@ public DownloadableReportResponse generateRefugeeEnrolmentHeadcountsAndFteReport
}
}

private Map<String, EnrolmentHeadcountFteResult> getEnrolmentHeadcountFteResultForLastSeptCollection(CollectionEntity collection){
var lastSeptCollectionOpt = sdcSchoolCollectionRepository.findLastCollectionByType(CollectionTypeCodes.SEPTEMBER.getTypeCode(), collection.getCollectionID(), collection.getSnapshotDate());
private Map<String, EnrolmentHeadcountFteResult> getEnrolmentHeadcountFteResultForLastSeptCollection(UUID collectionID){
var lastSeptCollectionOpt = sdcSchoolCollectionRepository.findLastCollectionByType(CollectionTypeCodes.SEPTEMBER.getTypeCode(), collectionID);
if(lastSeptCollectionOpt.isEmpty()) {
throw new EntityNotFoundException(CollectionEntity.class, COLLECTION_ID, collection.getCollectionID().toString());
throw new EntityNotFoundException(CollectionEntity.class, COLLECTION_ID, collectionID.toString());
}
List<EnrolmentHeadcountFteResult> lastSeptCollectionRawData = sdcSchoolCollectionStudentRepository.getEnrolmentHeadcountsAndFteWithRefugeeByCollectionId(lastSeptCollectionOpt.get().getCollectionID());
return lastSeptCollectionRawData.stream().collect(Collectors.toMap(EnrolmentHeadcountFteResult::getSchoolID, item -> item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ void testGetMinistryReportCSV_ValidIndySpecialEducationFundingType_ShouldReturnR

CollectionEntity collectionSept = createMockCollectionEntity();
collectionSept.setCloseDate(LocalDateTime.now().minusDays(20));
collectionSept.setSnapshotDate(LocalDate.now().minusWeeks(4));
collectionSept.setCollectionTypeCode(CollectionTypeCodes.SEPTEMBER.getTypeCode());
collectionRepository.save(collectionSept);

Expand Down Expand Up @@ -1153,108 +1152,6 @@ void testGetMinistryReportCSV_TypeENROLLED_HEADCOUNTS_AND_FTE_REPORT_ShouldRetur
assertThat(summary1.getReportType()).isEqualTo(ENROLLED_HEADCOUNTS_AND_FTE_REPORT.getCode());
}

@Test
void testGetMinistryReportCSV_TypeENROLMENT_HEADCOUNTS_AND_FTE_REPORT_FOR_OL_AND_CE_SCHOOLS_ShouldReturnReportData() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SDC_MINISTRY_REPORTS";
final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority);

var school = this.createMockSchool();
school.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode());
school.setFacilityTypeCode(FacilityTypeCodes.DIST_LEARN.getCode());
when(this.restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(school));

CollectionEntity collectionSept = createMockCollectionEntity();
collectionSept.setCloseDate(LocalDateTime.now().minusDays(20));
collectionSept.setSnapshotDate(LocalDate.now().minusWeeks(4));
collectionSept.setCollectionTypeCode(CollectionTypeCodes.SEPTEMBER.getTypeCode());
var savedSeptColl = collectionRepository.save(collectionSept);

SdcDistrictCollectionEntity sdcMockDistrictSept = createMockSdcDistrictCollectionEntity(savedSeptColl, null);
sdcDistrictCollectionRepository.save(sdcMockDistrictSept).getSdcDistrictCollectionID();

school.setDistrictId(sdcMockDistrictSept.getDistrictID().toString());
SdcSchoolCollectionEntity sdcSchoolCollectionEntitySept = createMockSdcSchoolCollectionEntity(savedSeptColl, UUID.fromString(school.getSchoolId()));
sdcSchoolCollectionRepository.save(sdcSchoolCollectionEntitySept);

var sdcSchoolCollectionStudentSept1 = createMockSchoolStudentEntity(sdcSchoolCollectionEntitySept);
sdcSchoolCollectionStudentRepository.saveAll(List.of(sdcSchoolCollectionStudentSept1));

CollectionEntity collection = createMockCollectionEntity();
collection.setCollectionTypeCode(CollectionTypeCodes.MAY.getTypeCode());
collection.setCloseDate(LocalDateTime.now().plusDays(2));
collection = collectionRepository.save(collection);

SdcDistrictCollectionEntity sdcMockDistrict = createMockSdcDistrictCollectionEntity(collection, null);
sdcDistrictCollectionRepository.save(sdcMockDistrict);

SdcDistrictCollectionEntity sdcMockDistrict2 = createMockSdcDistrictCollectionEntity(collection, null);
sdcDistrictCollectionRepository.save(sdcMockDistrict2);

SdcSchoolCollectionEntity sdcSchoolCollectionEntity1 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()));

SchoolTombstone school2 = createMockSchool();
school2.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode());
school2.setFacilityTypeCode(FacilityTypeCodes.DIST_LEARN.getCode());
school2.setDistrictId(sdcMockDistrict2.getDistrictID().toString());
SdcSchoolCollectionEntity sdcSchoolCollectionEntity2 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school2.getSchoolId()));

sdcSchoolCollectionRepository.saveAll(List.of(sdcSchoolCollectionEntity1, sdcSchoolCollectionEntity2));

var sdcSchoolCollectionStudent1 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity1);
var sdcSchoolCollectionStudent2 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity2);
sdcSchoolCollectionStudentRepository.saveAll(List.of(sdcSchoolCollectionStudent1, sdcSchoolCollectionStudent2));

var resultActions1 = this.mockMvc.perform(
get(URL.BASE_MINISTRY_HEADCOUNTS + "/" + collection.getCollectionID() + "/enrolment-fte-headcounts-for-ce-ol-schools/download").with(mockAuthority))
.andDo(print()).andExpect(status().isOk());

val summary1 = objectMapper.readValue(resultActions1.andReturn().getResponse().getContentAsByteArray(), new TypeReference<DownloadableReportResponse>() {
});

assertThat(summary1).isNotNull();
assertThat(summary1.getReportType()).isEqualTo(ENROLMENT_HEADCOUNTS_AND_FTE_REPORT_FOR_OL_AND_CE_SCHOOLS.getCode());
}

@Test
void testGetMinistryReportCSV_TypeENROLMENT_HEADCOUNTS_AND_FTE_REPORT_FOR_OL_AND_CE_SCHOOLS_ShouldReturnBadRequest() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SDC_MINISTRY_REPORTS";
final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority);

var school = this.createMockSchool();
school.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode());
school.setFacilityTypeCode(FacilityTypeCodes.DIST_LEARN.getCode());
when(this.restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(school));

CollectionEntity collection = createMockCollectionEntity();
collection.setCollectionTypeCode("JULY");
collection.setCloseDate(LocalDateTime.now().plusDays(2));
collection = collectionRepository.save(collection);

SdcDistrictCollectionEntity sdcMockDistrict = createMockSdcDistrictCollectionEntity(collection, null);
sdcDistrictCollectionRepository.save(sdcMockDistrict);

SdcDistrictCollectionEntity sdcMockDistrict2 = createMockSdcDistrictCollectionEntity(collection, null);
sdcDistrictCollectionRepository.save(sdcMockDistrict2);

SchoolTombstone school1 = createMockSchool();
school1.setDistrictId(sdcMockDistrict.getDistrictID().toString());
SdcSchoolCollectionEntity sdcSchoolCollectionEntity1 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school1.getSchoolId()));

SchoolTombstone school2 = createMockSchool();
school2.setDistrictId(sdcMockDistrict2.getDistrictID().toString());
SdcSchoolCollectionEntity sdcSchoolCollectionEntity2 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school2.getSchoolId()));

sdcSchoolCollectionRepository.saveAll(List.of(sdcSchoolCollectionEntity1, sdcSchoolCollectionEntity2));

var sdcSchoolCollectionStudent1 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity1);
var sdcSchoolCollectionStudent2 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity2);
sdcSchoolCollectionStudentRepository.saveAll(List.of(sdcSchoolCollectionStudent1, sdcSchoolCollectionStudent2));

this.mockMvc.perform(
get(URL.BASE_MINISTRY_HEADCOUNTS + "/" + collection.getCollectionID() + "/enrolment-fte-headcounts-for-ce-ol-schools/download").with(mockAuthority))
.andDo(print()).andExpect(status().isBadRequest());
}

@Test
void testGetMinistryReportCSV_IndyFundingResult_ShouldReturnReportData() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SDC_MINISTRY_REPORTS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,82 @@ void testSpecialEdStudentSchoolAgedAdultGANotEligible() {
)).isTrue();
}

@Test
void testSpecialEdEligibility_INDPSchools_WithFundingCode20() {
UUID assignedStudentID = UUID.randomUUID();

var mockCollection = createMockCollectionEntity();
mockCollection.setCollectionTypeCode(CollectionTypeCodes.FEBRUARY.getTypeCode());
mockCollection.setCloseDate(LocalDateTime.now().plusDays(2));
CollectionEntity collection = collectionRepository.save(mockCollection);

SchoolTombstone school = createMockSchool();
school.setSchoolCategoryCode(SchoolCategoryCodes.INDEPEND.getCode());
UUID schoolId = UUID.fromString(school.getSchoolId());
doReturn(Optional.of(school)).when(restUtils).getSchoolBySchoolID(schoolId.toString());

var sdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(collection, schoolId);
sdcSchoolCollectionRepository.save(sdcSchoolCollectionEntity);

val entity = this.createMockSchoolStudentEntity(sdcSchoolCollectionEntity);
entity.setAssignedStudentId(assignedStudentID);
entity.setEnrolledGradeCode("08");
entity.setSchoolFundingCode("20");

PenMatchResult penMatchResult = getPenMatchResult();
penMatchResult.getMatchingRecords().get(0).setStudentID(String.valueOf(assignedStudentID));
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);

List<ProgramEligibilityIssueCode> listWithoutEnrollmentError = rulesProcessor.processRules(
createMockStudentRuleData(
entity,
school
)
);

assertThat(listWithoutEnrollmentError.stream().anyMatch(e ->
e.equals(ProgramEligibilityIssueCode.INDP_FIRST_NATION_SPED)
)).isTrue();
}

@Test
void testSpecialEdEligibility_INDPSchools_WithFundingCode16() {
UUID assignedStudentID = UUID.randomUUID();

var mockCollection = createMockCollectionEntity();
mockCollection.setCollectionTypeCode(CollectionTypeCodes.FEBRUARY.getTypeCode());
mockCollection.setCloseDate(LocalDateTime.now().plusDays(2));
CollectionEntity collection = collectionRepository.save(mockCollection);

SchoolTombstone school = createMockSchool();
school.setSchoolCategoryCode(SchoolCategoryCodes.INDEPEND.getCode());
UUID schoolId = UUID.fromString(school.getSchoolId());
doReturn(Optional.of(school)).when(restUtils).getSchoolBySchoolID(schoolId.toString());

var sdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(collection, schoolId);
sdcSchoolCollectionRepository.save(sdcSchoolCollectionEntity);

val entity = this.createMockSchoolStudentEntity(sdcSchoolCollectionEntity);
entity.setAssignedStudentId(assignedStudentID);
entity.setEnrolledGradeCode("08");
entity.setSchoolFundingCode("16");

PenMatchResult penMatchResult = getPenMatchResult();
penMatchResult.getMatchingRecords().get(0).setStudentID(String.valueOf(assignedStudentID));
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);

List<ProgramEligibilityIssueCode> listWithoutEnrollmentError = rulesProcessor.processRules(
createMockStudentRuleData(
entity,
school
)
);

assertThat(listWithoutEnrollmentError.stream().anyMatch(e ->
e.equals(ProgramEligibilityIssueCode.INDP_FIRST_NATION_SPED)
)).isFalse();
}

@Test
void testSpecialEdEligibilityInFebCollection() {
UUID assignedStudentID = UUID.randomUUID();
Expand Down

0 comments on commit 21c0d7c

Please sign in to comment.