diff --git a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt index 5768b67a5a..e2b4bcd412 100644 --- a/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt +++ b/projects/workforce-allocations-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/AllocationDemandIntegrationTest.kt @@ -80,7 +80,8 @@ class AllocationDemandIntegrationTest { NamedCourt("Court One"), CaseType.CUSTODY, ProbationStatus(ManagementStatus.CURRENTLY_MANAGED), - Manager("JJ001", Name("Chip", null, "Rockefeller"), "T001", "PO") + Manager("JJ001", Name("Chip", null, "Rockefeller"), "T001", "PO"), + LocalDate.of(2023, 12, 31) ), AllocationResponse( "T456789", @@ -91,7 +92,8 @@ class AllocationDemandIntegrationTest { NamedCourt("Court Two"), CaseType.CUSTODY, ProbationStatus(ManagementStatus.CURRENTLY_MANAGED), - Manager("JJ001", Name("Chip", null, "Rockefeller"), "T001", "PO") + Manager("JJ001", Name("Chip", null, "Rockefeller"), "T001", "PO"), + null ) ) @@ -101,6 +103,8 @@ class AllocationDemandIntegrationTest { mockMvc.perform(post("/allocation-demand").withToken().withJson(request)) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("\$.cases.length()", `is`(2))) + .andExpect(jsonPath("$.cases[0].comHandoverDate").value("2023-12-31")) + .andExpect(jsonPath("$.cases[1].comHandoverDate").doesNotExist()) } @Test diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandResponse.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandResponse.kt index aee95d4669..880adb72dd 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandResponse.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/AllocationDemandResponse.kt @@ -1,5 +1,7 @@ package uk.gov.justice.digital.hmpps.api.model +import java.time.LocalDate + data class AllocationResponse( val crn: String, val name: Name, @@ -9,7 +11,8 @@ data class AllocationResponse( val court: NamedCourt, val type: CaseType = CaseType.UNKNOWN, val probationStatus: ProbationStatus, - val communityPersonManager: Manager? + val communityPersonManager: Manager?, + val comHandoverDate: LocalDate? ) data class AllocationDemandResponse(val cases: List) diff --git a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandRepository.kt b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandRepository.kt index 61336fcd7b..a139e90955 100644 --- a/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandRepository.kt +++ b/projects/workforce-allocations-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandRepository.kt @@ -98,7 +98,8 @@ class AllocationDemandRepository(val jdbcTemplate: NamedParameterJdbcTemplate) { rs.getString("community_manager_team_code"), gradeMap[rs.getString("community_manager_grade")] ) - } + }, + rs.getDate("com_handover_date").toLocalDate() ) } } @@ -234,7 +235,8 @@ SELECT o.CRN crn, ias.FORENAME ias_forename, ias.FORENAME2 ias_middle_name, ias.SURNAME ias_surname, - iasg.CODE_DESCRIPTION ias_grade + iasg.CODE_DESCRIPTION ias_grade, + kd.KEY_DATE com_handover_date FROM OFFENDER o JOIN EVENT e ON e.OFFENDER_ID = o.OFFENDER_ID AND e.ACTIVE_FLAG = 1 JOIN OFFENDER_MANAGER cm ON cm.OFFENDER_ID = o.OFFENDER_ID AND cm.ACTIVE_FLAG = 1 @@ -249,6 +251,12 @@ FROM OFFENDER o LEFT OUTER JOIN R_STANDARD_REFERENCE_LIST cmsg ON cms.STAFF_GRADE_ID = cmsg.STANDARD_REFERENCE_LIST_ID LEFT OUTER JOIN R_STANDARD_REFERENCE_LIST du ON du.STANDARD_REFERENCE_LIST_ID = d.ENTRY_LENGTH_UNITS_ID LEFT OUTER JOIN CUSTODY c ON c.DISPOSAL_ID = d.DISPOSAL_ID AND c.SOFT_DELETED = 0 + LEFT OUTER JOIN (SELECT kd.CUSTODY_ID, kd.KEY_DATE + FROM KEY_DATE kd + JOIN R_STANDARD_REFERENCE_LIST srl + ON srl.STANDARD_REFERENCE_LIST_ID = kd.KEY_DATE_TYPE_ID + AND srl.CODE_VALUE = 'POM2' + AND kd.SOFT_DELETED = 0) kd ON kd.CUSTODY_ID = c.CUSTODY_ID LEFT OUTER JOIN R_STANDARD_REFERENCE_LIST cs ON cs.STANDARD_REFERENCE_LIST_ID = c.CUSTODIAL_STATUS_ID LEFT OUTER JOIN INITIAL_APPOINTMENT ia ON e.EVENT_ID = ia.EVENT_ID AND ia.ROW_NUM = 1 LEFT OUTER JOIN STAFF ias ON ias.STAFF_ID = ia.STAFF_ID diff --git a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandMapperTest.kt b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandMapperTest.kt index 7706c625f9..decb6e1153 100644 --- a/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandMapperTest.kt +++ b/projects/workforce-allocations-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/allocations/AllocationDemandMapperTest.kt @@ -56,7 +56,8 @@ class AllocationDemandMapperTest { Name("Bob", null, "Smith"), "Team1", "PSO" - ) + ), + LocalDate.now() ) whenever(resultSet.getString("crn")).thenReturn(expected.crn) @@ -88,6 +89,7 @@ class AllocationDemandMapperTest { whenever(resultSet.getString("ias_middle_name")).thenReturn(expected.initialAppointment?.staff?.name?.middleName) whenever(resultSet.getString("ias_surname")).thenReturn(expected.initialAppointment?.staff?.name?.surname) whenever(resultSet.getString("ias_grade")).thenReturn(expected.initialAppointment?.staff?.grade) + whenever(resultSet.getDate("com_handover_date")).thenReturn(Date.valueOf(expected.comHandoverDate)) } @Test