Skip to content

Commit

Permalink
PI-1837: Add registrations to overview (#3449)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 authored Mar 8, 2024
1 parent 72a4993 commit fb5efdb
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class DataLoader(
PersonGenerator.REQUIREMENT,
PersonGenerator.REQUIREMENT_CONTACT_1,
PersonGenerator.REQUIREMENT_CONTACT_2,
PersonGenerator.REGISTER_TYPE_1,
PersonGenerator.REGISTER_TYPE_2,
PersonGenerator.REGISRATION_1,
PersonGenerator.REGISRATION_2
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ object PersonGenerator {
requirementId = REQUIREMENT.id
)

val REGISTER_TYPE_1 = generateRegisterType("CODE1", "Restraining Order")
val REGISTER_TYPE_2 = generateRegisterType("CODE2", "Domestic Abuse Perpetrator")
val REGISRATION_1 = generateRegistration(REGISTER_TYPE_1, OVERVIEW.id)
val REGISRATION_2 = generateRegistration(REGISTER_TYPE_2, OVERVIEW.id)

fun generateEvent(
person: Person,
id: Long = IdGenerator.getAndIncrement(),
Expand Down Expand Up @@ -165,7 +170,8 @@ object PersonGenerator {
personalCircumstances = personalCircumstances,
provisions = provisions,
telephoneNumber = telephoneNumber,
preferredName = preferredName
preferredName = preferredName,
registrations = emptyList()
)

fun generateRequirement(
Expand Down Expand Up @@ -216,5 +222,17 @@ object PersonGenerator {
id: Long = IdGenerator.getAndIncrement(),
softDeleted: Boolean = false
) = AdditionalOffence(id, event, date, offence, softDeleted)

fun generateRegisterType(
code: String,
description: String,
id: Long = IdGenerator.getAndIncrement()
) = RegisterType(code, description, id)

fun generateRegistration(
type: RegisterType,
personId: Long,
id: Long = IdGenerator.getAndIncrement(),
) = Registration(personId, type, false, false, id)
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal class OverviewIntegrationTest {
assertThat(res.sentences[0].eventNumber, equalTo(EVENT_1.eventNumber))
assertThat(res.personalDetails.dateOfBirth, equalTo(OVERVIEW.dateOfBirth))
assertThat(res.personalDetails.dateOfBirth, equalTo(OVERVIEW.dateOfBirth))
assertThat(res.registrations, equalTo(listOf("Restraining Order", "Domestic Abuse Perpetrator")))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ data class Overview(
val personalDetails: PersonalDetails,
val previousOrders: PreviousOrders,
val schedule: Schedule,
val sentences: List<Sentence>
val sentences: List<Sentence>,
val registrations: List<String>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Person(
@OneToMany(mappedBy = "personId")
val provisions: List<Provision>,

@OneToMany(mappedBy = "personId")
val registrations: List<Registration>,

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.justice.digital.hmpps.integrations.delius.overview.entity

import jakarta.persistence.*
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.hibernate.annotations.Immutable
import org.hibernate.annotations.SQLRestriction

@Immutable
@Entity
@SQLRestriction("soft_deleted = 0 and deregistered = 0")
@Table(name = "registration")
class Registration(
@Column(name = "offender_id")
val personId: Long,

@ManyToOne
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "register_type_id")
val type: RegisterType,

@Column(name = "deregistered", columnDefinition = "number")
val deRegistered: Boolean,

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

@Id
@Column(name = "registration_id")
val id: Long
)

@Entity
@Immutable
@Table(name = "r_register_type")
class RegisterType(

val code: String,

val description: String,

@Id
@Column(name = "register_type_id")
val id: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OverviewService(
sentences = sentences.mapNotNull { it },
activity = null, //ToDo
compliance = Compliance(currentBreaches = activeEventsBreached, failureToComplyInLast12Months = 0), //ToDo
registrations = person.registrations.map { it.type.description }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class OverviewControllerTest {
previousOrders = PreviousOrders(0, 1),
sentences = emptyList(),
schedule = Schedule(null),
registrations = emptyList()
)
whenever(overviewService.getOverview(crn)).thenReturn(overview)
val res = controller.getOverview("X000004")
Expand Down

0 comments on commit fb5efdb

Please sign in to comment.