From c87e4c6001c35bc84292dafa45f047d50f9e62fa Mon Sep 17 00:00:00 2001 From: Paul McPhee Date: Fri, 13 Sep 2024 13:54:23 +0100 Subject: [PATCH] PI-2521: Fix null institions --- .../justice/digital/hmpps/data/generator/SentenceGenerator.kt | 2 +- .../justice/digital/hmpps/api/model/conviction/Conviction.kt | 2 +- .../digital/hmpps/integrations/delius/event/entity/Event.kt | 4 ++-- .../integrations/delius/event/sentence/entity/Disposal.kt | 2 +- .../hmpps/integrations/delius/service/ConvictionService.kt | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) 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 d94be243b6..83e66d3688 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 @@ -206,7 +206,7 @@ object SentenceGenerator { disposal: Disposal, custodialStatus: ReferenceData, prisonerNumber: String, - institution: Institution, + institution: Institution?, id: Long = IdGenerator.getAndIncrement() ) = Custody(disposal, custodialStatus, prisonerNumber = prisonerNumber, institution = institution, id = id) 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 d0180052d9..115c09a635 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 @@ -99,7 +99,7 @@ data class AdditionalSentence( data class Custody( val bookingNumber: String?, - val institution: Institution, + val institution: Institution?, val keyDates: CustodyRelatedKeyDates, val status: KeyValue, val sentenceStartDate: LocalDate 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 a918ce1538..b78bc92168 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 @@ -101,10 +101,10 @@ interface EventRepository : JpaRepository { @Query( """ select - case when d.disposal_id is null and ca.outcome_code = '101' then 1 else 0 end as awaitingPsr + sum(case when d.disposal_id is null and ca.outcome_code = '101' then 1 else 0 end) as awaitingPsr from event e left join disposal d on d.event_id = e.event_id and d.soft_deleted = 0 - left join (select distinct ca.event_id, oc.code_value as outcome_code + left join (select ca.event_id, oc.code_value as outcome_code from court_appearance ca join r_standard_reference_list oc on ca.outcome_id = oc.standard_reference_list_id) ca on ca.event_id = e.event_id diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/sentence/entity/Disposal.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/sentence/entity/Disposal.kt index 9202664034..c4b6694226 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/sentence/entity/Disposal.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/sentence/entity/Disposal.kt @@ -223,7 +223,7 @@ class Custody( JoinColumn(name = "institution_id", referencedColumnName = "institution_id"), JoinColumn(name = "establishment", referencedColumnName = "establishment") ) - val institution: Institution, + val institution: Institution? = null, @OneToMany(mappedBy = "custody") val keyDates: List = listOf(), 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 174937413c..5ee331d23a 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 @@ -57,7 +57,7 @@ class ConvictionService( inBreach, failureToComplyCount, breachEnd, - eventRepository.awaitingPSR(id) == 1, + eventRepository.awaitingPSR(id) > 0, convictionDate, referralDate, toOffences(), @@ -194,7 +194,7 @@ class ConvictionService( fun CustodyEntity.toCustody(): Custody = Custody( prisonerNumber, - institution.toInstitution(), + institution?.toInstitution(), populateKeyDates(keyDates), KeyValue(status.code, status.description), disposal.startDate