diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index 940d896c32..c1022c4533 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -11,6 +11,8 @@ import uk.gov.justice.digital.hmpps.api.model.DocumentType import uk.gov.justice.digital.hmpps.data.generator.* import uk.gov.justice.digital.hmpps.user.AuditUserRepository import java.time.LocalDate +import java.time.LocalTime +import java.time.ZoneId import java.time.ZonedDateTime @Component @@ -113,7 +115,14 @@ class DataLoader( val noSentenceEvent = SentenceGenerator.generateEvent(PersonGenerator.NO_SENTENCE, referralDate = LocalDate.now()) - val noSentenceManager = SentenceGenerator.generateOrderManager(noSentenceEvent, StaffGenerator.UNALLOCATED) + val noSentenceManager = + SentenceGenerator.generateOrderManager( + noSentenceEvent, + StaffGenerator.UNALLOCATED, + CourtGenerator.PROBATIONARE_AREA, + ZonedDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneId.of("Europe/London")), + ZonedDateTime.of(LocalDate.now().minusDays(1), LocalTime.NOON, ZoneId.of("Europe/London")) + ) val outcome = SentenceGenerator.OUTCOME val courtAppearance = SentenceGenerator.generateCourtAppearance(noSentenceEvent, outcome, ZonedDateTime.now()) em.saveAll(noSentenceEvent, noSentenceManager, outcome, courtAppearance) @@ -121,13 +130,20 @@ class DataLoader( val newEvent = SentenceGenerator.generateEvent(PersonGenerator.NEW_TO_PROBATION, referralDate = LocalDate.now()) val newSentence = SentenceGenerator.generateSentence(newEvent, LocalDate.now(), DisposalTypeGenerator.CURFEW_ORDER) - val newManager = SentenceGenerator.generateOrderManager(newEvent, StaffGenerator.UNALLOCATED) + val newManager = + SentenceGenerator.generateOrderManager( + newEvent, + StaffGenerator.UNALLOCATED, + CourtGenerator.PROBATIONARE_AREA, + ZonedDateTime.of(LocalDate.now().minusDays(1), LocalTime.NOON, ZoneId.of("Europe/London")), + ZonedDateTime.of(LocalDate.now().minusDays(3), LocalTime.NOON, ZoneId.of("Europe/London")) + ) em.saveAll(newEvent, newSentence, newManager) val currentEvent = SentenceGenerator.CURRENTLY_MANAGED val currentSentence = SentenceGenerator.CURRENT_SENTENCE val custody = SentenceGenerator.CURRENT_CUSTODY - val currentManager = SentenceGenerator.generateOrderManager(currentEvent, StaffGenerator.ALLOCATED) + val currentManager = SentenceGenerator.CURRENT_ORDER_MANAGER val mainOffence = SentenceGenerator.MAIN_OFFENCE_DEFAULT val additionalOffence = SentenceGenerator.ADDITIONAL_OFFENCE_DEFAULT val requirement = SentenceGenerator.generateRequirement(disposal = currentSentence) @@ -187,7 +203,14 @@ class DataLoader( terminationDate = LocalDate.now().minusDays(7), active = false ) - val preManager = SentenceGenerator.generateOrderManager(preEvent, StaffGenerator.ALLOCATED) + val preManager = + SentenceGenerator.generateOrderManager( + preEvent, + StaffGenerator.ALLOCATED, + CourtGenerator.PROBATIONARE_AREA, + ZonedDateTime.of(LocalDate.now().minusDays(7), LocalTime.NOON, ZoneId.of("Europe/London")), + ZonedDateTime.of(LocalDate.now().minusDays(10), LocalTime.NOON, ZoneId.of("Europe/London")) + ) em.saveAll(preEvent, preSentence, preManager) em.merge(CourtCaseNoteGenerator.CASE_NOTE) diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt index 13bac143a3..a3cc568083 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt @@ -9,7 +9,9 @@ import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.event.nsi.Nsi import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person +import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.ProbationAreaEntity import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff +import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Team import java.time.LocalDate import java.time.LocalTime import java.time.ZoneId @@ -55,6 +57,14 @@ object SentenceGenerator { ZonedDateTime.of(LocalDate.now(), LocalTime.NOON, TIME_ZONE) ) + val CURRENT_ORDER_MANAGER = SentenceGenerator.generateOrderManager( + CURRENTLY_MANAGED, + StaffGenerator.ALLOCATED, + CourtGenerator.PROBATIONARE_AREA, + ZonedDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneId.of("Europe/London")), + ZonedDateTime.of(LocalDate.now().minusDays(3), LocalTime.NOON, ZoneId.of("Europe/London")) + ) + val CONDITIONAL_RELEASE_KEY_DATE = generateKeyDates(LocalDate.now(), CURRENT_CUSTODY, ReferenceDataGenerator.ACR) val LED_KEY_DATE = generateKeyDates(LocalDate.now().plusDays(1), CURRENT_CUSTODY, ReferenceDataGenerator.LED) val HDC_KEY_DATE = generateKeyDates(LocalDate.now().plusDays(2), CURRENT_CUSTODY, ReferenceDataGenerator.HDE) @@ -140,11 +150,15 @@ object SentenceGenerator { fun generateOrderManager( event: Event, - staff: Staff, + staff: Staff? = null, + probationArea: ProbationAreaEntity, + allocatedDate: ZonedDateTime, + endDate: ZonedDateTime, + team: Team? = null, active: Boolean = true, softDeleted: Boolean = false, id: Long = IdGenerator.getAndIncrement() - ) = OrderManager(event, staff, active, softDeleted, id) + ) = OrderManager(event, staff, active, probationArea, team, allocatedDate, endDate, softDeleted, id) fun generateCourtAppearance( event: Event, @@ -203,7 +217,7 @@ object SentenceGenerator { offenceCount = 1, PersonGenerator.CURRENTLY_MANAGED.id, ZonedDateTime.of(LocalDate.now().minusDays(3), LocalTime.NOON, TIME_ZONE), - LocalDate.now().plusDays(1) + ZonedDateTime.of(LocalDate.now().plusDays(1), LocalTime.NOON, TIME_ZONE), ) val ADDITIONAL_OFFENCE_DEFAULT = generateAdditionalOffence( @@ -211,7 +225,7 @@ object SentenceGenerator { ADDITIONAL_OFFENCE, LocalDate.now(), ZonedDateTime.of(LocalDate.now().minusMonths(1), LocalTime.NOON, TIME_ZONE), - LocalDate.now().plusMonths(1), + ZonedDateTime.of(LocalDate.now().plusMonths(1), LocalTime.NOON, TIME_ZONE), ) fun generateOffence( @@ -252,7 +266,7 @@ object SentenceGenerator { offenceCount: Long, offenderId: Long, created: ZonedDateTime, - updated: LocalDate, + updated: ZonedDateTime, tics: Long? = null, verdict: String? = null, id: Long = IdGenerator.getAndIncrement(), @@ -264,7 +278,7 @@ object SentenceGenerator { offence: Offence, date: LocalDate, created: ZonedDateTime, - updated: LocalDate, + updated: ZonedDateTime, id: Long = IdGenerator.getAndIncrement(), softDeleted: Boolean = false, offenceCount: Long? = null, diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt index 41aaa24533..d6ed64e8a4 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/StaffGenerator.kt @@ -1,5 +1,6 @@ package uk.gov.justice.digital.hmpps.data.generator +import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Officer import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.OfficerPk import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PartitionArea @@ -10,7 +11,8 @@ object StaffGenerator { val UNALLOCATED = generate("N01UATU") val ALLOCATED = generate("N01ABBA") val OFFICER = generateOfficer() - fun generate(code: String, id: Long = IdGenerator.getAndIncrement()) = Staff(code, "Bob", "Micheal", "Smith", id) + fun generate(code: String, id: Long = IdGenerator.getAndIncrement(), grade: ReferenceData? = null) = + Staff(code, "Bob", "Micheal", "Smith", grade, id) fun generateOfficer() = Officer( diff --git a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionIntegrationTest.kt b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionIntegrationTest.kt index 4f54056622..0761f024de 100644 --- a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionIntegrationTest.kt +++ b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionIntegrationTest.kt @@ -15,6 +15,7 @@ import uk.gov.justice.digital.hmpps.api.model.KeyValue import uk.gov.justice.digital.hmpps.api.model.conviction.* import uk.gov.justice.digital.hmpps.data.generator.AdditionalSentenceGenerator.SENTENCE_DISQ import uk.gov.justice.digital.hmpps.data.generator.CourtGenerator.BHAM +import uk.gov.justice.digital.hmpps.data.generator.CourtGenerator.PROBATIONARE_AREA import uk.gov.justice.digital.hmpps.data.generator.DisposalTypeGenerator.CURFEW_ORDER import uk.gov.justice.digital.hmpps.data.generator.InstitutionGenerator.WSIHMP import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator @@ -22,8 +23,10 @@ import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.ADDITIONAL_OFFENCE import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.COURT_APPEARANCE +import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.CURRENT_ORDER_MANAGER import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.CURRENT_SENTENCE import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.MAIN_OFFENCE +import uk.gov.justice.digital.hmpps.data.generator.StaffGenerator.ALLOCATED import uk.gov.justice.digital.hmpps.data.generator.UnpaidWorkGenerator.UNPAID_WORK_DETAILS_1 import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken @@ -217,6 +220,20 @@ internal class ConvictionIntegrationTest { COURT_APPEARANCE.court.courtName, KeyValue(COURT_APPEARANCE.appearanceType.code, COURT_APPEARANCE.appearanceType.description), COURT_APPEARANCE.person.crn + ), + listOf( + OrderManager( + PROBATIONARE_AREA.id, + null, + CURRENT_ORDER_MANAGER.id, + ALLOCATED.getName(), + ALLOCATED.code, + CURRENT_ORDER_MANAGER.allocationDate, + CURRENT_ORDER_MANAGER.endDate, + null, + null, + PROBATIONARE_AREA.code + ) ) ) diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/Conviction.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/Conviction.kt index 03218628e9..63707bff97 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/Conviction.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/Conviction.kt @@ -20,7 +20,8 @@ data class Conviction( val latestCourtAppearanceOutcome: KeyValue?, val custody: Custody? = null, val responsibleCourt: Court?, - val courtAppearance: CourtAppearanceBasic? + val courtAppearance: CourtAppearanceBasic?, + val orderManagers: List? ) data class Offence( @@ -33,7 +34,7 @@ data class Offence( val verdict: String?, val offenderId: Long, val createdDatetime: ZonedDateTime, - val lastUpdatedDatetime: LocalDate, + val lastUpdatedDatetime: ZonedDateTime, ) data class OffenceDetail( @@ -159,3 +160,16 @@ data class CourtAppearanceBasic( val crn: String ) +data class OrderManager( + val probationAreaId: Long, + val teamId: Long?, + val officerId: Long, + val name: String?, + val staffCode: String?, + val dateStartOfAllocation: ZonedDateTime, + val dateEndOfAllocation: ZonedDateTime, + val gradeCode: String?, + val teamCode: String?, + val probationAreaCode: String +) + diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Event.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Event.kt index 4f8e732e69..2332bd4a01 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Event.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Event.kt @@ -10,8 +10,11 @@ import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.en import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Court import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Disposal import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person +import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.ProbationAreaEntity import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff +import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Team import java.time.LocalDate +import java.time.ZonedDateTime @Immutable @Entity @@ -63,6 +66,9 @@ class Event( @OneToMany(mappedBy = "event") val courtAppearances: List = emptyList(), + @OneToMany(mappedBy = "event") + val orderManagers: List = emptyList(), + @ManyToOne @JoinColumn(name = "court_id") val court: Court?, @@ -107,11 +113,23 @@ class OrderManager( @ManyToOne @JoinColumn(name = "allocation_staff_id") - val staff: Staff, + val staff: Staff?, @Column(name = "active_flag", columnDefinition = "number") val active: Boolean, + @ManyToOne + @JoinColumn(name = "probation_area_id") + val probationArea: ProbationAreaEntity, + + @OneToOne + @JoinColumn(name = "allocation_team_id") + val team: Team?, + + val allocationDate: ZonedDateTime, + + val endDate: ZonedDateTime, + @Column(columnDefinition = "number") val softDeleted: Boolean, diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/MainOffence.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/MainOffence.kt index 48781bd14a..59133106b2 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/MainOffence.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/MainOffence.kt @@ -42,7 +42,7 @@ class MainOffence( val created: ZonedDateTime, @Column(name = "last_updated_datetime", nullable = false) - val updated: LocalDate, + val updated: ZonedDateTime, @Column(updatable = false, columnDefinition = "NUMBER") val softDeleted: Boolean = false @@ -78,7 +78,7 @@ class AdditionalOffence( val created: ZonedDateTime, @Column(name = "last_updated_datetime", nullable = false) - val updated: LocalDate, + val updated: ZonedDateTime, @Id @Column(name = "additional_offence_id") diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/provider/entity/Staff.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/provider/entity/Staff.kt index be7ed42c09..76638ab3ab 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/provider/entity/Staff.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/provider/entity/Staff.kt @@ -1,12 +1,8 @@ package uk.gov.justice.digital.hmpps.integrations.delius.provider.entity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id -import jakarta.persistence.JoinColumn -import jakarta.persistence.ManyToOne -import jakarta.persistence.Table +import jakarta.persistence.* import org.hibernate.annotations.Immutable +import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData @Immutable @Entity @@ -25,6 +21,10 @@ class Staff( @Column val surname: String, + @ManyToOne + @JoinColumn(name = "staff_grade_id") + val grade: ReferenceData?, + @Id @Column(name = "staff_id") val id: Long @@ -32,6 +32,13 @@ class Staff( fun isUnallocated(): Boolean { return code.endsWith("U") } + + fun getName(): String { + return when { + forename2 == null -> "$forename $surname" + else -> "$forename $forename2 $surname" + } + } } @Immutable diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/ConvictionService.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/ConvictionService.kt index ec9054f7c5..4f3cf1b82b 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/ConvictionService.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/ConvictionService.kt @@ -9,6 +9,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.getPerson import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.Offence as OffenceEntity +import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.OrderManager as OrderManagerEntity import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.AdditionalSentence as AdditionalSentenceEntity import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Court as CourtEntity import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Custody as CustodyEntity @@ -44,7 +45,8 @@ class ConvictionService( toLatestCourtAppearanceOutcome(), disposal?.custody?.toCustody(), court?.toCourt(), - toLatestOrSentencingCourtAppearanceOf() + toLatestOrSentencingCourtAppearanceOf(), + orderManagers.map { it.toOrderManager() } ) fun Event.toOffences(): List { @@ -235,6 +237,19 @@ class ConvictionService( KeyValue(courtType.code, courtType.description), ) + fun OrderManagerEntity.toOrderManager(): OrderManager = + OrderManager( + probationArea.id, + team?.id, + id, + staff?.getName(), + staff?.code, + allocationDate, + endDate, + staff?.grade?.code, + team?.code, + probationArea.code + ) } enum class KeyDateTypes(val code: String) {