Skip to content

Commit 05a53bf

Browse files
committed
add more fields to prisoner search response
1 parent c701ed7 commit 05a53bf

File tree

6 files changed

+118
-30
lines changed

6 files changed

+118
-30
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/prison/PrisonController.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController
1717
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
1818
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
1919
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
20+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonInPrison
2021
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
2122
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError.Type.BAD_REQUEST
2223
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError.Type.ENTITY_NOT_FOUND
@@ -55,7 +56,7 @@ class PrisonController(
5556
fun getPerson(
5657
@PathVariable hmppsId: String,
5758
@RequestAttribute filters: ConsumerFilters?,
58-
): DataResponse<Person?> {
59+
): DataResponse<PersonInPrison?> {
5960
val response = getPersonService.getPrisoner(hmppsId, filters)
6061

6162
if (response.hasErrorCausedBy(BAD_REQUEST, causedBy = UpstreamApi.NOMIS)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps
2+
3+
class PersonInPrison(
4+
person: Person,
5+
val category: String?,
6+
val crsa: String?,
7+
val dateOfReception: String?,
8+
val status: String?,
9+
val prisonId: String?,
10+
val prisonName: String?,
11+
val cellLocation: String?,
12+
) : Person(
13+
firstName = person.firstName,
14+
lastName = person.lastName,
15+
middleName = person.middleName,
16+
dateOfBirth = person.dateOfBirth,
17+
gender = person.gender,
18+
ethnicity = person.ethnicity,
19+
aliases = person.aliases,
20+
identifiers = person.identifiers,
21+
pncId = person.pncId,
22+
hmppsId = person.hmppsId,
23+
contactDetails = person.contactDetails,
24+
currentExclusion = person.currentExclusion,
25+
exclusionMessage = person.exclusionMessage,
26+
currentRestriction = person.currentRestriction,
27+
restrictionMessage = person.restrictionMessage,
28+
)

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/prisoneroffendersearch/POSPrisoner.kt

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffender
22

33
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
44
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
5+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonInPrison
56
import java.time.LocalDate
67

78
data class POSPrisoner(
@@ -21,6 +22,10 @@ data class POSPrisoner(
2122
val prisonName: String? = null,
2223
val cellLocation: String? = null,
2324
val inOutStatus: String? = null,
25+
val category: String? = null,
26+
val crsa: String? = null,
27+
val dateOfReception: String? = null,
28+
val status: String? = null,
2429
) {
2530
fun toPerson(): Person =
2631
Person(
@@ -38,4 +43,30 @@ data class POSPrisoner(
3843
),
3944
pncId = this.pncNumber,
4045
)
46+
47+
fun toPersonInPrison(): PersonInPrison =
48+
PersonInPrison(
49+
Person(
50+
firstName = this.firstName,
51+
lastName = this.lastName,
52+
middleName = this.middleNames,
53+
dateOfBirth = this.dateOfBirth,
54+
gender = this.gender,
55+
ethnicity = this.ethnicity,
56+
aliases = this.aliases.map { it.toAlias() },
57+
identifiers =
58+
Identifiers(
59+
nomisNumber = this.prisonerNumber,
60+
croNumber = this.croNumber,
61+
),
62+
pncId = this.pncNumber,
63+
),
64+
cellLocation = this.cellLocation,
65+
prisonId = this.prisonId,
66+
prisonName = this.prisonName,
67+
category = this.category,
68+
crsa = this.crsa,
69+
dateOfReception = this.dateOfReception,
70+
status = this.status,
71+
)
4172
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonService.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
77
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.NomisNumber
88
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.OffenderSearchResponse
99
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonInPrison
1011
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1112
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
1213
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
@@ -120,7 +121,7 @@ class GetPersonService(
120121
fun getPrisoner(
121122
hmppsId: String,
122123
filters: ConsumerFilters?,
123-
): Response<Person?> {
124+
): Response<PersonInPrison?> {
124125
val prisonerNomisNumber = getNomisNumber(hmppsId)
125126

126127
if (prisonerNomisNumber.errors.isNotEmpty()) {
@@ -167,7 +168,7 @@ class GetPersonService(
167168
}
168169

169170
return Response(
170-
data = posPrisoner?.toPerson(),
171+
data = posPrisoner?.toPersonInPrison(),
171172
errors = prisonResponse.errors,
172173
)
173174
}

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/prison/PrisonControllerTest.kt

+46-20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.springframework.test.web.servlet.MockMvc
1818
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
1919
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc
2020
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
21+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonInPrison
2122
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
2223
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
2324
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
@@ -68,18 +69,27 @@ internal class PrisonControllerTest(
6869
whenever(getPersonService.getPrisoner(eq(hmppsId), anyOrNull())).thenReturn(
6970
Response(
7071
data =
71-
Person(
72-
firstName = "Barry",
73-
lastName = "Allen",
74-
middleName = "Jonas",
75-
dateOfBirth = LocalDate.parse("2023-03-01"),
76-
gender = "Male",
77-
ethnicity = "Caucasian",
78-
pncId = "PNC123456",
79-
currentExclusion = true,
80-
exclusionMessage = "An exclusion is present",
81-
currentRestriction = true,
82-
restrictionMessage = "A restriction is present",
72+
PersonInPrison(
73+
Person(
74+
firstName = "Barry",
75+
lastName = "Allen",
76+
middleName = "Jonas",
77+
dateOfBirth = LocalDate.parse("2023-03-01"),
78+
gender = "Male",
79+
ethnicity = "Caucasian",
80+
pncId = "PNC123456",
81+
currentExclusion = true,
82+
exclusionMessage = "An exclusion is present",
83+
currentRestriction = true,
84+
restrictionMessage = "A restriction is present",
85+
),
86+
category = "C",
87+
crsa = "HIGH",
88+
dateOfReception = "2023-05-01",
89+
status = "ACTIVE IN",
90+
prisonId = "MDI",
91+
prisonName = "HMP Leeds",
92+
cellLocation = "A-1-002",
8393
),
8494
),
8595
)
@@ -90,6 +100,13 @@ internal class PrisonControllerTest(
90100
"""
91101
{
92102
"data":{
103+
"category": "C",
104+
"crsa": "HIGH",
105+
"dateOfReception": "2023-05-01",
106+
"status": "ACTIVE IN",
107+
"prisonId": "MDI",
108+
"prisonName": "HMP Leeds",
109+
"cellLocation": "A-1-002",
93110
"firstName":"Barry",
94111
"lastName":"Allen",
95112
"middleName":"Jonas",
@@ -119,14 +136,23 @@ internal class PrisonControllerTest(
119136
whenever(getPersonService.getPrisoner(eq(hmppsId), anyOrNull())).thenReturn(
120137
Response(
121138
data =
122-
Person(
123-
firstName = "Barry",
124-
lastName = "Allen",
125-
middleName = "Jonas",
126-
dateOfBirth = LocalDate.parse("2023-03-01"),
127-
gender = "Male",
128-
ethnicity = "Caucasian",
129-
pncId = "PNC123456",
139+
PersonInPrison(
140+
Person(
141+
firstName = "Barry",
142+
lastName = "Allen",
143+
middleName = "Jonas",
144+
dateOfBirth = LocalDate.parse("2023-03-01"),
145+
gender = "Male",
146+
ethnicity = "Caucasian",
147+
pncId = "PNC123456",
148+
),
149+
category = "C",
150+
crsa = "HIGH",
151+
dateOfReception = "2023-05-01",
152+
status = "ACTIVE IN",
153+
prisonId = "MDI",
154+
prisonName = "HMP Leeds",
155+
cellLocation = "A-1-002",
130156
),
131157
),
132158
)

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/services/GetPersonServiceTest.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffend
1818
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
1919
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.OffenderSearchResponse
2020
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
21+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonInPrison
2122
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonOnProbation
2223
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
2324
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
@@ -141,14 +142,14 @@ internal class GetPersonServiceTest(
141142

142143
it("returns a prisoner when valid hmppsId is provided") {
143144
val validHmppsId = "G2996UX"
144-
val person = Person(firstName = "Sam", lastName = "Mills")
145+
val person = PersonInPrison(Person(firstName = "Sam", lastName = "Mills"), category = null, crsa = null, dateOfReception = null, status = null, prisonId = null, prisonName = null, cellLocation = null)
145146
whenever(prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = "G2996UX")).thenReturn(
146147
Response(data = POSPrisoner(firstName = "Sam", lastName = "Mills")),
147148
)
148149

149150
val result = getPersonService.getPrisoner(validHmppsId, blankConsumerFilters)
150151

151-
result.data.shouldBeTypeOf<Person>()
152+
result.data.shouldBeTypeOf<PersonInPrison>()
152153
result.data!!.firstName.shouldBe(person.firstName)
153154
result.data!!.lastName.shouldBe(person.lastName)
154155
result.errors.shouldBe(emptyList())
@@ -212,23 +213,23 @@ internal class GetPersonServiceTest(
212213

213214
val result = getPersonService.getPrisoner(correctPrisonHmppsId, ConsumerFilters(prisons = listOf(prisonId)))
214215

215-
result.data.shouldBeTypeOf<Person>()
216+
result.data.shouldBeTypeOf<PersonInPrison>()
216217
result.data!!.firstName.shouldBe(posPrisoner.firstName)
217218
result.data!!.lastName.shouldBe(posPrisoner.lastName)
218219
result.errors.shouldBe(emptyList())
219220
}
220221

221222
it("returns prisoner if no prison filter present") {
222223
val validHmppsId = "G2996UX"
223-
val person = Person(firstName = "Sam", lastName = "Mills")
224+
val person = PersonInPrison(Person(firstName = "Sam", lastName = "Mills"), category = null, crsa = null, dateOfReception = null, status = null, prisonId = null, prisonName = null, cellLocation = null)
224225

225226
whenever(prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = validHmppsId)).thenReturn(
226227
Response(data = POSPrisoner(firstName = "Sam", lastName = "Mills")),
227228
)
228229

229230
val result = getPersonService.getPrisoner(validHmppsId, ConsumerFilters(prisons = null))
230231

231-
result.data.shouldBeTypeOf<Person>()
232+
result.data.shouldBeTypeOf<PersonInPrison>()
232233
result.data!!.firstName.shouldBe(person.firstName)
233234
result.data!!.lastName.shouldBe(person.lastName)
234235
result.errors.shouldBe(emptyList())
@@ -258,15 +259,15 @@ internal class GetPersonServiceTest(
258259

259260
it("returns prisoner if no consumer filters present") {
260261
val validHmppsId = "G2996UX"
261-
val person = Person(firstName = "Sam", lastName = "Mills")
262+
val person = PersonInPrison(Person(firstName = "Sam", lastName = "Mills"), category = null, crsa = null, dateOfReception = null, status = null, prisonId = null, prisonName = null, cellLocation = null)
262263

263264
whenever(prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = validHmppsId)).thenReturn(
264265
Response(data = POSPrisoner(firstName = "Sam", lastName = "Mills")),
265266
)
266267

267268
val result = getPersonService.getPrisoner(validHmppsId, null)
268269

269-
result.data.shouldBeTypeOf<Person>()
270+
result.data.shouldBeTypeOf<PersonInPrison>()
270271
result.data!!.firstName.shouldBe(person.firstName)
271272
result.data!!.lastName.shouldBe(person.lastName)
272273
result.errors.shouldBe(emptyList())

0 commit comments

Comments
 (0)