Skip to content

Commit

Permalink
Fix predicate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkrepo committed Jan 31, 2025
1 parent 23403bb commit 40c37ec
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class TampereRegionalSurvey(private val accessControl: AccessControl) {
where("date_part('year', age(${bind(yearlyStatDay)}, p.date_of_birth)) = 5")
}

val voucherPredicate = Predicate {
val voucherDaycarePredicate = Predicate {
where("$it.provider_type = ANY ('{PRIVATE_SERVICE_VOUCHER}')")
}

Expand Down Expand Up @@ -334,29 +334,32 @@ class TampereRegionalSurvey(private val accessControl: AccessControl) {
val voucherAssistance =
tx.getYearlyAssistanceCount(
statDay = yearlyStatDay,
daycarePred = voucherPredicate,
daycarePred =
voucherDaycarePredicate.and(
Predicate { where("$it.type && '{CENTRE}'") }
),
)

val voucherGeneralAssistance =
tx.getYearlyAssistanceLevelCount(
statDay = yearlyStatDay,
daycarePred = voucherPredicate,
daycarePred = voucherDaycarePredicate,
assistancePred =
Predicate { where("$it.level = ANY ('{GENERAL_SUPPORT}')") },
)

val voucherSpecialAssistance =
tx.getYearlyAssistanceLevelCount(
statDay = yearlyStatDay,
daycarePred = voucherPredicate,
daycarePred = voucherDaycarePredicate,
assistancePred =
Predicate { where("$it.level = ANY ('{SPECIAL_SUPPORT}')") },
)

val voucherEnhancedAssistance =
tx.getYearlyAssistanceLevelCount(
statDay = yearlyStatDay,
daycarePred = voucherPredicate,
daycarePred = voucherDaycarePredicate,
assistancePred =
Predicate { where("$it.level = ANY ('{INTENSIFIED_SUPPORT}')") },
)
Expand Down Expand Up @@ -395,7 +398,9 @@ class TampereRegionalSurvey(private val accessControl: AccessControl) {
reportingDays: List<LocalDate>
): List<MonthlyAssistanceResult> {
val data =
getMonthlyAssistanceCountRows(reportingDays = reportingDays).associateBy { it.month }
getMonthlyMunicipalAssistanceCountRows(reportingDays = reportingDays).associateBy {
it.month
}

return (1..12).map { month -> data[month] ?: MonthlyAssistanceResult(month = month) }
}
Expand Down Expand Up @@ -566,7 +571,7 @@ GROUP BY month
.toList<MonthlyMunicipalShiftCareResult>()
}

private fun Database.Read.getMonthlyAssistanceCountRows(
private fun Database.Read.getMonthlyMunicipalAssistanceCountRows(
reportingDays: List<LocalDate>
): List<MonthlyAssistanceResult> {
return createQuery {
Expand All @@ -579,6 +584,8 @@ FROM unnest(${bind(reportingDays)}::date[]) day
ON daterange(pl.start_date, pl.end_date, '[]') @> day
JOIN daycare d ON pl.unit_id = d.id
WHERE pl.type = ANY ('{DAYCARE,PRESCHOOL_DAYCARE,PRESCHOOL_DAYCARE_ONLY}')
AND d.provider_type = ANY ('{MUNICIPAL}')
AND d.type && '{CENTRE}'
AND (EXISTS (SELECT FROM assistance_factor af WHERE af.child_id = pl.child_id AND af.valid_during @> day)
OR EXISTS (SELECT
FROM assistance_action an
Expand Down

0 comments on commit 40c37ec

Please sign in to comment.