Skip to content

Commit

Permalink
Merge pull request #6213 from espoon-voltti/placement-tool-fixes
Browse files Browse the repository at this point in the history
Korjauksia esiopetussijoitusten tuontiin
  • Loading branch information
patari authored Jan 7, 2025
2 parents 89d3851 + 6625225 commit 285340c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import fi.espoo.evaka.messaging.getUnreadMessagesCounts
import fi.espoo.evaka.messaging.upsertEmployeeMessageAccount
import fi.espoo.evaka.pis.getPersonBySSN
import fi.espoo.evaka.placement.PlacementType
import fi.espoo.evaka.placement.insertPlacement
import fi.espoo.evaka.shared.AreaId
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
Expand Down Expand Up @@ -73,8 +72,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
final val employee =
DevEmployee(id = EmployeeId(UUID.randomUUID()), firstName = "Test", lastName = "Employee")
private val admin = AuthenticatedUser.Employee(employee.id, setOf(UserRole.ADMIN))
val currentPlacementStart = LocalDate.of(2020, 11, 1)
val currentPlacementEnd = LocalDate.of(2021, 5, 31)
val serviceNeedOption =
ServiceNeedOption(
ServiceNeedOptionId(UUID.randomUUID()),
Expand All @@ -83,14 +80,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
"Esiopetus ja liittyvä varhaiskasvatus",
PlacementType.PRESCHOOL_DAYCARE,
)
val partTimeServiceNeedOption =
ServiceNeedOption(
ServiceNeedOptionId(UUID.randomUUID()),
"Esiopetus",
"Esiopetus",
"Esiopetus",
PlacementType.PRESCHOOL,
)
val preschoolTerm =
PreschoolTerm(
PreschoolTermId(UUID.randomUUID()),
Expand Down Expand Up @@ -160,32 +149,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
tx.insert(
fi.espoo.evaka.serviceneed.ServiceNeedOption(
id = serviceNeedOption.id,
nameFi = "Esiopetus",
nameSv = "Esiopetus",
nameEn = "Esiopetus",
validPlacementType = PlacementType.PRESCHOOL,
defaultOption = true,
feeCoefficient = BigDecimal("0.00"),
occupancyCoefficient = BigDecimal("0.50"),
occupancyCoefficientUnder3y = BigDecimal("1.75"),
realizedOccupancyCoefficient = BigDecimal("0.50"),
realizedOccupancyCoefficientUnder3y = BigDecimal("1.75"),
daycareHoursPerWeek = 0,
contractDaysPerMonth = null,
daycareHoursPerMonth = null,
partDay = true,
partWeek = true,
feeDescriptionFi = "",
feeDescriptionSv = "",
voucherValueDescriptionFi = "",
voucherValueDescriptionSv = "",
validFrom = LocalDate.of(2000, 1, 1),
validTo = null,
)
)
tx.insert(
fi.espoo.evaka.serviceneed.ServiceNeedOption(
id = partTimeServiceNeedOption.id,
nameFi = "Esiopetus ja liittyvä varhaiskasvatus",
nameSv = "Esiopetus ja liittyvä varhaiskasvatus",
nameEn = "Esiopetus ja liittyvä varhaiskasvatus",
Expand Down Expand Up @@ -238,14 +201,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
endDate = child.dateOfBirth.plusYears(18),
)
)
tx.insertPlacement(
PlacementType.DAYCARE,
child.id,
unit.id,
currentPlacementStart,
currentPlacementEnd,
false,
)
}
}

Expand Down Expand Up @@ -334,15 +289,7 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
fun `create application with one guardian`() {
insertPersonData()
val data = PlacementToolData(childId = child.id, preschoolId = unit.id)
service.createApplication(
db,
admin,
clock,
data,
partTimeServiceNeedOption.id,
serviceNeedOption.id,
preschoolTerm.id,
)
service.createApplication(db, admin, clock, data, serviceNeedOption.id, preschoolTerm.id)

clock.tick()
asyncJobRunner.runPendingJobsSync(clock)
Expand Down Expand Up @@ -396,15 +343,7 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
MockPersonDetailsService.addDependants(adult2, child)
}
val data = PlacementToolData(childId = child.id, preschoolId = unit.id)
service.createApplication(
db,
admin,
clock,
data,
partTimeServiceNeedOption.id,
serviceNeedOption.id,
preschoolTerm.id,
)
service.createApplication(db, admin, clock, data, serviceNeedOption.id, preschoolTerm.id)

clock.tick()
asyncJobRunner.runPendingJobsSync(clock)
Expand All @@ -429,15 +368,7 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
whenever(featureConfig.placementToolApplicationStatus)
.thenReturn(ApplicationStatus.WAITING_DECISION)
val data = PlacementToolData(childId = child.id, preschoolId = unit.id)
service.createApplication(
db,
admin,
clock,
data,
partTimeServiceNeedOption.id,
serviceNeedOption.id,
preschoolTerm.id,
)
service.createApplication(db, admin, clock, data, serviceNeedOption.id, preschoolTerm.id)

clock.tick()
asyncJobRunner.runPendingJobsSync(clock)
Expand Down Expand Up @@ -483,7 +414,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
admin,
clock,
data,
partTimeServiceNeedOption.id,
serviceNeedOption.id,
preschoolTerm.id,
)
Expand All @@ -500,7 +430,6 @@ class PlacementToolServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
admin,
clock,
data,
partTimeServiceNeedOption.id,
serviceNeedOption.id,
preschoolTerm.id,
)
Expand Down Expand Up @@ -545,6 +474,47 @@ ${child.ssn!!};${unit.id}
assertEquals(summary.childId, child!!.id)
}

@Test
fun `create application from ssn for waiting decision works with incomplete family data`() {
whenever(featureConfig.placementToolApplicationStatus)
.thenReturn(ApplicationStatus.WAITING_DECISION)
db.transaction { tx -> tx.insert(child, DevPersonType.RAW_ROW) }
MockPersonDetailsService.add(
MockVtjDataset(
persons = listOf(MockVtjPerson.from(child), MockVtjPerson.from(adult)),
guardianDependants = mapOf(adult.ssn!! to listOf(child.ssn!!)),
)
)
db.transaction { tx -> tx.insert(testFeeThresholds) }

controller.createPlacementToolApplications(
dbInstance(),
admin,
clock,
MockMultipartFile(
"test.csv",
"""
lapsen_id;esiopetusyksikon_id
${child.ssn!!};${unit.id}
"""
.trimIndent()
.toByteArray(StandardCharsets.UTF_8),
),
)
asyncJobRunner.runPendingJobsSync(clock)

val applicationSummaries =
db.read {
val person = it.getPersonBySSN(adult.ssn!!)
it.fetchApplicationSummariesForGuardian(person!!.id)
}
assertEquals(1, applicationSummaries.size)
val summary = applicationSummaries.first()
assertEquals(summary.preferredUnitId, unit.id)
val child = db.read { it.getPersonBySSN(child.ssn!!) }
assertEquals(summary.childId, child!!.id)
}

@Test
fun `next preschool term is received correctly`() {
val nextTerms = controller.getNextPreschoolTerm(dbInstance(), admin, clock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package fi.espoo.evaka.application

import fi.espoo.evaka.Audit
import fi.espoo.evaka.daycare.PreschoolTerm
import fi.espoo.evaka.daycare.getChild
import fi.espoo.evaka.daycare.getDaycare
import fi.espoo.evaka.daycare.getPreschoolTerm
import fi.espoo.evaka.daycare.getPreschoolTerms
Expand All @@ -20,7 +19,6 @@ import fi.espoo.evaka.pis.service.PersonService
import fi.espoo.evaka.pis.service.getBlockedGuardians
import fi.espoo.evaka.pis.service.getChildGuardiansAndFosterParents
import fi.espoo.evaka.placement.PlacementType
import fi.espoo.evaka.placement.getPlacementsForChildDuring
import fi.espoo.evaka.serviceneed.getServiceNeedOptions
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
Expand Down Expand Up @@ -71,7 +69,6 @@ class PlacementToolService(
msg.user,
clock,
msg.data,
msg.partTimeServiceNeedOption,
msg.defaultServiceNeedOption,
msg.nextPreschoolTerm,
)
Expand All @@ -84,15 +81,6 @@ class PlacementToolService(
file: MultipartFile,
) {
val serviceNeedOptions = tx.getServiceNeedOptions()
val partTimeServiceNeedOptionId =
serviceNeedOptions
.firstOrNull {
it.validPlacementType == PlacementType.PRESCHOOL && it.defaultOption
}
?.id
if (null == partTimeServiceNeedOptionId) {
throw NotFound("No part time service need option found")
}
val defaultServiceNeedOptionId =
serviceNeedOptions
.firstOrNull {
Expand All @@ -116,7 +104,6 @@ class PlacementToolService(
user,
childIdentifier,
preschoolId,
partTimeServiceNeedOptionId,
defaultServiceNeedOptionId,
nextPreschoolTermId,
)
Expand All @@ -127,7 +114,6 @@ class PlacementToolService(
ChildId(UUID.fromString(childIdentifier)),
preschoolId,
),
partTimeServiceNeedOptionId,
defaultServiceNeedOptionId,
nextPreschoolTermId,
)
Expand All @@ -144,17 +130,17 @@ class PlacementToolService(
clock: EvakaClock,
msg: AsyncJob.PlacementToolFromSSN,
) {
val child = db.read { tx -> tx.getPersonBySSN(msg.ssn) }
val childId =
db.read { tx -> tx.getPersonBySSN(msg.ssn)?.id }
?: initFromVtj(db, msg.user, clock, msg.ssn)
if (child?.vtjGuardiansQueried == null) initFromVtj(db, msg.user, clock, msg.ssn)
else child.id
db.transaction { tx ->
asyncJobRunner.plan(
tx,
listOf(
AsyncJob.PlacementTool(
msg.user,
PlacementToolData(childId, msg.preschoolId),
msg.partTimeServiceNeedOption,
msg.defaultServiceNeedOption,
msg.nextPreschoolTerm,
)
Expand Down Expand Up @@ -184,13 +170,12 @@ class PlacementToolService(
user: AuthenticatedUser,
clock: EvakaClock,
data: PlacementToolData,
partTimeServiceNeedOptionId: ServiceNeedOptionId?,
defaultServiceNeedOptionId: ServiceNeedOptionId?,
nextPreschoolTermId: PreschoolTermId,
) {
dbc.transaction { tx ->
if (tx.getChild(data.childId) == null) {
throw Exception("Child id is null or child not found")
if (tx.getPersonById(data.childId) == null) {
throw Exception("No person found with id ${data.childId}")
}
val guardianIds =
tx.getChildGuardiansAndFosterParents(data.childId, clock.today()) -
Expand Down Expand Up @@ -232,18 +217,6 @@ class PlacementToolService(

val application = tx.fetchApplicationDetails(applicationId)!!
val serviceNeedOptions = tx.getServiceNeedOptions()
val partTimeServiceNeedOption =
serviceNeedOptions
.firstOrNull { it.id == partTimeServiceNeedOptionId }
?.let {
ServiceNeedOption(
it.id,
it.nameFi,
it.nameSv,
it.nameEn,
it.validPlacementType,
)
}
val defaultServiceNeedOption =
serviceNeedOptions
.firstOrNull { it.id == defaultServiceNeedOptionId }
Expand All @@ -265,7 +238,6 @@ class PlacementToolService(
application,
data,
guardianIds,
partTimeServiceNeedOption!!,
defaultServiceNeedOption!!,
nextPreschoolTerm,
)
Expand Down Expand Up @@ -307,17 +279,10 @@ class PlacementToolService(
application: ApplicationDetails,
data: PlacementToolData,
guardianIds: List<PersonId>,
partTimeServiceNeedOption: ServiceNeedOption,
defaultServiceNeedOption: ServiceNeedOption,
preschoolTerm: PreschoolTerm,
) {
val preferredUnit = tx.getDaycare(data.preschoolId)!!
val partTime =
tx.getPlacementsForChildDuring(data.childId, clock.today(), null).firstOrNull()?.type in
listOf(
PlacementType.DAYCARE_PART_TIME,
PlacementType.DAYCARE_PART_TIME_FIVE_YEAR_OLDS,
)

// update preferences to application
val updatedApplication =
Expand All @@ -335,9 +300,7 @@ class PlacementToolService(
endTime = "",
shiftCare = false,
partTime = false,
serviceNeedOption =
if (partTime) partTimeServiceNeedOption
else defaultServiceNeedOption,
serviceNeedOption = defaultServiceNeedOption,
),
urgent = false,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,19 @@ sealed interface AsyncJob : AsyncJobPayload {
override val user: AuthenticatedUser? = null
}

@JsonIgnoreProperties("partTimeServiceNeedOption") // only present in old jobs
data class PlacementTool(
override val user: AuthenticatedUser,
val data: PlacementToolData,
val partTimeServiceNeedOption: ServiceNeedOptionId,
val defaultServiceNeedOption: ServiceNeedOptionId,
val nextPreschoolTerm: PreschoolTermId,
) : AsyncJob

@JsonIgnoreProperties("partTimeServiceNeedOption") // only present in old jobs
data class PlacementToolFromSSN(
override val user: AuthenticatedUser,
val ssn: String,
val preschoolId: DaycareId,
val partTimeServiceNeedOption: ServiceNeedOptionId,
val defaultServiceNeedOption: ServiceNeedOptionId,
val nextPreschoolTerm: PreschoolTermId,
) : AsyncJob
Expand Down

0 comments on commit 285340c

Please sign in to comment.