Skip to content

Commit

Permalink
Merge pull request #389 from bcgov/feature/EDX-1280
Browse files Browse the repository at this point in the history
EDX-1280 - Adds headcounts for special ed, headers, headcounts, and o…
  • Loading branch information
arcshiftsolutions authored Jan 10, 2024
2 parents 4515dbb + 536b0ef commit 7ea64a4
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public SdcSchoolCollectionStudentHeadcounts getSdcSchoolCollectionStudentHeadcou
return sdcSchoolCollectionStudentHeadcountService.getCareerHeadcounts(sdcSchoolCollectionEntity, compare);
case "indigenous":
return sdcSchoolCollectionStudentHeadcountService.getIndigenousHeadcounts(sdcSchoolCollectionEntity, compare);

case "special-ed":
return sdcSchoolCollectionStudentHeadcountService.getSpecialEdHeadcounts(sdcSchoolCollectionEntity, compare);
default:
log.error("Invalid type for getSdcSchoolCollectionStudentHeadcounts::" + type);
throw new InvalidParameterException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package ca.bc.gov.educ.studentdatacollection.api.helpers;

import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes;
import ca.bc.gov.educ.studentdatacollection.api.exception.StudentDataCollectionAPIRuntimeException;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository;
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.*;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.function.Function;

@Component
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class SpecialEdHeadcountHelper extends HeadcountHelper<SpecialEdHeadcountResult>{
private static final String LEVEL_1_TITLE = "Level 1";
private static final String A_CODE_TITLE = "A - Physically Dependent";
private static final String B_CODE_TITLE = "B - Deafblind";
private static final String LEVEL_2_TITLE = "Level 2";
private static final String C_CODE_TITLE = "C - Moderate to Profound Intellectual Disability";
private static final String D_CODE_TITLE = "D - Physical Disability or Chronic Health Impairment";
private static final String E_CODE_TITLE = "E - Visual Impairment";
private static final String F_CODE_TITLE = "F - Deaf or Hard of Hearing";
private static final String G_CODE_TITLE = "G - Autism Spectrum Disorder";
private static final String LEVEL_3_TITLE = "Level 3";
private static final String H_CODE_TITLE = "H - Intensive Behaviour Interventions or Serious Mental Illness";
private static final String OTHER_TITLE = "Other";
private static final String K_CODE_TITLE = "K - Mild Intellectual Disability";
private static final String P_CODE_TITLE = "P - Gifted";
private static final String Q_CODE_TITLE = "Q - Learning Disability";
private static final String R_CODE_TITLE = "R - Moderate Behaviour Support/Mental Illness";
private static final String ALL_LEVELS_TITLE = "All Levels & Categories";
private static final String ELIGIBLE_TITLE = "Eligible";
private static final String REPORTED_TITLE = "Reported";
private static final List<String> HEADER_COLUMN_TITLES = List.of(ELIGIBLE_TITLE, REPORTED_TITLE);
private static final String LEVEL_1_TITLE_KEY = "level1Key";
private static final String A_CODE_TITLE_KEY = "aCodeKey";
private static final String B_CODE_TITLE_KEY = "bCodeKey";
private static final String LEVEL_2_TITLE_KEY = "level2Key";
private static final String C_CODE_TITLE_KEY = "cCodeKey";
private static final String D_CODE_TITLE_KEY = "dCodeKey";
private static final String E_CODE_TITLE_KEY = "eCodeKey";
private static final String F_CODE_TITLE_KEY = "fCodeKey";
private static final String G_CODE_TITLE_KEY = "gCodeKey";
private static final String LEVEL_3_TITLE_KEY = "level3Key";
private static final String H_CODE_TITLE_KEY = "hHodeKey";
private static final String OTHER_TITLE_KEY = "otherKey";
private static final String K_CODE_TITLE_KEY = "kCodeKey";
private static final String P_CODE_TITLE_KEY = "pCodeKey";
private static final String Q_CODE_TITLE_KEY = "qCodeKey";
private static final String R_CODE_TITLE_KEY = "rCodeKey";
private static final String ALL_LEVELS_TITLE_KEY = "allLevelKey";

public SpecialEdHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollectionRepository, SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository) {
super(sdcSchoolCollectionRepository, sdcSchoolCollectionStudentRepository);
headcountMethods = getHeadcountMethods();
sectionTitles = getSelectionTitles();
rowTitles = getRowTitles();
gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList();
}

public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List<HeadcountHeader> headcountHeaderList) {
UUID previousCollectionID = getPreviousSeptemberCollectionID(sdcSchoolCollectionEntity);
List<HeadcountHeader> previousHeadcountHeaderList = getHeaders(previousCollectionID);
setComparisonValues(headcountHeaderList, previousHeadcountHeaderList);
}

public List<HeadcountHeader> getHeaders(UUID sdcSchoolCollectionID) {
SpecialEdHeadcountHeaderResult result = sdcSchoolCollectionStudentRepository.getSpecialEdHeadersBySchoolId(sdcSchoolCollectionID);
List<HeadcountHeader> headcountHeaderList = new ArrayList<>();
Arrays.asList(A_CODE_TITLE, B_CODE_TITLE, C_CODE_TITLE, D_CODE_TITLE, E_CODE_TITLE, F_CODE_TITLE, G_CODE_TITLE, H_CODE_TITLE, K_CODE_TITLE, P_CODE_TITLE, Q_CODE_TITLE, R_CODE_TITLE).forEach(headerTitle -> {
HeadcountHeader headcountHeader = new HeadcountHeader();
headcountHeader.setColumns(new HashMap<>());
headcountHeader.setTitle(headerTitle);
headcountHeader.setOrderedColumnTitles(HEADER_COLUMN_TITLES);
switch (headerTitle) {
case A_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getTotalEligibleA())).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getReportedA())).build());
}
case B_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleB()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedB()).build());
}
case C_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleC()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedC()).build());
}
case D_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getTotalEligibleD())).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getReportedD())).build());
}
case E_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleE()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedE()).build());
}
case F_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleF()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedF()).build());
}
case G_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getTotalEligibleG())).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getReportedG())).build());
}
case H_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleH()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedH()).build());
}
case K_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleK()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedK()).build());
}
case P_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getTotalEligibleP())).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(String.valueOf(result.getReportedP())).build());
}
case Q_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleQ()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedQ()).build());
}
case R_CODE_TITLE -> {
headcountHeader.getColumns().put(ELIGIBLE_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getTotalEligibleR()).build());
headcountHeader.getColumns().put(REPORTED_TITLE, HeadcountHeaderColumn.builder().currentValue(result.getReportedR()).build());
}
default -> {
log.error("Unexpected header title. This cannot happen::" + headerTitle);
throw new StudentDataCollectionAPIRuntimeException("Unexpected header title. This cannot happen::" + headerTitle);
}
}
headcountHeaderList.add(headcountHeader);
});
return headcountHeaderList;
}

private Map<String, Function<SpecialEdHeadcountResult, String>> getHeadcountMethods() {
Map<String, Function<SpecialEdHeadcountResult, String>> headcountMethods = new HashMap<>();

headcountMethods.put(LEVEL_1_TITLE_KEY, SpecialEdHeadcountResult::getLevelOnes);
headcountMethods.put(A_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdACodes);
headcountMethods.put(B_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdBCodes);
headcountMethods.put(LEVEL_2_TITLE_KEY, SpecialEdHeadcountResult::getLevelTwos);
headcountMethods.put(C_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdCCodes);
headcountMethods.put(D_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdDCodes);
headcountMethods.put(E_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdECodes);
headcountMethods.put(F_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdFCodes);
headcountMethods.put(G_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdGCodes);
headcountMethods.put(LEVEL_3_TITLE_KEY, SpecialEdHeadcountResult::getLevelThrees);
headcountMethods.put(H_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdHCodes);
headcountMethods.put(OTHER_TITLE_KEY, SpecialEdHeadcountResult::getOtherLevels);
headcountMethods.put(K_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdKCodes);
headcountMethods.put(P_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdPCodes);
headcountMethods.put(Q_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdQCodes);
headcountMethods.put(R_CODE_TITLE_KEY, SpecialEdHeadcountResult::getSpecialEdRCodes);
headcountMethods.put(ALL_LEVELS_TITLE_KEY, SpecialEdHeadcountResult::getAllLevels);



return headcountMethods;
}
private Map<String, String> getSelectionTitles() {
Map<String, String> sectionTitles = new HashMap<>();
sectionTitles.put(LEVEL_1_TITLE_KEY, LEVEL_1_TITLE);
sectionTitles.put(A_CODE_TITLE_KEY, LEVEL_1_TITLE);
sectionTitles.put(B_CODE_TITLE_KEY, LEVEL_1_TITLE);
sectionTitles.put(LEVEL_2_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(C_CODE_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(D_CODE_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(E_CODE_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(F_CODE_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(G_CODE_TITLE_KEY, LEVEL_2_TITLE);
sectionTitles.put(LEVEL_3_TITLE_KEY, LEVEL_3_TITLE);
sectionTitles.put(H_CODE_TITLE_KEY, LEVEL_3_TITLE);
sectionTitles.put(OTHER_TITLE_KEY, OTHER_TITLE);
sectionTitles.put(K_CODE_TITLE_KEY, OTHER_TITLE);
sectionTitles.put(P_CODE_TITLE_KEY, OTHER_TITLE);
sectionTitles.put(Q_CODE_TITLE_KEY, OTHER_TITLE);
sectionTitles.put(R_CODE_TITLE_KEY, OTHER_TITLE);
sectionTitles.put(ALL_LEVELS_TITLE_KEY, ALL_LEVELS_TITLE);
return sectionTitles;
}
private Map<String, String> getRowTitles() {
Map<String, String> rowTitles = new LinkedHashMap<>();
rowTitles.put(LEVEL_1_TITLE_KEY, LEVEL_1_TITLE);
rowTitles.put(A_CODE_TITLE_KEY, A_CODE_TITLE);
rowTitles.put(B_CODE_TITLE_KEY, B_CODE_TITLE);
rowTitles.put(LEVEL_2_TITLE_KEY, LEVEL_2_TITLE);
rowTitles.put(C_CODE_TITLE_KEY, C_CODE_TITLE);
rowTitles.put(D_CODE_TITLE_KEY, D_CODE_TITLE);
rowTitles.put(E_CODE_TITLE_KEY, E_CODE_TITLE);
rowTitles.put(F_CODE_TITLE_KEY, F_CODE_TITLE);
rowTitles.put(G_CODE_TITLE_KEY, G_CODE_TITLE);
rowTitles.put(LEVEL_3_TITLE_KEY, LEVEL_3_TITLE);
rowTitles.put(H_CODE_TITLE_KEY, H_CODE_TITLE);
rowTitles.put(OTHER_TITLE_KEY, OTHER_TITLE);
rowTitles.put(K_CODE_TITLE_KEY, K_CODE_TITLE);
rowTitles.put(P_CODE_TITLE_KEY, P_CODE_TITLE);
rowTitles.put(Q_CODE_TITLE_KEY, Q_CODE_TITLE);
rowTitles.put(R_CODE_TITLE_KEY, R_CODE_TITLE);
rowTitles.put(ALL_LEVELS_TITLE_KEY, ALL_LEVELS_TITLE);
return rowTitles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,59 @@ NOT IN (SELECT saga.sdcSchoolCollectionStudentID FROM SdcSagaEntity saga WHERE s
""")
IndigenousHeadcountHeaderResult getIndigenousHeadersBySchoolId(@Param("sdcSchoolCollectionID") UUID sdcSchoolCollectionID);

@Query("SELECT " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'A' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleA, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'A' THEN 1 END) AS reportedA, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'B' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleB, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'B' THEN 1 END) AS reportedB, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'C' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleC, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'C' THEN 1 END) AS reportedC, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'D' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleD, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'D' THEN 1 END) AS reportedD, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'E' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleE, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'E' THEN 1 END) AS reportedE, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'F' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleF, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'F' THEN 1 END) AS reportedF, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'G' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleG, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'G' THEN 1 END) AS reportedG, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'H' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleH, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'H' THEN 1 END) AS reportedH, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'K' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleK, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'K' THEN 1 END) AS reportedK, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'P' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleP, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'P' THEN 1 END) AS reportedP, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'Q' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleQ, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'Q' THEN 1 END) AS reportedQ, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'R' AND s.specialEducationNonEligReasonCode IS NULL THEN 1 END) AS totalEligibleR, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'R' THEN 1 END) AS reportedR " +
"FROM SdcSchoolCollectionStudentEntity s " +
"WHERE s.sdcSchoolCollection.sdcSchoolCollectionID = :sdcSchoolCollectionID")
SpecialEdHeadcountHeaderResult getSpecialEdHeadersBySchoolId(@Param("sdcSchoolCollectionID") UUID sdcSchoolCollectionID);

@Query("SELECT " +
"s.enrolledGradeCode AS enrolledGradeCode, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode IN ('A', 'B') THEN 1 END) AS levelOnes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'A' THEN 1 END) AS specialEdACodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'B' THEN 1 END) AS specialEdBCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode IN ('C', 'D', 'E', 'F', 'G') THEN 1 END) AS levelTwos, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'C' THEN 1 END) AS specialEdCCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'D' THEN 1 END) AS specialEdDCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'E' THEN 1 END) AS specialEdECodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'F' THEN 1 END) AS specialEdFCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'G' THEN 1 END) AS specialEdGCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode IN ('H') THEN 1 END) AS levelThrees, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'H' THEN 1 END) AS specialEdHCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode IN ('K', 'P', 'Q', 'R') THEN 1 END) AS otherLevels, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'K' THEN 1 END) AS specialEdKCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'P' THEN 1 END) AS specialEdPCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'Q' THEN 1 END) AS specialEdQCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode = 'R' THEN 1 END) AS specialEdRCodes, " +
"COUNT(CASE WHEN s.specialEducationCategoryCode IN ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'K', 'P', 'Q', 'R') THEN 1 END) AS allLevels " +
"FROM SdcSchoolCollectionStudentEntity s " +
"WHERE s.sdcSchoolCollection.sdcSchoolCollectionID = :sdcSchoolCollectionID " +
"GROUP BY s.enrolledGradeCode " +
"ORDER BY s.enrolledGradeCode")
List<SpecialEdHeadcountResult> getSpecialEdHeadcountsBySchoolId(@Param("sdcSchoolCollectionID") UUID sdcSchoolCollectionID);

@Modifying
@Query(value = "DELETE FROM SDC_SCHOOL_COLLECTION_STUDENT WHERE SDC_SCHOOL_COLLECTION_ID = :sdcSchoolCollectionID", nativeQuery = true)
Expand Down
Loading

0 comments on commit 7ea64a4

Please sign in to comment.