diff --git a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/ContactService.kt b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/ContactService.kt index 9a77937034..d28a5490f1 100644 --- a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/ContactService.kt +++ b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/contact/ContactService.kt @@ -34,6 +34,7 @@ class ContactService( Contact( type = contactTypeRepository.getByCode(detail.typeCode.value), date = detail.date, + startTime = detail.date, person = person, event = event, licenceConditionId = licenceConditionId, diff --git a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Disposal.kt b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Disposal.kt index 5606745870..9cf8b00c2f 100644 --- a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Disposal.kt +++ b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/Disposal.kt @@ -43,12 +43,7 @@ class Disposal( @Column(updatable = false, columnDefinition = "NUMBER") val softDeleted: Boolean = false -) { - fun isLongerThan20Months(): Boolean? { - val endDate = if (lengthInDays != null) date.plusDays(lengthInDays) else notionalEndDate ?: return null - return endDate > date.plusMonths(20) - } -} +) @Immutable @Entity diff --git a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationAction.kt b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationAction.kt index 9dd9236dd4..2e4bc46edc 100644 --- a/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationAction.kt +++ b/projects/prison-custody-status-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationAction.kt @@ -8,6 +8,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactTy import uk.gov.justice.digital.hmpps.integrations.delius.custody.entity.Custody import uk.gov.justice.digital.hmpps.integrations.delius.custody.entity.CustodyHistoryRepository import uk.gov.justice.digital.hmpps.integrations.delius.custody.entity.CustodyRepository +import uk.gov.justice.digital.hmpps.integrations.delius.custody.entity.canBeReleased import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.prison.PrisonManagerService import uk.gov.justice.digital.hmpps.integrations.delius.probationarea.institution.entity.Institution import uk.gov.justice.digital.hmpps.integrations.delius.probationarea.institution.entity.InstitutionRepository @@ -53,21 +54,23 @@ class UpdateLocationAction( else -> null } - return custody.updateLocationAt(institution, prisonerMovement.occurredAt) { - referenceDataRepository.getCustodyEventType(CustodyEventTypeCode.LOCATION_CHANGE.code) - }?.let { history -> - custodyRepository.save(custody) - custodyHistoryRepository.save(history) - (pomInstitutionOverride ?: institution).probationArea?.let { - prisonManagerService.allocateToProbationArea( - custody.disposal, - it, - prisonerMovement.occurredAt - ) - } - createLocationChangeContact(prisonerMovement, custody) + return institution?.let { institution -> + custody.updateLocationAt(institution, prisonerMovement.occurredAt) { + referenceDataRepository.getCustodyEventType(CustodyEventTypeCode.LOCATION_CHANGE.code) + }?.let { history -> + custodyRepository.save(custody) + custodyHistoryRepository.save(history) + (pomInstitutionOverride ?: institution).probationArea?.let { + prisonManagerService.allocateToProbationArea( + custody.disposal, + it, + prisonerMovement.occurredAt + ) + } + createLocationChangeContact(prisonerMovement, custody) - ActionResult.Success(ActionResult.Type.LocationUpdated, prisonerMovement.telemetryProperties()) + ActionResult.Success(ActionResult.Type.LocationUpdated, prisonerMovement.telemetryProperties()) + } } ?: ActionResult.Ignored("PrisonerLocationCorrect", prisonerMovement.telemetryProperties()) } @@ -87,7 +90,9 @@ class UpdateLocationAction( isAbsconded() -> institutionRepository.getByCode(InstitutionCode.UNLAWFULLY_AT_LARGE.code) - else -> institutionRepository.getByCode(InstitutionCode.IN_COMMUNITY.code) + custody.canBeReleased() -> institutionRepository.getByCode(InstitutionCode.IN_COMMUNITY.code) + + else -> custody.institution } private fun createLocationChangeContact(prisonerMovement: PrisonerMovement, custody: Custody) { diff --git a/projects/prison-custody-status-to-delius/src/main/resources/application-prisoner-movement.yml b/projects/prison-custody-status-to-delius/src/main/resources/application-prisoner-movement.yml index 2034fa5ccc..ef81c0f85a 100644 --- a/projects/prison-custody-status-to-delius/src/main/resources/application-prisoner-movement.yml +++ b/projects/prison-custody-status-to-delius/src/main/resources/application-prisoner-movement.yml @@ -3,14 +3,14 @@ prisoner.movement.configs: - ADMISSION actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - RELEASED_TO_HOSPITAL actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus featureFlag: messages_released_hospital - types: - RELEASED @@ -26,8 +26,8 @@ prisoner.movement.configs: - HQ actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus featureFlag: messages_released_hospital - types: - RELEASED @@ -38,8 +38,8 @@ prisoner.movement.configs: - ETR actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - RELEASED reasons: @@ -47,8 +47,8 @@ prisoner.movement.configs: reasonOverride: RO actionNames: - Release - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - RELEASED reasons: @@ -56,25 +56,25 @@ prisoner.movement.configs: - UAL_ECL actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - RELEASED actionNames: - Release - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - TEMPORARY_ABSENCE_RETURN actionNames: - Recall - - UpdateStatus - UpdateLocation + - UpdateStatus - types: - TRANSFERRED reasons: - INT actionNames: - Recall + - UpdateLocation - UpdateStatus - - UpdateLocation \ No newline at end of file diff --git a/projects/prison-custody-status-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationActionTest.kt b/projects/prison-custody-status-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationActionTest.kt index fcb9c426b4..a55bb49804 100644 --- a/projects/prison-custody-status-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationActionTest.kt +++ b/projects/prison-custody-status-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/actions/UpdateLocationActionTest.kt @@ -67,8 +67,6 @@ internal class UpdateLocationActionTest { @MethodSource("noChangeMovements") fun `no changes made when location is correct`(custody: Custody, prisonerMovement: PrisonerMovement) { if (prisonerMovement.type == RELEASED && prisonerMovement.reason.isBlank()) { - whenever(institutionRepository.findByCode(InstitutionCode.IN_COMMUNITY.code)) - .thenReturn(InstitutionGenerator.STANDARD_INSTITUTIONS[InstitutionCode.IN_COMMUNITY]) whenever(institutionRepository.findByNomisCdeCode(InstitutionGenerator.DEFAULT.nomisCdeCode!!)) .thenReturn(InstitutionGenerator.DEFAULT) } else if (prisonerMovement.isAbsconded()) {