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

Implementing status-information endpoint #447

Merged
merged 11 commits into from
Jul 3, 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
136 changes: 136 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,51 @@ paths:
examples:
NoQueryParametersBadRequestError:
$ref: "#/components/examples/InternalServerError"

/v1/persons/{hmppsId}/risks/dynamic:
get:
tags:
- persons
- alerts
summary: Returns dynamic risks associated with a person.
parameters:
- $ref: "#/components/parameters/hmppsId"
- $ref: "#/components/parameters/page"
- $ref: "#/components/parameters/perPage"
responses:
"200":
description: Successfully found dynamic risks for a person with the provided HMPPS ID.
content:
application/json:
schema:
type: object
properties:
data:
type: array
minItems: 0
items:
$ref: "#/components/schemas/DynamicRisk"
pagination:
$ref: "#/components/schemas/Pagination"
"404":
description: Failed to find dynamic risks for a person with the provided HMPPS ID.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
examples:
PersonNotFoundError:
$ref: "#/components/examples/PersonNotFoundError"
"500":
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
examples:
NoQueryParametersBadRequestError:
$ref: "#/components/examples/InternalServerError"

/v1/persons/{hmppsId}/risk-management-plan:
get:
tags:
Expand Down Expand Up @@ -754,6 +799,7 @@ paths:
examples:
NoQueryParametersBadRequestError:
$ref: "#/components/examples/InternalServerError"

/v1/epf/person-details/{hmppsId}/{eventNumber}:
get:
summary: Probation case information for the Effective Proposals Framework service
Expand Down Expand Up @@ -1082,6 +1128,50 @@ paths:
examples:
NoQueryParametersBadRequestError:
$ref: "#/components/examples/InternalServerError"

/v1/persons/{hmppsId}/status-information:
get:
tags:
- persons
- alerts
summary: Returns the status information associated with a person.
parameters:
- $ref: "#/components/parameters/hmppsId"
- $ref: "#/components/parameters/page"
- $ref: "#/components/parameters/perPage"
responses:
"200":
description: Successfully found status information for a person with the provided HMPPS ID.
content:
application/json:
schema:
type: object
properties:
data:
type: array
minItems: 0
items:
$ref: "#/components/schemas/StatusInformation"
pagination:
$ref: "#/components/schemas/Pagination"
"404":
description: Failed to find status information for a person with the provided HMPPS ID.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
examples:
PersonNotFoundError:
$ref: "#/components/examples/PersonNotFoundError"
"500":
description: An upstream service was not responding, so we cannot verify the accuracy of any data we did get.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
examples:
NoQueryParametersBadRequestError:
$ref: "#/components/examples/InternalServerError"
components:
parameters:
hmppsId:
Expand Down Expand Up @@ -1449,6 +1539,29 @@ components:
$ref: "#/components/schemas/KeyValue"
condition:
$ref: "#/components/schemas/KeyValue"
DynamicRisk:
type: object
properties:
code:
type: string
nullable: true
example: RCCO
description:
type: string
nullable: true
example: Child Concerns - Safeguarding concerns where a child is at risk from the offender
startDate:
type: string
nullable: true
example: 2022-01-01
reviewDate:
type: string
nullable: true
example: 2025-01-01
notes:
type: string
nullable: true
example: This is a note
Error:
type: object
properties:
Expand Down Expand Up @@ -2517,6 +2630,29 @@ components:
`SEC86` - Section 86 of 2000 Act,
`SUP` - Sentence Length,
`SUSP` - Suspension Period
StatusInformation:
type: object
properties:
code:
type: string
nullable: true
example: ASFO
description:
type: string
nullable: true
example: Serious Further Offence - Subject to SFO review/investigation
startDate:
type: string
nullable: true
example: 2022-01-01
reviewDate:
type: string
nullable: true
example: 2025-01-01
notes:
type: string
nullable: true
example: This is a note
RiskAssessment:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.decodeUrlCharacters
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.StatusInformation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetStatusInformationForPersonService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.PaginatedResponse
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.util.paginateWith

@RestController
@RequestMapping("/v1/persons")
class StatusInformationController(
@Autowired val getStatusInformationForPersonService: GetStatusInformationForPersonService,
@Autowired val auditService: AuditService,
) {
@GetMapping("{encodedHmppsId}/status-information")
fun getStatusInformation(
@PathVariable encodedHmppsId: String,
@RequestParam(required = false, defaultValue = "1", name = "page") page: Int,
@RequestParam(required = false, defaultValue = "10", name = "perPage") perPage: Int,
): PaginatedResponse<StatusInformation> {
val hmppsId = encodedHmppsId.decodeUrlCharacters()
val response = getStatusInformationForPersonService.execute(hmppsId)

if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
throw EntityNotFoundException("Could not find person with id: $hmppsId")
}
auditService.createEvent("GET_STATUS_INFORMATION", mapOf("hmppsId" to hmppsId))
return response.data.paginateWith(page, perPage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.MappaDetail
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Offence
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Sentence
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.StatusInformation
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.ndelius.NDeliusSupervisions

Expand Down Expand Up @@ -93,6 +94,29 @@ class NDeliusGateway(
}
}

fun getStatusInformationForPerson(id: String): Response<List<StatusInformation>> {
val result =
webClient.request<NDeliusSupervisions>(
HttpMethod.GET,
"/case/$id/supervisions",
authenticationHeader(),
UpstreamApi.NDELIUS,
)

return when (result) {
is WebClientWrapperResponse.Success -> {
Response(data = result.data.personStatus.map { it.toStatusInformation() })
}

is WebClientWrapperResponse.Error -> {
Response(
data = emptyList(),
errors = result.errors,
)
}
}
}

fun getMappaDetailForPerson(id: String): Response<MappaDetail?> {
val result =
webClient.request<NDeliusSupervisions>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps

data class StatusInformation(
val code: String? = null,
val description: String? = null,
val startDate: String? = null,
val reviewDate: String? = null,
val notes: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.ndelius

import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.StatusInformation

class NDeliusPersonStatus(
val code: String? = null,
val description: String? = null,
val startDate: String? = null,
val reviewDate: String? = null,
val notes: String? = null,
) {
fun toStatusInformation(): StatusInformation =
StatusInformation(
code = this.code,
description = this.description,
startDate = this.startDate,
reviewDate = this.reviewDate,
notes = this.notes,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ data class NDeliusSupervisions(
val mappaDetail: NDeliusMappaDetail? = null,
val supervisions: List<NDeliusSupervision>,
val dynamicRisks: List<NDeliusDynamicRisk>,
val personStatus: List<NDeliusPersonStatus>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.NDeliusGateway
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.StatusInformation

@Service
class GetStatusInformationForPersonService(
@Autowired val nDeliusGateway: NDeliusGateway,
@Autowired val getPersonService: GetPersonService,
) {
fun execute(hmppsId: String): Response<List<StatusInformation>> {
val personResponse = getPersonService.execute(hmppsId = hmppsId)
val deliusCrn = personResponse.data?.identifiers?.deliusCrn

var nDeliusPersonStatus: Response<List<StatusInformation>> = Response(data = emptyList())

if (deliusCrn != null) {
val allNDeliusPersonStatus = nDeliusGateway.getStatusInformationForPerson(deliusCrn)
val filteredNDeliusPersonStatus =
allNDeliusPersonStatus.data.filter {
it.code in
listOf(
"ASFO", "WRSM",
)
}
nDeliusPersonStatus = Response(data = filteredNDeliusPersonStatus, errors = allNDeliusPersonStatus.errors)
}

return Response(
data = nDeliusPersonStatus.data,
errors = personResponse.errors + nDeliusPersonStatus.errors,
)
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ authorisation:
- "/v1/persons/.*/risks/dynamic"
- "/v1/persons/.*/licences/conditions"
- "/v1/persons/.*/person-responsible-officer"
- "/v1/persons/.*/status-information"
event-service:
- "/v1/config/authorisation"
1 change: 1 addition & 0 deletions src/main/resources/application-local-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ authorisation:
- "/v1/persons/.*/protected-characteristics"
- "/v1/persons/.*/risks/mappadetail"
- "/v1/persons/.*/risks/categories"
- "/v1/persons/.*/status-information"
- "/v1/persons/.*/risks/dynamic"
- "/v1/persons/.*/case-notes"
- "/v1/persons/.*/person-responsible-officer"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ authorisation:
- "/v1/persons/.*/risks/categories"
- "/v1/persons/.*/case-notes"
- "/v1/persons/.*/person-responsible-officer"
- "/v1/persons/.*/status-information"
- "/v1/persons/.*/risk-management-plan"
- "/v1/epf/person-details/.*/\\.*+[^/]*$"
- "/health"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ authorisation:
- "/v1/persons/.*/risks/mappadetail"
- "/v1/persons/.*/risks/categories"
- "/v1/persons/.*/risk-management-plan"
- "/v1/persons/.*/status-information"
- "/health"
- "/health/ping"
- "/health/readiness"
Expand Down
Loading
Loading