Skip to content

Commit

Permalink
Merge pull request #5755 from espoon-voltti/no-meals-for-preschoolers…
Browse files Browse the repository at this point in the history
…-during-term-break

Ei tilata ruokia esiopetuslapsille loma-aikana
  • Loading branch information
Wnt authored Oct 2, 2024
2 parents 155bbe5 + a978146 commit 79687ee
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 53 deletions.
36 changes: 0 additions & 36 deletions service/src/main/kotlin/fi/espoo/evaka/placement/PlacementType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,6 @@ enum class PlacementType : DatabaseEnum {
PREPARATORY_DAYCARE_ONLY -> dailyPreparatoryTime
}

fun fixedScheduleOnlyRange(
date: LocalDate,
dailyPreschoolTime: TimeRange?,
dailyPreparatoryTime: TimeRange?,
preschoolTerms: List<PreschoolTerm>,
): TimeRange? =
when (this) {
CLUB,
DAYCARE,
DAYCARE_PART_TIME,
DAYCARE_FIVE_YEAR_OLDS,
DAYCARE_PART_TIME_FIVE_YEAR_OLDS,
TEMPORARY_DAYCARE,
TEMPORARY_DAYCARE_PART_DAY,
SCHOOL_SHIFT_CARE,
PRESCHOOL_DAYCARE,
PRESCHOOL_CLUB,
PRESCHOOL_DAYCARE_ONLY,
PREPARATORY_DAYCARE,
PREPARATORY_DAYCARE_ONLY -> null
PRESCHOOL ->
if (
preschoolTerms.firstNotNullOfOrNull { it.scheduleType(date) } ==
ScheduleType.FIXED_SCHEDULE
)
dailyPreschoolTime
else null
PREPARATORY ->
if (
preschoolTerms.firstNotNullOfOrNull { it.scheduleType(date) } ==
ScheduleType.FIXED_SCHEDULE
)
dailyPreparatoryTime
else null
}

override val sqlType: String = "placement_type"

companion object {
Expand Down
39 changes: 22 additions & 17 deletions service/src/main/kotlin/fi/espoo/evaka/reports/MealReportUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import fi.espoo.evaka.daycare.*
import fi.espoo.evaka.mealintegration.MealType
import fi.espoo.evaka.mealintegration.MealTypeMapper
import fi.espoo.evaka.placement.PlacementType
import fi.espoo.evaka.placement.ScheduleType
import fi.espoo.evaka.reservations.ChildData
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.domain.TimeRange
Expand Down Expand Up @@ -52,8 +53,7 @@ data class MealInfo(
)

private fun childMeals(
fixedScheduleRange: TimeRange?,
reservations: List<TimeRange>,
presentTimeRanges: List<TimeRange>,
absent: Boolean,
mealtimes: DaycareMealtimes,
usePreschoolMealTypes: Boolean,
Expand All @@ -62,10 +62,6 @@ private fun childMeals(
if (absent) {
return emptySet()
}
// list of time ranges when child will be present according to fixed schedule or reservation
// times
val presentTimeRanges =
if (fixedScheduleRange != null) listOf(fixedScheduleRange) else reservations
// if we don't have data about when child will be present, default to breakfast + lunch + snack
if (presentTimeRanges.isEmpty()) {
return setOf(
Expand Down Expand Up @@ -117,22 +113,31 @@ fun mealReportData(
val mealInfoMap =
children
.flatMap { childInfo ->
val fixedScheduleRange =
childInfo.placementType.fixedScheduleOnlyRange(
date,
childInfo.dailyPreschoolTime,
childInfo.dailyPreparatoryTime,
preschoolTerms,
)
val absent =
val absenceRecord =
childInfo.absences?.size == childInfo.placementType.absenceCategories().size
val usePreschoolMealTypes =
preschoolPlacementTypes.contains(childInfo.placementType)

val scheduleType =
childInfo.placementType.scheduleType(date, emptyList(), preschoolTerms)
val effectivelyAbsent =
if (scheduleType == ScheduleType.TERM_BREAK) true else absenceRecord

// list of time ranges when child will be present according to fixed schedule or
// reservation times
val presentTimeRanges =
if (scheduleType == ScheduleType.FIXED_SCHEDULE)
listOfNotNull(
childInfo.placementType.fixedScheduleRange(
childInfo.dailyPreschoolTime,
childInfo.dailyPreparatoryTime,
)
)
else childInfo.reservations ?: emptyList()

childMeals(
fixedScheduleRange,
childInfo.reservations ?: emptyList(),
absent,
presentTimeRanges,
effectivelyAbsent,
childInfo.mealTimes,
usePreschoolMealTypes,
)
Expand Down
124 changes: 124 additions & 0 deletions service/src/test/kotlin/fi/espoo/evaka/reports/MealReportTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,130 @@ class MealReportTests {
)
}

@Test
fun `mealReportData should return no meals during preschool term break times for preschool type placements`() {
val testDate = LocalDate.of(2023, 5, 10)
val childInfo =
listOf(
MealReportChildInfo(
placementType = PlacementType.PRESCHOOL, // Preschool type placement
firstName = "Alice",
lastName = "Johnson",
reservations = listOf(), // No specific reservations
absences = null, // No absences
dietInfo = null,
mealTextureInfo = null,
dailyPreschoolTime = TimeRange(LocalTime.of(10, 0), LocalTime.of(14, 30)),
dailyPreparatoryTime = null,
mealTimes =
DaycareMealtimes(
breakfast = TimeRange(LocalTime.of(8, 0), LocalTime.of(8, 20)),
lunch = TimeRange(LocalTime.of(11, 0), LocalTime.of(11, 20)),
snack = TimeRange(LocalTime.of(14, 0), LocalTime.of(14, 20)),
supper = null,
eveningSnack = null,
),
)
)
val preschoolTerms =
listOf(
PreschoolTerm(
finnishPreschool =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
id = PreschoolTermId(UUID.randomUUID()),
extendedTerm =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
swedishPreschool =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
termBreaks =
DateSet.of( // Term break in effect
listOf(FiniteDateRange(testDate.minusDays(2), testDate.plusDays(2)))
),
applicationPeriod =
FiniteDateRange(LocalDate.of(2022, 1, 1), LocalDate.of(2022, 12, 31)),
)
)

val report =
mealReportData(
children = childInfo,
date = testDate,
preschoolTerms = preschoolTerms,
DefaultMealTypeMapper,
)

val expectedMealTypes = emptySet<MealType>()
val actualMealTypes = report.map { it.mealType }.toSet()

assertEquals(
expectedMealTypes,
actualMealTypes,
"Expected no meals during preschool term break times for preschool type placements",
)
}

@Test
fun `mealReportData should return no meals during preschool term break times for preparatory type placements`() {
val testDate = LocalDate.of(2023, 5, 10)
val childInfo =
listOf(
MealReportChildInfo(
placementType = PlacementType.PREPARATORY, // Preparatory type placement
firstName = "Alice",
lastName = "Johnson",
reservations = listOf(), // No specific reservations
absences = null, // No absences
dietInfo = null,
mealTextureInfo = null,
dailyPreschoolTime = TimeRange(LocalTime.of(10, 0), LocalTime.of(14, 30)),
dailyPreparatoryTime = null,
mealTimes =
DaycareMealtimes(
breakfast = TimeRange(LocalTime.of(8, 0), LocalTime.of(8, 20)),
lunch = TimeRange(LocalTime.of(11, 0), LocalTime.of(11, 20)),
snack = TimeRange(LocalTime.of(14, 0), LocalTime.of(14, 20)),
supper = null,
eveningSnack = null,
),
)
)
val preschoolTerms =
listOf(
PreschoolTerm(
finnishPreschool =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
id = PreschoolTermId(UUID.randomUUID()),
extendedTerm =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
swedishPreschool =
FiniteDateRange(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 12, 31)),
termBreaks =
DateSet.of( // Term break in effect
listOf(FiniteDateRange(testDate.minusDays(2), testDate.plusDays(2)))
),
applicationPeriod =
FiniteDateRange(LocalDate.of(2022, 1, 1), LocalDate.of(2022, 12, 31)),
)
)

val report =
mealReportData(
children = childInfo,
date = testDate,
preschoolTerms = preschoolTerms,
DefaultMealTypeMapper,
)

val expectedMealTypes = emptySet<MealType>()
val actualMealTypes = report.map { it.mealType }.toSet()

assertEquals(
expectedMealTypes,
actualMealTypes,
"Expected no meals during preschool term break times for preschool type placements",
)
}

@Test
fun `mealReportData should provide individual rows for meals when child has special diet`() {
val testDate = LocalDate.of(2023, 5, 10)
Expand Down

0 comments on commit 79687ee

Please sign in to comment.