Skip to content

Commit c3a5887

Browse files
Added completed by information
1 parent 5523803 commit c3a5887

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired
1111
import org.springframework.web.bind.annotation.GetMapping
1212
import org.springframework.web.bind.annotation.PathVariable
1313
import org.springframework.web.bind.annotation.RequestMapping
14+
import org.springframework.web.bind.annotation.RequestParam
1415
import org.springframework.web.bind.annotation.RestController
1516
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.exception.EntityNotFoundException
1617
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.DataResponse
@@ -60,14 +61,23 @@ class PLPController(
6061
],
6162
)
6263
fun getReviewSchedule(
63-
@Parameter(description = "A HmppsId ", example = "A123123") @PathVariable hmppsId: String,
64+
@Parameter(description = "A HmppsId", example = "A123123") @PathVariable hmppsId: String,
65+
@Parameter(description = "Filter by review schedule statuses", example = "[\"COMPLETED\", \"PENDING\"]")
66+
@RequestParam(required = false) statuses: List<String>?,
6467
): DataResponse<ReviewSchedules> {
6568
val response = getReviewScheduleForPersonService.execute(hmppsId)
6669

6770
if (response.hasError(UpstreamApiError.Type.ENTITY_NOT_FOUND)) {
6871
throw EntityNotFoundException("Could not find person with id: $hmppsId")
6972
}
73+
7074
auditService.createEvent("GET_REVIEW_SCHEDULE", mapOf("hmppsId" to hmppsId))
71-
return DataResponse(response.data)
75+
76+
// Filter the review schedules by statuses if the query parameter is provided
77+
val filteredData =
78+
response.data.reviewSchedules
79+
.filter { statuses == null || it.status in statuses }
80+
81+
return DataResponse(ReviewSchedules(filteredData))
7282
}
7383
}

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ data class ReviewSchedule(
2929
val updatedAt: Instant,
3030
val updatedAtPrison: String,
3131
val version: Int,
32-
var completedBy: String?,
33-
var completedByRole: String?,
32+
var reviewCompletedBy: String?,
33+
var reviewCompletedByRole: String?,
34+
var reviewCompletedAt: Instant,
3435
)
3536

3637
data class ActionPlanReviewsResponse(
@@ -45,11 +46,11 @@ data class ScheduledActionPlanReviewResponse(
4546
val calculationRule: String,
4647
val createdBy: String,
4748
val createdByDisplayName: String,
48-
val createdAt: java.time.OffsetDateTime,
49+
val createdAt: Instant,
4950
val createdAtPrison: String,
5051
val updatedBy: String,
5152
val updatedByDisplayName: String,
52-
val updatedAt: java.time.OffsetDateTime,
53+
val updatedAt: Instant,
5354
val updatedAtPrison: String,
5455
val exemptionReason: String? = null,
5556
val version: Int? = null,
@@ -66,4 +67,7 @@ data class CompletedActionPlanReviewResponse(
6667
val reviewScheduleReference: UUID? = null,
6768
val conductedBy: String? = null,
6869
val conductedByRole: String? = null,
70+
val updatedBy: String,
71+
val updatedByDisplayName: String,
72+
val updatedAt: Instant,
6973
)

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ class GetReviewScheduleForPersonService(
3434

3535
// Step 4: Update review schedules with completed reviews
3636
val updatedReviewSchedules =
37-
reviewSchedulesResponse.data.reviewSchedules
38-
.filter { it.status == "COMPLETED" }
39-
.map { reviewSchedule ->
40-
val completed = mappedReviews[reviewSchedule.reference]
41-
completed?.let {
42-
reviewSchedule.copy(
43-
completedBy = it.conductedBy,
44-
completedByRole = it.conductedByRole,
45-
)
46-
} ?: reviewSchedule
37+
reviewSchedulesResponse.data.reviewSchedules.map { reviewSchedule ->
38+
val completed = mappedReviews[reviewSchedule.reference]
39+
if (reviewSchedule.status == "COMPLETED" && completed != null) {
40+
reviewSchedule.copy(
41+
reviewCompletedBy = completed.conductedBy ?: completed.updatedByDisplayName,
42+
reviewCompletedByRole = completed.conductedByRole ?: "CIAG",
43+
reviewCompletedAt = completed.updatedAt,
44+
)
45+
} else {
46+
reviewSchedule
4747
}
48-
48+
}
4949
// Step 5: Return the updated review schedules
5050
return Response(
5151
ReviewSchedules(updatedReviewSchedules),

0 commit comments

Comments
 (0)