Skip to content

Commit

Permalink
PI-1669 assessment summary (#2929)
Browse files Browse the repository at this point in the history
* PI-1669 WIP

* PI-1669 WIP

* PI-1669

* Formatting changes

* remove unused class

* PI-1669

* PI-1669 tidy up

* PI-1669 mapping amendments

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
anthony-britton-moj and github-actions[bot] authored Dec 19, 2023
1 parent 84bed8f commit 505feb2
Show file tree
Hide file tree
Showing 49 changed files with 2,499 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.springframework.util.ResourceUtils
Expand Down Expand Up @@ -34,7 +33,7 @@ object ResourceLoader {

inline fun <reified T> notification(filename: String): Notification<T> {
val file = ResourceUtils.getFile("classpath:messages/$filename.json")
val stringMessage = MAPPER.readValue(file, jacksonTypeRef<Notification<String>>())
val stringMessage = MAPPER.readValue<Notification<String>>(file)
return Notification(
message = MAPPER.readValue(stringMessage.message, T::class.java),
attributes = stringMessage.attributes
Expand Down
1 change: 1 addition & 0 deletions projects/assessment-summary-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ configure<ClassPathExtension> {
jacocoExclusions = listOf(
"**/config/**",
"**/entity/**",
"**/integrations/oasys/**",
"**/AppKt.class"
)
}
13 changes: 13 additions & 0 deletions projects/assessment-summary-and-delius/deploy/database/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ database:
access:
username_key: /assessment-summary-and-delius/db-username
password_key: /assessment-summary-and-delius/db-password
tables:
- contact
- deregistration
- domain_event
- oasys_assessment
- oasys_assmnt_section_score
- oasys_sentence_plan
- oasys_sp_need
- oasys_sp_text
- oasys_sp_work_summary
- offender
- registration
- registration_review

audit:
username: AssessmentSummaryAndDelius
Expand Down
5 changes: 5 additions & 0 deletions projects/assessment-summary-and-delius/deploy/values-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ generic-service:
env:
SENTRY_ENVIRONMENT: prod
INTEGRATIONS_ORDS_URL: https://bridge-oasys.az.justice.gov.uk/eor/oasys
FLIPT_URL: http://feature-flags.hmpps-probation-integration.svc.cluster.local

namespace_secrets:
flipt-client:
FLIPT_TOKEN: TOKEN
Original file line number Diff line number Diff line change
@@ -1,25 +1,85 @@
package uk.gov.justice.digital.hmpps.data

import jakarta.annotation.PostConstruct
import jakarta.persistence.EntityManager
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
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

@Component
@ConditionalOnProperty("seed.database")
class DataLoader(
private val auditUserRepository: AuditUserRepository
private val auditUserRepository: AuditUserRepository,
private val entityManager: EntityManager
) : ApplicationListener<ApplicationReadyEvent> {

@PostConstruct
fun saveAuditUser() {
auditUserRepository.save(UserGenerator.AUDIT_USER)
}

@Transactional
override fun onApplicationEvent(are: ApplicationReadyEvent) {
// Perform dev/test database setup here, using JPA repositories and generator classes...
saveAll(*ReferenceDataGenerator.BUSINESS_INTERACTIONS.toTypedArray())
saveAll(*ReferenceDataGenerator.COURTS.toTypedArray())
saveAll(*ReferenceDataGenerator.OFFENCES.toTypedArray())
saveAll(ReferenceDataGenerator.FLAG_DATASET, ReferenceDataGenerator.DEFAULT_FLAG)
saveAll(*ContactGenerator.TYPES.values.toTypedArray())
saveAll(*RegistrationGenerator.TYPES.values.toTypedArray())
saveAll(*ReferenceDataGenerator.REQ_MAIN_CATS.toTypedArray())

PersonGenerator.NO_RISK.withEvent().withRisk(Risk.M, Risk.L)
PersonGenerator.LOW_RISK
.withEvent()
.withRisk(Risk.H)
.withAssessment("10096930")
.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)
}

private fun Person.withEvent(): Person {
val personManager = PersonGenerator.generateManager(this)
val event = PersonGenerator.generateEvent(this)
saveAll(this, personManager, event)
this.set(Person::manager, personManager)
return this
}

private fun Person.withAssessment(oasysId: String): Person {
val contact =
ContactGenerator.generateContact(this, ContactGenerator.TYPES[ContactType.Code.OASYS_ASSESSMENT.value]!!)
val assessment = AssessmentGenerator.generate(this, contact, LocalDate.parse("2013-06-07"), oasysId = oasysId)
entityManager.merge(assessment)
return this
}

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

private fun Person.withAccreditedProgramRequirement(): Person {
saveAll(PersonGenerator.generateRequirement(this))
return this
}

private fun saveAll(vararg entities: Any) = entities.forEach(entityManager::merge)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.digital.hmpps.data.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.hibernate.annotations.Immutable
import org.springframework.data.jpa.repository.JpaRepository

@Immutable
@Entity
@Table(name = "iaps_offender")
class IapsPerson(
@Id
@Column(name = "offender_id")
val personId: Long,

@Column(columnDefinition = "number")
val iapsFlag: Boolean
)

interface IapsPersonRepository : JpaRepository<IapsPerson, Long>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessment
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.Contact
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Court
import uk.gov.justice.digital.hmpps.integrations.delius.court.entity.Offence
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.Person
import java.time.LocalDate
import java.util.*

object AssessmentGenerator {
fun generate(
person: Person,
contact: Contact,
date: LocalDate = LocalDate.now().minusDays(7),
eventNumber: String = "1",
court: Court? = null,
offence: Offence? = null,
totalScore: Long = 50,
description: String? = "Oasys Assessment",
assessedBy: String? = "John Smith",
riskFlags: String? = "M,N,M,L,N,L,L,H,N",
concernFlags: String? = "YES,NO,NO,DK,YES,NO,NO,YES",
dateCreated: LocalDate = date,
dateReceived: LocalDate = LocalDate.now().minusDays(2),
initialSentencePlanDate: LocalDate? = null,
sentencePlanReviewDate: LocalDate? = null,
reviewTerminated: Boolean? = null,
reviewNumber: String? = null,
layerType: String? = "Layer_3",
ogrsScore1: Long? = 21,
ogrsScore2: Long? = 42,
ogpScore1: Long? = 13,
ogpScore2: Long? = 26,
ovpScore1: Long? = 6,
ovpScore2: Long? = 12,
softDeleted: Boolean = false,
oasysId: String = UUID.randomUUID().toString(),
id: Long = 0
) = OasysAssessment(
oasysId,
date,
person,
eventNumber,
contact,
court,
offence,
totalScore,
description,
assessedBy,
riskFlags,
concernFlags,
dateCreated,
dateReceived,
initialSentencePlanDate,
sentencePlanReviewDate,
reviewTerminated,
reviewNumber,
layerType,
ogrsScore1,
ogrsScore2,
ogpScore1,
ogpScore2,
ovpScore1,
ovpScore2,
softDeleted,
id
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.justice.digital.hmpps.data.generator

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.Person

object ContactGenerator {
val TYPES = ContactType.Code.entries.map { generateType(it.value) }.associateBy { it.code }

fun generateContact(
person: Person,
type: ContactType,
eventId: Long? = null,
alert: Boolean? = false,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Contact(type, person, eventId, alert, softDeleted, id)

fun generateType(code: String, id: Long = IdGenerator.getAndIncrement()) = ContactType(code, id)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package uk.gov.justice.digital.hmpps.data.generator

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")

fun generate(
crn: String,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Person(crn, softDeleted, id)

fun generateManager(
person: Person,
probationAreaId: Long = ProviderGenerator.DEFAULT_PROVIDER_ID,
teamId: Long = ProviderGenerator.DEFAULT_TEAM_ID,
staffId: Long = ProviderGenerator.DEFAULT_STAFF_ID,
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = PersonManager(person, probationAreaId, teamId, staffId, active, softDeleted, id)

fun generateEvent(
person: Person,
number: String = "1",
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Event(number, person.id, active, softDeleted, id)

fun generateRequirement(
person: Person,
mainCategory: RequirementMainCategory = ReferenceDataGenerator.REQ_MAIN_CATS.first(),
additionalMainCategory: RequirementAdditionalMainCategory? = null,
subCategory: ReferenceData? = null,
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Requirement(person, mainCategory, additionalMainCategory, subCategory, active, softDeleted, id)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

object ProviderGenerator {
val DEFAULT_PROVIDER_ID = IdGenerator.getAndIncrement()
val DEFAULT_TEAM_ID = IdGenerator.getAndIncrement()
val DEFAULT_STAFF_ID = IdGenerator.getAndIncrement()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.audit.BusinessInteraction
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
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.RequirementMainCategory
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.Dataset
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import java.time.ZonedDateTime

object ReferenceDataGenerator {
val BUSINESS_INTERACTIONS = BusinessInteractionCode.entries.map {
BusinessInteraction(
IdGenerator.getAndIncrement(),
it.code,
ZonedDateTime.now()
)
}
val FLAG_DATASET = generateDataset(Dataset.Code.REGISTER_TYPE_FLAG.value)
val DEFAULT_FLAG = generateReferenceData("1", dataset = FLAG_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) }

fun generateReferenceData(
code: String,
description: String = "Description of $code",
dataset: Dataset,
id: Long = IdGenerator.getAndIncrement()
) = ReferenceData(code, description, dataset.id, id)

fun generateDataset(code: String, id: Long = IdGenerator.getAndIncrement()) = Dataset(code, id)

fun generateCourt(code: String, id: Long = IdGenerator.getAndIncrement()) = Court(code, id)

fun generateOffence(code: String, id: Long = IdGenerator.getAndIncrement()) = Offence(code, id)

fun generateReqMainCat(code: String, id: Long = IdGenerator.getAndIncrement()) = RequirementMainCategory(code, id)
}
Loading

0 comments on commit 505feb2

Please sign in to comment.