Skip to content

Commit

Permalink
Added PRP & Youth FTE zero reason
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Jan 10, 2025
1 parent abd71f9 commit 8886401
Show file tree
Hide file tree
Showing 23 changed files with 174 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(10)
@Order(100)
public class AdultStudentCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Component
@Slf4j
@Order(13)
@Order(130)
public class AlternateProgramsCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Component
@Slf4j
@Order(8)
@Order(80)
public class CollectionAndFacilityTypeCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Component
@Slf4j
@Order(11)
@Order(110)
public class CollectionAndGradeCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(7)
@Order(70)
public class DistrictDoubleReportedCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Component
@Slf4j
@Order(4)
@Order(40)
public class GraduatedAdultIndySchoolCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(9)
@Order(90)
public class IndAuthorityDoubleReportedCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Component
@Slf4j
@Order(5)
@Order(50)
public class IndependentSchoolAndBandCodeCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@Component
@Slf4j
@Order(12)
@Order(120)
public class NewOnlineStudentCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(6)
@Order(60)
public class NoCoursesInLastTwoYearsAdultCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(6)
@Order(60)
public class NoCoursesInLastTwoYearsSchoolAgedCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(1)
@Order(10)
public class OffshoreStudentCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ca.bc.gov.educ.studentdatacollection.api.calculator.impl;

import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculator;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes;
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.FteCalculationResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Arrays;

import static ca.bc.gov.educ.studentdatacollection.api.constants.v1.ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL;

@Component
@Slf4j
@Order(31)
public class PRPorYouthSchoolCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
public void setNext(FteCalculator nextCalculator) {
this.nextCalculator = nextCalculator;
}
@Override
public FteCalculationResult calculateFte(StudentRuleData studentData) {
log.debug("PRPorYouthSchoolCalculator: Starting calculation for student :: " + studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
var prpAndYouthSchools = Arrays.asList(FacilityTypeCodes.SHORT_PRP.getCode(), FacilityTypeCodes.LONG_PRP.getCode(), FacilityTypeCodes.YOUTH.getCode());

if(prpAndYouthSchools.contains(studentData.getSchool().getFacilityTypeCode())) {
FteCalculationResult fteCalculationResult = new FteCalculationResult();
fteCalculationResult.setFte(BigDecimal.ZERO);
fteCalculationResult.setFteZeroReason(PRP_OR_YOUTH_SCHOOL.getCode());
log.debug("PRPorYouthSchoolCalculator: Fte result {} calculated with zero reason '{}' for student :: {}", fteCalculationResult.getFte(), fteCalculationResult.getFteZeroReason(), studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
return fteCalculationResult;
} else {
log.debug("PRPorYouthSchoolCalculator: No FTE result, moving to next calculation for student :: " + studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID());
return this.nextCalculator.calculateFte(studentData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Component
@Slf4j
@Order(14)
@Order(140)
public class StudentGradeCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(16)
@Order(160)
public class StudentGraduatedCalculator implements FteCalculator {
@Override
public void setNext(FteCalculator nextCalculator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(2)
@Order(20)
public class StudentOutOfProvinceCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(15)
@Order(150)
public class SupportBlocksCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Component
@Slf4j
@Order(3)
@Order(30)
public class TooYoungCalculator implements FteCalculator {
FteCalculator nextCalculator;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(5)
@Order(50)
public class ZeroCoursesAdultCalculator implements FteCalculator {
FteCalculator nextCalculator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Component
@Slf4j
@Order(5)
@Order(50)
public class ZeroCoursesSchoolAgedCalculator implements FteCalculator {
FteCalculator nextCalculator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public enum ZeroFteReasonCodes {

TOO_YOUNG("TOOYOUNG", "The student is too young."),
PRP_OR_YOUTH_SCHOOL("PRPYOUTH", "Student is funded outside of the funding allocation system."),
OUT_OF_PROVINCE("OUTOFPROV", "Out-of-Province/International Students are not eligible for funding."),
OFFSHORE("OFFSHORE", "Offshore students do not receive funding."),
INACTIVE("INACTIVE", "The student has not been reported as \"active\" in a new course in the last two years."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,13 @@ SELECT
WHEN TRIM(sld_student.GRAD) = 'Y' THEN 'true'
ELSE 'false'
END as IS_GRADUATED,
TO_NUMBER(TO_CHAR(sld_student.STUDENT_FTE_VALUE / 10000,'99999.9999')) AS FTE,
CASE
WHEN (SELECT schl.FACILITY_TYPE_CODE from SCHOOL schl WHERE SUBSTR( DISTNO||'' ||SCHLNO, 4) = schl.SCHOOL_NUMBER AND SUBSTR( sld_student.DISTNO||'' ||SCHLNO, 0 , 3) = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) in ('SHORT_PRP', 'LONG_PRP', 'YOUTH') THEN 0
ELSE TO_NUMBER(TO_CHAR(sld_student.STUDENT_FTE_VALUE / 10000,'99999.9999'))
END as FTE,
CASE
WHEN (SELECT schl.FACILITY_TYPE_CODE from SCHOOL schl WHERE SUBSTR( DISTNO||'' ||SCHLNO, 4) = schl.SCHOOL_NUMBER AND SUBSTR( sld_student.DISTNO||'' ||SCHLNO, 0 , 3) = (SELECT dist.DISTRICT_NUMBER from DISTRICT dist WHERE schl.DISTRICT_ID = dist.DISTRICT_ID)) in ('SHORT_PRP', 'LONG_PRP', 'YOUTH') THEN 'PRPYOUTH'
END as FTE_ZERO_REASON_CODE,
(SELECT LISTAGG(stud_prog.ENROLLED_PROGRAM_CODE, '') WITHIN GROUP (ORDER BY 1)
FROM STUDENT_PROGRAMS stud_prog
WHERE stud_prog.REPORT_DATE = sld_student.REPORT_DATE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package ca.bc.gov.educ.studentdatacollection.api.calculator.impl;

import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculator;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ZeroFteReasonCodes;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity;
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.FteCalculationResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

class PrpOrYouthSchoolCalculatorTest {

private PRPorYouthSchoolCalculator prPorYouthSchoolCalculator;
private FteCalculator nextCalculator;

@BeforeEach
public void setup() {
nextCalculator = mock(FteCalculator.class);
prPorYouthSchoolCalculator = new PRPorYouthSchoolCalculator();
prPorYouthSchoolCalculator.setNext(nextCalculator);
}

@Test
void testCalculateFte_StudentPrpSchool() {
// Given
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
student.setDob(format.format(LocalDateTime.now().minusYears(6)));
StudentRuleData studentData = new StudentRuleData();
studentData.setSdcSchoolCollectionStudentEntity(student);
studentData.setSchool(createSchool());

// When
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData);

// Then
assertEquals(BigDecimal.ZERO, result.getFte());
assertEquals(ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL.getCode(), result.getFteZeroReason());
verify(nextCalculator, never()).calculateFte(any());
}

@Test
void testCalculateFte_StudentYouthSchool() {
// Given
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
student.setDob(format.format(LocalDateTime.now().minusYears(6)));
StudentRuleData studentData = new StudentRuleData();
studentData.setSdcSchoolCollectionStudentEntity(student);
var school = createSchool();
school.setFacilityTypeCode(FacilityTypeCodes.YOUTH.getCode());
studentData.setSchool(school);

// When
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData);

// Then
assertEquals(BigDecimal.ZERO, result.getFte());
assertEquals(ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL.getCode(), result.getFteZeroReason());
verify(nextCalculator, never()).calculateFte(any());
}

@Test
void testCalculateFte_StudentExactlyOldEnough() {
// Given
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
student.setDob(format.format(LocalDateTime.now().minusYears(6)));
StudentRuleData studentData = new StudentRuleData();
studentData.setSdcSchoolCollectionStudentEntity(student);
var school = createSchool();
school.setFacilityTypeCode(FacilityTypeCodes.STANDARD.getCode());
studentData.setSchool(school);

// When
FteCalculationResult expectedResult = new FteCalculationResult();
expectedResult.setFte(BigDecimal.ONE);
expectedResult.setFteZeroReason(null);

when(nextCalculator.calculateFte(any())).thenReturn(expectedResult);
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData);

// Then
assertEquals(expectedResult, result);
verify(nextCalculator).calculateFte(studentData);
}

private SchoolTombstone createSchool(){
SchoolTombstone schoolTombstone = new SchoolTombstone();
schoolTombstone.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode());
schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.LONG_PRP.getCode());
schoolTombstone.setDistrictId(UUID.randomUUID().toString());
return schoolTombstone;
}
}

0 comments on commit 8886401

Please sign in to comment.