Skip to content

Commit 8e94341

Browse files
authoredDec 23, 2024
return additional conducted by/role (#548)
* return additional conductedby/role * return additional conductedby/role * return additional conductedby/role
1 parent d4fc461 commit 8e94341

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed
 

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

+25
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.springframework.http.HttpMethod
66
import org.springframework.stereotype.Component
77
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper
88
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.WebClientWrapper.WebClientWrapperResponse
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ActionPlanReviewsResponse
910
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.InductionSchedule
1011
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
1112
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.ReviewSchedules
@@ -68,6 +69,30 @@ class PLPGateway(
6869
}
6970
}
7071

72+
fun getReviews(prisonerNumber: String): Response<ActionPlanReviewsResponse> {
73+
val result =
74+
webClient.request<ActionPlanReviewsResponse>(
75+
HttpMethod.GET,
76+
"/action-plans/$prisonerNumber/reviews",
77+
authenticationHeader(),
78+
UpstreamApi.PLP,
79+
)
80+
81+
return when (result) {
82+
is WebClientWrapperResponse.Success -> {
83+
val response = result.data
84+
Response(data = response)
85+
}
86+
87+
is WebClientWrapperResponse.Error -> {
88+
Response(
89+
data = ActionPlanReviewsResponse(completedReviews = listOf()),
90+
errors = result.errors,
91+
)
92+
}
93+
}
94+
}
95+
7196
private fun authenticationHeader(): Map<String, String> {
7297
val token = hmppsAuthGateway.getClientToken("PLP")
7398
return mapOf(

‎src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/hmpps/ReviewSchedule.kt

+39-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
44
import com.fasterxml.jackson.annotation.JsonInclude
55
import java.time.Instant
66
import java.time.LocalDate
7+
import java.util.UUID
78

89
@JsonIgnoreProperties(ignoreUnknown = true)
910
@JsonInclude(JsonInclude.Include.USE_DEFAULTS)
@@ -14,7 +15,7 @@ data class ReviewSchedules(
1415
@JsonIgnoreProperties(ignoreUnknown = true)
1516
@JsonInclude(JsonInclude.Include.USE_DEFAULTS)
1617
data class ReviewSchedule(
17-
val reference: String,
18+
val reference: UUID,
1819
val reviewDateFrom: LocalDate,
1920
val reviewDateTo: LocalDate,
2021
val status: String,
@@ -28,4 +29,41 @@ data class ReviewSchedule(
2829
val updatedAt: Instant,
2930
val updatedAtPrison: String,
3031
val version: Int,
32+
var conductedBy: String?,
33+
var conductedRole: String?,
34+
)
35+
36+
data class ActionPlanReviewsResponse(
37+
val latestReviewSchedule: ScheduledActionPlanReviewResponse? = null,
38+
val completedReviews: List<CompletedActionPlanReviewResponse>,
39+
)
40+
41+
data class ScheduledActionPlanReviewResponse(
42+
val reviewDateFrom: LocalDate,
43+
val reviewDateTo: LocalDate,
44+
val status: String,
45+
val calculationRule: String,
46+
val createdBy: String,
47+
val createdByDisplayName: String,
48+
val createdAt: java.time.OffsetDateTime,
49+
val createdAtPrison: String,
50+
val updatedBy: String,
51+
val updatedByDisplayName: String,
52+
val updatedAt: java.time.OffsetDateTime,
53+
val updatedAtPrison: String,
54+
val exemptionReason: String? = null,
55+
val version: Int? = null,
56+
)
57+
58+
data class CompletedActionPlanReviewResponse(
59+
val reference: UUID,
60+
val deadlineDate: LocalDate,
61+
val completedDate: LocalDate,
62+
val createdBy: String,
63+
val createdByDisplayName: String,
64+
val createdAt: java.time.OffsetDateTime,
65+
val createdAtPrison: String,
66+
val reviewScheduleReference: UUID? = null,
67+
val conductedBy: String? = null,
68+
val conductedByRole: String? = null,
3169
)

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

+35-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,42 @@ class GetReviewScheduleForPersonService(
1212
@Autowired val getPersonService: GetPersonService,
1313
) {
1414
fun execute(hmppsId: String): Response<ReviewSchedules> {
15-
val response = getPersonService.getNomisNumber(hmppsId = hmppsId)
15+
// Step 1: Get the NOMIS number for the given HMPPS ID
16+
val nomisNumberResponse = getPersonService.getNomisNumber(hmppsId)
17+
val nomisNumber =
18+
nomisNumberResponse.data?.nomisNumber
19+
?: return Response(ReviewSchedules(emptyList()), nomisNumberResponse.errors)
1620

17-
response.data?.nomisNumber?.let {
18-
return plpGateway.getReviewSchedules(it)
21+
// Step 2: Fetch completed reviews
22+
val plpReviewsResponse = plpGateway.getReviews(nomisNumber)
23+
if (plpReviewsResponse.errors.isNotEmpty()) {
24+
return Response(ReviewSchedules(emptyList()), plpReviewsResponse.errors)
1925
}
20-
return Response(ReviewSchedules(listOf()), response.errors)
26+
val completedReviews = plpReviewsResponse.data.completedReviews
27+
val mappedReviews = completedReviews.associateBy { it.reviewScheduleReference }
28+
29+
// Step 3: Fetch review schedules
30+
val reviewSchedulesResponse = plpGateway.getReviewSchedules(nomisNumber)
31+
if (reviewSchedulesResponse.errors.isNotEmpty()) {
32+
return Response(ReviewSchedules(emptyList()), reviewSchedulesResponse.errors)
33+
}
34+
35+
// Step 4: Update review schedules with completed reviews
36+
val updatedReviewSchedules =
37+
reviewSchedulesResponse.data.reviewSchedules.map { reviewSchedule ->
38+
val completed = mappedReviews[reviewSchedule.reference]
39+
completed?.let {
40+
reviewSchedule.copy(
41+
conductedBy = it.conductedBy,
42+
conductedRole = it.conductedByRole,
43+
)
44+
} ?: reviewSchedule
45+
}
46+
47+
// Step 5: Return the updated review schedules
48+
return Response(
49+
ReviewSchedules(updatedReviewSchedules),
50+
emptyList(),
51+
)
2152
}
2253
}

0 commit comments

Comments
 (0)