Skip to content

Commit

Permalink
Pi 1991 refactor (#3472)
Browse files Browse the repository at this point in the history
* PI-1991: Refactor and added more data
  • Loading branch information
pmcphee77 authored Mar 14, 2024
1 parent deb3584 commit 6244fe2
Show file tree
Hide file tree
Showing 24 changed files with 518 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class DataLoader(
override fun onApplicationEvent(are: ApplicationReadyEvent) {

entityManager.persist(PersonGenerator.OVERVIEW.gender)
PersonGenerator.OVERVIEW.disabilities.forEach { entityManager.persist(it.type) }
PersonGenerator.OVERVIEW.provisions.forEach { entityManager.persist(it.type) }
PersonGenerator.OVERVIEW.personalCircumstances.forEach {
PersonGenerator.DISABILITIES.forEach { entityManager.persist(it.type) }
PersonGenerator.PROVISIONS.forEach { entityManager.persist(it.type) }
PersonGenerator.PERSONAL_CIRCUMSTANCES.forEach {
entityManager.persist(it.type)
entityManager.persist(it.subType)
}

entityManager.persistCollection(PersonGenerator.OVERVIEW.disabilities)
entityManager.persistCollection(PersonGenerator.OVERVIEW.provisions)
entityManager.persistCollection(PersonGenerator.OVERVIEW.personalCircumstances)
entityManager.persistCollection(PersonGenerator.DISABILITIES)
entityManager.persistCollection(PersonGenerator.PROVISIONS)
entityManager.persistCollection(PersonGenerator.PERSONAL_CIRCUMSTANCES)
entityManager.persist(PersonGenerator.OVERVIEW)

entityManager.persist(PersonGenerator.EVENT_1)
Expand Down Expand Up @@ -85,6 +85,7 @@ class DataLoader(
PersonDetailsGenerator.GENDER_FEMALE,
PersonDetailsGenerator.RELIGION_DEFAULT,
PersonDetailsGenerator.SEXUAL_ORIENTATION,
PersonDetailsGenerator.LANGUAGE_RD,
PersonDetailsGenerator.PERSONAL_DETAILS,
PersonDetailsGenerator.DISABILITY_1_RD,
PersonDetailsGenerator.DISABILITY_2_RD,
Expand All @@ -110,8 +111,11 @@ class DataLoader(
PersonDetailsGenerator.PERSON_ADDRESS_TYPE_2,
PersonDetailsGenerator.PERSON_ADDRESS_2,
PersonDetailsGenerator.NULL_ADDRESS,
PersonDetailsGenerator.PREVIOUS_ADDRESS,
PersonDetailsGenerator.DOCUMENT_1,
PersonDetailsGenerator.DOCUMENT_2
PersonDetailsGenerator.DOCUMENT_2,
PersonDetailsGenerator.ALIAS_1,
PersonDetailsGenerator.ALIAS_2
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,62 @@ object PersonGenerator {
additionalOffences = additionalOffences
)

val DISABILITIES: List<Disability> = listOf(
Disability(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "D01", "Mental Illness"),
LocalDate.now().minusDays(1),
LocalDate.now().minusDays(1)
),
Disability(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "D02", "Visual Impairment"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
)

val PERSONAL_CIRCUMSTANCES: List<PersonalCircumstance> = listOf(
PersonalCircumstance(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "E01", "Employment"),
PersonalCircumstanceSubType(
IdGenerator.getAndIncrement(),
"Full-time employed (30 or more hours per week"
),
LocalDate.now(),
LocalDate.now().minusDays(1)
),
PersonalCircumstance(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "A02", "Accommodation"),
PersonalCircumstanceSubType(IdGenerator.getAndIncrement(), "Friends/Family (settled)"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
)

val PROVISIONS: List<Provision> = listOf(
Provision(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "FF01", "Flex refreshment breaks"),
LocalDate.now(),
LocalDate.now().minusDays(1)
),
Provision(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "CC02", "Colour/visibility marking"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
)

fun generateOverview(
crn: String,
forename: String = "Forename",
Expand All @@ -134,62 +190,8 @@ object PersonGenerator {
preferredName: String? = "Dee",
dateOfBirth: LocalDate = LocalDate.now().minusYears(50),
gender: ReferenceData = ReferenceData(IdGenerator.getAndIncrement(), "M", "Male"),
id: Long = IdGenerator.getAndIncrement(),
disabilities: List<Disability> = listOf(
Disability(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "D01", "Mental Illness"),
LocalDate.now().minusDays(1),
LocalDate.now().minusDays(1)
),
Disability(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "D02", "Visual Impairment"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
),
personalCircumstances: List<PersonalCircumstance> = listOf(
PersonalCircumstance(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "E01", "Employment"),
PersonalCircumstanceSubType(
IdGenerator.getAndIncrement(),
"Full-time employed (30 or more hours per week"
),
LocalDate.now(),
LocalDate.now().minusDays(1)
),
PersonalCircumstance(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "A02", "Accommodation"),
PersonalCircumstanceSubType(IdGenerator.getAndIncrement(), "Friends/Family (settled)"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
),
provisions: List<Provision> = listOf(
Provision(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "FF01", "Flex refreshment breaks"),
LocalDate.now(),
LocalDate.now().minusDays(1)
),
Provision(
IdGenerator.getAndIncrement(),
id,
ReferenceData(IdGenerator.getAndIncrement(), "CC02", "Colour/visibility marking"),
LocalDate.now(),
LocalDate.now().minusDays(1)
)
),

) = Person(
id: Long = IdGenerator.getAndIncrement()
) = Person(
id = id,
crn = crn,
forename = forename,
Expand All @@ -198,14 +200,10 @@ object PersonGenerator {
surname = surname,
dateOfBirth = dateOfBirth,
gender = gender,
disabilities = disabilities,
emailAddress = emailAddress,
mobileNumber = mobileNumber,
personalCircumstances = personalCircumstances,
provisions = provisions,
telephoneNumber = telephoneNumber,
preferredName = preferredName,
registrations = emptyList(),
pnc = "pnc",
religion = null,
sexualOrientation = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package uk.gov.justice.digital.hmpps.data.generator.personalDetails

import uk.gov.justice.digital.hmpps.data.generator.IdGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.ContactAddress
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonAddress
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonDocument
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalContact
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalContactEntity
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import java.time.LocalDate
import java.time.ZonedDateTime
Expand All @@ -14,12 +15,17 @@ object PersonDetailsGenerator {
val GENDER_FEMALE = ReferenceData(IdGenerator.getAndIncrement(), "F", "Female")
val RELIGION_DEFAULT = ReferenceData(IdGenerator.getAndIncrement(), "C", "Christian")
val SEXUAL_ORIENTATION = ReferenceData(IdGenerator.getAndIncrement(), "H", "Heterosexual")
val LANGUAGE_RD = ReferenceData(IdGenerator.getAndIncrement(), "E", "Arabic")

val PERSONAL_DETAILS = generatePersonDetails(
"X000005", "Caroline",
"Louise", "Bloggs", "Caz", GENDER_FEMALE, RELIGION_DEFAULT, SEXUAL_ORIENTATION
"Louise", "Bloggs", "Caz", GENDER_FEMALE, RELIGION_DEFAULT,
SEXUAL_ORIENTATION, LANGUAGE_RD, "Smith"
)

val ALIAS_1 = generateAlias("Sam", "Edward", "Smith", PERSONAL_DETAILS.id)
val ALIAS_2 = generateAlias("Joe", "Richard", "Jones", PersonGenerator.OVERVIEW.id)

val DISABILITY_1_RD = ReferenceData(IdGenerator.getAndIncrement(), "D20", "Some Illness")
val DISABILITY_2_RD = ReferenceData(IdGenerator.getAndIncrement(), "D20", "Blind")
val PERSONAL_CIRCUMSTANCE_1_RD = ReferenceData(IdGenerator.getAndIncrement(), "E02", "Employed")
Expand Down Expand Up @@ -79,7 +85,7 @@ object PersonDetailsGenerator {

val RELATIONSHIP_TYPE = ReferenceData(IdGenerator.getAndIncrement(), "FM01", "Family Member")
val CONTACT_ADDRESS = generateContactAddress("31", "Test Steet", "Test town", "Test County", "NE1 56A")
val PERSONAL_CONTACT_1 = PersonalContact(
val PERSONAL_CONTACT_1 = PersonalContactEntity(
IdGenerator.getAndIncrement(),
PERSONAL_DETAILS.id,
"Sam",
Expand All @@ -102,7 +108,8 @@ object PersonDetailsGenerator {
"NE2 56A",
PERSONAL_DETAILS.id,
PERSON_ADDRESS_STATUS_1,
PERSON_ADDRESS_TYPE_1
PERSON_ADDRESS_TYPE_1,
verified = true
)
val PERSON_ADDRESS_2 = generatePersonAddress(
"43",
Expand All @@ -112,8 +119,22 @@ object PersonDetailsGenerator {
"NE4 5AN",
PERSONAL_DETAILS.id,
PERSON_ADDRESS_STATUS_2,
PERSON_ADDRESS_TYPE_2
PERSON_ADDRESS_TYPE_2,
verified = true
)

val PREVIOUS_ADDRESS = generatePersonAddress(
"43",
"Test Avenue",
"Test town",
"Test County",
"NE4 END",
PERSONAL_DETAILS.id,
PERSON_ADDRESS_STATUS_2,
PERSON_ADDRESS_TYPE_2,
endDate = LocalDate.now().minusYears(1)
)

val NULL_ADDRESS = PersonAddress(
PERSONAL_DETAILS.id,
PERSON_ADDRESS_STATUS_2,
Expand All @@ -127,6 +148,7 @@ object PersonDetailsGenerator {
null,
LocalDate.now(),
null,
true,
LocalDate.now(),
false,
IdGenerator.getAndIncrement()
Expand Down Expand Up @@ -164,7 +186,9 @@ object PersonDetailsGenerator {
postcode: String,
personId: Long,
status: ReferenceData,
type: ReferenceData
type: ReferenceData,
endDate: LocalDate? = null,
verified: Boolean? = null
) = PersonAddress(
personId = personId,
id = IdGenerator.getAndIncrement(),
Expand All @@ -178,13 +202,16 @@ object PersonDetailsGenerator {
softDeleted = false,
lastUpdated = LocalDate.now().minusDays(10),
startDate = LocalDate.now().minusDays(10),
endDate = endDate,
status = status,
type = type
type = type,
typeVerified = verified
)

fun generatePersonDetails(
crn: String, forename: String, secondName: String, surname: String, preferredName: String,
gender: ReferenceData, religion: ReferenceData, sexualOrientation: ReferenceData
gender: ReferenceData, religion: ReferenceData, sexualOrientation: ReferenceData, language: ReferenceData,
previousSurname: String
) = Person(
id = IdGenerator.getAndIncrement(),
crn = crn,
Expand All @@ -200,10 +227,8 @@ object PersonDetailsGenerator {
gender = gender,
religion = religion,
sexualOrientation = sexualOrientation,
personalCircumstances = emptyList(),
disabilities = emptyList(),
provisions = emptyList(),
personalContacts = emptyList()
language = language,
previousSurname = previousSurname
)

fun generateDocument(personId: Long, alfrescoId: String, name: String, documentType: String) = PersonDocument(
Expand All @@ -216,5 +241,13 @@ object PersonDetailsGenerator {
primaryKeyId = personId,
type = documentType
)

fun generateAlias(forename: String, secondName: String, surname: String, personId: Long) = Alias(
id = IdGenerator.getAndIncrement(),
forename = forename,
secondName = secondName,
surname = surname,
personId = personId
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import uk.gov.justice.digital.hmpps.api.model.overview.Overview
import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ADDITIONAL_OFFENCE_1
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ADDITIONAL_OFFENCE_2
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.DISABILITIES
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.EVENT_1
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.MAIN_OFFENCE_1
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.OVERVIEW
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.PERSONAL_CIRCUMSTANCES
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.PROVISIONS
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

Expand All @@ -36,27 +39,27 @@ internal class OverviewIntegrationTest {
assertThat(res.personalDetails.name.forename, equalTo(person.forename))
assertThat(
res.personalDetails.disabilities[0].description,
equalTo(OVERVIEW.disabilities[0].type.description)
equalTo(DISABILITIES[0].type.description)
)
assertThat(
res.personalDetails.disabilities[1].description,
equalTo(OVERVIEW.disabilities[1].type.description)
equalTo(DISABILITIES[1].type.description)
)
assertThat(
res.personalDetails.provisions[0].description,
equalTo(OVERVIEW.provisions[0].type.description)
equalTo(PROVISIONS[0].type.description)
)
assertThat(
res.personalDetails.provisions[1].description,
equalTo(OVERVIEW.provisions[1].type.description)
equalTo(PROVISIONS[1].type.description)
)
assertThat(
res.personalDetails.personalCircumstances[0].type,
equalTo(OVERVIEW.personalCircumstances[0].type.description)
equalTo(PERSONAL_CIRCUMSTANCES[0].type.description)
)
assertThat(
res.personalDetails.personalCircumstances[1].type,
equalTo(OVERVIEW.personalCircumstances[1].type.description)
equalTo(PERSONAL_CIRCUMSTANCES[1].type.description)
)
assertThat(
res.schedule.nextAppointment?.description,
Expand Down
Loading

0 comments on commit 6244fe2

Please sign in to comment.