Skip to content

Commit

Permalink
PI-2289: Added aliases to soc details endpoint (#3930)
Browse files Browse the repository at this point in the history
* PI-2289: Added aliases to soc details endpoint
  • Loading branch information
pmcphee77 authored Jun 20, 2024
1 parent 4c65efa commit 07ad57a
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class DataLoader(
DetailsGenerator.INSTITUTION,
DetailsGenerator.RELIGION,
DetailsGenerator.NATIONALITY,
DetailsGenerator.MALE,
DetailsGenerator.FEMALE,
DetailsGenerator.PERSON,
DetailsGenerator.ALIAS_1,
DetailsGenerator.ALIAS_2,
DetailsGenerator.DEFAULT_PA,
DetailsGenerator.DISTRICT,
DetailsGenerator.TEAM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ object DetailsGenerator {
"BRITISH",
"BRITISH"
)

val MALE = ReferenceData(
IdGenerator.getAndIncrement(),
"MALE",
"MALE"
)

val FEMALE = ReferenceData(
IdGenerator.getAndIncrement(),
"FEMALE",
"FEMALE"
)

val PERSON = DetailPerson(
IdGenerator.getAndIncrement(),
"X012773",
Expand All @@ -22,6 +35,7 @@ object DetailsGenerator {
RELIGION,
NATIONALITY,
listOf(),
listOf(),
LocalDate.now().minusYears(18),
"Smith",
"Bob",
Expand All @@ -30,6 +44,29 @@ object DetailsGenerator {
true
)

val ALIAS_1 = PersonAlias(
PERSON,
"Phil",
"Jack",
"Paul",
"Brown",
LocalDate.of(1977, 12, 8),
MALE,
false,
IdGenerator.getAndIncrement(),
)

val ALIAS_2 = PersonAlias(
PERSON,
"Phillis",
"Jackie",
"Paula",
"Brown",
LocalDate.of(1976, 5, 18),
FEMALE,
false,
IdGenerator.getAndIncrement(),
)
val INSTITUTION = Institution(IdGenerator.getAndIncrement(), "HMP-LDN")

val RELEASE_TYPE = ReferenceData(IdGenerator.getAndIncrement(), "RSN1", "Release reason")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ internal class DetailsIntegrationTest {
DetailsGenerator.RECALL.date,
DetailsGenerator.RECALL.reason.description,
NSIGenerator.RECALL_NSI.referralDate,
NSIGenerator.BREACH_NSI.referralDate
NSIGenerator.BREACH_NSI.referralDate,
listOf(
OffenderAlias(
id = DetailsGenerator.ALIAS_1.aliasID,
dateOfBirth = DetailsGenerator.ALIAS_1.dateOfBirth,
firstName = DetailsGenerator.ALIAS_1.firstName,
middleNames = listOf(DetailsGenerator.ALIAS_1.secondName!!, DetailsGenerator.ALIAS_1.thirdName!!),
surname = DetailsGenerator.ALIAS_1.surname,
gender = DetailsGenerator.MALE.description
),
OffenderAlias(
id = DetailsGenerator.ALIAS_2.aliasID,
dateOfBirth = DetailsGenerator.ALIAS_2.dateOfBirth,
firstName = DetailsGenerator.ALIAS_2.firstName,
middleNames = listOf(DetailsGenerator.ALIAS_2.secondName!!, DetailsGenerator.ALIAS_2.thirdName!!),
surname = DetailsGenerator.ALIAS_2.surname,
gender = DetailsGenerator.FEMALE.description
)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class DetailPerson(
@OneToMany(mappedBy = "person")
val personManager: List<PersonManager>,

@OneToMany(mappedBy = "person")
val offenderAliases: List<PersonAlias>,

@Column(name = "date_of_birth_date")
val dateOfBirth: LocalDate,

Expand Down Expand Up @@ -164,6 +167,42 @@ class DetailDistrict(
val id: Long
)

@Immutable
@Entity
@Table(name = "alias")
@SQLRestriction("soft_deleted = 0")
class PersonAlias(

@ManyToOne
@JoinColumn(name = "offender_id")
val person: DetailPerson,

@Column(name = "first_name")
val firstName: String,

@Column(name = "second_name")
val secondName: String? = null,

@Column(name = "third_name")
val thirdName: String? = null,

val surname: String,

@Column(name = "date_of_birth_date")
val dateOfBirth: LocalDate,

@ManyToOne
@JoinColumn(name = "gender_id")
val gender: ReferenceData,

@Column(name = "soft_deleted", columnDefinition = "number")
val softDeleted: Boolean = false,

@Id
@Column(name = "alias_id")
val aliasID: Long,
)

interface DetailRepository : JpaRepository<DetailPerson, Long> {
@EntityGraph(
attributePaths = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ data class Detail(
val lastRecallDate: LocalDate? = null,
val recallReason: String? = null,
val nsiRecallDate: LocalDate? = null,
val nsiBreachDate: LocalDate? = null
val nsiBreachDate: LocalDate? = null,
val offenderAliases: List<OffenderAlias> = emptyList()
)

data class Name(
Expand Down Expand Up @@ -59,4 +60,13 @@ data class KeyDate(
val data: LocalDate
)

data class OffenderAlias(
val id: Long,
val dateOfBirth: LocalDate?,
val firstName: String,
val middleNames: List<String>,
val surname: String,
val gender: String
)

fun DetailPerson.name() = Name(forename, listOfNotNull(secondName, thirdName).joinToString(" "), surname)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import uk.gov.justice.digital.hmpps.controller.IdentifierType
import uk.gov.justice.digital.hmpps.entity.*
import uk.gov.justice.digital.hmpps.model.*
import uk.gov.justice.digital.hmpps.model.KeyDate
import uk.gov.justice.digital.hmpps.model.OffenderAlias
import uk.gov.justice.digital.hmpps.model.Team
import java.time.LocalDate

Expand Down Expand Up @@ -77,7 +78,17 @@ class DetailService(
recallDate,
recallReason,
nsiDates.firstOrNull { it.name == "recall" }?.referralDate,
nsiDates.firstOrNull { it.name == "breach" }?.referralDate
nsiDates.firstOrNull { it.name == "breach" }?.referralDate,
offenderAliases = p.offenderAliases.map {
OffenderAlias(
id = it.aliasID,
dateOfBirth = it.dateOfBirth,
firstName = it.firstName,
middleNames = listOfNotNull(it.secondName, it.thirdName),
surname = it.surname,
gender = it.gender.description
)
},
)
}
}
Expand Down

0 comments on commit 07ad57a

Please sign in to comment.