Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Feb 15, 2024
1 parent 033cabd commit 49b59ed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,8 +26,8 @@ prisoner.movement.configs:
- HQ
actionNames:
- Recall
- UpdateStatus
- UpdateLocation
- UpdateStatus
featureFlag: messages_released_hospital
- types:
- RELEASED
Expand All @@ -38,43 +38,43 @@ prisoner.movement.configs:
- ETR
actionNames:
- Recall
- UpdateStatus
- UpdateLocation
- UpdateStatus
- types:
- RELEASED
reasons:
- ECSL
reasonOverride: RO
actionNames:
- Release
- UpdateStatus
- UpdateLocation
- UpdateStatus
- types:
- RELEASED
reasons:
- UAL
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 49b59ed

Please sign in to comment.