Skip to content

Commit

Permalink
Merge pull request #5960 from espoon-voltti/preschool-application-rep…
Browse files Browse the repository at this point in the history
…ort-next-term

Näytetään esiopetushakemuksien raportilla vain tulevan kauden hakemukset
  • Loading branch information
patari authored Nov 13, 2024
2 parents 721b479 + daafce8 commit 27329b9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import FiniteDateRange from 'lib-common/finite-date-range'
import LocalDate from 'lib-common/local-date'
import LocalTime from 'lib-common/local-time'

Expand Down Expand Up @@ -32,6 +33,18 @@ xdescribe('Preschool application report', () => {
})

test('rows are shown', async () => {
const nextTermStart = LocalDate.of(2025, 8, 6)
const nextTermRange = new FiniteDateRange(
nextTermStart,
LocalDate.of(2026, 5, 29)
)
await Fixture.preschoolTerm({
finnishPreschool: nextTermRange,
swedishPreschool: nextTermRange,
extendedTerm: nextTermRange,
applicationPeriod: nextTermRange,
termBreaks: []
}).save()
const area = await Fixture.careArea().save()
const unit1 = await Fixture.daycare({
areaId: area.id,
Expand Down Expand Up @@ -65,7 +78,8 @@ xdescribe('Preschool application report', () => {
null,
[unit1.id],
false,
'WAITING_UNIT_CONFIRMATION'
'WAITING_UNIT_CONFIRMATION',
nextTermStart
),
id: uuidv4()
}
Expand All @@ -86,7 +100,8 @@ xdescribe('Preschool application report', () => {
null,
[unit2.id],
false,
'WAITING_UNIT_CONFIRMATION'
'WAITING_UNIT_CONFIRMATION',
nextTermStart
),
id: uuidv4()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import fi.espoo.evaka.application.persistence.daycare.Child
import fi.espoo.evaka.application.persistence.daycare.DaycareFormV0
import fi.espoo.evaka.shared.DaycareId
import fi.espoo.evaka.shared.auth.UserRole
import fi.espoo.evaka.shared.data.DateSet
import fi.espoo.evaka.shared.dev.DevCareArea
import fi.espoo.evaka.shared.dev.DevDaycare
import fi.espoo.evaka.shared.dev.DevEmployee
import fi.espoo.evaka.shared.dev.DevGuardian
import fi.espoo.evaka.shared.dev.DevPerson
import fi.espoo.evaka.shared.dev.DevPersonType
import fi.espoo.evaka.shared.dev.DevPreschoolTerm
import fi.espoo.evaka.shared.dev.insert
import fi.espoo.evaka.shared.dev.insertTestApplication
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.domain.MockEvakaClock
import java.time.LocalDate
Expand All @@ -43,6 +46,30 @@ class PreschoolApplicationReportTest : FullApplicationTest(resetDbBeforeEach = t
@BeforeEach
fun setup() {
db.transaction { tx ->
val currentTermStart = LocalDate.of(2024, 8, 7)
FiniteDateRange(start = currentTermStart, end = LocalDate.of(2025, 5, 30)).let {
tx.insert(
DevPreschoolTerm(
finnishPreschool = it,
swedishPreschool = it,
extendedTerm = it,
applicationPeriod = it,
termBreaks = DateSet.empty(),
)
)
}
val nextTermStart = LocalDate.of(2025, 8, 6)
FiniteDateRange(start = nextTermStart, end = LocalDate.of(2026, 5, 29)).let {
tx.insert(
DevPreschoolTerm(
finnishPreschool = it,
swedishPreschool = it,
extendedTerm = it,
applicationPeriod = it,
termBreaks = DateSet.empty(),
)
)
}
val areaId = tx.insert(DevCareArea())
unitId1 = tx.insert(DevDaycare(areaId = areaId, name = "Koulu A"))
unitId2 = tx.insert(DevDaycare(areaId = areaId, name = "Koulu B"))
Expand Down Expand Up @@ -70,6 +97,7 @@ class PreschoolApplicationReportTest : FullApplicationTest(resetDbBeforeEach = t
child = Child(dateOfBirth = child1.dateOfBirth),
guardian = Adult(),
apply = Apply(preferredUnits = listOf(unitId1)),
preferredStartDate = nextTermStart,
),
)

Expand All @@ -93,6 +121,31 @@ class PreschoolApplicationReportTest : FullApplicationTest(resetDbBeforeEach = t
child = Child(dateOfBirth = child2.dateOfBirth),
guardian = Adult(),
apply = Apply(preferredUnits = listOf(unitId2)),
preferredStartDate = nextTermStart,
),
)

val child3 =
DevPerson(
lastName = "Testiläinen",
firstName = "Matti",
dateOfBirth = LocalDate.of(2019, 1, 2),
ssn = null,
)
val childId3 = tx.insert(child3, DevPersonType.CHILD)
tx.insert(DevGuardian(guardianId = guardianId, childId = childId3))
tx.insertTestApplication(
type = ApplicationType.PRESCHOOL,
status = ApplicationStatus.WAITING_UNIT_CONFIRMATION,
guardianId = guardianId,
childId = childId3,
document =
DaycareFormV0(
type = ApplicationType.PRESCHOOL,
child = Child(dateOfBirth = child3.dateOfBirth),
guardian = Adult(),
apply = Apply(preferredUnits = listOf(unitId2)),
preferredStartDate = currentTermStart,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ class PlacementToolService(
throw NotFound("No default service need option found")
}
val nextPreschoolTermId =
tx.getPreschoolTerms().firstOrNull { it.finnishPreschool.start > clock.today() }?.id
if (null == nextPreschoolTermId) {
throw NotFound("No next preschool term found")
}
findNextPreschoolTerm(tx, clock.today())?.id
?: throw NotFound("No next preschool term found")
val placements = file.inputStream.use { parsePlacementToolCsv(it) }
asyncJobRunner
.plan(
Expand Down Expand Up @@ -364,6 +362,9 @@ class PlacementToolService(
user.evakaUserId,
)
}

fun findNextPreschoolTerm(tx: Database.Read, date: LocalDate) =
tx.getPreschoolTerms().firstOrNull { it.finnishPreschool.start > date }
}

fun parsePlacementToolCsv(inputStream: InputStream): Map<String, DaycareId> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package fi.espoo.evaka.reports

import fi.espoo.evaka.application.PlacementToolService
import fi.espoo.evaka.daycare.PreschoolTerm
import fi.espoo.evaka.shared.ApplicationId
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
Expand All @@ -19,7 +21,10 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class PreschoolApplicationReport(private val accessControl: AccessControl) {
class PreschoolApplicationReport(
private val accessControl: AccessControl,
private val placementToolService: PlacementToolService,
) {

@GetMapping("/employee/reports/preschool-application")
fun getPreschoolApplicationReport(
Expand All @@ -37,7 +42,10 @@ class PreschoolApplicationReport(private val accessControl: AccessControl) {
clock,
Action.Unit.READ_PRESCHOOL_APPLICATION_REPORT,
)
tx.getPreschoolApplicationReportRows(clock.today(), filter)
val nextPreschoolTerm =
placementToolService.findNextPreschoolTerm(tx, clock.today())
?: return@read emptyList()
tx.getPreschoolApplicationReportRows(clock.today(), filter, nextPreschoolTerm)
}
}
}
Expand All @@ -46,6 +54,7 @@ class PreschoolApplicationReport(private val accessControl: AccessControl) {
private fun Database.Read.getPreschoolApplicationReportRows(
today: LocalDate,
filter: AccessControlFilter<DaycareId>,
preschoolTerm: PreschoolTerm,
): List<PreschoolApplicationReportRow> =
createQuery {
sql(
Expand All @@ -71,6 +80,7 @@ LEFT JOIN daycare current_unit ON placement.unit_id = current_unit.id
WHERE application.type = 'PRESCHOOL'
AND application.status = 'WAITING_UNIT_CONFIRMATION'
AND ${predicate(filter.forTable("application_unit"))}
AND ${bind(preschoolTerm.finnishPreschool)} @> (application.document ->> 'preferredStartDate')::date
"""
.trimIndent()
)
Expand Down

0 comments on commit 27329b9

Please sign in to comment.