Skip to content

Commit

Permalink
PI-2708 Add review contact notes to review notes
Browse files Browse the repository at this point in the history
Also add note about risk level change
  • Loading branch information
marcus-bcl committed Dec 19, 2024
1 parent db4aa56 commit da3a0a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ internal class IntegrationTest {
assertThat(
review.contact.notes?.trim(), equalTo(
"""
The OASys assessment of Review on 07/12/2023 identified the Risk to children to be H.
Type: Safeguarding - Risk to children
Next Review Date: ${DeliusDateFormatter.format(LocalDate.now().plusMonths(6))}
""".trimIndent()
Expand Down Expand Up @@ -387,14 +388,13 @@ internal class IntegrationTest {
registrationRepository.findByPersonIdAndTypeCode(person.id, RiskType.CHILDREN.code).single()
assertThat(riskToChildren.level?.code, equalTo(RiskLevel.H.code))
assertThat(riskToChildren.reviews, hasSize(2))
assertThat(
riskToChildren.reviews[1].contact.notes?.trim(), equalTo(
"""
Type: Safeguarding - Risk to children
Next Review Date: 14/12/2023
""".trimIndent()
)
)
val expectedReviewNotes = """
The OASys assessment of Review on 07/12/2023 identified the Risk to children to be H.
Type: Safeguarding - Risk to children
Next Review Date: 14/12/2023
""".trimIndent()
assertThat(riskToChildren.reviews[1].notes?.trim(), equalTo(expectedReviewNotes))
assertThat(riskToChildren.reviews[1].contact.notes?.trim(), equalTo(expectedReviewNotes))
assertThat(domainEvents.ofType(RiskType.CHILDREN), hasSize(0))

val riskToPrisoner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Registration(
private set

fun withReview(contact: Contact): Registration {
reviews += RegistrationReview(personId, this, contact, nextReviewDate, null, teamId, staffId)
reviews += RegistrationReview(personId, this, contact, nextReviewDate, null, teamId, staffId, contact.notes)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,27 @@ class RiskService(
.partition { it.level != null && it.level.code == riskLevel.code }
val events = registrationsToRemove.map { person.removeRegistration(it) }.toMutableList()

val type = registerTypeRepository.getByCode(riskType.code)
val level = referenceDataRepository.registerLevel(riskLevel.code)
val existingLevel = RiskLevel.maxByCode(registrationsToRemove.mapNotNull { it.level?.code })
val assessmentNote =
"The OASys assessment of ${summary.furtherInformation.pOAssessmentDesc} on ${summary.dateCompleted.toDeliusDate()} identified the ${type.description} ${
when {
existingLevel == null -> "to be"
existingLevel.ordinal < riskLevel.ordinal -> "to have increased to"
existingLevel.ordinal > riskLevel.ordinal -> "to have decreased to"
else -> "to have remained"
}
} ${level.description}."

// Add registration with the identified level if it doesn't already exist
if (matchingRegistrations.isEmpty()) {
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} ${
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()
|$assessmentNote
|${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()
events += registrations.addRegistration(person, type, level, notes).regEvent(person.crn)

// Registrations in the type's duplicate group should also be removed
Expand All @@ -104,8 +107,9 @@ class RiskService(
}

// Always add a review, regardless of whether the register level has changed
registrationRepository.findByPersonIdAndTypeCode(person.id, riskType.code).singleOrNull()
?.let { it.withReview(it.reviewContact(person)) }
registrationRepository.findByPersonIdAndTypeCode(person.id, riskType.code).singleOrNull()?.let {
it.withReview(it.reviewContact(person, "$assessmentNote\n${it.notes()}"))
}

return@flatMap events
}
Expand Down Expand Up @@ -144,16 +148,19 @@ class RiskService(
return registration
}

private fun Person.removeRegistration(it: Registration, notes: String? = null): HmppsDomainEvent {
val contact = contactService.createContact(ContactDetail(DEREGISTRATION, notes = notes ?: it.notes()), this)
it.deregister(contact)
return it.deRegEvent(crn)
private fun Person.removeRegistration(
registration: Registration,
notes: String = registration.notes()
): HmppsDomainEvent {
val contact = contactService.createContact(ContactDetail(DEREGISTRATION, notes = notes), this)
registration.deregister(contact)
return registration.deRegEvent(crn)
}

private fun Registration.reviewContact(person: Person) = contactService.createContact(
private fun Registration.reviewContact(person: Person, notes: String = notes()) = contactService.createContact(
ContactDetail(
ContactType.Code.REGISTRATION_REVIEW,
notes = notes(),
notes = notes,
contactType = type.reviewContactType
),
person
Expand Down

0 comments on commit da3a0a0

Please sign in to comment.