From 736f3d0fd905dfcd79a6dab97e22d94bc3d28984 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Thu, 10 Oct 2024 17:46:29 +0100 Subject: [PATCH 01/14] MAN-28 - add licence condition information to api --- .../justice/digital/hmpps/data/DataLoader.kt | 4 + .../generator/LicenceConditionGenerator.kt | 43 +++++++++++ .../digital/hmpps/SentenceIntegrationTest.kt | 17 ++++- .../api/model/sentence/LicenceCondition.kt | 12 +++ .../hmpps/api/model/sentence/Sentence.kt | 3 +- .../sentence/entity/LicenceCondition.kt | 76 +++++++++++++++++++ .../digital/hmpps/service/SentenceService.kt | 19 ++++- .../hmpps/service/SentenceServiceTest.kt | 6 +- 8 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt create mode 100644 projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt create mode 100644 projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index 735071c8be..8f29fac989 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -95,6 +95,10 @@ class DataLoader( OffenderManagerGenerator.OFFENDER_MANAGER_INACTIVE, PersonGenerator.DEFAULT_DISPOSAL_TYPE, PersonGenerator.ACTIVE_ORDER, + LicenceConditionGenerator.LIC_COND_MAIN_CAT, + LicenceConditionGenerator.LIC_COND_SUB_CAT, + LicenceConditionGenerator.LC_WITH_NOTES, + LicenceConditionGenerator.LC_WITHOUT_NOTES, PersonGenerator.TERMINATION_REASON, PersonGenerator.REF_DATA_YEARS, PersonGenerator.INACTIVE_ORDER_1, diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt new file mode 100644 index 0000000000..fd3aabcd76 --- /dev/null +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt @@ -0,0 +1,43 @@ +package uk.gov.justice.digital.hmpps.data.generator + +import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ACTIVE_ORDER +import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData +import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition +import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceConditionMainCategory +import java.time.LocalDate + +object LicenceConditionGenerator { + + val LIC_COND_MAIN_CAT = LicenceConditionMainCategory( + IdGenerator.getAndIncrement(), + "LicMain", + "lic cond main" + ) + + val LIC_COND_SUB_CAT = ReferenceData( + IdGenerator.getAndIncrement(), + "LicSub", + "Lic Sub cat" + ) + + val LC_WITHOUT_NOTES = LicenceCondition( + IdGenerator.getAndIncrement(), + LIC_COND_MAIN_CAT, + null, + ACTIVE_ORDER.id, + LocalDate.now().minusDays(14), + null, + null + ) + + val LC_WITH_NOTES = LicenceCondition( + IdGenerator.getAndIncrement(), + LIC_COND_MAIN_CAT, + LIC_COND_SUB_CAT, + ACTIVE_ORDER.id, + LocalDate.now().minusDays(7), + LocalDate.now(), + "licence condition notes" + ) + +} \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index be40682c7e..6282dbef00 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -62,6 +62,7 @@ class SentenceIntegrationTest { null, listOf(), listOf(), + null, null ), Sentence( @@ -114,7 +115,21 @@ class SentenceIntegrationTest { CourtDocument(COURT_DOCUMENT.alfrescoId, LocalDate.now().minusDays(1), "court report"), CourtDocument(EVENT_DOCUMENT.alfrescoId, LocalDate.now().minusDays(3), "event report") ), - "3 minutes completed (of 12 hours)" + "3 minutes completed (of 12 hours)", + listOf( + LicenceCondition( + "lic cond main", + "Lic Sub cat", + LocalDate.now().minusDays(7), + LocalDate.now(), + "licence condition notes", + false, + ), + LicenceCondition( + "lic cond main", + imposedReleasedDate = LocalDate.now().minusDays(14), + ) + ) ) ), ProbationHistory(2, LocalDate.now().minusDays(7), 2, 2) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt new file mode 100644 index 0000000000..9c3c34038b --- /dev/null +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -0,0 +1,12 @@ +package uk.gov.justice.digital.hmpps.api.model.sentence + +import java.time.LocalDate + +data class LicenceCondition( + val mainDescription: String, + val subTypeDescription: String? = null, + val imposedReleasedDate: LocalDate, + val actualStartDate: LocalDate? = null, + val notes: String? = null, + val hasNotesBeenTruncated: Boolean? = null +) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt index ace75da39f..03417dacdc 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt @@ -8,5 +8,6 @@ data class Sentence( val order: Order? = null, val requirements: List = listOf(), val courtDocuments: List = listOf(), - val unpaidWorkProgress: String? + val unpaidWorkProgress: String?, + val licenceConditions: List? ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt new file mode 100644 index 0000000000..f51bd2c480 --- /dev/null +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt @@ -0,0 +1,76 @@ +package uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity + +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.referencedata.entity.ReferenceData +import java.time.LocalDate + +@Immutable +@Entity +@Table(name = "lic_condition") +@SQLRestriction("soft_deleted = 0 and active_flag = 1") +class LicenceCondition( + @Id + @Column(name = "lic_condition_id", nullable = false) + val id: Long, + + @ManyToOne + @JoinColumn(name = "lic_cond_type_main_cat_id") + val mainCategory: LicenceConditionMainCategory, + + @ManyToOne + @JoinColumn(name = "lic_cond_type_sub_cat_id") + val subCategory: ReferenceData?, + + @Column + val disposalId: Long, + + @Column(name = "start_date", nullable = false) + val imposedReleasedDate: LocalDate, + + @Column(name = "commencement_date") + val actualStartDate: LocalDate?, + + @Column(name = "lic_condition_notes", columnDefinition = "clob") + val notes: String?, + + @Column(name = "active_flag", columnDefinition = "number", nullable = false) + val active: Boolean = true, + + @Column(columnDefinition = "number") + val softDeleted: Boolean = false +) { + fun getTruncatedNotes(): String? { + notes?.let { return it.chunked(1500)[0] } ?: return null + } + + fun hasNotesBeenTruncated(): Boolean? { + return notes?.let { + when { + it.length > 1500 -> true + else -> false + } + } + } +} + +interface LicenceConditionRepository : JpaRepository { + fun findAllByDisposalId(disposalId: Long): List +} + +@Immutable +@Table(name = "r_lic_cond_type_main_cat") +@Entity +class LicenceConditionMainCategory( + @Id + @Column(name = "lic_cond_type_main_cat_id") + val id: Long, + + @Column + val code: String, + + @Column + val description: String +) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index b08df7ea98..9fbcb70be7 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -10,6 +10,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.CourtDocumentDetails import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.DocumentRepository import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.* +import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition import java.time.Duration import java.time.LocalDate import kotlin.time.toKotlinDuration @@ -24,7 +25,8 @@ class SentenceService( private val requirementRepository: RequirementRepository, private val documentRepository: DocumentRepository, private val offenderManagerRepository: OffenderManagerRepository, - private val upwAppointmentRepository: UpwAppointmentRepository + private val upwAppointmentRepository: UpwAppointmentRepository, + private val licenceConditionRepository: LicenceConditionRepository ) { fun getEvents(crn: String): SentenceOverview { val person = personRepository.getPerson(crn) @@ -67,9 +69,21 @@ class SentenceService( requirements = requirementRepository.getRequirements(id, eventNumber) .map { it.toRequirement() }, courtDocuments = documentRepository.getCourtDocuments(id, eventNumber).map { it.toCourtDocument() }, - disposal?.id?.let { getUnpaidWorkTime(it) } + disposal?.id?.let { getUnpaidWorkTime(it) }, + licenceConditions = disposal?.let { licenceConditionRepository.findAllByDisposalId(disposal.id).map { + it.toLicenceCondition() + } }?.ifEmpty { null }, ) + fun EntityLicenceCondition.toLicenceCondition() = + LicenceCondition( + mainCategory.description, + subCategory?.description, + imposedReleasedDate, + actualStartDate, + getTruncatedNotes(), + hasNotesBeenTruncated()) + fun ExtraSentence.toAdditionalSentence(): AdditionalSentence = AdditionalSentence(length, amount, notes, type.description) @@ -152,4 +166,5 @@ class SentenceService( } return null } + } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt index ba1f43b813..577c86a369 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt @@ -49,6 +49,9 @@ class SentenceServiceTest { @Mock lateinit var upwAppointmentRepository: UpwAppointmentRepository + @Mock + lateinit var licenceConditionRepository: LicenceConditionRepository + @InjectMocks lateinit var service: SentenceService @@ -263,7 +266,8 @@ class SentenceServiceTest { ) ), listOf(CourtDocument("A001", LocalDate.now(), "Pre Sentence Event")), - "65 hours 36 minutes completed (of 70 hours)" + "65 hours 36 minutes completed (of 70 hours)", + null ) ), ProbationHistory(0, null, 0, 0) From 090707ab9fef214fb13d8992a71c7f35b5b8eb02 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Thu, 10 Oct 2024 18:03:53 +0100 Subject: [PATCH 02/14] MAN-28 - update model from nullable list to non nullable list --- .../uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt | 2 +- .../uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt | 2 +- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 2 +- .../uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 6282dbef00..0ccc246103 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -63,7 +63,7 @@ class SentenceIntegrationTest { listOf(), listOf(), null, - null + listOf() ), Sentence( OffenceDetails( diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt index 03417dacdc..c4cae7c0b9 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/Sentence.kt @@ -9,5 +9,5 @@ data class Sentence( val requirements: List = listOf(), val courtDocuments: List = listOf(), val unpaidWorkProgress: String?, - val licenceConditions: List? + val licenceConditions: List = listOf() ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 9fbcb70be7..c3a579bed0 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -72,7 +72,7 @@ class SentenceService( disposal?.id?.let { getUnpaidWorkTime(it) }, licenceConditions = disposal?.let { licenceConditionRepository.findAllByDisposalId(disposal.id).map { it.toLicenceCondition() - } }?.ifEmpty { null }, + } } ?: emptyList(), ) fun EntityLicenceCondition.toLicenceCondition() = diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt index 577c86a369..386a43b05d 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt @@ -267,7 +267,7 @@ class SentenceServiceTest { ), listOf(CourtDocument("A001", LocalDate.now(), "Pre Sentence Event")), "65 hours 36 minutes completed (of 70 hours)", - null + listOf() ) ), ProbationHistory(0, null, 0, 0) From bc9ae950134f063d6afc19bd4da0e59d43f6b3c7 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 09:50:20 +0100 Subject: [PATCH 03/14] MAN-28 - update model so that notes are sent as a list --- .../generator/LicenceConditionGenerator.kt | 11 +++++- .../digital/hmpps/SentenceIntegrationTest.kt | 23 ++++++++++- .../api/model/sentence/LicenceCondition.kt | 7 +++- .../sentence/entity/LicenceCondition.kt | 15 +------- .../digital/hmpps/service/SentenceService.kt | 38 ++++++++++++++++++- 5 files changed, 74 insertions(+), 20 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt index fd3aabcd76..7944322dcd 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt @@ -37,7 +37,16 @@ object LicenceConditionGenerator { ACTIVE_ORDER.id, LocalDate.now().minusDays(7), LocalDate.now(), - "licence condition notes" + """ + Comment added by CVL Service on 22/04/2024 at 10:00 + Licence Condition created automatically from the Create and Vary a licence system of + Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. + --------------------------------------------------------- + Comment added by Joe Root on 23/04/2024 at 13:45 + You must not drink any alcohol until Wednesday 7th August 2024 unless your + probation officer says you can. You will need to wear an electronic tag all the time so + we can check this. + """.trimIndent() ) } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 0ccc246103..6ade7aa05e 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -20,6 +20,7 @@ import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate + @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class SentenceIntegrationTest { @@ -122,8 +123,26 @@ class SentenceIntegrationTest { "Lic Sub cat", LocalDate.now().minusDays(7), LocalDate.now(), - "licence condition notes", - false, + listOf( + LicenceConditionNote( + "Comment added by CVL Service on 22/04/2024 at 10:00", + """ + Licence Condition created automatically from the Create and Vary a licence system of + Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. + + """.trimIndent(), + false + ), + LicenceConditionNote( + "Comment added by Joe Root on 23/04/2024 at 13:45", + """ + You must not drink any alcohol until Wednesday 7th August 2024 unless your + probation officer says you can. You will need to wear an electronic tag all the time so + we can check this. + """.trimIndent(), + false + ) + ) ), LicenceCondition( "lic cond main", diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt index 9c3c34038b..8da8988c70 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -7,6 +7,11 @@ data class LicenceCondition( val subTypeDescription: String? = null, val imposedReleasedDate: LocalDate, val actualStartDate: LocalDate? = null, - val notes: String? = null, + val notes: List = listOf() +) + +data class LicenceConditionNote( + val createdBy: String, + val note: String, val hasNotesBeenTruncated: Boolean? = null ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt index f51bd2c480..08874594a0 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt @@ -41,20 +41,7 @@ class LicenceCondition( @Column(columnDefinition = "number") val softDeleted: Boolean = false -) { - fun getTruncatedNotes(): String? { - notes?.let { return it.chunked(1500)[0] } ?: return null - } - - fun hasNotesBeenTruncated(): Boolean? { - return notes?.let { - when { - it.length > 1500 -> true - else -> false - } - } - } -} +) interface LicenceConditionRepository : JpaRepository { fun findAllByDisposalId(disposalId: Long): List diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index c3a579bed0..490e9ab803 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -81,8 +81,42 @@ class SentenceService( subCategory?.description, imposedReleasedDate, actualStartDate, - getTruncatedNotes(), - hasNotesBeenTruncated()) + populateLicenceConditionNotes(notes) + ) + + fun populateLicenceConditionNotes(notes: String?): List { + val noteLength = 1500 + + notes?.let { + val splitParam = "---------------------------------------------------------" + System.lineSeparator() + return notes.split(splitParam).map { + val noteSplitList = it.split(System.lineSeparator()) + val note = noteSplitList.drop(1).joinToString(System.lineSeparator()) + + LicenceConditionNote( + noteSplitList.first(), + note.chunked(noteLength)[0], + note.let { n -> + when { + n.length > noteLength -> true + else -> false + } + } + ) + } + + } + return listOf() + } + + fun hasNotesBeenTruncated(notes: String): Boolean? { + return notes.let { + when { + it.length > 1500 -> true + else -> false + } + } + } fun ExtraSentence.toAdditionalSentence(): AdditionalSentence = AdditionalSentence(length, amount, notes, type.description) From 50acf6c357b9f12291f3dc75ed997204b39a013c Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:50:26 +0000 Subject: [PATCH 04/14] Formatting changes --- .../generator/LicenceConditionGenerator.kt | 1 - .../digital/hmpps/SentenceIntegrationTest.kt | 5 ++-- .../digital/hmpps/service/SentenceService.kt | 23 ++++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt index 7944322dcd..820a8a049d 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt @@ -48,5 +48,4 @@ object LicenceConditionGenerator { we can check this. """.trimIndent() ) - } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 6ade7aa05e..ccf6eb4d23 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -20,7 +20,6 @@ import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate - @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class SentenceIntegrationTest { @@ -132,7 +131,7 @@ class SentenceIntegrationTest { """.trimIndent(), false - ), + ), LicenceConditionNote( "Comment added by Joe Root on 23/04/2024 at 13:45", """ @@ -143,7 +142,7 @@ class SentenceIntegrationTest { false ) ) - ), + ), LicenceCondition( "lic cond main", imposedReleasedDate = LocalDate.now().minusDays(14), diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 490e9ab803..f0fc7b8962 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -70,9 +70,11 @@ class SentenceService( .map { it.toRequirement() }, courtDocuments = documentRepository.getCourtDocuments(id, eventNumber).map { it.toCourtDocument() }, disposal?.id?.let { getUnpaidWorkTime(it) }, - licenceConditions = disposal?.let { licenceConditionRepository.findAllByDisposalId(disposal.id).map { - it.toLicenceCondition() - } } ?: emptyList(), + licenceConditions = disposal?.let { + licenceConditionRepository.findAllByDisposalId(disposal.id).map { + it.toLicenceCondition() + } + } ?: emptyList(), ) fun EntityLicenceCondition.toLicenceCondition() = @@ -94,14 +96,14 @@ class SentenceService( val note = noteSplitList.drop(1).joinToString(System.lineSeparator()) LicenceConditionNote( - noteSplitList.first(), - note.chunked(noteLength)[0], - note.let { n -> - when { - n.length > noteLength -> true - else -> false - } + noteSplitList.first(), + note.chunked(noteLength)[0], + note.let { n -> + when { + n.length > noteLength -> true + else -> false } + } ) } @@ -200,5 +202,4 @@ class SentenceService( } return null } - } \ No newline at end of file From 65cfc524f2c0f1b7923306789cde6545d13dca10 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 19:28:02 +0100 Subject: [PATCH 05/14] MAN-28 - process note without 'Comment added by...' --- .../justice/digital/hmpps/data/DataLoader.kt | 1 + .../generator/LicenceConditionGenerator.kt | 12 ++++++++++++ .../digital/hmpps/SentenceIntegrationTest.kt | 18 +++++++++++++++--- .../api/model/sentence/LicenceCondition.kt | 2 +- .../digital/hmpps/service/SentenceService.kt | 10 ++++++---- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index 8f29fac989..b40008235e 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -99,6 +99,7 @@ class DataLoader( LicenceConditionGenerator.LIC_COND_SUB_CAT, LicenceConditionGenerator.LC_WITH_NOTES, LicenceConditionGenerator.LC_WITHOUT_NOTES, + LicenceConditionGenerator.LC_WITH_NOTES_WITHOUT_ADDED_BY, PersonGenerator.TERMINATION_REASON, PersonGenerator.REF_DATA_YEARS, PersonGenerator.INACTIVE_ORDER_1, diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt index 820a8a049d..90d3c26f64 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt @@ -48,4 +48,16 @@ object LicenceConditionGenerator { we can check this. """.trimIndent() ) + + val LC_WITH_NOTES_WITHOUT_ADDED_BY = LicenceCondition( + IdGenerator.getAndIncrement(), + LIC_COND_MAIN_CAT, + LIC_COND_SUB_CAT, + ACTIVE_ORDER.id, + LocalDate.now().minusDays(7), + LocalDate.now(), + """ + He shall not contact or associate with Peter Jones without the prior approval of the supervising officer; + """.trimIndent() + ) } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index ccf6eb4d23..c52d24c8a9 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -124,7 +124,7 @@ class SentenceIntegrationTest { LocalDate.now(), listOf( LicenceConditionNote( - "Comment added by CVL Service on 22/04/2024 at 10:00", + "Comment added by CVL Service on 22/04/2024 at 10:00" + System.lineSeparator(), """ Licence Condition created automatically from the Create and Vary a licence system of Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. @@ -133,19 +133,30 @@ class SentenceIntegrationTest { false ), LicenceConditionNote( - "Comment added by Joe Root on 23/04/2024 at 13:45", + "Comment added by Joe Root on 23/04/2024 at 13:45" + System.lineSeparator(), """ You must not drink any alcohol until Wednesday 7th August 2024 unless your probation officer says you can. You will need to wear an electronic tag all the time so we can check this. """.trimIndent(), false - ) + ), ) ), LicenceCondition( "lic cond main", imposedReleasedDate = LocalDate.now().minusDays(14), + ), + LicenceCondition( + "lic cond main", + "Lic Sub cat", + LocalDate.now().minusDays(7), + LocalDate.now(), + listOf( + LicenceConditionNote( + note = "He shall not contact or associate with Peter Jones without the prior approval of the supervising officer;", + hasNotesBeenTruncated = false) + ) ) ) ) @@ -153,6 +164,7 @@ class SentenceIntegrationTest { ProbationHistory(2, LocalDate.now().minusDays(7), 2, 2) ) + assertEquals(expected, response) } diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt index 8da8988c70..a402152875 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -11,7 +11,7 @@ data class LicenceCondition( ) data class LicenceConditionNote( - val createdBy: String, + val createdBy: String? = null, val note: String, val hasNotesBeenTruncated: Boolean? = null ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index f0fc7b8962..eb60743956 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -92,12 +92,14 @@ class SentenceService( notes?.let { val splitParam = "---------------------------------------------------------" + System.lineSeparator() return notes.split(splitParam).map { - val noteSplitList = it.split(System.lineSeparator()) - val note = noteSplitList.drop(1).joinToString(System.lineSeparator()) + note -> + val addedBy = Regex("^Comment added by .+? on \\d{2}\\/\\d{2}\\/\\d{4} at \\d{2}:\\d{2}" + + System.lineSeparator()).find(note)?.value + val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note LicenceConditionNote( - noteSplitList.first(), - note.chunked(noteLength)[0], + addedBy, + noteText, note.let { n -> when { n.length > noteLength -> true From 81c2bb63d9ade124c517ecdb2661ebd981702d6c Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:29:41 +0000 Subject: [PATCH 06/14] Formatting changes --- .../gov/justice/digital/hmpps/SentenceIntegrationTest.kt | 5 +++-- .../gov/justice/digital/hmpps/service/SentenceService.kt | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index c52d24c8a9..b030daa1bb 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -154,8 +154,9 @@ class SentenceIntegrationTest { LocalDate.now(), listOf( LicenceConditionNote( - note = "He shall not contact or associate with Peter Jones without the prior approval of the supervising officer;", - hasNotesBeenTruncated = false) + note = "He shall not contact or associate with Peter Jones without the prior approval of the supervising officer;", + hasNotesBeenTruncated = false + ) ) ) ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index eb60743956..43eba883f9 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -91,10 +91,11 @@ class SentenceService( notes?.let { val splitParam = "---------------------------------------------------------" + System.lineSeparator() - return notes.split(splitParam).map { - note -> - val addedBy = Regex("^Comment added by .+? on \\d{2}\\/\\d{2}\\/\\d{4} at \\d{2}:\\d{2}" - + System.lineSeparator()).find(note)?.value + return notes.split(splitParam).map { note -> + val addedBy = Regex( + "^Comment added by .+? on \\d{2}\\/\\d{2}\\/\\d{4} at \\d{2}:\\d{2}" + + System.lineSeparator() + ).find(note)?.value val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note LicenceConditionNote( From 8ef3d6cf15df8d0e76752d7d6cb3439e92e66684 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 19:45:53 +0100 Subject: [PATCH 07/14] MAN-28 - process note without 'Comment added by...' --- .../uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt | 6 ++---- .../digital/hmpps/api/model/sentence/LicenceCondition.kt | 1 + .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 5 +++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index c52d24c8a9..c7590cfef6 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -124,16 +124,15 @@ class SentenceIntegrationTest { LocalDate.now(), listOf( LicenceConditionNote( - "Comment added by CVL Service on 22/04/2024 at 10:00" + System.lineSeparator(), + "Comment added by CVL Service on 22/04/2024 at 10:00", """ Licence Condition created automatically from the Create and Vary a licence system of Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. - """.trimIndent(), false ), LicenceConditionNote( - "Comment added by Joe Root on 23/04/2024 at 13:45" + System.lineSeparator(), + "Comment added by Joe Root on 23/04/2024 at 13:45", """ You must not drink any alcohol until Wednesday 7th August 2024 unless your probation officer says you can. You will need to wear an electronic tag all the time so @@ -164,7 +163,6 @@ class SentenceIntegrationTest { ProbationHistory(2, LocalDate.now().minusDays(7), 2, 2) ) - assertEquals(expected, response) } diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt index a402152875..54affee7a5 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -12,6 +12,7 @@ data class LicenceCondition( data class LicenceConditionNote( val createdBy: String? = null, +// val createdByDate: String? = null, val note: String, val hasNotesBeenTruncated: Boolean? = null ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index eb60743956..4312298a29 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -97,9 +97,10 @@ class SentenceService( + System.lineSeparator()).find(note)?.value val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note + LicenceConditionNote( - addedBy, - noteText, + addedBy?.removeSuffix(System.lineSeparator()), + noteText.removeSuffix(System.lineSeparator()), note.let { n -> when { n.length > noteLength -> true From 25840f4a489b9c6b67b10c97a053c7820c7037c7 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 20:33:57 +0100 Subject: [PATCH 08/14] MAN-28 - update LicenceConditionNote.createdBy --- .../uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt | 4 ++-- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 950c4a9f47..d8ee1401fa 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -124,7 +124,7 @@ class SentenceIntegrationTest { LocalDate.now(), listOf( LicenceConditionNote( - "Comment added by CVL Service on 22/04/2024 at 10:00", + "Comment added by CVL Service", """ Licence Condition created automatically from the Create and Vary a licence system of Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. @@ -132,7 +132,7 @@ class SentenceIntegrationTest { false ), LicenceConditionNote( - "Comment added by Joe Root on 23/04/2024 at 13:45", + "Comment added by Joe Root", """ You must not drink any alcohol until Wednesday 7th August 2024 unless your probation officer says you can. You will need to wear an electronic tag all the time so diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 8a2f21666f..e315557c25 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -100,7 +100,7 @@ class SentenceService( LicenceConditionNote( - addedBy?.removeSuffix(System.lineSeparator()), + addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(23)?.reversed(), noteText.removeSuffix(System.lineSeparator()), note.let { n -> when { From 9a2f401a788ef22be2eadeb2fd6ea9ca4a40da86 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 22:13:13 +0100 Subject: [PATCH 09/14] MAN-28 - add new attribute to response --- .../uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt | 2 ++ .../digital/hmpps/api/model/sentence/LicenceCondition.kt | 2 +- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index d8ee1401fa..fc217a29db 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -125,6 +125,7 @@ class SentenceIntegrationTest { listOf( LicenceConditionNote( "Comment added by CVL Service", + LocalDate.of(2024, 4, 22), """ Licence Condition created automatically from the Create and Vary a licence system of Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. @@ -133,6 +134,7 @@ class SentenceIntegrationTest { ), LicenceConditionNote( "Comment added by Joe Root", + LocalDate.of(2024, 4, 23), """ You must not drink any alcohol until Wednesday 7th August 2024 unless your probation officer says you can. You will need to wear an electronic tag all the time so diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt index 54affee7a5..9b4606662d 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -12,7 +12,7 @@ data class LicenceCondition( data class LicenceConditionNote( val createdBy: String? = null, -// val createdByDate: String? = null, + val createdByDate: LocalDate? = null, val note: String, val hasNotesBeenTruncated: Boolean? = null ) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index e315557c25..adeb7138b8 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -13,6 +13,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition import java.time.Duration import java.time.LocalDate +import java.time.format.DateTimeFormatter import kotlin.time.toKotlinDuration import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentence as ExtraSentence @@ -98,9 +99,12 @@ class SentenceService( ).find(note)?.value val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note + val createdBy = addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(23)?.reversed() + val dateCreatedBy = addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(9,19)?.reversed() LicenceConditionNote( - addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(23)?.reversed(), + createdBy, + dateCreatedBy?.let { LocalDate.parse(it, DateTimeFormatter.ofPattern("d/MM/yyyy")) }, noteText.removeSuffix(System.lineSeparator()), note.let { n -> when { From ae59bf2646bacf4e7d1e5751f65058ce05adaeb5 Mon Sep 17 00:00:00 2001 From: "probation-integration-bot[bot]" <177347787+probation-integration-bot[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 21:14:56 +0000 Subject: [PATCH 10/14] Formatting changes --- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index adeb7138b8..66f71b75ce 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -100,7 +100,8 @@ class SentenceService( val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note val createdBy = addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(23)?.reversed() - val dateCreatedBy = addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(9,19)?.reversed() + val dateCreatedBy = + addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(9, 19)?.reversed() LicenceConditionNote( createdBy, From c2c43fea22030830a7d5f31e99e124f2fe95bbe0 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 22:20:51 +0100 Subject: [PATCH 11/14] MAN-28 - limit licence note to 1500 characters --- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index adeb7138b8..159ea226ed 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -105,7 +105,7 @@ class SentenceService( LicenceConditionNote( createdBy, dateCreatedBy?.let { LocalDate.parse(it, DateTimeFormatter.ofPattern("d/MM/yyyy")) }, - noteText.removeSuffix(System.lineSeparator()), + noteText.removeSuffix(System.lineSeparator()).chunked(1500)[0], note.let { n -> when { n.length > noteLength -> true From 8c81d516643afe1cf6a6c652b7e28ddd77fcd788 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Wed, 16 Oct 2024 22:56:24 +0100 Subject: [PATCH 12/14] MAN-28 - limit licence note to 1500 characters --- .../data/generator/LicenceConditionGenerator.kt | 3 +-- .../digital/hmpps/SentenceIntegrationTest.kt | 17 +++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt index 90d3c26f64..d387d786b6 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/LicenceConditionGenerator.kt @@ -39,8 +39,7 @@ object LicenceConditionGenerator { LocalDate.now(), """ Comment added by CVL Service on 22/04/2024 at 10:00 - Licence Condition created automatically from the Create and Vary a licence system of - Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. + Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer.Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as desi123456 --------------------------------------------------------- Comment added by Joe Root on 23/04/2024 at 13:45 You must not drink any alcohol until Wednesday 7th August 2024 unless your diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index fc217a29db..f2a7100cde 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -19,6 +19,8 @@ import uk.gov.justice.digital.hmpps.service.toSummary import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate +import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT +import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_SUB_CAT @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -118,8 +120,8 @@ class SentenceIntegrationTest { "3 minutes completed (of 12 hours)", listOf( LicenceCondition( - "lic cond main", - "Lic Sub cat", + LIC_COND_MAIN_CAT.description, + LIC_COND_SUB_CAT.description, LocalDate.now().minusDays(7), LocalDate.now(), listOf( @@ -127,10 +129,9 @@ class SentenceIntegrationTest { "Comment added by CVL Service", LocalDate.of(2024, 4, 22), """ - Licence Condition created automatically from the Create and Vary a licence system of - Allow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. + Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer.Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as desi """.trimIndent(), - false + true ), LicenceConditionNote( "Comment added by Joe Root", @@ -145,12 +146,12 @@ class SentenceIntegrationTest { ) ), LicenceCondition( - "lic cond main", + LIC_COND_MAIN_CAT.description, imposedReleasedDate = LocalDate.now().minusDays(14), ), LicenceCondition( - "lic cond main", - "Lic Sub cat", + LIC_COND_MAIN_CAT.description, + LIC_COND_SUB_CAT.description, LocalDate.now().minusDays(7), LocalDate.now(), listOf( From 69df04bd3f6c274dc2e209d2ce9079b717528525 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Thu, 17 Oct 2024 00:22:57 +0100 Subject: [PATCH 13/14] MAN-28 - remove characters not needed --- .../uk/gov/justice/digital/hmpps/service/SentenceService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 193e810b40..96ebbc7659 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -94,7 +94,7 @@ class SentenceService( val splitParam = "---------------------------------------------------------" + System.lineSeparator() return notes.split(splitParam).map { note -> val addedBy = Regex( - "^Comment added by .+? on \\d{2}\\/\\d{2}\\/\\d{4} at \\d{2}:\\d{2}" + "^Comment added by .+? on \\d{2}/\\d{2}/\\d{4} at \\d{2}:\\d{2}" + System.lineSeparator() ).find(note)?.value val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note From 21ac1a51d23c0d987a5e13fe757fd8fcdb8e2f66 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Thu, 17 Oct 2024 10:39:59 +0100 Subject: [PATCH 14/14] MAN-28 - apply review comments --- .../digital/hmpps/SentenceIntegrationTest.kt | 4 +- .../digital/hmpps/service/SentenceService.kt | 42 +++++++------------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index f2a7100cde..c12beab5aa 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -126,7 +126,7 @@ class SentenceIntegrationTest { LocalDate.now(), listOf( LicenceConditionNote( - "Comment added by CVL Service", + "CVL Service", LocalDate.of(2024, 4, 22), """ Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer.Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as desi @@ -134,7 +134,7 @@ class SentenceIntegrationTest { true ), LicenceConditionNote( - "Comment added by Joe Root", + "Joe Root", LocalDate.of(2024, 4, 23), """ You must not drink any alcohol until Wednesday 7th August 2024 unless your diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 96ebbc7659..4955ec9058 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -6,16 +6,16 @@ import uk.gov.justice.digital.hmpps.api.model.overview.Rar import uk.gov.justice.digital.hmpps.api.model.sentence.* import uk.gov.justice.digital.hmpps.api.model.sentence.Offence import uk.gov.justice.digital.hmpps.api.model.sentence.Requirement +import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.CourtDocumentDetails import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.DocumentRepository import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.* -import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition import java.time.Duration import java.time.LocalDate -import java.time.format.DateTimeFormatter import kotlin.time.toKotlinDuration import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentence as ExtraSentence +import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition @Service class SentenceService( @@ -93,26 +93,23 @@ class SentenceService( notes?.let { val splitParam = "---------------------------------------------------------" + System.lineSeparator() return notes.split(splitParam).map { note -> - val addedBy = Regex( - "^Comment added by .+? on \\d{2}/\\d{2}/\\d{4} at \\d{2}:\\d{2}" + val matchResult = Regex( + "^Comment added by (.+?) on (\\d{2}/\\d{2}/\\d{4}) at \\d{2}:\\d{2}" + System.lineSeparator() - ).find(note)?.value - val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note + ).find(note) + val commentLine = matchResult?.value + val commentText = commentLine?.let { note.removePrefix(commentLine) } ?: note + + val userCreatedBy = matchResult?.groupValues?.get(1) + val dateCreatedBy = matchResult?.groupValues?.get(2) + ?.let { LocalDate.parse(it, DeliusDateFormatter) } - val createdBy = addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(23)?.reversed() - val dateCreatedBy = - addedBy?.removeSuffix(System.lineSeparator())?.reversed()?.substring(9, 19)?.reversed() LicenceConditionNote( - createdBy, - dateCreatedBy?.let { LocalDate.parse(it, DateTimeFormatter.ofPattern("d/MM/yyyy")) }, - noteText.removeSuffix(System.lineSeparator()).chunked(1500)[0], - note.let { n -> - when { - n.length > noteLength -> true - else -> false - } - } + userCreatedBy, + dateCreatedBy, + commentText.removeSuffix(System.lineSeparator()).chunked(1500)[0], + note.length > noteLength ) } @@ -120,15 +117,6 @@ class SentenceService( return listOf() } - fun hasNotesBeenTruncated(notes: String): Boolean? { - return notes.let { - when { - it.length > 1500 -> true - else -> false - } - } - } - fun ExtraSentence.toAdditionalSentence(): AdditionalSentence = AdditionalSentence(length, amount, notes, type.description)