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