Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* PI-1528 add LAO endpoint

* PI-1528 Add new endpoints for AP and Delius

* PI-1528 Add registration info (mappa and other)

* PI-1528 Add offence details

* added Entity Graph for registrations
  • Loading branch information
anthony-britton-moj authored Oct 4, 2023
1 parent 8c35b41 commit ecbf133
Show file tree
Hide file tree
Showing 20 changed files with 905 additions and 18 deletions.
1 change: 1 addition & 0 deletions projects/approved-premises-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply(plugin = "com.google.cloud.tools.jib")
dependencies {
implementation(project(":libs:audit"))
implementation(project(":libs:commons"))
implementation(project(":libs:limited-access"))
implementation(project(":libs:messaging"))
implementation(project(":libs:oauth-client"))
implementation(project(":libs:oauth-server"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceD
import uk.gov.justice.digital.hmpps.integrations.delius.staff.StaffRepository
import uk.gov.justice.digital.hmpps.integrations.delius.team.TeamRepository
import uk.gov.justice.digital.hmpps.user.AuditUserRepository
import java.time.LocalDate

@Component
@ConditionalOnProperty("seed.database")
Expand Down Expand Up @@ -78,7 +79,8 @@ class DataLoader(
private val transferReasonRepository: TransferReasonRepository,
private val caseloadRepository: CaseloadRepository,
private val registrationRepository: RegistrationRepository,
private val referralRepository: ReferralRepository
private val referralRepository: ReferralRepository,
private val probationCaseDataLoader: ProbationCaseDataLoader
) : ApplicationListener<ApplicationReadyEvent> {

@PostConstruct
Expand Down Expand Up @@ -159,7 +161,8 @@ class DataLoader(
registrationRepository.save(
PersonGenerator.generateRegistration(
person,
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.GANG_AFFILIATION.value]!!
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.GANG_AFFILIATION.value]!!,
LocalDate.now()
)
)

Expand All @@ -179,6 +182,8 @@ class DataLoader(
caseloadRepository.save(CaseloadGenerator.generate(person, TeamGenerator.UNALLOCATED))

referralRepository.save(ReferralGenerator.EXISTING_REFERRAL)

probationCaseDataLoader.loadData()
}
}

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

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.OffenceGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
import uk.gov.justice.digital.hmpps.data.generator.asPerson
import uk.gov.justice.digital.hmpps.data.generator.asPersonManager
import uk.gov.justice.digital.hmpps.data.generator.asTeam
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCaseRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.probation.PersonManagerRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.AdditionalOffence
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.MainOffenceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Offence
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegisterType
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegistrationRepository
import uk.gov.justice.digital.hmpps.integrations.delius.staff.StaffRepository
import uk.gov.justice.digital.hmpps.integrations.delius.team.TeamRepository
import java.time.LocalDate

@Component
class ProbationCaseDataLoader(
private val probationAreaRepository: ProbationAreaRepository,
private val teamRepository: TeamRepository,
private val staffRepository: StaffRepository,
private val personManagerRepository: PersonManagerRepository,
private val probationCaseRepository: ProbationCaseRepository,
private val registrationRepository: RegistrationRepository,
private val eventRepository: EventRepository,
private val offenceRepository: OffenceRepository,
private val mainOffenceRepository: MainOffenceRepository,
private val additionalOffenceRepository: AdditionalOffenceRepository
) {
fun loadData() {
offenceRepository.saveAll(listOf(OffenceGenerator.OFFENCE_ONE, OffenceGenerator.OFFENCE_TWO))
probationAreaRepository.save(ProbationCaseGenerator.COM_PROVIDER)
teamRepository.save(ProbationCaseGenerator.COM_TEAM.asTeam())
staffRepository.save(ProbationCaseGenerator.COM_UNALLOCATED)
probationCaseRepository.save(ProbationCaseGenerator.CASE_COMPLEX)
probationCaseRepository.save(ProbationCaseGenerator.CASE_SIMPLE)

personManagerRepository.saveAll(
listOf(
ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_COMPLEX).asPersonManager(),
ProbationCaseGenerator.generateManager(ProbationCaseGenerator.CASE_SIMPLE).asPersonManager()
)
)

registrationRepository.save(
PersonGenerator.generateRegistration(
ProbationCaseGenerator.CASE_COMPLEX.asPerson(),
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.MAPPA.value]!!,
LocalDate.now().minusDays(7),
ReferenceDataGenerator.REGISTER_CATEGORIES["M3"],
ReferenceDataGenerator.REGISTER_LEVELS["M2"]
)
)

registrationRepository.save(
PersonGenerator.generateRegistration(
ProbationCaseGenerator.CASE_COMPLEX.asPerson(),
ReferenceDataGenerator.REGISTER_TYPES[RegisterType.Code.SEX_OFFENCE.value]!!,
LocalDate.now().minusDays(7)
)
)

val event = PersonGenerator.generateEvent(
"1",
ProbationCaseGenerator.CASE_COMPLEX.id
).apply(eventRepository::save)

mainOffenceRepository.save(
OffenceGenerator.generateMainOffence(
event,
OffenceGenerator.OFFENCE_ONE,
LocalDate.now().minusDays(7)
)
)

additionalOffenceRepository.save(
OffenceGenerator.generateAdditionalOffence(
event,
OffenceGenerator.OFFENCE_TWO,
LocalDate.now().minusDays(5)
)
)
}
}

interface OffenceRepository : JpaRepository<Offence, Long>
interface AdditionalOffenceRepository : JpaRepository<AdditionalOffence, Long>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.Event
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.AdditionalOffence
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.MainOffence
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Offence
import java.time.LocalDate

object OffenceGenerator {
val OFFENCE_ONE = generate("OFF1", "Offence One")
val OFFENCE_TWO = generate("OFF2", "Offence Two")

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

fun generateMainOffence(
event: Event,
offence: Offence,
date: LocalDate,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = MainOffence(event, offence, date, softDeleted, id)

fun generateAdditionalOffence(
event: Event,
offence: Offence,
date: LocalDate,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = AdditionalOffence(event, offence, date, softDeleted, id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.Person
import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.probation.PersonManager
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegisterType
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.Registration
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.staff.Staff
import uk.gov.justice.digital.hmpps.integrations.delius.team.Team
import java.time.LocalDate
import java.time.ZonedDateTime

object PersonGenerator {
val DEFAULT = generate(crn = "A000001")
val EVENT = PersonGenerator.generateEvent("7", DEFAULT.id)
val EVENT = generateEvent("7", DEFAULT.id)
fun generate(
crn: String,
id: Long = IdGenerator.getAndIncrement()
) = Person(id = id, crn = crn)

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

fun generateRegistration(
person: Person,
type: RegisterType,
date: LocalDate,
category: ReferenceData? = null,
level: ReferenceData? = null,
softDeleted: Boolean = false,
deregistered: Boolean = false,
lastUpdatedDateTime: ZonedDateTime = ZonedDateTime.now(),
id: Long = IdGenerator.getAndIncrement()
) = Registration(person.id, type, softDeleted, deregistered, id)
) = Registration(person.id, type, category, level, date, softDeleted, deregistered, lastUpdatedDateTime, id)
}

object PersonManagerGenerator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_PROVIDER
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_TEAM
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator.COM_UNALLOCATED
import uk.gov.justice.digital.hmpps.integrations.delius.person.CommunityManager
import uk.gov.justice.digital.hmpps.integrations.delius.person.CommunityManagerTeam
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCase
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.team.Team
import java.time.LocalDate

object ProbationCaseGenerator {
val COM_PROVIDER = ProbationAreaGenerator.generate("N01")
val COM_TEAM = generateComTeam("N01COM", "Community Manager Team")
val COM_UNALLOCATED = StaffGenerator.generate("Unallocated", "N01COMU")
val CASE_COMPLEX = generate(
"C246139",
"James",
"Brown",
LocalDate.of(1979, 3, 12),
"John",
"Jack",
"A5671YZ",
ReferenceDataGenerator.GENDER_MALE,
ReferenceDataGenerator.ETHNICITY_WHITE,
ReferenceDataGenerator.NATIONALITY_BRITISH,
ReferenceDataGenerator.RELIGION_OTHER,
ReferenceDataGenerator.GENDER_IDENTITY_PNS,
currentExclusion = true,
currentRestriction = true
)
val CASE_SIMPLE = generate("S517283", "Teresa", "Green", LocalDate.of(1987, 8, 2))

fun generate(
crn: String,
forename: String,
surname: String,
dateOfBirth: LocalDate,
secondName: String? = null,
thirdName: String? = null,
nomsId: String? = null,
gender: ReferenceData? = null,
ethnicity: ReferenceData? = null,
nationality: ReferenceData? = null,
religion: ReferenceData? = null,
genderIdentity: ReferenceData? = null,
currentExclusion: Boolean = false,
currentRestriction: Boolean = false,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = ProbationCase(
crn,
nomsId,
forename,
secondName,
thirdName,
surname,
dateOfBirth,
gender,
ethnicity,
nationality,
religion,
genderIdentity,
currentExclusion,
currentRestriction,
listOf(),
softDeleted,
id
)

fun generateComTeam(code: String, description: String, id: Long = IdGenerator.getAndIncrement()) =
CommunityManagerTeam(code, description, id)

fun generateManager(
pc: ProbationCase,
team: CommunityManagerTeam = COM_TEAM,
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = CommunityManager(pc, team, active, softDeleted, id)
}

fun ProbationCase.asPerson() = PersonGenerator.generate(crn, id)
fun CommunityManagerTeam.asTeam() = Team(id, code, description, COM_PROVIDER, null)
fun CommunityManager.asPersonManager() =
PersonManagerGenerator.generate(person.asPerson(), COM_TEAM.asTeam(), COM_UNALLOCATED, id)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ package uk.gov.justice.digital.hmpps.data.generator
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.ADDRESS_STATUS
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.ADDRESS_TYPE
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.ALL_DATASETS
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.ETHNICITY
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.GENDER
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.GENDER_IDENTITY
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.HOSTEL_CODE
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.NATIONALITY
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.REGISTER_CATEGORY
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.REGISTER_LEVEL
import uk.gov.justice.digital.hmpps.data.generator.DatasetGenerator.RELIGION
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.MoveOnCategory
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.ReferralSource
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.Category
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.Level
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegisterType
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.Dataset
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.DatasetCode
Expand All @@ -32,20 +41,33 @@ object ReferenceDataGenerator {

val OTHER_REFERRAL_SOURCE = generateReferralSource("OTH")
val MC05 = generateMoveOnCategory("MC05")
val REGISTER_TYPES = RegisterType.Code.values()
.map { RegisterType(it.value, IdGenerator.getAndIncrement()) }
val REGISTER_TYPES = RegisterType.Code.entries
.map { RegisterType(it.value, "Description of ${it.value}", IdGenerator.getAndIncrement()) }
.associateBy { it.code }

val REFERRAL_COMPLETED = generate("APRC", ALL_DATASETS[DatasetCode.NSI_OUTCOME]!!.id)

val ETHNICITY_WHITE = generate("W1", ETHNICITY.id, "White: British/English/Welsh/Scottish/Northern Irish")
val GENDER_MALE = generate("M", GENDER.id, "Male")
val GENDER_IDENTITY_PNS = generate("GIRF", GENDER_IDENTITY.id, "Prefer not to say")
val NATIONALITY_BRITISH = generate("BRIT", NATIONALITY.id, "British")
val RELIGION_OTHER = generate("OTH", RELIGION.id, "Other")

val REGISTER_CATEGORIES = Category.entries.map {
generate(it.name, REGISTER_CATEGORY.id, "MAPPA Category ${it.name}")
}.associateBy { it.code }
val REGISTER_LEVELS: Map<String, ReferenceData> = Level.entries.map {
generate(it.name, REGISTER_LEVEL.id, "MAPPA Level ${it.name}")
}.associateBy { it.code }

fun generate(
code: String,
datasetId: Long,
description: String = "Description of $code",
id: Long = IdGenerator.getAndIncrement()
) = ReferenceData(id, code, description, datasetId)

fun all() = listOf(
fun all(): List<ReferenceData> = listOf(
OWNER_ADDRESS_TYPE,
AP_ADDRESS_TYPE,
MAIN_ADDRESS_STATUS,
Expand All @@ -61,19 +83,30 @@ object ReferenceDataGenerator {
RISK_UNKNOWN,
ORDER_EXPIRED,
NON_ARRIVAL,
REFERRAL_COMPLETED
)
REFERRAL_COMPLETED,
ETHNICITY_WHITE,
GENDER_MALE,
GENDER_IDENTITY_PNS,
NATIONALITY_BRITISH,
RELIGION_OTHER
) + REGISTER_CATEGORIES.values + REGISTER_LEVELS.values

fun generateReferralSource(code: String, id: Long = IdGenerator.getAndIncrement()) = ReferralSource(id, code)
fun generateMoveOnCategory(code: String, id: Long = IdGenerator.getAndIncrement()) = MoveOnCategory(id, code)
}

object DatasetGenerator {
val ALL_DATASETS = DatasetCode.values().map { Dataset(IdGenerator.getAndIncrement(), it) }.associateBy { it.code }
val ALL_DATASETS = DatasetCode.entries.map { Dataset(IdGenerator.getAndIncrement(), it) }.associateBy { it.code }
val ADDRESS_TYPE = ALL_DATASETS[DatasetCode.ADDRESS_TYPE]!!
val ADDRESS_STATUS = ALL_DATASETS[DatasetCode.ADDRESS_STATUS]!!
val HOSTEL_CODE = ALL_DATASETS[DatasetCode.HOSTEL_CODE]!!
val STAFF_GRADE = ALL_DATASETS[DatasetCode.STAFF_GRADE]!!

val GENDER = ALL_DATASETS[DatasetCode.GENDER]!!
val GENDER_IDENTITY = ALL_DATASETS[DatasetCode.GENDER_IDENTITY]!!
val ETHNICITY = ALL_DATASETS[DatasetCode.ETHNICITY]!!
val NATIONALITY = ALL_DATASETS[DatasetCode.NATIONALITY]!!
val RELIGION = ALL_DATASETS[DatasetCode.RELIGION]!!
val REGISTER_CATEGORY = ALL_DATASETS[DatasetCode.REGISTER_CATEGORY]!!
val REGISTER_LEVEL = ALL_DATASETS[DatasetCode.REGISTER_LEVEL]!!
fun all() = ALL_DATASETS.values
}
Loading

0 comments on commit ecbf133

Please sign in to comment.