Skip to content

Commit

Permalink
PI-2558 Add support for "Rescheduled - PoP request" outcome (#4279)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Oct 4, 2024
1 parent f89ffa4 commit 5b0a6b0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object ContactGenerator {
compliantAcceptable = false
)

ContactOutcome.Code.RESCHEDULED_SERVICE_REQUEST -> generateOutcome(
ContactOutcome.Code.RESCHEDULED_SERVICE_REQUEST, ContactOutcome.Code.RESCHEDULED_POP_REQUEST -> generateOutcome(
it.value,
attendance = false,
compliantAcceptable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ internal class MergeAppointmentIntegrationTest {
null,
null,
null,
null
null,
null,
)
val result = status().isOk
makeRequest(person, referralId, mergeAppointment, result)
Expand Down Expand Up @@ -103,7 +104,8 @@ internal class MergeAppointmentIntegrationTest {
null,
null,
null,
null
null,
null,
)

makeRequest(person, referralId, mergeAppointment, status().isConflict)
Expand Down Expand Up @@ -134,15 +136,16 @@ internal class MergeAppointmentIntegrationTest {
null,
null,
appointmentId,
null
null,
"Joe Bloggs",
)
val result = status().isOk

makeRequest(person, referralId, mergeAppointment, result)

val existing =
contactRepository.findByPersonCrnAndExternalReference(person.crn, mergeAppointment.previousUrn!!)!!
assertThat(existing.outcome?.code, equalTo(ContactOutcome.Code.RESCHEDULED_SERVICE_REQUEST.value))
assertThat(existing.outcome?.code, equalTo(ContactOutcome.Code.RESCHEDULED_POP_REQUEST.value))
assertFalse(existing.attended!!)
assertThat(existing.rarActivity, equalTo(false))

Expand Down Expand Up @@ -184,7 +187,8 @@ internal class MergeAppointmentIntegrationTest {
Outcome(Attended.YES, true, null, false),
null,
appointmentId,
null
null,
"Service Provider",
)
val result = status().isOk

Expand Down Expand Up @@ -229,7 +233,8 @@ internal class MergeAppointmentIntegrationTest {
null,
null,
null,
null
null,
null,
)

makeRequest(person, referralId, mergeAppointment, status().isBadRequest)
Expand All @@ -253,7 +258,8 @@ internal class MergeAppointmentIntegrationTest {
Outcome(Attended.LATE, false, NoSessionReasonType.POP_UNACCEPTABLE, true),
null,
null,
null
null,
null,
)
val result = status().isOk

Expand Down Expand Up @@ -292,7 +298,8 @@ internal class MergeAppointmentIntegrationTest {
null,
null,
null,
null
null,
null,
)

makeRequest(person, referralId, mergeAppointment, status().isNotFound)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps.api.model

import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactOutcome.Code
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.service.Outcome
import java.time.ZonedDateTime
Expand All @@ -17,7 +18,8 @@ data class MergeAppointment(
val outcome: Outcome?,
val sentenceId: Long?,
val previousId: UUID?,
val deliusId: Long?
val deliusId: Long?,
val rescheduleRequestedBy: String?,
) {
val referralUrn
get() = "urn:hmpps:interventions-referral:$referralId"
Expand All @@ -31,4 +33,10 @@ data class MergeAppointment(
get() = if (countsTowardsRar) ContactType.Code.CRSAPT else ContactType.Code.CRSSAA

val end: ZonedDateTime = start.plusMinutes(durationInMinutes)

val rescheduleOutcome
get() = when (rescheduleRequestedBy) {
null, "Service Provider" -> Code.RESCHEDULED_SERVICE_REQUEST.value
else -> Code.RESCHEDULED_POP_REQUEST.value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class ContactOutcome(
FAILED_TO_COMPLY("AFTC"),
FAILED_TO_ATTEND("AFTA"),
RESCHEDULED_SERVICE_REQUEST("RSSR"),
RESCHEDULED_POP_REQUEST("RSOF"),
SENT_HOME("ATSS"),
WITHDRAWN("APPW")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class AppointmentService(
mergeAppointment.start,
mergeAppointment.end,
mergeAppointment.countsTowardsRar
)?.addNotes(mergeAppointment.notes)
replacement?.also {
appointment.outcome = outcomeRepository.getByCode(Code.RESCHEDULED_SERVICE_REQUEST.value)
)?.also {
it.addNotes(mergeAppointment.notes)
appointment.outcome = outcomeRepository.getByCode(mergeAppointment.rescheduleOutcome)
appointment.rarActivity = false
contactRepository.save(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ internal class ReferralResourceTest {
null,
null,
null,
null
null,
null,
)
val ex = assertThrows<ResponseStatusException> {
referralResource.mergeAppointment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ internal class AppointmentServiceTest {
null,
53L,
null,
9562746271
9562746271,
null,
)
val nsi = NsiGenerator.generate(
NsiGenerator.TYPES.values.first(),
Expand Down

0 comments on commit 5b0a6b0

Please sign in to comment.