diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt index 8cc2795a0f..5c6b386a6b 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt @@ -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) @@ -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, @@ -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 ) } diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt index 856f85e2ea..cff3a660cf 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt @@ -122,6 +122,62 @@ object PersonGenerator { additionalOffences = additionalOffences ) + val DISABILITIES: List = 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 = 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 = 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", @@ -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 = 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 = 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 = 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, @@ -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 diff --git a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt index 161b8d5d14..b05a2e0a91 100644 --- a/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt +++ b/projects/manage-supervision-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/personalDetails/PersonDetailsGenerator.kt @@ -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 @@ -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") @@ -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", @@ -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", @@ -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, @@ -127,6 +148,7 @@ object PersonDetailsGenerator { null, LocalDate.now(), null, + true, LocalDate.now(), false, IdGenerator.getAndIncrement() @@ -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(), @@ -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, @@ -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( @@ -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 + ) } diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/OverviewIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/OverviewIntegrationTest.kt index 46e9a7a90d..8abf7ed4a4 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/OverviewIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/OverviewIntegrationTest.kt @@ -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 @@ -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, diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PersonalDetailsIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PersonalDetailsIntegrationTest.kt index 48d7c8c1fe..7704c8f4bd 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PersonalDetailsIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PersonalDetailsIntegrationTest.kt @@ -14,8 +14,13 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import org.springframework.util.ResourceUtils import uk.gov.justice.digital.hmpps.api.model.Name +import uk.gov.justice.digital.hmpps.api.model.PersonSummary +import uk.gov.justice.digital.hmpps.api.model.personalDetails.PersonalContact import uk.gov.justice.digital.hmpps.api.model.personalDetails.PersonalDetails +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.ALIAS_1 +import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_CONTACT_1 import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_DETAILS +import uk.gov.justice.digital.hmpps.service.toContact import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate @@ -39,15 +44,19 @@ internal class PersonalDetailsIntegrationTest { assertThat(res.preferredName, equalTo("Caz")) assertThat(res.preferredGender, equalTo("Female")) assertThat(res.religionOrBelief, equalTo("Christian")) + assertThat(res.preferredLanguage, equalTo("Arabic")) + assertThat(res.previousSurname, equalTo("Smith")) assertThat(res.sexualOrientation, equalTo("Heterosexual")) assertThat(res.mainAddress?.status, equalTo("Main Address")) - assertThat(res.mainAddress?.postcode, equalTo("NE2 56A")) + assertThat(res.mainAddress?.verified, equalTo(true)) assertThat(res.mainAddress?.type, equalTo("Address type 1")) assertThat(res.mainAddress?.postcode, equalTo("NE2 56A")) assertThat(res.otherAddresses.size, equalTo(1)) assertThat(res.otherAddresses[0].type, equalTo("Address type 2")) assertThat(res.otherAddresses[0].status, equalTo("Another Address")) + assertThat(res.otherAddresses[0].verified, equalTo(true)) assertThat(res.otherAddresses[0].postcode, equalTo("NE4 5AN")) + assertThat(res.previousAddresses[0].postcode, equalTo("NE4 END")) assertThat(res.contacts.size, equalTo(1)) assertThat(res.contacts[0].name, equalTo(Name("Sam", "Steven", "Smith"))) assertThat(res.contacts[0].address?.postcode, equalTo("NE1 56A")) @@ -70,6 +79,7 @@ internal class PersonalDetailsIntegrationTest { assertThat(res.documents[1].name, equalTo("other.doc")) assertThat(res.documents[0].id, equalTo("A001")) assertThat(res.documents[1].id, equalTo("A002")) + assertThat(res.aliases[0].forename, equalTo(ALIAS_1.forename)) } @Test @@ -111,4 +121,44 @@ internal class PersonalDetailsIntegrationTest { mockMvc.perform(get("/personal-details/X000005/document/A010").withToken()) .andExpect(status().isNotFound) } + + @Test + fun `personal summary is returned`() { + + val person = PERSONAL_DETAILS + val res = mockMvc + .perform(get("/personal-details/${person.crn}/summary").withToken()) + .andExpect(status().isOk) + .andReturn().response.contentAsJson() + assertThat(res.crn, equalTo(person.crn)) + assertThat(res.pnc, equalTo(person.pnc)) + assertThat(res.dateOfBirth, equalTo(person.dateOfBirth)) + assertThat(res.name, equalTo(Name(person.forename, person.secondName, person.surname))) + } + + @Test + fun `personal contact is returned`() { + + val person = PERSONAL_DETAILS + val contact = PERSONAL_CONTACT_1 + val res = mockMvc + .perform(get("/personal-details/${person.crn}/personal-contact/${contact.id}").withToken()) + .andExpect(status().isOk) + .andReturn().response.contentAsJson() + assertThat(res, equalTo(contact.toContact())) + } + + @Test + fun `personal summary not found`() { + mockMvc + .perform(get("/personal-details/X999999/summary").withToken()) + .andExpect(status().isNotFound) + } + + @Test + fun `personal contact not found`() { + mockMvc + .perform(get("/personal-details/X999999/personal-contact/999999999").withToken()) + .andExpect(status().isNotFound) + } } diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsController.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsController.kt index 0ad7b8f6d2..eaa64d6a12 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsController.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsController.kt @@ -25,4 +25,14 @@ class PersonalDetailsController(private val personalDetailsService: PersonalDeta @Operation(summary = "Download document") fun downloadDocument(@PathVariable crn: String, @PathVariable documentId: String) = personalDetailsService.downloadDocument(crn, documentId) + + @GetMapping("/summary") + @Operation(summary = "Person Summary") + fun getPersonSummary(@PathVariable crn: String) = + personalDetailsService.getPersonSummary(crn) + + @GetMapping("/personal-contact/{id}") + @Operation(summary = "Person Contact") + fun getPersonContact(@PathVariable crn: String, @PathVariable id: Long) = + personalDetailsService.getPersonContact(crn, id) } diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonSummary.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonSummary.kt new file mode 100644 index 0000000000..58c7011fb3 --- /dev/null +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/PersonSummary.kt @@ -0,0 +1,10 @@ +package uk.gov.justice.digital.hmpps.api.model + +import java.time.LocalDate + +data class PersonSummary( + val name: Name, + val crn: String, + val pnc: String?, + val dateOfBirth: LocalDate +) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt index 66537cb5d4..22ada74956 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/Address.kt @@ -12,6 +12,7 @@ data class Address( val postcode: String?, val from: LocalDate, val to: LocalDate?, + val verified: Boolean?, val lastUpdated: LocalDate?, val type: String?, val status: String? @@ -27,6 +28,7 @@ data class Address( postcode: String? = null, from: LocalDate, to: LocalDate? = null, + verified: Boolean? = null, lastUpdated: LocalDate? = null, type: String? = null, status: String? = null @@ -47,6 +49,7 @@ data class Address( postcode, from, to, + verified, lastUpdated, type, status diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalDetails.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalDetails.kt index 7c78a7bd5e..73158dff40 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalDetails.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/personalDetails/PersonalDetails.kt @@ -8,10 +8,14 @@ data class PersonalDetails( val name: Name, val contacts: List, val mainAddress: Address?, - val otherAddresses: List
, + val otherAddresses: List
= emptyList(), + val previousAddresses: List
= emptyList(), val preferredGender: String, val dateOfBirth: LocalDate, val preferredName: String?, + val previousSurname: String?, + val preferredLanguage: String?, + val aliases: List, val telephoneNumber: String?, val mobileNumber: String?, val email: String?, diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Disability.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Disability.kt index 85c6f4397e..cef2a06835 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Disability.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Disability.kt @@ -5,6 +5,7 @@ import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import java.time.LocalDate @@ -37,3 +38,6 @@ class Disability( ) +interface DisabilityRepository : JpaRepository { + fun findByPersonId(personId: Long): List +} \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt index 92ad88d252..f1a8d76a95 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Person.kt @@ -3,10 +3,9 @@ package uk.gov.justice.digital.hmpps.integrations.delius.overview.entity import jakarta.persistence.* import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction -import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalContact import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import java.time.LocalDate @@ -52,43 +51,55 @@ class Person( @Column(name = "e_mail_address") val emailAddress: String?, + @Column(name = "previous_surname") + val previousSurname: String? = null, + @ManyToOne @JoinColumn(name = "gender_id") val gender: ReferenceData, @ManyToOne @JoinColumn(name = "religion_id") - val religion: ReferenceData?, + val religion: ReferenceData? = null, + + @ManyToOne + @JoinColumn(name = "language_id") + val language: ReferenceData? = null, @ManyToOne @JoinColumn(name = "sexual_orientation_id") val sexualOrientation: ReferenceData?, - @OneToMany(mappedBy = "personId") - val personalCircumstances: List, - - @OneToMany(mappedBy = "personId") - val disabilities: List, - - @OneToMany(mappedBy = "personId") - val provisions: List, - - @OneToMany(mappedBy = "personId") - val registrations: List = emptyList(), - - @OneToMany(mappedBy = "personId") - val personalContacts: List = emptyList(), - @Column(columnDefinition = "number") val softDeleted: Boolean = false ) -interface PersonOverviewRepository : JpaRepository { - @EntityGraph(attributePaths = ["gender"]) - fun findByCrn(crn: String): Person? +interface PersonSummaryEntity { + val forename: String + val secondName: String? + val thirdName: String? + val surname: String + val crn: String + val pnc: String? + val dateOfBirth: LocalDate } -fun PersonOverviewRepository.getPerson(crn: String) = findByCrn(crn) ?: throw NotFoundException("Person", "crn", crn) +interface PersonRepository : JpaRepository { + + fun findByCrn(crn: String): Person? + + @Query( + """ + select p.first_name as forename, p.second_name as secondName, p.third_name as thirdName, + p.surname, p.crn, p.pnc_number as pnc, p.date_of_birth_date as dateOfBirth + from offender p where p.crn = :crn and p.soft_deleted = 0 + """, nativeQuery = true + ) + fun findSummary(crn: String): PersonSummaryEntity? +} +fun PersonRepository.getPerson(crn: String) = findByCrn(crn) ?: throw NotFoundException("Person", "crn", crn) +fun PersonRepository.getSummary(crn: String): PersonSummaryEntity = + findSummary(crn) ?: throw NotFoundException("Person", "crn", crn) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/PersonalCircumstance.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/PersonalCircumstance.kt index 5b4f77b833..0741c2ca81 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/PersonalCircumstance.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/PersonalCircumstance.kt @@ -5,6 +5,7 @@ import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import java.time.LocalDate @@ -42,6 +43,10 @@ class PersonalCircumstance( ) +interface PersonCircumstanceRepository : JpaRepository { + fun findByPersonId(personId: Long): List +} + @Immutable @Entity @Table(name = "r_circumstance_sub_type") diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Provision.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Provision.kt index 228a275f64..4660af5fbb 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Provision.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Provision.kt @@ -5,6 +5,7 @@ import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import java.time.LocalDate @@ -35,4 +36,8 @@ class Provision( @Column(name = "soft_deleted", columnDefinition = "number") val softDeleted: Boolean = false, - ) \ No newline at end of file + ) + +interface ProvisionRepository : JpaRepository { + fun findByPersonId(personId: Long): List +} \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Registration.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Registration.kt index 14656cc206..a4ab486798 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Registration.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/overview/entity/Registration.kt @@ -5,12 +5,14 @@ import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository @Immutable @Entity @SQLRestriction("soft_deleted = 0 and deregistered = 0") @Table(name = "registration") class Registration( + @Column(name = "offender_id") val personId: Long, @@ -30,6 +32,10 @@ class Registration( val id: Long ) +interface RegistrationRepository : JpaRepository { + fun findByPersonId(personId: Long): List +} + @Entity @Immutable @Table(name = "r_register_type") diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalDetails.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt similarity index 65% rename from projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalDetails.kt rename to projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt index c9fe55f4ee..dd237ab0f3 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalDetails.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Address.kt @@ -3,22 +3,16 @@ package uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity import jakarta.persistence.* import org.hibernate.annotations.Immutable import org.hibernate.annotations.SQLRestriction +import org.hibernate.type.YesNoConverter import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository -import uk.gov.justice.digital.hmpps.exception.NotFoundException -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData import java.time.LocalDate -interface PersonalDetailsRepository : JpaRepository { - @EntityGraph(attributePaths = ["gender", "religion", "personalContacts"]) - fun findByCrn(crn: String): Person? -} - @Immutable @Entity(name = "PersonalDetailsAddress") @Table(name = "offender_address") -@SQLRestriction("soft_deleted = 0 and end_date is null") +@SQLRestriction("soft_deleted = 0") class PersonAddress( @Column(name = "offender_id") @@ -47,6 +41,9 @@ class PersonAddress( val startDate: LocalDate, val endDate: LocalDate? = null, + @Convert(converter = YesNoConverter::class) + val typeVerified: Boolean? = false, + @Column(name = "last_updated_datetime") val lastUpdated: LocalDate?, @@ -63,7 +60,30 @@ interface PersonAddressRepository : JpaRepository { fun findByPersonId(personId: Long): List } -fun PersonalDetailsRepository.getPersonDetails(crn: String) = - findByCrn(crn) ?: throw NotFoundException("Person", "crn", crn) +@Immutable +@Entity +@Table(name = "address") +@SQLRestriction("soft_deleted = 0") +class ContactAddress( + @Id + @Column(name = "address_id") + val id: Long, + val buildingName: String?, + val addressNumber: String?, + val streetName: String?, + val district: String?, + @Column(name = "town_city") + val town: String?, + val county: String?, + val postcode: String?, + val telephoneNumber: String?, + + @Column(name = "last_updated_datetime") + val lastUpdated: LocalDate, + @Convert(converter = YesNoConverter::class) + val typeVerified: Boolean? = false, + @Column(columnDefinition = "NUMBER") + val softDeleted: Boolean = false +) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Alias.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Alias.kt new file mode 100644 index 0000000000..127874d0ce --- /dev/null +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Alias.kt @@ -0,0 +1,34 @@ +package uk.gov.justice.digital.hmpps.integrations.delius.overview.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Id +import jakarta.persistence.Table +import org.hibernate.annotations.Immutable +import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository + +@Immutable +@Entity +@Table(name = "alias") +@SQLRestriction("soft_deleted = 0") +class Alias( + @Id + @Column(name = "alias_id") + val id: Long, + @Column(name = "offender_id") + val personId: Long, + @Column(name = "first_name", length = 35) + val forename: String, + @Column(name = "second_name", length = 35) + val secondName: String? = null, + @Column(name = "third_name", length = 35) + val thirdName: String? = null, + @Column(name = "surname", length = 35) + val surname: String, + val softDeleted: Boolean = false +) + +interface AliasRepository : JpaRepository { + fun findByPersonId(personId: Long): List +} diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalDocument.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Document.kt similarity index 100% rename from projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalDocument.kt rename to projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/Document.kt diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContact.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt similarity index 55% rename from projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContact.kt rename to projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt index 93008aa4a8..016f0138d7 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContact.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/personalDetails/entity/PersonalContactEntity.kt @@ -2,19 +2,19 @@ package uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity import jakarta.persistence.* import org.hibernate.annotations.Immutable -import org.hibernate.annotations.SQLRestriction +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import uk.gov.justice.digital.hmpps.exception.NotFoundException import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData -import java.time.LocalDate @Entity @Immutable @Table(name = "personal_contact") -class PersonalContact( +class PersonalContactEntity( @Id @Column(name = "personal_contact_id") val id: Long, - @Id @Column(name = "offender_id") val personId: Long, @@ -42,27 +42,17 @@ class PersonalContact( val notes: String? = null, ) -@Immutable -@Entity -@Table(name = "address") -@SQLRestriction("soft_deleted = 0") -class ContactAddress( - @Id - @Column(name = "address_id") - val id: Long, - val buildingName: String?, - val addressNumber: String?, - val streetName: String?, - val district: String?, - @Column(name = "town_city") - val town: String?, - val county: String?, - val postcode: String?, - val telephoneNumber: String?, +interface PersonalContactRepository : JpaRepository { + fun findByPersonId(personId: Long): List - @Column(name = "last_updated_datetime") - val lastUpdated: LocalDate, + @Query( + """ + select pc from PersonalContactEntity pc join Person p on p.id = pc.personId + where p.crn = :crn and pc.id = :contactId + """ + ) + fun findById(crn: String, contactId: Long): PersonalContactEntity? +} - @Column(columnDefinition = "NUMBER") - val softDeleted: Boolean = false -) \ No newline at end of file +fun PersonalContactRepository.getContact(crn: String, id: Long): PersonalContactEntity = + findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt index 3171d2bda9..bc5ff82a4d 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/OverviewService.kt @@ -4,24 +4,31 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import uk.gov.justice.digital.hmpps.api.model.name import uk.gov.justice.digital.hmpps.api.model.overview.* -import uk.gov.justice.digital.hmpps.api.model.overview.Disability import uk.gov.justice.digital.hmpps.api.model.overview.Offence -import uk.gov.justice.digital.hmpps.api.model.overview.PersonalCircumstance -import uk.gov.justice.digital.hmpps.api.model.overview.Provision import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Disability +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonalCircumstance +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Provision @Service class OverviewService( - private val personRepository: PersonOverviewRepository, + private val personRepository: PersonRepository, private val contactRepository: ContactRepository, private val requirementRepository: RequirementRepository, + private val registrationRepository: RegistrationRepository, + private val provisionRepository: ProvisionRepository, + private val disabilityRepository: DisabilityRepository, + private val personalCircumstanceRepository: PersonCircumstanceRepository, private val eventRepository: EventRepository ) { @Transactional fun getOverview(crn: String): Overview { val person = personRepository.getPerson(crn) - val personalDetails = person.toPersonalDetails() + val provisions = provisionRepository.findByPersonId(person.id) + val personalCircumstances = personalCircumstanceRepository.findByPersonId(person.id) + val disabilities = disabilityRepository.findByPersonId(person.id) + val personalDetails = person.toPersonalDetails(personalCircumstances, disabilities, provisions) val schedule = Schedule(contactRepository.firstAppointment(person.id)?.toNextAppointment()) val events = eventRepository.findByPersonId(person.id) val activeEvents = events.filter { it.active } @@ -29,6 +36,8 @@ class OverviewService( val activeEventsBreached = activeEvents.count { it.inBreach } val previousOrders = events.count { !it.active && it.disposal != null } val previousOrdersBreached = events.count { !it.active && it.disposal != null && it.inBreach } + val registrations = registrationRepository.findByPersonId(person.id) + return Overview( personalDetails = personalDetails, @@ -37,7 +46,7 @@ class OverviewService( sentences = sentences.mapNotNull { it }, activity = null, //ToDo compliance = Compliance(currentBreaches = activeEventsBreached, failureToComplyInLast12Months = 0), //ToDo - registrations = person.registrations.map { it.type.description } + registrations = registrations.map { it.type.description } ) } @@ -58,7 +67,11 @@ class OverviewService( rar = disposal?.let { getRar(it.id) }) } - fun Person.toPersonalDetails() = PersonalDetails( + fun Person.toPersonalDetails( + personalCircumstances: List, + disabilities: List, + provisions: List + ) = PersonalDetails( name = name(), mobileNumber = mobileNumber, telephoneNumber = telephoneNumber, @@ -73,14 +86,17 @@ class OverviewService( fun uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Offence.toOffence() = Offence(code = code, description = description) - fun uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonalCircumstance.toPersonalCircumstance() = - PersonalCircumstance(type = type.description, subType = subType.description) + fun PersonalCircumstance.toPersonalCircumstance() = + uk.gov.justice.digital.hmpps.api.model.overview.PersonalCircumstance( + type = type.description, + subType = subType.description + ) - fun uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Disability.toDisability() = - Disability(description = type.description) + fun Disability.toDisability() = + uk.gov.justice.digital.hmpps.api.model.overview.Disability(description = type.description) fun uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Provision.toProvision() = - Provision(description = type.description) + uk.gov.justice.digital.hmpps.api.model.overview.Provision(description = type.description) fun Contact.toNextAppointment() = NextAppointment(description = type.description, date = startDateTime()) diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt index 9355ec300c..5cb3c08e60 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsService.kt @@ -6,27 +6,41 @@ import org.springframework.transaction.annotation.Transactional import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody import uk.gov.justice.digital.hmpps.alfresco.AlfrescoClient import uk.gov.justice.digital.hmpps.api.model.Name +import uk.gov.justice.digital.hmpps.api.model.PersonSummary import uk.gov.justice.digital.hmpps.api.model.overview.PersonalCircumstance import uk.gov.justice.digital.hmpps.api.model.personalDetails.* -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.Person +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.ContactAddress -import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalContact @Service class PersonalDetailsService( - private val personalDetailsRepository: PersonalDetailsRepository, + private val personRepository: PersonRepository, private val addressRepository: PersonAddressRepository, private val documentRepository: DocumentRepository, + private val provisionRepository: ProvisionRepository, + private val disabilityRepository: DisabilityRepository, + private val personalCircumstanceRepository: PersonCircumstanceRepository, + private val aliasRepository: AliasRepository, + private val personalContactRepository: PersonalContactRepository, private val alfrescoClient: AlfrescoClient ) { @Transactional fun getPersonalDetails(crn: String): PersonalDetails { - val person = personalDetailsRepository.getPersonDetails(crn) - val addresses = addressRepository.findByPersonId(person.id) - val mainAddress = addresses.firstOrNull { it.status.code == "M" }?.toAddress() - val otherAddresses = addresses.filter { it.status.code != "M" }.map(PersonAddress::toAddress).mapNotNull { it } + val person = personRepository.getPerson(crn) + val provisions = provisionRepository.findByPersonId(person.id) + val personalCircumstances = personalCircumstanceRepository.findByPersonId(person.id) + val disabilities = disabilityRepository.findByPersonId(person.id) + val allAddresses = addressRepository.findByPersonId(person.id) + val currentAddresses = allAddresses.filter { it.endDate == null } + val previousAddresses = + allAddresses.filter { it.endDate != null }.map(PersonAddress::toAddress).mapNotNull { it } + val aliases = aliasRepository.findByPersonId(person.id) + val personalContacts = personalContactRepository.findByPersonId(person.id) + val mainAddress = currentAddresses.firstOrNull { it.status.code == "M" }?.toAddress() + val otherAddresses = + currentAddresses.filter { it.status.code != "M" }.map(PersonAddress::toAddress).mapNotNull { it } val documents = documentRepository.findByPersonId(person.id) return PersonalDetails( @@ -34,31 +48,35 @@ class PersonalDetailsService( name = person.name(), mainAddress = mainAddress, otherAddresses = otherAddresses, - contacts = person.personalContacts.map(PersonalContact::toContact), + previousAddresses = previousAddresses, + contacts = personalContacts.map(PersonalContactEntity::toContact), preferredGender = person.gender.description, dateOfBirth = person.dateOfBirth, preferredName = person.preferredName, telephoneNumber = person.telephoneNumber, mobileNumber = person.mobileNumber, - circumstances = Circumstances(lastUpdated = person.personalCircumstances.maxOfOrNull { it.lastUpdated }, - circumstances = person.personalCircumstances.map { + circumstances = Circumstances(lastUpdated = personalCircumstances.maxOfOrNull { it.lastUpdated }, + circumstances = personalCircumstances.map { PersonalCircumstance( it.subType.description, it.type.description ) }), disabilities = Disabilities( - lastUpdated = person.disabilities.maxOfOrNull { it.lastUpdated }, - disabilities = person.disabilities.map { it.type.description }), + lastUpdated = disabilities.maxOfOrNull { it.lastUpdated }, + disabilities = disabilities.map { it.type.description }), provisions = Provisions( - lastUpdated = person.provisions.maxOfOrNull { it.lastUpdated }, - provisions = person.provisions.map { it.type.description }), + lastUpdated = provisions.maxOfOrNull { it.lastUpdated }, + provisions = provisions.map { it.type.description }), documents = documents.map(PersonDocument::toDocument), pnc = person.pnc, religionOrBelief = person.religion?.description, sex = person.gender.description, sexualOrientation = person.sexualOrientation?.description, - email = person.emailAddress + email = person.emailAddress, + preferredLanguage = person.language?.description, + previousSurname = person.previousSurname, + aliases = aliases.map { Name(forename = it.forename, middleName = it.secondName, it.surname) } ) } @@ -66,9 +84,17 @@ class PersonalDetailsService( val filename = documentRepository.getDocument(crn, id) return alfrescoClient.streamDocument(id, filename) } + + fun getPersonContact(crn: String, contactId: Long): PersonalContact { + return personalContactRepository.getContact(crn, contactId).toContact() + } + + fun getPersonSummary(crn: String): PersonSummary { + return personRepository.getSummary(crn).toPersonSummary() + } } -fun PersonalContact.toContact() = uk.gov.justice.digital.hmpps.api.model.personalDetails.PersonalContact( +fun PersonalContactEntity.toContact() = PersonalContact( name = Name(forename = forename, middleName = middleNames, surname = surname), relationship = relationship, address = address.toAddress(), @@ -87,6 +113,7 @@ fun PersonAddress.toAddress() = Address.from( postcode = postcode, from = startDate, to = endDate, + verified = typeVerified, lastUpdated = lastUpdated, status = status.description, type = type.description @@ -103,4 +130,5 @@ fun ContactAddress.toAddress() = uk.gov.justice.digital.hmpps.api.model.personal lastUpdated = lastUpdated ) -fun PersonDocument.toDocument() = Document(id = alfrescoId, name = name, lastUpdated = lastUpdated) \ No newline at end of file +fun PersonDocument.toDocument() = Document(id = alfrescoId, name = name, lastUpdated = lastUpdated) +fun PersonSummaryEntity.toPersonSummary() = PersonSummary(Name(forename, secondName, surname), crn, pnc, dateOfBirth) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsControllerTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsControllerTest.kt index b17b1c8a6e..27a3c1f294 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsControllerTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/api/controller/PersonalDetailsControllerTest.kt @@ -13,6 +13,7 @@ import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody import uk.gov.justice.digital.hmpps.api.model.Name +import uk.gov.justice.digital.hmpps.api.model.PersonSummary import uk.gov.justice.digital.hmpps.api.model.personalDetails.Circumstances import uk.gov.justice.digital.hmpps.api.model.personalDetails.Disabilities import uk.gov.justice.digital.hmpps.api.model.personalDetails.PersonalDetails @@ -20,6 +21,7 @@ import uk.gov.justice.digital.hmpps.api.model.personalDetails.Provisions import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator import uk.gov.justice.digital.hmpps.service.PersonalDetailsService import uk.gov.justice.digital.hmpps.service.toAddress +import uk.gov.justice.digital.hmpps.service.toContact import java.time.LocalDate @ExtendWith(MockitoExtension::class) @@ -53,7 +55,10 @@ internal class PersonalDetailsControllerTest { preferredName = "Steve", religionOrBelief = "Christian", sex = "Male", - sexualOrientation = "Heterosexual" + sexualOrientation = "Heterosexual", + previousSurname = "Smith", + preferredLanguage = "English", + aliases = emptyList() ) whenever(personalDetailsService.getPersonalDetails(crn)).thenReturn(personalDetails) val res = controller.getPersonalDetails("X000005") @@ -70,4 +75,28 @@ internal class PersonalDetailsControllerTest { val res = controller.downloadDocument(crn, alfrescoId) Assertions.assertEquals(expectedResponse.statusCode, res.statusCode) } + + @Test + fun `calls get Person Contact function `() { + val crn = "X000005" + val id = 1234L + val expectedResponse = PersonDetailsGenerator.PERSONAL_CONTACT_1.toContact() + whenever(personalDetailsService.getPersonContact(crn, id)).thenReturn(expectedResponse) + val res = controller.getPersonContact(crn, id) + assertThat(res.relationship, equalTo(PersonDetailsGenerator.PERSONAL_CONTACT_1.relationship)) + } + + @Test + fun `calls get Person summary function `() { + val crn = "X000005" + val expectedResponse = PersonSummary( + Name(forename = "TestName", middleName = null, surname = "TestSurname"), pnc = "Test PNC", + crn = "CRN", + dateOfBirth = LocalDate.now(), + ) + + whenever(personalDetailsService.getPersonSummary(crn)).thenReturn(expectedResponse) + val res = controller.getPersonSummary(crn) + assertThat(res, equalTo(expectedResponse)) + } } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/OverviewServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/OverviewServiceTest.kt index 7f98edb362..79b5f7fca4 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/OverviewServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/OverviewServiceTest.kt @@ -13,17 +13,14 @@ import uk.gov.justice.digital.hmpps.data.generator.ContactGenerator.FIRST_APPT_C import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.generateEvent import uk.gov.justice.digital.hmpps.datetime.EuropeLondon -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.ContactRepository -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.EventRepository -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonOverviewRepository -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.RequirementRepository +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import java.time.ZonedDateTime @ExtendWith(MockitoExtension::class) internal class OverviewServiceTest { @Mock - lateinit var personRepository: PersonOverviewRepository + lateinit var personRepository: PersonRepository @Mock lateinit var contactRepository: ContactRepository @@ -34,6 +31,18 @@ internal class OverviewServiceTest { @Mock lateinit var eventRepository: EventRepository + @Mock + lateinit var registrationRepository: RegistrationRepository + + @Mock + lateinit var provisionRepository: ProvisionRepository + + @Mock + lateinit var disabilityRepository: DisabilityRepository + + @Mock + lateinit var personalCircumstanceRepository: PersonCircumstanceRepository + @InjectMocks lateinit var service: OverviewService @@ -46,6 +55,12 @@ internal class OverviewServiceTest { EuropeLondon ) whenever(personRepository.findByCrn(crn)).thenReturn(PersonGenerator.OVERVIEW) + + whenever(registrationRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(provisionRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(disabilityRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(personalCircumstanceRepository.findByPersonId(any())).thenReturn(PersonGenerator.PERSONAL_CIRCUMSTANCES) + whenever(contactRepository.findFirstAppointment(any(), any(), any(), any())).thenReturn( listOf(FIRST_APPT_CONTACT) ) @@ -85,7 +100,7 @@ internal class OverviewServiceTest { ) assertThat( res.personalDetails.personalCircumstances[0].type, - equalTo(PersonGenerator.OVERVIEW.personalCircumstances[0].type.description) + equalTo(PersonGenerator.PERSONAL_CIRCUMSTANCES[0].type.description) ) assertThat(res.sentences.size, equalTo(2)) assertThat(res.sentences[0].rar?.scheduled, equalTo(2)) diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsServiceTest.kt index 8f6e6df5d4..3f737990ac 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/PersonalDetailsServiceTest.kt @@ -16,15 +16,17 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo import uk.gov.justice.digital.hmpps.alfresco.AlfrescoClient import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator +import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.* import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.DocumentRepository import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonAddressRepository -import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalDetailsRepository +import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.PersonalContactRepository +import java.time.LocalDate @ExtendWith(MockitoExtension::class) internal class PersonalDetailsServiceTest { @Mock - lateinit var personRepository: PersonalDetailsRepository + lateinit var personRepository: PersonRepository @Mock lateinit var addressRepository: PersonAddressRepository @@ -32,6 +34,21 @@ internal class PersonalDetailsServiceTest { @Mock lateinit var documentRepository: DocumentRepository + @Mock + lateinit var provisionRepository: ProvisionRepository + + @Mock + lateinit var disabilityRepository: DisabilityRepository + + @Mock + lateinit var personalCircumstanceRepository: PersonCircumstanceRepository + + @Mock + lateinit var aliasRepository: AliasRepository + + @Mock + lateinit var personalContactRepository: PersonalContactRepository + @Mock lateinit var alfrescoClient: AlfrescoClient @@ -43,6 +60,11 @@ internal class PersonalDetailsServiceTest { val crn = "X000005" whenever(personRepository.findByCrn(crn)).thenReturn(PersonDetailsGenerator.PERSONAL_DETAILS) + whenever(provisionRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(disabilityRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(personalCircumstanceRepository.findByPersonId(any())).thenReturn(PersonGenerator.PERSONAL_CIRCUMSTANCES) + whenever(aliasRepository.findByPersonId(any())).thenReturn(emptyList()) + whenever(personalContactRepository.findByPersonId(any())).thenReturn(emptyList()) whenever(addressRepository.findByPersonId(any())).thenReturn( listOf( @@ -78,4 +100,38 @@ internal class PersonalDetailsServiceTest { val res = service.downloadDocument(crn, alfrescoId) Assertions.assertEquals(expectedResponse.statusCode, res.statusCode) } + + @Test + fun `calls get contact function`() { + val crn = "X000005" + val id = 1234L + whenever(personalContactRepository.findById(crn, id)).thenReturn(PersonDetailsGenerator.PERSONAL_CONTACT_1) + val res = service.getPersonContact(crn, id) + assertThat(res, equalTo(PersonDetailsGenerator.PERSONAL_CONTACT_1.toContact())) + } + + @Test + fun `calls get summary function`() { + val crn = "X000005" + + val expected = Summary( + forename = "TestName", + surname = "TestSurname", crn = "CRN", pnc = "PNC", dateOfBirth = LocalDate.now().minusYears(50) + ) + whenever(personRepository.findSummary(crn)).thenReturn(expected) + val res = service.getPersonSummary(crn) + assertThat(res, equalTo(expected.toPersonSummary())) + } + + data class Summary( + override val forename: String, + override val secondName: String? = null, + override val thirdName: String? = null, + override val surname: String, + override val crn: String, + override val pnc: String?, + override val dateOfBirth: LocalDate + ) : PersonSummaryEntity { + + } } \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt index d3891d3fdc..a6d21c207b 100644 --- a/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt +++ b/projects/manage-supervision-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/SentenceServiceTest.kt @@ -14,7 +14,6 @@ import uk.gov.justice.digital.hmpps.api.model.sentence.MainOffence import uk.gov.justice.digital.hmpps.api.model.sentence.Offence import uk.gov.justice.digital.hmpps.api.model.sentence.SentenceOverview import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator -import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonOverviewRepository import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.EventSentenceRepository import java.time.LocalDate