Skip to content

Commit dc976dc

Browse files
WIP - Merging probation and prison data - WIP
1 parent 7138b03 commit dc976dc

32 files changed

+212
-109
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonController.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PersonController(
7070
}
7171

7272
auditService.createEvent("GET_PERSON_DETAILS", mapOf("hmppsId" to hmppsId))
73-
return mapOf("data" to response.data)
73+
return response.data
7474
}
7575

7676
@GetMapping("{encodedHmppsId}/images")

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Service
55
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.NomisGateway
66
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffenderSearchGateway
77
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
8+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
89
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
910

1011
@Service
@@ -15,13 +16,16 @@ class GetAddressesForPersonService(
1516
) {
1617
fun execute(hmppsId: String): Response<List<Address>> {
1718
val personResponse = getPersonService.execute(hmppsId = hmppsId)
18-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
19+
val personData = personResponse.data["probationOffenderSearch"]
1920

2021
var addressesFromNomis: Response<List<Address>> = Response(data = emptyList())
2122
val addressesFromDelius = probationOffenderSearchGateway.getAddressesForPerson(hmppsId = hmppsId)
2223

23-
if (nomisNumber != null) {
24-
addressesFromNomis = nomisGateway.getAddressesForPerson(id = nomisNumber)
24+
if (personData is Person) {
25+
val nomisNumber = personData.identifiers.nomisNumber
26+
if (nomisNumber != null) {
27+
addressesFromNomis = nomisGateway.getAddressesForPerson(id = nomisNumber)
28+
}
2529
}
2630

2731
return Response.merge(listOfNotNull(addressesFromNomis, addressesFromDelius))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GetAdjudicationsForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<List<Adjudication>> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
16+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
1717

1818
var adjudications: Response<List<Adjudication>> = Response(data = emptyList())
1919

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class GetAlertsForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<List<Alert>> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
16+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
17+
1718
var nomisAlerts: Response<List<Alert>> = Response(data = emptyList())
1819

1920
if (nomisNumber != null) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GetCaseNotesForPersonService(
1414
) {
1515
fun execute(filter: CaseNoteFilter): Response<List<CaseNote>> {
1616
val personResponse = getPersonService.execute(hmppsId = filter.hmppsId)
17-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
17+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
1818

1919
var caseNotes: Response<List<CaseNote>> = Response(data = emptyList())
2020

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GetCommunityOffenderManagerForPersonService(
1414
fun execute(hmppsId: String): Response<CommunityOffenderManager> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
1616

17-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
17+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
1818
var nDeliusMappaDetailResponse: Response<CommunityOffenderManager> = Response(data = CommunityOffenderManager())
1919

2020
if (deliusCrn != null) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class GetLicenceConditionService(
1414
) {
1515
fun execute(hmppsId: String): Response<PersonLicences> {
1616
val personResponse = getPersonService.execute(hmppsId = hmppsId)
17-
val crn = personResponse.data?.identifiers?.deliusCrn
17+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
1818

1919
var licences: Response<List<Licence>> = Response(data = emptyList())
2020
var personLicences = PersonLicences(hmppsId)
21-
if (crn != null) {
22-
licences = createAndVaryLicenceGateway.getLicenceSummaries(id = crn)
21+
if (deliusCrn != null) {
22+
licences = createAndVaryLicenceGateway.getLicenceSummaries(id = deliusCrn)
2323
licences.data.forEach {
2424
val conditions = createAndVaryLicenceGateway.getLicenceConditions(it.id)
2525
it.conditions = conditions.data

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GetMappaDetailForPersonService(
1414
fun execute(hmppsId: String): Response<MappaDetail?> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
1616

17-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
17+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
1818
var nDeliusMappaDetailResponse: Response<MappaDetail?> = Response(data = MappaDetail())
1919

2020
if (deliusCrn != null) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GetNeedsForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<Needs?> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
16+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
1717

1818
var personNeeds: Response<Needs?> = Response(data = null)
1919

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class GetOffencesForPersonService(
1515
) {
1616
fun execute(hmppsId: String): Response<List<Offence>> {
1717
val personResponse = getPersonService.execute(hmppsId = hmppsId)
18-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
19-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
18+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
19+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
2020

2121
var nomisOffences: Response<List<Offence>> = Response(data = emptyList())
2222
var nDeliusOffences: Response<List<Offence>> = Response(data = emptyList())

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

+27-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
22

33
import org.springframework.beans.factory.annotation.Autowired
44
import org.springframework.stereotype.Service
5+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.PrisonerOffenderSearchGateway
56
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.ProbationOffenderSearchGateway
67
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
78
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
89

910
@Service
1011
class GetPersonService(
12+
@Autowired val prisonerOffenderSearchGateway: PrisonerOffenderSearchGateway,
1113
@Autowired val probationOffenderSearchGateway: ProbationOffenderSearchGateway,
1214
) {
13-
fun execute(hmppsId: String): Response<Person?> {
14-
val personFromProbationOffenderSearch = probationOffenderSearchGateway.getPerson(id = hmppsId)
15+
fun execute(hmppsId: String): Response<Map<String, Person?>> {
16+
val probationResponse = probationOffenderSearchGateway.getPerson(id = hmppsId)
1517

16-
return Response(data = personFromProbationOffenderSearch.data, errors = personFromProbationOffenderSearch.errors)
18+
val prisonResponse =
19+
probationResponse.data?.identifiers?.nomisNumber?.let {
20+
prisonerOffenderSearchGateway.getPrisonOffender(nomsNumber = it)
21+
}
22+
23+
return if (prisonResponse != null) {
24+
Response(
25+
data =
26+
mapOf(
27+
"prisonerOffenderSearch" to prisonResponse.data?.toPerson(),
28+
"probationOffenderSearch" to probationResponse.data,
29+
),
30+
errors = prisonResponse.errors + probationResponse.errors,
31+
)
32+
} else {
33+
Response(
34+
data =
35+
mapOf(
36+
"probationOffenderSearch" to probationResponse.data,
37+
),
38+
errors = probationResponse.errors,
39+
)
40+
}
1741
}
1842
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GetPrisonOffenderManagerForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<PrisonOffenderManager> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
16+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
1717
var prisonOffenderManager: Response<PrisonOffenderManager> = Response(data = PrisonOffenderManager())
1818

1919
if (nomisNumber != null) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GetRiskCategoriesForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<RiskCategory?> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
16+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
1717

1818
var personRiskCategories: Response<RiskCategory?> = Response(data = RiskCategory())
1919

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GetRiskPredictorScoresForPersonService(
1313
) {
1414
fun execute(hmppsId: String): Response<List<RiskPredictorScore>> {
1515
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
16+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
1717

1818
var personRiskPredictorScores: Response<List<RiskPredictorScore>> = Response(data = emptyList())
1919

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
33
import org.springframework.beans.factory.annotation.Autowired
44
import org.springframework.stereotype.Service
55
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.AssessRisksAndNeedsGateway
6+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
67
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
78
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Risks
89

@@ -13,12 +14,15 @@ class GetRiskSeriousHarmForPersonService(
1314
) {
1415
fun execute(hmppsId: String): Response<Risks?> {
1516
val personResponse = getPersonService.execute(hmppsId = hmppsId)
16-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
17+
val personData = personResponse.data["probationOffenderSearch"]
1718

1819
var personRisks: Response<Risks?> = Response(data = null)
1920

20-
if (deliusCrn != null) {
21-
personRisks = assessRisksAndNeedsGateway.getRiskSeriousHarmForPerson(id = deliusCrn)
21+
if (personData is Person) {
22+
val deliusCrn = personData.identifiers.deliusCrn
23+
if (deliusCrn != null) {
24+
personRisks = assessRisksAndNeedsGateway.getRiskSeriousHarmForPerson(id = deliusCrn)
25+
}
2226
}
2327

2428
return Response(

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class GetSentencesForPersonService(
1616
) {
1717
fun execute(hmppsId: String): Response<List<Sentence>> {
1818
val personResponse = getPersonService.execute(hmppsId = hmppsId)
19-
val nomisNumber = personResponse.data?.identifiers?.nomisNumber
20-
val deliusCrn = personResponse.data?.identifiers?.deliusCrn
19+
val nomisNumber = personResponse.data["probationOffenderSearch"]?.identifiers?.nomisNumber
20+
val deliusCrn = personResponse.data["probationOffenderSearch"]?.identifiers?.deliusCrn
2121
var bookingIdsResponse: Response<List<NomisBooking>> = Response(data = emptyList())
2222
var nDeliusSentencesResponse: Response<List<Sentence>> = Response(data = emptyList())
2323

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/PersonControllerTest.kt

+28-20
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ internal class PersonControllerTest(
227227
beforeTest {
228228
Mockito.reset(getPersonService)
229229
Mockito.reset(auditService)
230-
whenever(getPersonService.execute(hmppsId)).thenReturn(Response(data = person))
230+
whenever(getPersonService.execute(hmppsId)).thenReturn(
231+
Response(
232+
data = mapOf("probationOffenderSearch" to person),
233+
),
234+
)
231235
}
232236

233237
it("returns a 200 OK status code") {
@@ -250,13 +254,17 @@ internal class PersonControllerTest(
250254
it("returns a 404 status code when a person cannot be found in both upstream APIs") {
251255
whenever(getPersonService.execute(idThatDoesNotExist)).thenReturn(
252256
Response(
253-
data = null,
257+
data = emptyMap(),
254258
errors =
255259
listOf(
256260
UpstreamApiError(
257261
causedBy = UpstreamApi.PROBATION_OFFENDER_SEARCH,
258262
type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
259263
),
264+
UpstreamApiError(
265+
causedBy = UpstreamApi.PRISONER_OFFENDER_SEARCH,
266+
type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
267+
),
260268
),
261269
),
262270
)
@@ -270,7 +278,7 @@ internal class PersonControllerTest(
270278
it("does not return a 404 status code when a person was found in one upstream API") {
271279
whenever(getPersonService.execute(idThatDoesNotExist)).thenReturn(
272280
Response(
273-
data = Person("someFirstName", "someLastName"),
281+
data = mapOf("probationOffenderSearch" to Person("someFirstName", "someLastName")),
274282
errors =
275283
listOf(
276284
UpstreamApiError(
@@ -300,23 +308,23 @@ internal class PersonControllerTest(
300308
result.response.contentAsString.shouldBe(
301309
"""
302310
{
303-
"data": {
304-
"firstName": "Silly",
305-
"lastName": "Sobbers",
306-
"middleName": null,
307-
"dateOfBirth": null,
308-
"gender": null,
309-
"ethnicity": null,
310-
"aliases": [],
311-
"identifiers": {
312-
"nomisNumber": null,
313-
"croNumber": null,
314-
"deliusCrn": null
315-
},
316-
"pncId": null,
317-
"hmppsId": null,
318-
"contactDetails": null
319-
}
311+
"probationOffenderSearch": {
312+
"firstName": "Silly",
313+
"lastName": "Sobbers",
314+
"middleName": null,
315+
"dateOfBirth": null,
316+
"gender": null,
317+
"ethnicity": null,
318+
"aliases": [],
319+
"identifiers": {
320+
"nomisNumber": null,
321+
"croNumber": null,
322+
"deliusCrn": null
323+
},
324+
"pncId": null,
325+
"hmppsId": null,
326+
"contactDetails": null
327+
}
320328
}
321329
""".removeWhitespaceAndNewlines(),
322330
)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ internal class GetAddressesForPersonServiceTest(
4242
Mockito.reset(nomisGateway)
4343
Mockito.reset(personService)
4444

45-
whenever(personService.execute(hmppsId = deliusCrn)).thenReturn(Response(person))
46-
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
45+
whenever(personService.execute(hmppsId = deliusCrn)).thenReturn(Response(data = mapOf("probationOffenderSearch" to person), errors = emptyList()))
46+
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(Response(data = mapOf("probationOffenderSearch" to person), errors = emptyList()))
4747

4848
whenever(probationOffenderSearchGateway.getAddressesForPerson(hmppsId)).thenReturn(Response(data = emptyList()))
4949
whenever(nomisGateway.getAddressesForPerson(prisonerNumber)).thenReturn(Response(data = emptyList()))

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ internal class GetAdjudicationsForPersonServiceTest(
3737
Mockito.reset(getPersonService)
3838
Mockito.reset(adjudicationsGateway)
3939

40-
whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
40+
whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(
41+
Response(
42+
data = mapOf("probationOffenderSearch" to person),
43+
errors = emptyList(),
44+
),
45+
)
4146
whenever(adjudicationsGateway.getReportedAdjudicationsForPerson(id = prisonerNumber)).thenReturn(Response(adjudications))
4247
}
4348

@@ -49,7 +54,7 @@ internal class GetAdjudicationsForPersonServiceTest(
4954
it("should return a list of errors if person not found") {
5055
whenever(getPersonService.execute(hmppsId = "notfound")).thenReturn(
5156
Response(
52-
data = null,
57+
data = emptyMap(),
5358
errors =
5459
listOf(
5560
UpstreamApiError(

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ internal class GetAlertsForPersonServiceTest(
3939
Mockito.reset(nomisGateway)
4040
Mockito.reset(personService)
4141

42-
whenever(personService.execute(hmppsId = deliusCrn)).thenReturn(Response(person))
43-
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
42+
whenever(personService.execute(hmppsId = deliusCrn)).thenReturn(
43+
Response(
44+
data = mapOf("probationOffenderSearch" to person),
45+
),
46+
)
47+
48+
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(
49+
Response(
50+
data = mapOf("probationOffenderSearch" to person),
51+
),
52+
)
4453

4554
whenever(nomisGateway.getAlertsForPerson(prisonerNumber)).thenReturn(
4655
Response(
@@ -68,7 +77,7 @@ internal class GetAlertsForPersonServiceTest(
6877
beforeEach {
6978
whenever(personService.execute(hmppsId = hmppsId)).thenReturn(
7079
Response(
71-
data = null,
80+
data = emptyMap(),
7281
errors =
7382
listOf(
7483
UpstreamApiError(

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ class GetCaseNotesForPersonServiceTest(
4141
Mockito.reset(getPersonService)
4242
Mockito.reset(caseNotesGateway)
4343

44-
whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
44+
whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(
45+
Response(
46+
data = mapOf("probationOffenderSearch" to person),
47+
),
48+
)
49+
4550
whenever(caseNotesGateway.getCaseNotesForPerson(id = nomisNumber, filter)).thenReturn(Response(caseNotes))
4651
}
4752

0 commit comments

Comments
 (0)