From 403ae8c9da67512e6a1ff0c39b111cf774c61a79 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 19 Dec 2024 13:38:12 +0000 Subject: [PATCH] PI-2707 Update notes to show when risk has increased or decreased --- .../uk/gov/justice/digital/hmpps/IntegrationTest.kt | 6 +++++- .../uk/gov/justice/digital/hmpps/enum/RiskLevel.kt | 4 ++++ .../uk/gov/justice/digital/hmpps/enum/RiskType.kt | 4 ---- .../gov/justice/digital/hmpps/service/RiskService.kt | 10 +++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 78ab5ce1b..d28d71a75 100644 --- a/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -418,7 +418,11 @@ internal class IntegrationTest { val riskToPublic = registrationRepository.findByPersonIdAndTypeCode(person.id, RiskType.PUBLIC.code).single() assertThat(riskToPublic.level?.code, equalTo(RiskLevel.V.code)) - assertThat(riskToPublicBefore.reviews, hasSize(1)) + assertThat(riskToPublic.reviews, hasSize(1)) + assertThat( + riskToPublic.notes, + startsWith("The OASys assessment of Review on 07/12/2023 identified the Risk to public to have increased to V.") + ) assertThat(domainEvents.ofType(RiskType.PUBLIC), hasSize(2)) assertThat( domainEvents.ofType(RiskType.PUBLIC).map { it.eventType }, diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskLevel.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskLevel.kt index d4e31467c..7da68d890 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskLevel.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskLevel.kt @@ -8,5 +8,9 @@ enum class RiskLevel(val code: String) { fun of(vararg values: String?): RiskLevel? = values.filterNotNull().mapNotNull(RiskLevel::of).maxByOrNull { it.ordinal } + + fun byCode(code: String): RiskLevel? = entries.firstOrNull { it.code == code } + + fun maxByCode(codes: List): RiskLevel? = codes.mapNotNull(RiskLevel::byCode).maxByOrNull { it.ordinal } } } \ No newline at end of file diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskType.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskType.kt index 81ba111cf..4558672ab 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskType.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/enum/RiskType.kt @@ -8,8 +8,4 @@ enum class RiskType(val code: String, val riskLevel: (AssessmentSummary) -> Risk PRISONER("REG16", { RiskLevel.of(it.riskPrisonersCustody) }), PUBLIC("REG17", { RiskLevel.of(it.riskPublicCommunity, it.riskPublicCustody) }), STAFF("AV2S", { RiskLevel.of(it.riskStaffCommunity, it.riskStaffCustody) }); - - companion object { - fun of(value: String): RiskType? = entries.firstOrNull { it.name.equals(value, true) } - } } \ No newline at end of file diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RiskService.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RiskService.kt index 4f52c8f19..7f7d72c6c 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RiskService.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/RiskService.kt @@ -78,8 +78,16 @@ class RiskService( val type = registerTypeRepository.getByCode(riskType.code) val level = referenceDataRepository.registerLevel(riskLevel.code) val roshSummary = ordsClient.getRoshSummary(summary.assessmentPk)?.assessments?.singleOrNull() + + val existingLevel = RiskLevel.maxByCode(registrationsToRemove.mapNotNull { it.level?.code }) val notes = """ - |The OASys assessment of ${summary.furtherInformation.pOAssessmentDesc} on ${summary.dateCompleted.toDeliusDate()} identified the ${type.description} to be ${level.description}. + |The OASys assessment of ${summary.furtherInformation.pOAssessmentDesc} on ${summary.dateCompleted.toDeliusDate()} identified the ${type.description} ${ + when { + existingLevel == null || existingLevel.ordinal == riskLevel.ordinal -> "to be" + existingLevel.ordinal < riskLevel.ordinal -> "to have increased to" + else -> "to have decreased to" + } + } ${level.description}. |${roshSummary?.whoAtRisk?.let { "\n|*R10.1 Who is at risk*\n|$it" }} |${roshSummary?.natureOfRisk?.let { "\n|*R10.2 What is the nature of the risk*\n|$it" }} """.trimMargin()