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-2611 Update additional registrations from OASys risks #4471

Merged
merged 1 commit into from
Nov 28, 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
18 changes: 18 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.enum.RiskLevel
import uk.gov.justice.digital.hmpps.enum.RiskOfSeriousHarmType
import uk.gov.justice.digital.hmpps.enum.RiskOfSeriousHarmType.*
import uk.gov.justice.digital.hmpps.enum.RiskType
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Event
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person
import uk.gov.justice.digital.hmpps.service.Risk
import uk.gov.justice.digital.hmpps.set
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
import java.time.LocalDate
Expand All @@ -33,7 +36,12 @@ class DataLoader(
saveAll(*ReferenceDataGenerator.BUSINESS_INTERACTIONS.toTypedArray())
saveAll(*ReferenceDataGenerator.COURTS.toTypedArray())
saveAll(*ReferenceDataGenerator.OFFENCES.toTypedArray())
saveAll(ReferenceDataGenerator.FLAG_DATASET, ReferenceDataGenerator.DEFAULT_FLAG)
saveAll(
ReferenceDataGenerator.FLAG_DATASET,
ReferenceDataGenerator.ROSH_FLAG,
ReferenceDataGenerator.SAFEGUARDING_FLAG
)
saveAll(ReferenceDataGenerator.LEVELS_DATASET, *ReferenceDataGenerator.LEVELS.toTypedArray())
saveAll(*ContactGenerator.TYPES.values.toTypedArray())
saveAll(*RegistrationGenerator.TYPES.values.toTypedArray())
saveAll(*ReferenceDataGenerator.REQ_MAIN_CATS.toTypedArray())
Expand All @@ -43,18 +51,26 @@ class DataLoader(
)
saveAll(ReferenceDataGenerator.DISPOSAL_TYPE)

PersonGenerator.NO_RISK.withEvent().withRisk(Risk.M, Risk.L)
PersonGenerator.LOW_RISK
PersonGenerator.NO_ROSH.withEvent().withRiskOfSeriousHarm(M, L)
PersonGenerator.LOW_ROSH
.withEvent()
.withRisk(Risk.M, Risk.H)
.withAssessment("10096930")
.withRiskOfSeriousHarm(M, H)
.withAssessment("2")
.withAccreditedProgramRequirement()
PersonGenerator.MEDIUM_RISK.withEvent().withRisk(Risk.M)
PersonGenerator.HIGH_RISK.withEvent().withRisk(Risk.L, Risk.H)
PersonGenerator.VERY_HIGH_RISK.withEvent().withRisk(Risk.L, Risk.M, Risk.H)
PersonGenerator.MEDIUM_ROSH.withEvent().withRiskOfSeriousHarm(M)
PersonGenerator.HIGH_ROSH.withEvent().withRiskOfSeriousHarm(L, H)
PersonGenerator.VERY_HIGH_ROSH.withEvent().withRiskOfSeriousHarm(L, M, H)
saveAll(PersonGenerator.PERSON_NO_EVENT)
PersonGenerator.PERSON_SOFT_DELETED_EVENT.withEvent(softDeleted = true).withRisk(Risk.L, Risk.M, Risk.H)
PersonGenerator.PERSON_SOFT_DELETED_EVENT.withEvent(softDeleted = true).withRiskOfSeriousHarm(L, M, H)
PersonGenerator.PRISON_ASSESSMENT.withEvent(custodial = true)
PersonGenerator.NO_EXISTING_RISKS.withEvent()
PersonGenerator.EXISTING_RISKS.withEvent().withRisks(
RiskType.CHILDREN to RiskLevel.H,
RiskType.STAFF to RiskLevel.V,
RiskType.KNOWN_ADULT to RiskLevel.M,
RiskType.PUBLIC to RiskLevel.M,
)
PersonGenerator.FEATURE_FLAG.withEvent().withRiskOfSeriousHarm(V)
}

private fun Person.withEvent(softDeleted: Boolean = false, custodial: Boolean = false): Person {
Expand All @@ -79,18 +95,31 @@ class DataLoader(
return this
}

private fun Person.withRisk(vararg risks: Risk): Person {
risks.forEach {
private fun Person.withRiskOfSeriousHarm(vararg riskOfSeriousHarmTypes: RiskOfSeriousHarmType): Person {
riskOfSeriousHarmTypes.forEach {
val type = RegistrationGenerator.TYPES[it.code]
val contact = entityManager.merge(ContactGenerator.generateContact(this, type!!.registrationContactType!!))
val registration = RegistrationGenerator.generate(this.id, LocalDate.parse("2023-06-14"), type, contact)
val registration = RegistrationGenerator.generate(this.id, LocalDate.parse("2023-06-14"), contact, type)
val reviewContact = entityManager.merge(ContactGenerator.generateContact(this, type.reviewContactType!!))
highestRiskColour = type.colour
saveAll(this, registration.withReview(reviewContact))
}
return this
}

private fun Person.withRisks(vararg risks: Pair<RiskType, RiskLevel>): Person {
risks.forEach { risk ->
val type = RegistrationGenerator.TYPES[risk.first.code]
val level = ReferenceDataGenerator.LEVELS.single { it.code == risk.second.code }
val contact = entityManager.merge(ContactGenerator.generateContact(this, type!!.registrationContactType!!))
val registration =
RegistrationGenerator.generate(this.id, LocalDate.parse("2023-06-14"), contact, type, level)
val reviewContact = entityManager.merge(ContactGenerator.generateContact(this, type.reviewContactType!!))
saveAll(this, registration.withReview(reviewContact))
}
return this
}

private fun Person.withAccreditedProgramRequirement(): Person {
saveAll(PersonGenerator.generateRequirement(this))
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData

object PersonGenerator {
val NO_RISK = generate("N123456")
val LOW_RISK = generate("L123456")
val MEDIUM_RISK = generate("M123456")
val HIGH_RISK = generate("H123456")
val VERY_HIGH_RISK = generate("V123456")
val PERSON_NO_EVENT = generate("E123456")
val PERSON_SOFT_DELETED_EVENT = generate("F123456")
val PRISON_ASSESSMENT = generate("O123456")
val NO_ROSH = generate("A000001")
val LOW_ROSH = generate("A000002")
val MEDIUM_ROSH = generate("A000003")
val HIGH_ROSH = generate("A000004")
val VERY_HIGH_ROSH = generate("A000005")
val PERSON_NO_EVENT = generate("A000006")
val PERSON_SOFT_DELETED_EVENT = generate("A000007")
val PRISON_ASSESSMENT = generate("A000008")

val NO_EXISTING_RISKS = generate("A000009")
val EXISTING_RISKS = generate("A000010")
val FEATURE_FLAG = generate("A000011")

fun generate(
crn: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.audit.BusinessInteraction
import uk.gov.justice.digital.hmpps.enum.RiskLevel
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Court
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Offence
Expand All @@ -19,7 +20,10 @@ object ReferenceDataGenerator {
)
}
val FLAG_DATASET = generateDataset(Dataset.Code.REGISTER_TYPE_FLAG.value)
val DEFAULT_FLAG = generateReferenceData("1", dataset = FLAG_DATASET)
val ROSH_FLAG = generateReferenceData("1", "RoSH", FLAG_DATASET)
val SAFEGUARDING_FLAG = generateReferenceData("3", "Safeguarding", FLAG_DATASET)
val LEVELS_DATASET = generateDataset(Dataset.Code.REGISTER_LEVEL.value)
val LEVELS = RiskLevel.entries.map { generateReferenceData(it.code, it.name, dataset = LEVELS_DATASET) }
val OFFENCES = listOf("80400", "00857").map { generateOffence(it) }
val COURTS = listOf("CRT150", "LVRPCC").map { generateCourt(it) }
val REQ_MAIN_CATS = listOf("RM38").map { generateReqMainCat(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.ROSH_FLAG
import uk.gov.justice.digital.hmpps.enum.RiskOfSeriousHarmType
import uk.gov.justice.digital.hmpps.enum.RiskType
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.RegisterType
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Registration
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import uk.gov.justice.digital.hmpps.service.Risk
import java.time.LocalDate

object RegistrationGenerator {

val TYPES = Risk.entries.map {
generateType(
it.code, colour = when (it) {
Risk.V -> "Red"
Risk.H -> "Orange"
Risk.M -> "Amber"
Risk.L -> "Green"
}
)
}.associateBy { it.code }
val TYPES = listOf(
RiskOfSeriousHarmType.entries.map { generateType(it.code, it.colour, flag = ROSH_FLAG) },
RiskType.entries.map { generateType(it.code, "Amber", "Risk to ${it.name.lowercase()}") }
).flatten().associateBy { it.code }

val RiskOfSeriousHarmType.colour
get() = when (this) {
RiskOfSeriousHarmType.V -> "Red"
RiskOfSeriousHarmType.H -> "Orange"
RiskOfSeriousHarmType.M -> "Amber"
RiskOfSeriousHarmType.L -> "Green"
}

fun generate(
personId: Long,
date: LocalDate,
type: RegisterType,
contact: Contact,
type: RegisterType,
level: ReferenceData? = null,
teamId: Long = ProviderGenerator.DEFAULT_TEAM_ID,
staffId: Long = ProviderGenerator.DEFAULT_STAFF_ID,
nextReviewDate: LocalDate? = type.reviewPeriod?.let { date.plusMonths(it) },
notes: String? = null,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Registration(personId, date, contact, teamId, staffId, type, nextReviewDate, softDeleted, id)
) = Registration(personId, date, contact, teamId, staffId, type, level, nextReviewDate, notes, softDeleted, id)

fun generateType(
code: String,
colour: String,
description: String = "Description of $code",
flag: ReferenceData = ReferenceDataGenerator.DEFAULT_FLAG,
flag: ReferenceData = ReferenceDataGenerator.SAFEGUARDING_FLAG,
registrationContactType: ContactType? = ContactGenerator.TYPES[ContactType.Code.REGISTRATION.value],
reviewContactType: ContactType? = ContactGenerator.TYPES[ContactType.Code.REGISTRATION_REVIEW.value],
reviewPeriod: Long? = 6,
colour: String? = null,
id: Long = IdGenerator.getAndIncrement()
) = RegisterType(code, description, flag, registrationContactType, reviewPeriod, reviewContactType, colour, id)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Type": "Notification",
"MessageId": "33ad848a-4342-5ff2-9fe9-d96307935317",
"Message": "{\n \"eventType\": \"assessment.summary.produced\",\n \"version\": 1,\n \"description\": \"Assessment Summary has been produced\",\n \"detailUrl\": \"http://localhost:{wiremock.port}/eor/oasys/ass/asssumm/E123456/ALLOW/10069390/COMPLETE\",\n \"occurredAt\": \"2023-12-05T15:32:32+00:00\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"E123456\"}]}}",
"Message": "{\n \"eventType\": \"assessment.summary.produced\",\n \"version\": 1,\n \"description\": \"Assessment Summary has been produced\",\n \"detailUrl\": \"http://localhost:{wiremock.port}/eor/oasys/ass/asssumm/A000001/ALLOW/1/COMPLETE\",\n \"occurredAt\": \"2023-12-05T15:32:32+00:00\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"A000001\"}]}}",
"Timestamp": "2023-12-05T15:32:33.823Z",
"MessageAttributes": {
"eventType": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"probNumber": "N123456",
"probNumber": "A000001",
"assessments": [
{
"assessmentPk": 10071389,
"assessmentPk": 1,
"assessmentType": "LAYER3",
"dateCompleted": "2023-12-07T12:22:44",
"assessorSignedDate": "2023-12-07T12:16:12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"probNumber": "L123456",
"probNumber": "A000002",
"assessments": [
{
"assessmentPk": 10096930,
"assessmentPk": 2,
"assessmentType": "LAYER3",
"dateCompleted": "2023-12-07T12:22:44",
"assessorSignedDate": "2023-12-07T12:16:12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"probNumber": "H123456",
"probNumber": "A000003",
"assessments": [
{
"assessmentPk": 100835871,
"assessmentPk": 3,
"assessmentType": "LAYER3",
"dateCompleted": "2023-12-15T08:34:44",
"assessorSignedDate": "2023-12-15T08:33:39",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"probNumber": "F123456",
"probNumber": "A000004",
"assessments": [
{
"assessmentPk": 10078385,
"assessmentPk": 4,
"assessmentType": "LAYER3",
"dateCompleted": "2023-12-15T08:34:44",
"assessorSignedDate": "2023-12-15T08:33:39",
Expand Down
Loading
Loading