Skip to content

Commit

Permalink
PI-1991: Added address tel number and circ, dis and provision endpoin…
Browse files Browse the repository at this point in the history
…ts (#3480)

* PI-1991: Added address tel number and circ, dis and provision endpoints

* PI-1991: Added requires interpreter
  • Loading branch information
pmcphee77 authored Mar 18, 2024
1 parent e752c71 commit 9c25582
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class DataLoader(
PersonDetailsGenerator.PROVISION_2,
PersonDetailsGenerator.PERSONAL_CIRC_1,
PersonDetailsGenerator.PERSONAL_CIRC_2,
PersonDetailsGenerator.PERSONAL_CIRC_PREV,
PersonDetailsGenerator.RELATIONSHIP_TYPE,
PersonDetailsGenerator.CONTACT_ADDRESS,
PersonDetailsGenerator.PERSONAL_CONTACT_1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.data.generator.UserGenerator.USER
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import java.time.LocalDate
Expand Down Expand Up @@ -128,14 +129,16 @@ object PersonGenerator {
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "D01", "Mental Illness"),
LocalDate.now().minusDays(1),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER
),
Disability(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "D02", "Visual Impairment"),
LocalDate.now(),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER
)
)

Expand All @@ -149,14 +152,21 @@ object PersonGenerator {
"Full-time employed (30 or more hours per week"
),
LocalDate.now(),
LocalDate.now().minusDays(1)
),
USER,
null,
true,
LocalDate.now().minusDays(1),

),
PersonalCircumstance(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "A02", "Accommodation"),
PersonalCircumstanceSubType(IdGenerator.getAndIncrement(), "Friends/Family (settled)"),
LocalDate.now(),
USER,
null,
true,
LocalDate.now().minusDays(1)
)
)
Expand All @@ -167,14 +177,16 @@ object PersonGenerator {
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "FF01", "Flex refreshment breaks"),
LocalDate.now(),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER
),
Provision(
IdGenerator.getAndIncrement(),
OVERVIEW.id,
ReferenceData(IdGenerator.getAndIncrement(), "CC02", "Colour/visibility marking"),
LocalDate.now(),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ object PersonDetailsGenerator {
val GENDER_IDENTITY_RD = ReferenceData(IdGenerator.getAndIncrement(), "GI", "Test Gender Identity")

val PERSONAL_DETAILS = generatePersonDetails(
"X000005", "Caroline",
"Louise", "Bloggs", "Caz", GENDER_FEMALE, RELIGION_DEFAULT,
SEXUAL_ORIENTATION, LANGUAGE_RD, "Smith", GENDER_IDENTITY_RD, "Some gender description"
"X000005",
"Caroline",
"Louise",
"Bloggs",
"Caz",
GENDER_FEMALE,
RELIGION_DEFAULT,
SEXUAL_ORIENTATION,
LANGUAGE_RD,
"Smith",
GENDER_IDENTITY_RD,
"Some gender description",
requiresInterpreter = true
)

val ALIAS_1 = generateAlias("Sam", "Edward", "Smith", PERSONAL_DETAILS.id)
Expand All @@ -43,29 +53,33 @@ object PersonDetailsGenerator {
PERSONAL_DETAILS.id,
DISABILITY_1_RD,
LocalDate.now().minusDays(1),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER,
)
val DISABILITY_2 = Disability(
IdGenerator.getAndIncrement(),
PERSONAL_DETAILS.id,
DISABILITY_2_RD,
LocalDate.now().minusDays(2),
LocalDate.now().minusDays(2)
LocalDate.now().minusDays(2),
USER,
)

val PROVISION_1 = Provision(
IdGenerator.getAndIncrement(),
PERSONAL_DETAILS.id,
PROVISION_1_RD,
LocalDate.now().minusDays(1),
LocalDate.now().minusDays(1)
LocalDate.now().minusDays(1),
USER,
)
val PROVISION_2 = Provision(
IdGenerator.getAndIncrement(),
PERSONAL_DETAILS.id,
PROVISION_2_RD,
LocalDate.now().minusDays(2),
LocalDate.now().minusDays(2)
LocalDate.now().minusDays(2),
USER,
)

val PERSONAL_CIRC_1 = PersonalCircumstance(
Expand All @@ -74,6 +88,9 @@ object PersonDetailsGenerator {
PERSONAL_CIRCUMSTANCE_1_RD,
PERSONAL_CIRCUMSTANCE_SUBTYPE_1,
LocalDate.now().minusDays(1),
USER,
notes = "Some Notes",
evidenced = true,
LocalDate.now().minusDays(1)
)
val PERSONAL_CIRC_2 = PersonalCircumstance(
Expand All @@ -82,9 +99,25 @@ object PersonDetailsGenerator {
PERSONAL_CIRCUMSTANCE_2_RD,
PERSONAL_CIRCUMSTANCE_SUBTYPE_2,
LocalDate.now().minusDays(1),
USER,
notes = "Some Notes",
evidenced = true,
LocalDate.now().minusDays(1)
)

val PERSONAL_CIRC_PREV = PersonalCircumstance(
IdGenerator.getAndIncrement(),
PERSONAL_DETAILS.id,
PERSONAL_CIRCUMSTANCE_2_RD,
PERSONAL_CIRCUMSTANCE_SUBTYPE_2,
LocalDate.now().minusDays(1),
USER,
notes = "Previous circumstance Notes",
evidenced = true,
LocalDate.now().minusDays(8),
endDate = LocalDate.now().minusDays(3),
)

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 = PersonalContactEntity(
Expand Down Expand Up @@ -153,6 +186,7 @@ object PersonDetailsGenerator {
null,
null,
null,
telephoneNumber = null,
LocalDate.now(),
null,
true,
Expand Down Expand Up @@ -214,13 +248,24 @@ object PersonDetailsGenerator {
status = status,
type = type,
typeVerified = verified,
telephoneNumber = "0191876865",
lastUpdatedUser = USER
)

fun generatePersonDetails(
crn: String, forename: String, secondName: String, surname: String, preferredName: String,
gender: ReferenceData, religion: ReferenceData, sexualOrientation: ReferenceData, language: ReferenceData,
previousSurname: String, genderIdentity: ReferenceData, genderIdentityDescription: String
crn: String,
forename: String,
secondName: String,
surname: String,
preferredName: String,
gender: ReferenceData,
religion: ReferenceData,
sexualOrientation: ReferenceData,
language: ReferenceData,
previousSurname: String,
genderIdentity: ReferenceData,
genderIdentityDescription: String,
requiresInterpreter: Boolean = false
) = Person(
id = IdGenerator.getAndIncrement(),
crn = crn,
Expand All @@ -239,7 +284,8 @@ object PersonDetailsGenerator {
language = language,
previousSurname = previousSurname,
genderIdentity = genderIdentity,
genderIdentityDescription = genderIdentityDescription
genderIdentityDescription = genderIdentityDescription,
requiresInterpreter = requiresInterpreter,
)

fun generateDocument(personId: Long, alfrescoId: String, name: String, documentType: String) = PersonDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ 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.AddressOverview
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.api.model.personalDetails.*
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.ALIAS_1
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.DISABILITY_1
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.DISABILITY_2
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_CIRC_1
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_CIRC_2
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_CIRC_PREV
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.data.generator.personalDetails.PersonDetailsGenerator.PREVIOUS_ADDRESS
import uk.gov.justice.digital.hmpps.service.toContact
import uk.gov.justice.digital.hmpps.service.toSummary
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PROVISION_1
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PROVISION_2
import uk.gov.justice.digital.hmpps.service.*
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
import java.time.LocalDate
Expand Down Expand Up @@ -82,6 +86,7 @@ internal class PersonalDetailsIntegrationTest {
assertThat(res.aliases[0].forename, equalTo(ALIAS_1.forename))
assertThat(res.genderIdentity, equalTo("Test Gender Identity"))
assertThat(res.selfDescribedGender, equalTo("Some gender description"))
assertThat(res.requiresInterpreter, equalTo(true))
}

@Test
Expand Down Expand Up @@ -167,7 +172,6 @@ internal class PersonalDetailsIntegrationTest {
@Test
fun `addresses are returned`() {
val person = PERSONAL_DETAILS
val contact = PERSONAL_CONTACT_1
val res = mockMvc
.perform(get("/personal-details/${person.crn}/addresses").withToken())
.andExpect(status().isOk)
Expand All @@ -185,4 +189,62 @@ internal class PersonalDetailsIntegrationTest {
.perform(get("/personal-details/X999999/addresses").withToken())
.andExpect(status().isNotFound)
}

@Test
fun `circumstances are returned`() {
val person = PERSONAL_DETAILS
val res = mockMvc
.perform(get("/personal-details/${person.crn}/circumstances").withToken())
.andExpect(status().isOk)
.andReturn().response.contentAsJson<CircumstanceOverview>()
assertThat(res.personSummary, equalTo(person.toSummary()))
assertThat(res.circumstances[0], equalTo(PERSONAL_CIRC_1.toCircumstance()))
assertThat(res.circumstances[1], equalTo(PERSONAL_CIRC_2.toCircumstance()))
assertThat(res.circumstances[2], equalTo(PERSONAL_CIRC_PREV.toCircumstance()))
}

@Test
fun `circumstances not found`() {
mockMvc
.perform(get("/personal-details/X999999/circumstances").withToken())
.andExpect(status().isNotFound)
}

@Test
fun `disabilities are returned`() {
val person = PERSONAL_DETAILS
val res = mockMvc
.perform(get("/personal-details/${person.crn}/disabilities").withToken())
.andExpect(status().isOk)
.andReturn().response.contentAsJson<DisabilityOverview>()
assertThat(res.personSummary, equalTo(person.toSummary()))
assertThat(res.disabilities[0], equalTo(DISABILITY_1.toDisability()))
assertThat(res.disabilities[1], equalTo(DISABILITY_2.toDisability()))
}

@Test
fun `disabilities not found`() {
mockMvc
.perform(get("/personal-details/X999999/disabilities").withToken())
.andExpect(status().isNotFound)
}

@Test
fun `provisions are returned`() {
val person = PERSONAL_DETAILS
val res = mockMvc
.perform(get("/personal-details/${person.crn}/provisions").withToken())
.andExpect(status().isOk)
.andReturn().response.contentAsJson<ProvisionOverview>()
assertThat(res.personSummary, equalTo(person.toSummary()))
assertThat(res.provisions[0], equalTo(PROVISION_1.toProvision()))
assertThat(res.provisions[1], equalTo(PROVISION_2.toProvision()))
}

@Test
fun `provisions not found`() {
mockMvc
.perform(get("/personal-details/X999999/provisions").withToken())
.andExpect(status().isNotFound)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ class PersonalDetailsController(private val personalDetailsService: PersonalDeta
@Operation(summary = "Person Addresses")
fun getPersonAddresses(@PathVariable crn: String) =
personalDetailsService.getPersonAddresses(crn)

@GetMapping("/circumstances")
@Operation(summary = "Person Circumstances")
fun getPersonCircumstances(@PathVariable crn: String) =
personalDetailsService.getPersonCircumstances(crn)

@GetMapping("/disabilities")
@Operation(summary = "Person Disabilities")
fun getPersonDisabilities(@PathVariable crn: String) =
personalDetailsService.getPersonDisabilities(crn)

@GetMapping("/provisions")
@Operation(summary = "Person Provisions")
fun getPersonProvisions(@PathVariable crn: String) =
personalDetailsService.getPersonProvisions(crn)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class Address(
val town: String?,
val county: String?,
val postcode: String?,
val telephoneNumber: String?,
val from: LocalDate,
val to: LocalDate?,
val verified: Boolean?,
Expand All @@ -28,6 +29,7 @@ data class Address(
town: String? = null,
county: String? = null,
postcode: String? = null,
telephoneNumber: String?,
from: LocalDate,
to: LocalDate? = null,
verified: Boolean? = null,
Expand All @@ -50,6 +52,7 @@ data class Address(
town,
county,
postcode,
telephoneNumber,
from,
to,
verified,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.justice.digital.hmpps.api.model.personalDetails

import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.PersonSummary
import java.time.LocalDate

data class CircumstanceOverview(
val personSummary: PersonSummary,
val circumstances: List<Circumstance>
)

data class Circumstance(
val type: String,
val subType: String,
val notes: String?,
val verified: Boolean = false,
val startDate: LocalDate,
val lastUpdated: LocalDate,
val lastUpdatedBy: Name
)
Loading

0 comments on commit 9c25582

Please sign in to comment.