diff --git a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt index 73061633b1..abc92cc6eb 100644 --- a/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt +++ b/projects/court-case-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/SentenceGenerator.kt @@ -332,6 +332,11 @@ object SentenceGenerator { ) = LicenceCondition( disposal, LocalDate.now(), + LocalDate.now(), + "commencement notes", + LocalDate.now(), + "termination notes", + LocalDateTime.now().truncatedTo(ChronoUnit.MICROS), ReferenceDataGenerator.LIC_COND_MAIN_CAT, ReferenceDataGenerator.LIC_COND_SUB_CAT, "Licence Condition notes", diff --git a/projects/court-case-and-delius/src/dev/resources/simulations/__files/get_licence_conditions_C123456.json b/projects/court-case-and-delius/src/dev/resources/simulations/__files/get_licence_conditions_C123456.json new file mode 100644 index 0000000000..c8fdf77e60 --- /dev/null +++ b/projects/court-case-and-delius/src/dev/resources/simulations/__files/get_licence_conditions_C123456.json @@ -0,0 +1,22 @@ +{ + "licenceConditions": [ + { + "licenceConditionNotes": "Licence Condition notes", + "startDate": "2024-08-07", + "commencementDate": "2024-08-07", + "commencementNotes": "commencement notes", + "terminationDate": "2024-08-07", + "terminationNotes": "termination notes", + "createdDateTime": "2024-08-07T11:36:08.308673", + "active": true, + "licenceConditionTypeMainCat": { + "code": "LicMain", + "description": "lic cond main" + }, + "licenceConditionTypeSubCat": { + "code": "LicSub", + "description": "Lic Sub cat" + } + } + ] +} \ No newline at end of file diff --git a/projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-convictions.json b/projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-convictions.json index aa91910dab..126f2edf7f 100644 --- a/projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-convictions.json +++ b/projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-convictions.json @@ -1,5 +1,18 @@ { "mappings": [ + { + "request": { + "method": "GET", + "urlPathTemplate": "/secure/offenders/crn/{crn}/convictions/{convictionId}/licenceConditions" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "bodyFileName": "get_licence_conditions_C123456.json" + } + }, { "request": { "method": "GET", diff --git a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionByCrnAndEventIdIntegrationTest.kt b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionByCrnAndEventIdIntegrationTest.kt index 98b05b05e2..16b4be3c68 100644 --- a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionByCrnAndEventIdIntegrationTest.kt +++ b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ConvictionByCrnAndEventIdIntegrationTest.kt @@ -15,6 +15,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPat import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import uk.gov.justice.digital.hmpps.api.model.Attendances import uk.gov.justice.digital.hmpps.api.model.KeyValue +import uk.gov.justice.digital.hmpps.api.model.LicenceConditions import uk.gov.justice.digital.hmpps.api.model.conviction.* import uk.gov.justice.digital.hmpps.data.generator.AdditionalSentenceGenerator.SENTENCE_DISQ import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.ATTENDANCE_CONTACT_1 @@ -297,6 +298,20 @@ internal class ConvictionByCrnAndEventIdIntegrationTest { .andReturn().response.contentAsJson>() assertThat(response.size, equalTo(1)) - assertThat(response[0].reportManagers?.size, equalTo(1)) + assertThat(response[0].reportManagers.size, equalTo(1)) + } + + @Test + fun `call convictions by id and licence conditions`() { + val crn = PersonGenerator.CURRENTLY_MANAGED.crn + val event = SentenceGenerator.CURRENTLY_MANAGED + + val response = mockMvc + .perform(get("/probation-case/$crn/convictions/${event.id}/licenceConditions").withToken()) + .andExpect(status().isOk) + .andReturn().response.contentAsJson() + + assertThat(response.licenceConditions.size, equalTo(1)) + assertThat(response.licenceConditions[0].licenceConditionNotes, equalTo("Licence Condition notes")) } } \ No newline at end of file diff --git a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProxyIntegrationTest.kt b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProxyIntegrationTest.kt index 2366a8a560..9f6749abef 100644 --- a/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProxyIntegrationTest.kt +++ b/projects/court-case-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/ProxyIntegrationTest.kt @@ -253,6 +253,10 @@ internal class ProxyIntegrationTest { "CONVICTION_BY_ID_COURT_REPORTS": { "convictionId": "?", "activeOnly": true + }, + "CONVICTION_BY_ID_LICENCE_CONDITIONS": { + "convictionId": "?", + "activeOnly": true } } } @@ -261,7 +265,7 @@ internal class ProxyIntegrationTest { .withToken() ).andExpect(status().is2xxSuccessful).andReturn().response.contentAsJson() - assertThat(res.totalNumberOfRequests, equalTo(12)) + assertThat(res.totalNumberOfRequests, equalTo(13)) assertThat(res.totalNumberOfCrns, equalTo(2)) assertThat(res.currentPageNumber, equalTo(1)) } diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/LicenceConditions.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/LicenceConditions.kt new file mode 100644 index 0000000000..0de9b403b8 --- /dev/null +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/LicenceConditions.kt @@ -0,0 +1,22 @@ +package uk.gov.justice.digital.hmpps.api.model + +import java.time.LocalDate +import java.time.LocalDateTime + +data class LicenceConditions( + val licenceConditions: List = emptyList() +) + +data class LicenceCondition( + val licenceConditionNotes: String? = null, + val startDate: LocalDate, + val commencementDate: LocalDate? = null, + val commencementNotes: String? = null, + val terminationDate: LocalDate? = null, + val terminationNotes: String? = null, + val createdDateTime: LocalDateTime, + val active: Boolean, + val licenceConditionTypeMainCat: KeyValue? = null, + val licenceConditionTypeSubCat: KeyValue? = null + +) diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/ProbationRecord.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/ProbationRecord.kt index 4d9c84c6dc..04dc5f8d9f 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/ProbationRecord.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/ProbationRecord.kt @@ -126,10 +126,3 @@ data class Requirement( val length: Long? ) -data class LicenceCondition( - val description: String?, - val subTypeDescription: String?, - val startDate: LocalDate?, - val notes: String?, - val active: Boolean -) diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/CommunityApiController.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/CommunityApiController.kt index 5928bd303b..9325f5d2f7 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/CommunityApiController.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/CommunityApiController.kt @@ -252,6 +252,26 @@ class CommunityApiController( return proxy(request) } + @GetMapping("/offenders/crn/{crn}/convictions/{convictionId}/licenceConditions") + fun convictionByIdCLicenceConditions( + request: HttpServletRequest, + @PathVariable crn: String, + @PathVariable convictionId: Long, + ): Any { + + sendComparisonReport( + mapOf( + "crn" to crn, + "convictionId" to convictionId + ), Uri.CONVICTION_BY_ID_LICENCE_CONDITIONS, request + ) + + if (featureFlags.enabled("ccd-conviction-by-id-licence-conditions")) { + return convictionResource.getConvictionLicenceConditions(crn, convictionId) + } + return proxy(request) + } + @GetMapping("/**") fun proxy(request: HttpServletRequest): ResponseEntity { val headers = request.headerNames.asSequence().associateWith { request.getHeader(it) }.toMutableMap() diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/Uri.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/Uri.kt index b584f12599..276b34d46d 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/Uri.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/proxy/Uri.kt @@ -73,5 +73,11 @@ enum class Uri( "getConvictionCourtReports", listOf("crn", "convictionId"), ), + CONVICTION_BY_ID_LICENCE_CONDITIONS( + "/secure/offenders/crn/{crn}/convictions/{convictionId}/licenceConditions", + "convictionResource", + "getConvictionLicenceConditions", + listOf("crn", "convictionId"), + ), DUMMY("/dummy", "dummyResource", "getDummy", listOf("crn")), } \ No newline at end of file diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/ConvictionResource.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/ConvictionResource.kt index 7941b5eae2..e49c126e29 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/ConvictionResource.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/resource/ConvictionResource.kt @@ -101,4 +101,10 @@ class ConvictionResource( @PathVariable crn: String, @PathVariable convictionId: Long ) = courtReportService.getCourtReportsFor(crn, convictionId) + + @GetMapping("/{convictionId}/licenceConditions") + fun getConvictionLicenceConditions( + @PathVariable crn: String, + @PathVariable convictionId: Long + ) = requirementService.getLicenceConditionsForConvictionId(crn, convictionId) } diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/conviction/entity/Requirement.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/conviction/entity/Requirement.kt index 82a7eca55d..acd559d4af 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/conviction/entity/Requirement.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/conviction/entity/Requirement.kt @@ -8,6 +8,7 @@ import uk.gov.justice.digital.hmpps.api.model.KeyValue import uk.gov.justice.digital.hmpps.exception.NotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.AdRequirementMainCategory +import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.LicenceCondition import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.RequirementMainCategory import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Custody import java.time.LocalDate @@ -148,6 +149,9 @@ class Disposal( @OneToOne(mappedBy = "disposal") val custody: Custody?, + + @OneToMany(mappedBy = "disposal") + val licenceConditions: List = emptyList(), ) @Entity(name = "conviction_custody") diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/LicenceCondition.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/LicenceCondition.kt index 4a327b898d..912a4f6f49 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/LicenceCondition.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/event/entity/LicenceCondition.kt @@ -1,23 +1,16 @@ package uk.gov.justice.digital.hmpps.integrations.delius.event.entity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id -import jakarta.persistence.JoinColumn -import jakarta.persistence.Lob -import jakarta.persistence.ManyToOne -import jakarta.persistence.Table +import jakarta.persistence.* import org.hibernate.annotations.Immutable -import org.hibernate.annotations.SQLRestriction import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.Disposal import java.time.LocalDate +import java.time.LocalDateTime @Immutable @Table(name = "lic_condition") @Entity -@SQLRestriction("soft_deleted = 0 and active_flag = 1") class LicenceCondition( @ManyToOne @JoinColumn(name = "disposal_id") @@ -26,9 +19,26 @@ class LicenceCondition( @Column val startDate: LocalDate, + @Column + val commencementDate: LocalDate?, + + @Lob + @Column + val commencementNotes: String?, + + @Column + val terminationDate: LocalDate?, + + @Lob + @Column + val terminationNotes: String?, + + @Column(name = "created_datetime") + val createdDateTime: LocalDateTime, + @ManyToOne @JoinColumn(name = "lic_cond_type_main_cat_id") - val mainCategory: LicenceConditionMainCategory, + val mainCategory: LicenceConditionMainCategory?, @ManyToOne @JoinColumn(name = "lic_cond_type_sub_cat_id") diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/CourtAppearanceService.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/CourtAppearanceService.kt index 3d6370da00..4f0cdef2c3 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/CourtAppearanceService.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/CourtAppearanceService.kt @@ -33,6 +33,6 @@ fun CourtAppearance.toCourtAppearance() = CourtAppearanceBasic( appearanceDate = appearanceDate, courtCode = court.code, courtName = court.courtName, - appearanceType = KeyValue(court.courtType.code, court.courtType.description), + appearanceType = KeyValue(appearanceType.code, appearanceType.description), crn = person.crn ) diff --git a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/RequirementService.kt b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/RequirementService.kt index 2f1304339c..d17bfc1a46 100644 --- a/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/RequirementService.kt +++ b/projects/court-case-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/RequirementService.kt @@ -1,6 +1,8 @@ package uk.gov.justice.digital.hmpps.integrations.delius.service import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.api.model.KeyValue +import uk.gov.justice.digital.hmpps.api.model.LicenceConditions import uk.gov.justice.digital.hmpps.api.model.conviction.ConvictionRequirements import uk.gov.justice.digital.hmpps.api.model.conviction.PssRequirement import uk.gov.justice.digital.hmpps.api.model.conviction.PssRequirements @@ -9,6 +11,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.event.conviction.entity. import uk.gov.justice.digital.hmpps.integrations.delius.event.conviction.entity.ConvictionRequirementRepository import uk.gov.justice.digital.hmpps.integrations.delius.event.conviction.entity.Event import uk.gov.justice.digital.hmpps.integrations.delius.event.conviction.entity.getByEventId +import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.LicenceCondition import uk.gov.justice.digital.hmpps.integrations.delius.event.sentence.entity.PssRequirementRepository import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.getPerson @@ -36,6 +39,16 @@ class RequirementService( ) } + fun getLicenceConditionsForConvictionId(crn: String, convictionId: Long): LicenceConditions { + val event = getEventForPersonByCrnAndEventId(crn, convictionId) + val licenceConditions = event.disposal?.let { + it.licenceConditions.map { lc -> + lc.toLicenceCondition() + } + } + return LicenceConditions(licenceConditions ?: emptyList()) + } + fun getPssRequirementsByConvictionId(crn: String, convictionId: Long): PssRequirements { val event = getEventForPersonByCrnAndEventId(crn, convictionId) @@ -63,5 +76,15 @@ fun PssRequirementEntity.toPssRequirement(): PssRequirement = active ) - - +fun LicenceCondition.toLicenceCondition() = uk.gov.justice.digital.hmpps.api.model.LicenceCondition( + active = active, + commencementDate = commencementDate, + commencementNotes = commencementNotes, + createdDateTime = createdDateTime, + licenceConditionNotes = notes, + licenceConditionTypeMainCat = mainCategory?.let { KeyValue(it.code, it.description) }, + licenceConditionTypeSubCat = subCategory?.let { KeyValue(it.code, it.description) }, + startDate = startDate, + terminationDate = terminationDate, + terminationNotes = terminationNotes +)