Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2707 Update notes to show when risk has increased or decreased #4505

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>): RiskLevel? = codes.mapNotNull(RiskLevel::byCode).maxByOrNull { it.ordinal }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading