Skip to content

Commit

Permalink
PI-1712 fix ETR (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Dec 5, 2023
1 parent 47d15e6 commit 395e2c3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class DataLoader(
createReleasablePerson(PersonGenerator.RELEASABLE_ECSL_ACTIVE)
createReleasablePerson(PersonGenerator.RELEASABLE_ECSL_INACTIVE)
createAbsconded()
createEtrInCustody()
}

private fun createReferenceData() {
Expand Down Expand Up @@ -250,6 +251,16 @@ class DataLoader(
)
}

private fun createEtrInCustody() {
createPerson(PersonGenerator.ETR_IN_CUSTODY)
createEvent(
EventGenerator.custodialEvent(
PersonGenerator.ETR_IN_CUSTODY,
InstitutionGenerator.DEFAULT
)
)
}

private fun createPerson(person: Person) {
personRepository.save(person)
personManagerRepository.save(PersonManagerGenerator.generate(person))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ object NotificationGenerator {
val PRISONER_RELEASED_ECSL_ACTIVE = ResourceLoader.notification<HmppsDomainEvent>("prisoner-released-ecsl-active")
val PRISONER_RELEASED_ECSL_INACTIVE = ResourceLoader.notification<HmppsDomainEvent>("prisoner-released-ecsl-inactive")
val PRISONER_ABSCONDED = ResourceLoader.notification<HmppsDomainEvent>("prisoner-absconded")
val PRISONER_ETR_IN_CUSTODY = ResourceLoader.notification<HmppsDomainEvent>("prisoner-received-etr-custody")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object PersonGenerator {
val RELEASABLE_ECSL_ACTIVE = generate(NotificationGenerator.PRISONER_RELEASED_ECSL_ACTIVE.nomsId())
val RELEASABLE_ECSL_INACTIVE = generate(NotificationGenerator.PRISONER_RELEASED_ECSL_INACTIVE.nomsId())
val ABSCONDED = generate(NotificationGenerator.PRISONER_ABSCONDED.nomsId())
val ETR_IN_CUSTODY = generate(NotificationGenerator.PRISONER_ETR_IN_CUSTODY.nomsId())

fun generate(nomsNumber: String, id: Long = IdGenerator.getAndIncrement()) = Person(id, nomsNumber)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Type": "Notification",
"MessageId": "a7c8e4ab-5d55-45a5-b69d-2ad0539245de",
"TopicArn": "",
"Message": "{\"eventType\":\"prison-offender-events.prisoner.released\",\"additionalInformation\":{\"nomsNumber\":\"A0019AA\",\"reason\":\"RELEASED\",\"source\":\"PRISON\",\"nomisMovementReasonCode\":\"ETR\",\"details\":\"ACTIVE IN:REL-ETR\",\"currentLocation\":\"OUTSIDE_PRISON\",\"prisonId\":\"SWI\",\"currentPrisonStatus\":\"NOT_UNDER_PRISON_CARE\"},\"version\":1,\"occurredAt\":\"2023-08-04T08:09:36.649098+01:00\",\"publishedAt\":\"2023-08-04T09:06:46.65281576+01:00\",\"description\":\"A prisoner has been released Early Release Scheme\", \"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"A0019AA\"}]}}",
"Timestamp": "2023-08-04T09:06:46.65281576+01:00",
"SignatureVersion": "1",
"Signature": "",
"SigningCertURL": "",
"UnsubscribeURL": "",
"MessageAttributes": {
"eventType": {
"Type": "String",
"Value": "prison-offender-events.prisoner.released"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,37 @@ class PcstdIntegrationTest : PcstdIntegrationTestBase() {
)
}
}

@Test
fun `etr release when in custody in delius`() {
val notification = NotificationGenerator.PRISONER_ETR_IN_CUSTODY
val nomsNumber = notification.nomsId()

channelManager.getChannel(queueName).publishAndWait(notification)

val custody = getCustody(nomsNumber)
assertTrue(custody.isInCustody())
assertThat(custody.status.code, equalTo(CustodialStatusCode.IN_CUSTODY.code))
assertThat(custody.institution?.code, equalTo(InstitutionCode.OTHER_IRC.code))

verifyContact(custody, ContactType.Code.CHANGE_OF_INSTITUTION)
verifyCustodyHistory(
custody,
CustodyEventTester(
CustodyEventTypeCode.LOCATION_CHANGE,
InstitutionGenerator.STANDARD_INSTITUTIONS[InstitutionCode.OTHER_IRC]?.description
)
)

verifyTelemetry("RecallNotRequired", "PrisonerStatusCorrect", "LocationUpdated") {
mapOf(
"occurredAt" to notification.message.occurredAt.toString(),
"nomsNumber" to "A0019AA",
"institution" to "SWI",
"reason" to "RELEASED",
"movementReason" to "ETR",
"movementType" to "Released"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ object MovementReasonCodes {
const val DISCHARGED_OR_DEPORTED = "DD"
const val DEPORTED_NO_SENTENCE = "DE"
const val DEPORTED_LICENCE = "DL"
const val EARLY_REMOVAL_SCHEME = "ETR"
const val DETAINED_MENTAL_HEALTH = "HO"
const val RELEASE_MENTAL_HEALTH = "HQ"
const val FINAL_DISCHARGE_PSYCHIATRIC = "HP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ sealed interface PrisonerMovement {
fun isIrcRelease() = this is Released && reason in listOf(
MovementReasonCodes.DISCHARGED_OR_DEPORTED,
MovementReasonCodes.DEPORTED_NO_SENTENCE,
MovementReasonCodes.DEPORTED_LICENCE
MovementReasonCodes.DEPORTED_LICENCE,
MovementReasonCodes.EARLY_REMOVAL_SCHEME
)

fun isAbsconded() = this is Released && reason in listOf(
Expand Down

0 comments on commit 395e2c3

Please sign in to comment.