Skip to content

Commit

Permalink
Merge pull request #1580 from bcgov/feature/isfsReport
Browse files Browse the repository at this point in the history
feature/isfsReport
  • Loading branch information
SodhiA1 authored Jan 30, 2025
2 parents 8fa0aed + 5290efa commit 98ae7f9
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public enum MinistryReportTypeCode {
INDY_FUNDING_REPORT_FUNDED("indy-funding-report-funded"),
ONLINE_INDY_FUNDING_REPORT("online-indy-funding-report"),
NON_GRADUATED_ADULT_INDY_FUNDING_REPORT("non-graduated-adult-indy-funding-report"),
REFUGEE_ENROLMENT_HEADCOUNTS_AND_FTE_REPORT("refugee-enrolment-fte-headcounts")

REFUGEE_ENROLMENT_HEADCOUNTS_AND_FTE_REPORT("refugee-enrolment-fte-headcounts"),
ISFS_PRELIMINARY_REPORT("isfs-prelim-report")
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ca.bc.gov.educ.studentdatacollection.api.constants.v1.ministryreports;

import lombok.Getter;

@Getter
public enum ISFSPreliminaryHeader {

REPORT_DATE("REPORT_DATE"),
DISTNO("DISTNO"),
SCHLNO("SCHLNO"),
PRIM_FUND("PRIM_FUND"),
ELEM_FUND("ELEM_FUND"),
JUNR_FUND("JUNR_FUND"),
SECN_FUND("SECN_FUND"),
DL_13_FUND("DL_13_FUND"),
DL_14_FUND("DL_14_FUND"),
SL_1_HC("SL_1_HC"),
SL_2_HC("SL_2_HC"),
SL_3_HC("SL_3_HC"),
SL_SES_HC("SL_SES_HC"),
ADP_FTE("ADP_FTE"),
ADE_FTE("ADE_FTE"),
ADJ_FTE("ADJ_FTE"),
ADS_FTE("ADS_FTE"),
DL_AK9_FTE("DL_AK9_FTE"),
DL_AAC_FTE("DL_AAC_FTE"),
ES_KH_FTE("ES_KH_FTE"),
ES_KF_FTE("ES_KF_FTE"),
ES_PR_FTE("ES_PR_FTE"),
ES_EL_FTE("ES_EL_FTE"),
ES_JR_FTE("ES_JR_FTE"),
ES_SR_FTE("ES_SR_FTE"),
DL_13_FTE("DL_13_FTE"),
DL_14_FTE("DL_14_FTE"),
HS_HC("HS_HC"),
IS_POSTED("IS_POSTED");

private final String code;
ISFSPreliminaryHeader(String code) { this.code = code; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public DownloadableReportResponse getMinistryDownloadableReport(UUID collectionI
case NON_GRADUATED_ADULT_INDY_FUNDING_REPORT -> ministryReportsService.generateIndyFundingGraduateReport(collectionID);
case REFUGEE_ENROLMENT_HEADCOUNTS_AND_FTE_REPORT -> ministryReportsService.generateRefugeeEnrolmentHeadcountsAndFteReport(collectionID);
case POSTED_DUPLICATES -> ministryReportsService.generatePostedDuplicatesReport(collectionID);
case ISFS_PRELIMINARY_REPORT -> ministryReportsService.generateISFSPrelimReport(collectionID);
default -> new DownloadableReportResponse();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,94 @@ WHERE sscs.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')
GROUP BY sscs.sdcSchoolCollection.schoolID, sscs.sdcSchoolCollection.sdcSchoolCollectionID """)
List<EnrolmentHeadcountFteResult> getEnrolmentHeadcountsAndFteByFebCollectionId(@Param("collectionID") UUID collectionID);

@Query(value = """
SELECT
sscs.sdcSchoolCollection.schoolID as schoolID,
COUNT(DISTINCT CASE WHEN sscs.specialEducationCategoryCode in ('A','B') AND sscs.specialEducationNonEligReasonCode IS NULL THEN sscs.sdcSchoolCollectionStudentID END) as specialEducationLevel1Count,
COUNT(DISTINCT CASE WHEN sscs.specialEducationCategoryCode in ('C','D','E','F','G') AND sscs.specialEducationNonEligReasonCode IS NULL THEN sscs.sdcSchoolCollectionStudentID END) as specialEducationLevel2Count,
COUNT(DISTINCT CASE WHEN sscs.specialEducationCategoryCode in ('H','J','M','N') AND sscs.specialEducationNonEligReasonCode IS NULL THEN sscs.sdcSchoolCollectionStudentID END) as specialEducationLevel4Count,
COUNT(DISTINCT CASE WHEN sscs.specialEducationCategoryCode in ('K','P','Q','R') AND sscs.specialEducationNonEligReasonCode IS NULL THEN sscs.sdcSchoolCollectionStudentID END) as specialEducationLevelOtherCount,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('KH') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAgedKHFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('KF') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAgedKFFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('01','02','03') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAged1to3Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('KH','KF','01','02','03','04','05','06','07','08','09') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAgedKto9Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('04','05','06','07','EU') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAged4to7EUFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('08','09','10','SU') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAged8to10SUFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('11','12') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAged11and12Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('10','11','12') AND s.fte > 0 and s.isSchoolAged = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as schoolAged10to12Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('KH','KF','01','02','03') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adultsKto3Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('KH','KF','01','02','03','04','05','06','07','08','09') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adultsKto9Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('04','05','06','07','EU') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adults4to7EUFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('08','09','10','SU') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adults8to10SUFte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('11','12') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adults11and12Fte,
(SELECT SUM(CASE WHEN s.enrolledGradeCode in ('10','11','12') AND s.fte > 0 and s.isAdult = true THEN s.fte ELSE 0 END ) FROM SdcSchoolCollectionStudentEntity s
WHERE s.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND s.sdcSchoolCollection.sdcSchoolCollectionID = sscs.sdcSchoolCollection.sdcSchoolCollectionID
AND s.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')) as adults10to12Fte,
COUNT(DISTINCT CASE WHEN sscs.enrolledGradeCode in ('HS') THEN sscs.sdcSchoolCollectionStudentID END) as totalHomeschoolCount
FROM SdcSchoolCollectionStudentEntity sscs
WHERE sscs.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED')
AND sscs.sdcSchoolCollection.collectionEntity.collectionID = :collectionID
AND sscs.sdcSchoolCollection.sdcDistrictCollectionID is null
GROUP BY sscs.sdcSchoolCollection.schoolID, sscs.sdcSchoolCollection.sdcSchoolCollectionID """)
List<ISFSPrelimHeadcountResult> getISFSPreliminaryDataByCollectionId(@Param("collectionID") UUID collectionID);

@Query("SELECT " +
" sscs.sdcSchoolCollection.schoolID as schoolID, " +

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -1024,6 +1025,75 @@ public DownloadableReportResponse generateInclusiveEducationVarianceReport(UUID
}
}

// ISFS Preliminary report
public DownloadableReportResponse generateISFSPrelimReport(UUID collectionID) {
var collectionOpt = collectionRepository.findById(collectionID);

if(collectionOpt.isEmpty()){
throw new EntityNotFoundException(Collection.class, COLLECTION_ID, collectionID.toString());
}

List<ISFSPrelimHeadcountResult> results = sdcSchoolCollectionStudentRepository.getISFSPreliminaryDataByCollectionId(collectionID);

List<String> headers = Arrays.stream(ISFSPreliminaryHeader.values()).map(ISFSPreliminaryHeader::getCode).toList();
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
.setHeader(headers.toArray(String[]::new))
.build();
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(byteArrayOutputStream));
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);

for (ISFSPrelimHeadcountResult result : results) {
var school = restUtils.getSchoolBySchoolID(result.getSchoolID()).orElseThrow(() -> new EntityNotFoundException(SchoolTombstone.class, SCHOOL_ID, result.getSchoolID()));

List<String> csvRowData = prepareISFSPrelimDataForCsv(getPrelimFinalResult(result, school), school, collectionOpt.get());
csvPrinter.printRecord(csvRowData);
}
csvPrinter.flush();

var downloadableReport = new DownloadableReportResponse();
downloadableReport.setReportType(ISFS_PRELIMINARY_REPORT.getCode());
downloadableReport.setDocumentData(Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));

return downloadableReport;
} catch (IOException e) {
throw new StudentDataCollectionAPIRuntimeException(e);
}
}

private ISFSPrelimHeadcountFinalResult getPrelimFinalResult(ISFSPrelimHeadcountResult queryResult, SchoolTombstone school){
ISFSPrelimHeadcountFinalResult finalResult = new ISFSPrelimHeadcountFinalResult();

finalResult.setSpecialEducationLevel1Count(queryResult.getSpecialEducationLevel1Count());
finalResult.setSpecialEducationLevel2Count(queryResult.getSpecialEducationLevel2Count());
finalResult.setSpecialEducationLevel3Count(queryResult.getSpecialEducationLevel3Count());
finalResult.setSpecialEducationLevelOtherCount(queryResult.getSpecialEducationLevelOtherCount());

if(school.getFacilityTypeCode().equalsIgnoreCase(FacilityTypeCodes.DIST_LEARN.getCode()) || school.getFacilityTypeCode().equalsIgnoreCase(FacilityTypeCodes.DISTONLINE.getCode())) {
finalResult.setDLAdultsKto9Fte(queryResult.getAdultsKto9Fte());
finalResult.setDLAdults10to12Fte(queryResult.getAdults10to12Fte());
finalResult.setDLSchoolAgedKto9Fte(queryResult.getSchoolAgedKto9Fte());
finalResult.setDLSchoolAged10to12Fte(queryResult.getSchoolAged10to12Fte());
}else{
finalResult.setStandardAdultsKto3Fte(queryResult.getAdultsKto3Fte());
finalResult.setStandardAdults4to7EUFte(queryResult.getAdults4to7EUFte());
finalResult.setStandardAdults8to10SUFte(queryResult.getAdults8to10SUFte());
finalResult.setStandardAdults11and12Fte(queryResult.getAdults11and12Fte());

finalResult.setStandardSchoolAgedKHFte(queryResult.getSchoolAgedKHFte());
finalResult.setStandardSchoolAgedKFFte(queryResult.getSchoolAgedKFFte());
finalResult.setStandardSchoolAged1to3Fte(queryResult.getSchoolAged1to3Fte());
finalResult.setStandardSchoolAged4to7EUFte(queryResult.getSchoolAged4to7EUFte());
finalResult.setStandardSchoolAged8to10SUFte(queryResult.getSchoolAged8to10SUFte());
finalResult.setStandardSchoolAged11and12Fte(queryResult.getSchoolAged11and12Fte());
}

finalResult.setTotalHomeschoolCount(queryResult.getTotalHomeschoolCount());

return finalResult;
}

// Enroled Headcounts and FTEs by School report
public DownloadableReportResponse generateEnrolledHeadcountsAndFteReport(UUID collectionID) {
var collectionOpt = collectionRepository.findById(collectionID);
Expand Down Expand Up @@ -1180,6 +1250,40 @@ private List<String> prepareInclusiveEducationVarianceForCsv(SpecialEdHeadcountR
));
}

private List<String> prepareISFSPrelimDataForCsv(ISFSPrelimHeadcountFinalResult headcountResult, SchoolTombstone school, CollectionEntity collection) {
return new ArrayList<>(Arrays.asList(
collection.getSnapshotDate().format(DateTimeFormatter.ofPattern("yyyyMMdd")),
school.getMincode().substring(0, 3),
school.getSchoolNumber(),
"",
"",
"",
"",
"",
"",
headcountResult.getSpecialEducationLevel1Count(),
headcountResult.getSpecialEducationLevel2Count(),
headcountResult.getSpecialEducationLevel3Count(),
headcountResult.getSpecialEducationLevelOtherCount(),
headcountResult.getStandardAdultsKto3Fte(),
headcountResult.getStandardAdults4to7EUFte(),
headcountResult.getStandardAdults8to10SUFte(),
headcountResult.getStandardAdults11and12Fte(),
headcountResult.getDLAdultsKto9Fte(),
headcountResult.getDLAdults10to12Fte(),
headcountResult.getStandardSchoolAgedKHFte(),
headcountResult.getStandardSchoolAgedKFFte(),
headcountResult.getStandardSchoolAged1to3Fte(),
headcountResult.getStandardSchoolAged4to7EUFte(),
headcountResult.getStandardSchoolAged8to10SUFte(),
headcountResult.getStandardSchoolAged11and12Fte(),
headcountResult.getDLSchoolAgedKto9Fte(),
headcountResult.getDLSchoolAged10to12Fte(),
headcountResult.getTotalHomeschoolCount(),
"N"
));
}

private List<String> prepareEnrolmentFteDataForCsv(EnrolmentHeadcountFteResult headcountResult, SchoolTombstone school) {
var facilityType = restUtils.getFacilityTypeCode(school.getFacilityTypeCode());
return new ArrayList<>(Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ISFSPrelimHeadcountFinalResult {
String specialEducationLevel1Count;
String specialEducationLevel2Count;
String specialEducationLevel3Count;
String specialEducationLevelOtherCount;

String standardAdultsKto3Fte;
String standardAdults4to7EUFte;
String standardAdults8to10SUFte;
String standardAdults11and12Fte;

String dLAdultsKto9Fte;
String dLAdults10to12Fte;

String standardSchoolAgedKHFte;
String standardSchoolAgedKFFte;
String standardSchoolAged1to3Fte;
String standardSchoolAged4to7EUFte;
String standardSchoolAged8to10SUFte;
String standardSchoolAged11and12Fte;

String dLSchoolAgedKto9Fte;
String dLSchoolAged10to12Fte;

String totalHomeschoolCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts;

public interface ISFSPrelimHeadcountResult extends HeadcountResult{
String getSpecialEducationLevel1Count();
String getSpecialEducationLevel2Count();
String getSpecialEducationLevel3Count();
String getSpecialEducationLevelOtherCount();

String getAdultsKto3Fte();
String getAdultsKto9Fte();
String getAdults4to7EUFte();
String getAdults8to10SUFte();
String getAdults11and12Fte();
String getAdults10to12Fte();

String getSchoolAgedKHFte();
String getSchoolAgedKFFte();
String getSchoolAged1to3Fte();
String getSchoolAgedKto9Fte();
String getSchoolAged4to7EUFte();
String getSchoolAged8to10SUFte();
String getSchoolAged11and12Fte();
String getSchoolAged10to12Fte();

String getTotalHomeschoolCount();
}
Loading

0 comments on commit 98ae7f9

Please sign in to comment.