Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2488 Add "underActiveSupervision" flag to probation person response #477

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrap
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
Expand Down Expand Up @@ -72,9 +73,9 @@ class ProbationOffenderSearchGateway(
}
}

fun getPerson(id: String? = null): Response<Person?> {
fun getPerson(id: String? = null): Response<PersonOnProbation?> {
val offender = getOffender(id)
return Response(data = offender.data?.toPerson(), errors = offender.errors)
return Response(data = offender.data?.toPersonOnProbation(), errors = offender.errors)
}

fun getPersons(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

data class OffenderSearchResponse(
val prisonerOffenderSearch: Person?,
val probationOffenderSearch: Person?,
val probationOffenderSearch: PersonOnProbation?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAlias
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate

data class Person(
open class Person(
@Schema(description = "First name", example = "John")
val firstName: String,
@JsonAlias("surname")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

class PersonOnProbation(
person: Person,
val underActiveSupervision: Boolean,
) : Person(
firstName = person.firstName,
lastName = person.lastName,
middleName = person.middleName,
dateOfBirth = person.dateOfBirth,
gender = person.gender,
ethnicity = person.ethnicity,
aliases = person.aliases,
identifiers = person.identifiers,
pncId = person.pncId,
hmppsId = person.hmppsId,
contactDetails = person.contactDetails,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.probationoffende

import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonProtectedCharacteristics
import java.time.LocalDate

Expand All @@ -16,8 +17,9 @@ data class Offender(
val contactDetails: ContactDetails? = null,
val otherIds: OtherIds = OtherIds(),
val age: Number = 0,
val activeProbationManagedSentence: Boolean = false,
) {
fun toPerson(): Person =
fun toPerson() =
Person(
firstName = this.firstName,
lastName = this.surname,
Expand All @@ -37,6 +39,12 @@ data class Offender(
contactDetails = this.contactDetails?.toContactDetails(),
)

fun toPersonOnProbation() =
PersonOnProbation(
toPerson(),
underActiveSupervision = this.activeProbationManagedSentence,
)

fun toPersonProtectedCharacteristics(): PersonProtectedCharacteristics =
PersonProtectedCharacteristics(
this.age,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ImageMetada
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.OffenderSearchResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonName
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PhoneNumber
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
Expand Down Expand Up @@ -228,7 +229,7 @@ internal class PersonControllerTest(
}

describe("GET $basePath/{id}") {
val probationOffenderSearch = Person("Sam", "Smith", identifiers = Identifiers(nomisNumber = "1234ABC"))
val probationOffenderSearch = PersonOnProbation(Person("Sam", "Smith", identifiers = Identifiers(nomisNumber = "1234ABC")), underActiveSupervision = true)
val prisonOffenderSearch = POSPrisoner("Kim", "Kardashian")
val prisonResponse = Response(data = prisonOffenderSearch, errors = emptyList())

Expand Down Expand Up @@ -285,7 +286,7 @@ internal class PersonControllerTest(
it("does not return a 404 status code when a person was found in one upstream API") {
whenever(getPersonService.getCombinedDataForPerson(idThatDoesNotExist)).thenReturn(
Response(
data = OffenderSearchResponse(prisonerOffenderSearch = null, probationOffenderSearch = Person("someFirstName", "someLastName")),
data = OffenderSearchResponse(prisonerOffenderSearch = null, probationOffenderSearch = PersonOnProbation(Person("someFirstName", "someLastName"), underActiveSupervision = false)),
errors =
listOf(
UpstreamApiError(
Expand Down Expand Up @@ -336,6 +337,7 @@ internal class PersonControllerTest(
"contactDetails":null
},
"probationOffenderSearch":{
"underActiveSupervision":true,
"firstName":"Sam",
"lastName":"Smith",
"middleName":null,
Expand All @@ -362,9 +364,7 @@ internal class PersonControllerTest(
}

describe("GET $basePath/$encodedHmppsId/name") {
val probationOffenderSearch = Person("Sam", "Smith", identifiers = Identifiers(nomisNumber = "1234ABC"))
val prisonOffenderSearch = POSPrisoner("Sam", "Smith")
val prisonResponse = Response(data = prisonOffenderSearch, errors = emptyList())

beforeTest {
Mockito.reset(getNameForPersonService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ImageMetadata
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
Expand All @@ -36,7 +37,7 @@ internal class GetImageMetadataForPersonServiceTest(
Mockito.reset(nomisGateway)

whenever(probationOffenderSearchGateway.getPerson(id = hmppsId)).thenReturn(
Response(data = Person(firstName = "Joey", lastName = "Tribbiani", identifiers = Identifiers(nomisNumber = prisonerNumber))),
Response(data = PersonOnProbation(Person(firstName = "Joey", lastName = "Tribbiani", identifiers = Identifiers(nomisNumber = prisonerNumber)), false)),
)
whenever(nomisGateway.getImageMetadataForPerson(prisonerNumber)).thenReturn(Response(data = emptyList()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.HomeDetenti
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.NonDtoDate
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReleaseDate
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.SentenceAdjustment
Expand Down Expand Up @@ -48,10 +49,13 @@ internal class GetLatestSentenceKeyDatesAndAdjustmentsForPersonServiceTest(
whenever(probationOffenderSearchGateway.getPerson(id = hmppsId)).thenReturn(
Response(
data =
Person(
firstName = "Baylan",
lastName = "Skoll",
identifiers = Identifiers(nomisNumber = nomisNumber),
PersonOnProbation(
Person(
firstName = "Baylan",
lastName = "Skoll",
identifiers = Identifiers(nomisNumber = nomisNumber),
),
false,
),
),
)
Expand Down Expand Up @@ -268,10 +272,13 @@ internal class GetLatestSentenceKeyDatesAndAdjustmentsForPersonServiceTest(
whenever(probationOffenderSearchGateway.getPerson(id = hmppsId)).thenReturn(
Response(
data =
Person(
firstName = "Shin",
lastName = "Hati",
identifiers = Identifiers(nomisNumber = null),
PersonOnProbation(
Person(
firstName = "Shin",
lastName = "Hati",
identifiers = Identifiers(nomisNumber = null),
),
false,
),
errors = emptyList(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.OffenderSearchResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
Expand All @@ -38,7 +39,7 @@ internal class GetPersonServiceTest(
Response(data = listOf(Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(nomisNumber = "A1234AA")))),
)
whenever(probationOffenderSearchGateway.getPerson(id = hmppsId)).thenReturn(
Response(data = Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(nomisNumber = "A1234AA"))),
Response(data = PersonOnProbation(Person(firstName = "Qui-gon", lastName = "Jin", identifiers = Identifiers(nomisNumber = "A1234AA")), underActiveSupervision = true)),
)
whenever(prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = "A1234AA")).thenReturn(
Response(data = POSPrisoner(firstName = "Sam", lastName = "Mills")),
Expand All @@ -52,17 +53,15 @@ internal class GetPersonServiceTest(
}

it("returns a person") {
val personFromProbationOffenderSearch = Person("Molly", "Mob")
val personFromProbationOffenderSearch = PersonOnProbation(Person("Molly", "Mob"), underActiveSupervision = true)

whenever(probationOffenderSearchGateway.getPerson(hmppsId)).thenReturn(
Response(personFromProbationOffenderSearch),
)

val result = getPersonService.execute(hmppsId)

val expectedResult = Person("Molly", "Mob")

result.data.shouldBe(expectedResult)
result.data.shouldBe(personFromProbationOffenderSearch)
}

it("returns null when a person isn't found in probation offender search") {
Expand All @@ -75,7 +74,7 @@ internal class GetPersonServiceTest(
}

it("returns a person with both probation and prison data when prison data exists") {
val personFromProbationOffenderSearch = Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA"))
val personFromProbationOffenderSearch = PersonOnProbation(Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA")), underActiveSupervision = true)
val personFromPrisonOffenderSearch = POSPrisoner("Sam", "Mills")

whenever(probationOffenderSearchGateway.getPerson(hmppsId)).thenReturn(
Expand All @@ -93,7 +92,7 @@ internal class GetPersonServiceTest(
}

it("returns errors when unable to retrieve prison data and data when probation data is available") {
val personFromProbationOffenderSearch = Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA"))
val personFromProbationOffenderSearch = PersonOnProbation(Person("Paula", "First", identifiers = Identifiers(nomisNumber = "A1234AA")), underActiveSupervision = true)

whenever(probationOffenderSearchGateway.getPerson(hmppsId)).thenReturn(Response(data = personFromProbationOffenderSearch))
whenever(prisonerOffenderSearchGateway.getPrisonOffender("A1234AA")).thenReturn(Response(data = null, errors = listOf(UpstreamApiError(UpstreamApi.PRISONER_OFFENDER_SEARCH, UpstreamApiError.Type.ENTITY_NOT_FOUND, "MockError"))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NeedsSmokeTest : DescribeSpec(
"type": "DRUG_MISUSE",
"riskOfHarm": false,
"riskOfReoffending": false,
"severity": "SEVERE"
"severity": "NO_NEED"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class PersonSmokeTest : DescribeSpec(
"contactDetails": null
},
"probationOffenderSearch": {
"underActiveSupervision": true,
"firstName": "string",
"lastName": "string",
"middleName": "string",
Expand Down Expand Up @@ -190,6 +191,7 @@ class PersonSmokeTest : DescribeSpec(
"contactDetails": null
},
"probationOffenderSearch": {
"underActiveSupervision": true,
"firstName": "string",
"lastName": "string",
"middleName": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SentencesSmokeTest : DescribeSpec(
},
"nonDto": {
"date": "2020-04-01",
"releaseDateType": "CRD"
"releaseDateType": "ARD"
},
"nonParole": {
"date": "2020-02-03",
Expand Down