Skip to content

Commit ea14064

Browse files
Merge branch 'main' into HIA-697
2 parents a2b6e66 + c3ba30e commit ea14064

33 files changed

+1053
-246
lines changed

openapi.yml

+144-14
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ paths:
9696
type: object
9797
properties:
9898
data:
99-
type: object
100-
properties:
101-
prisonerOffenderSearch:
102-
$ref: "#/components/schemas/Person"
103-
probationOffenderSearch:
10499
$ref: "#/components/schemas/Person"
105100
"404":
106101
description: Failed to find a person with the provided HMPPS ID.
@@ -815,6 +810,40 @@ paths:
815810
NoQueryParametersBadRequestError:
816811
$ref: "#/components/examples/InternalServerError"
817812

813+
/v1/persons/{HmppsId}/protected-characteristics:
814+
get:
815+
summary: Returns protected characteristics of a person.
816+
parameters:
817+
- $ref: "#/components/parameters/HmppsId"
818+
responses:
819+
"200":
820+
description: Successfully found licenses for a person with the provided HMPPS ID.
821+
content:
822+
application/json:
823+
schema:
824+
type: object
825+
properties:
826+
data:
827+
$ref: "#/components/schemas/PersonProtectedCharacteristics"
828+
"404":
829+
description: Failed to find licenses for a person with the provided HMPPS ID.
830+
content:
831+
application/json:
832+
schema:
833+
$ref: "#/components/schemas/Error"
834+
examples:
835+
PersonNotFoundError:
836+
$ref: "#/components/examples/PersonNotFoundError"
837+
"500":
838+
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
839+
content:
840+
application/json:
841+
schema:
842+
$ref: "#/components/schemas/Error"
843+
examples:
844+
NoQueryParametersBadRequestError:
845+
$ref: "#/components/examples/InternalServerError"
846+
818847
/{TBC}/v1/persons/{Id}/accommodations:
819848
get:
820849
summary: FUTURE ENDPOINT - Returns accommodation and referral information associated with a person.
@@ -1257,6 +1286,27 @@ components:
12571286
properties:
12581287
name:
12591288
type: string
1289+
Disability:
1290+
type: object
1291+
properties:
1292+
notes:
1293+
type: string
1294+
nullable: true
1295+
example: Walking issue
1296+
startDate:
1297+
type: string
1298+
format: date-time
1299+
nullable: true
1300+
example: 2013-04-11
1301+
endDate:
1302+
type: string
1303+
format: date-time
1304+
nullable: true
1305+
example: 2023-04-11
1306+
disabilityType:
1307+
$ref: "#/components/schemas/KeyValue"
1308+
condition:
1309+
$ref: "#/components/schemas/KeyValue"
12601310
Error:
12611311
type: object
12621312
properties:
@@ -1408,6 +1458,17 @@ components:
14081458
nullable: true
14091459
offenceRule:
14101460
nullable: true
1461+
KeyValue:
1462+
type: object
1463+
properties:
1464+
code:
1465+
type: string
1466+
nullable: true
1467+
example: Code
1468+
description:
1469+
type: string
1470+
nullable: true
1471+
example: Description
14111472
LatestSentenceKeyDatesAndAdjustments:
14121473
type: object
14131474
properties:
@@ -1468,7 +1529,6 @@ components:
14681529
format: date
14691530
example: 2023-03-01
14701531
description: tariffEarlyRemovalSchemeEligibilityDate.
1471-
14721532
Licence:
14731533
type: object
14741534
properties:
@@ -1731,6 +1791,56 @@ components:
17311791
items:
17321792
$ref: "#/components/schemas/Licence"
17331793
description: list of licences
1794+
PersonProtectedCharacteristics:
1795+
type: object
1796+
properties:
1797+
age:
1798+
type: number
1799+
nullable: false
1800+
example: 35
1801+
description: Age of the person
1802+
gender:
1803+
type: string
1804+
nullable: true
1805+
example: Female
1806+
description: Gender of the person
1807+
sexualOrientation:
1808+
type: string
1809+
nullable: true
1810+
example: Unknown
1811+
description: Sexual orientation of the person
1812+
ethnicity:
1813+
type: string
1814+
nullable: true
1815+
example: "White: Eng./Welsh/Scot./N.Irish/British"
1816+
description: Ethnicity of the person
1817+
nationality:
1818+
type: string
1819+
nullable: true
1820+
example: "Egyptian"
1821+
description: Nationality of the person
1822+
religion:
1823+
type: string
1824+
nullable: true
1825+
example: "Church of England (Anglican)"
1826+
description: Religion of the person
1827+
maritalStatus:
1828+
type: string
1829+
nullable: true
1830+
example: "Widowed"
1831+
description: Marital status of the person
1832+
disabilities:
1833+
type: array
1834+
minItems: 0
1835+
items:
1836+
$ref: "#/components/schemas/Disability"
1837+
reasonableAdjustments:
1838+
type: array
1839+
minItems: 0
1840+
items:
1841+
$ref: "#/components/schemas/ReasonableAdjustment"
1842+
1843+
17341844
Punishment:
17351845
type: object
17361846
properties:
@@ -1924,6 +2034,34 @@ components:
19242034
enum: [ ARD, CRD, NPD, PRRD ]
19252035
example: ARD
19262036
description: Indicates which type of non-DTO release date is the effective release date. One of 'ARD', 'CRD', 'NPD' or 'PRRD'.
2037+
ReasonableAdjustment:
2038+
type: object
2039+
properties:
2040+
treatmentCode:
2041+
type: string
2042+
nullable: true
2043+
example: "WHEELCHR_ACC"
2044+
description: MTreatment Code
2045+
commentText:
2046+
type: string
2047+
nullable: true
2048+
example: "abcd"
2049+
description: Comment Text
2050+
startDate:
2051+
type: string
2052+
format: date-time
2053+
nullable: true
2054+
example: 2013-04-11
2055+
endDate:
2056+
type: string
2057+
format: date-time
2058+
nullable: true
2059+
example: 2023-04-11
2060+
treatmentDescription:
2061+
type: string
2062+
nullable: true
2063+
example: "Wheelchair accessibility"
2064+
description: Treatment Description
19272065
ReleaseDate:
19282066
type: object
19292067
properties:
@@ -2112,8 +2250,6 @@ components:
21122250
$ref: "#/components/schemas/RiskOfSeriousRecidivism"
21132251
sexualPredictor:
21142252
$ref: "#/components/schemas/SexualPredictor"
2115-
2116-
21172253
GroupReconviction:
21182254
type: object
21192255
properties:
@@ -2214,7 +2350,6 @@ components:
22142350
$ref: "#/components/schemas/OtherRisks"
22152351
summary:
22162352
$ref: "#/components/schemas/Summary"
2217-
22182353
RiskToSelf:
22192354
type: object
22202355
properties:
@@ -2228,7 +2363,6 @@ components:
22282363
$ref: "#/components/schemas/Risk"
22292364
vulnerability:
22302365
$ref: "#/components/schemas/Risk"
2231-
22322366
Risk:
22332367
type: object
22342368
properties:
@@ -2255,7 +2389,6 @@ components:
22552389
type: string
22562390
example: "Risk of self harm concerns due to ..."
22572391
description: Supporting comments for any current concerns
2258-
22592392
OtherRisks:
22602393
type: object
22612394
properties:
@@ -2279,7 +2412,6 @@ components:
22792412
example: "YES"
22802413
enum: [ YES, NO, DK, NA ]
22812414
description: Risk to other prisoners
2282-
22832415
Summary:
22842416
type: object
22852417
properties:
@@ -2358,7 +2490,6 @@ components:
23582490
type: string
23592491
example: LOW
23602492
enum: [ VERY_HIGH, HIGH, MEDIUM, LOW ]
2361-
23622493
Needs:
23632494
type: object
23642495
properties:
@@ -2382,7 +2513,6 @@ components:
23822513
minItems: 0
23832514
items:
23842515
$ref: "#/components/schemas/Need"
2385-
23862516
Need:
23872517
type: object
23882518
properties:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person
2+
3+
import org.springframework.beans.factory.annotation.Autowired
4+
import org.springframework.web.bind.annotation.GetMapping
5+
import org.springframework.web.bind.annotation.PathVariable
6+
import org.springframework.web.bind.annotation.RequestMapping
7+
import org.springframework.web.bind.annotation.RestController
8+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonProtectedCharacteristics
11+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
12+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetProtectedCharacteristicsService
13+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
14+
15+
@RestController
16+
@RequestMapping("/v1/persons")
17+
class ProtectedCharacteristicsController(
18+
@Autowired val getProtectedCharacteristicsService: GetProtectedCharacteristicsService,
19+
@Autowired val auditService: AuditService,
20+
) {
21+
@GetMapping("{encodedHmppsId}/protected-characteristics")
22+
fun getPersonAddresses(
23+
@PathVariable encodedHmppsId: String,
24+
): Map<String, PersonProtectedCharacteristics?> {
25+
val hmppsId = encodedHmppsId.decodeUrlCharacters()
26+
val response = getProtectedCharacteristicsService.execute(hmppsId)
27+
28+
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
29+
throw EntityNotFoundException("Could not find person with id: $hmppsId")
30+
}
31+
auditService.createEvent("GET_PERSON_PROTECTED_CHARACTERISTICS", mapOf("hmppsId" to hmppsId))
32+
return mapOf("data" to response.data)
33+
}
34+
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/NomisGateway.kt

+50
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Address
1010
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Alert
1111
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ImageMetadata
1212
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Offence
13+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReasonableAdjustment
1314
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1415
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.RiskCategory
1516
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Sentence
@@ -23,6 +24,8 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisImageD
2324
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisInmateDetail
2425
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisOffenceHistoryDetail
2526
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisOffenderSentence
27+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisReasonableAdjustments
28+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisReferenceCode
2629
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisSentence
2730
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisSentenceSummary
2831

@@ -255,6 +258,53 @@ class NomisGateway(
255258
}
256259
}
257260

261+
fun getReasonableAdjustments(booking: String): Response<List<ReasonableAdjustment>> {
262+
val treatmentCodes = getReferenceDomains("HEALTH_TREAT").data
263+
val codes = treatmentCodes.map { "type=${it.code}" }.toList()
264+
val params = codes.joinToString(separator = "&", prefix = "?")
265+
val result =
266+
webClient.request<NomisReasonableAdjustments>(
267+
HttpMethod.GET,
268+
"/api/bookings/$booking/reasonable-adjustments$params",
269+
authenticationHeaderForCategories(),
270+
UpstreamApi.NOMIS,
271+
)
272+
273+
return when (result) {
274+
is WebClientWrapperResponse.Success -> {
275+
Response(data = result.data.reasonableAdjustments.map { it.toReasonableAdjustment() })
276+
}
277+
is WebClientWrapperResponse.Error -> {
278+
Response(
279+
data = emptyList(),
280+
errors = result.errors,
281+
)
282+
}
283+
}
284+
}
285+
286+
fun getReferenceDomains(domain: String): Response<List<NomisReferenceCode>> {
287+
val result =
288+
webClient.requestList<NomisReferenceCode>(
289+
HttpMethod.GET,
290+
"/api/reference-domains/domains/$domain/codes",
291+
authenticationHeaderForCategories(),
292+
UpstreamApi.NOMIS,
293+
)
294+
295+
return when (result) {
296+
is WebClientWrapperResponse.Success -> {
297+
Response(data = result.data)
298+
}
299+
is WebClientWrapperResponse.Error -> {
300+
Response(
301+
data = emptyList(),
302+
errors = result.errors,
303+
)
304+
}
305+
}
306+
}
307+
258308
private fun authenticationHeader(): Map<String, String> {
259309
val token = hmppsAuthGateway.getClientToken("NOMIS")
260310

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/PrisonerOffenderSearchGateway.kt

+24
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
1010
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1111
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
1212
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSGlobalSearch
13+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.prisoneroffendersearch.POSPrisoner
1314

1415
@Component
1516
class PrisonerOffenderSearchGateway(
@@ -54,6 +55,29 @@ class PrisonerOffenderSearchGateway(
5455
}
5556
}
5657

58+
fun getPrisonOffender(nomsNumber: String): Response<POSPrisoner?> {
59+
val result =
60+
webClient.request<POSPrisoner>(
61+
HttpMethod.GET,
62+
"/prisoner/$nomsNumber",
63+
authenticationHeader(),
64+
UpstreamApi.PRISONER_OFFENDER_SEARCH,
65+
)
66+
67+
return when (result) {
68+
is WebClientWrapperResponse.Success -> {
69+
Response(data = result.data)
70+
}
71+
72+
is WebClientWrapperResponse.Error -> {
73+
Response(
74+
data = null,
75+
errors = result.errors,
76+
)
77+
}
78+
}
79+
}
80+
5781
private fun authenticationHeader(): Map<String, String> {
5882
val token = hmppsAuthGateway.getClientToken("Prisoner Offender Search")
5983

0 commit comments

Comments
 (0)