Skip to content

Commit

Permalink
Feature/pi 1939 mas probabtion history (#3596)
Browse files Browse the repository at this point in the history
* PI-1939 - add probation history

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add probation history

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add probation history

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - refactor variable names

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add professional contact details

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add professional contact details

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add professional contact details

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - add professional contact details

Signed-off-by: Amardeep Chimber <[email protected]>

* PI-1939 - update tests

* PI-1939 - use offender_manager instead of perseonal_contact table for probabtion history

Signed-off-by: Amardeep Chimber <[email protected]>

* Formatting changes

* PI-1939 - add most recent termination date from inactive events to probation history

Signed-off-by: Amardeep Chimber <[email protected]>

---------

Signed-off-by: Amardeep Chimber <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
achimber-moj and github-actions[bot] authored Apr 9, 2024
1 parent 5e3b5db commit 2dd1f93
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.data.generator.CourtAppearanceGenerator.COURT_APPEARANCE
import uk.gov.justice.digital.hmpps.data.generator.CourtReportGenerator.COURT_REPORT
import uk.gov.justice.digital.hmpps.data.generator.CourtReportGenerator.DEFAULT_TYPE
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.COURT_DOCUMENT
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EVENT_DOCUMENT
import uk.gov.justice.digital.hmpps.user.AuditUserRepository

@Component
Expand Down Expand Up @@ -71,15 +67,20 @@ class DataLoader(
)
)
entityManager.persist(CourtGenerator.DEFAULT)
entityManager.persist(COURT_APPEARANCE)

entityManager.persist(DEFAULT_TYPE)
entityManager.persist(COURT_REPORT)
entityManager.persist(CourtReportGenerator.COURT_APPEARANCE)
entityManager.persist(CourtReportGenerator.DEFAULT_TYPE)
entityManager.persist(CourtReportGenerator.EVENT_DOCUMENT)
entityManager.persist(CourtReportGenerator.COURT_DOCUMENT)
entityManager.persist(CourtReportGenerator.COURT_REPORT)
entityManager.persist(COURT_APPEARANCE)

entityManager.persist(EVENT_DOCUMENT)
entityManager.persist(COURT_DOCUMENT)
entityManager.persist(CourtReportGenerator.DEFAULT_TYPE)
entityManager.persist(CourtReportGenerator.COURT_REPORT)

entityManager.persistAll(
OffenderManagerGenerator.OFFENDER_MANAGER_ACTIVE,
OffenderManagerGenerator.OFFENDER_MANAGER_INACTIVE,
PersonGenerator.DEFAULT_DISPOSAL_TYPE,
PersonGenerator.ACTIVE_ORDER,
PersonGenerator.INACTIVE_ORDER_1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtAppearance
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.CourtReportDocument
import uk.gov.justice.digital.hmpps.integrations.delius.personalDetails.entity.EventDocument
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtReport
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CourtReportType
import java.time.ZonedDateTime

object CourtReportGenerator {

val COURT_APPEARANCE = CourtAppearanceGenerator.generate()
val DEFAULT_TYPE = CourtReportType(IdGenerator.getAndIncrement(), "Pre-Sentence Report - Fast")
val COURT_REPORT = generate(DEFAULT_TYPE, CourtAppearanceGenerator.COURT_APPEARANCE)
fun generate(
courtReportType: CourtReportType?,
courtAppearance: CourtAppearance
) = CourtReport(IdGenerator.getAndIncrement(), courtReportType, courtAppearance)
val COURT_REPORT_TYPE = DEFAULT_TYPE
val COURT_REPORT = CourtReport(IdGenerator.getAndIncrement(), COURT_REPORT_TYPE, COURT_APPEARANCE)

val COURT_DOCUMENT = generateCourtDocument(
PersonGenerator.OVERVIEW.id,
"A003",
"court report",
"DOCUMENT",
COURT_REPORT.courtReportId
)

val EVENT_DOCUMENT = generateEventDocument(
PersonGenerator.OVERVIEW.id,
"A004",
"event report",
"DOCUMENT",
PersonGenerator.EVENT_1.id
)

fun generateCourtDocument(
personId: Long,
alfrescoId: String,
name: String,
documentType: String,
primaryKeyId: Long? = null
): CourtReportDocument {
val doc = CourtReportDocument()
doc.id = IdGenerator.getAndIncrement()
doc.lastUpdated = ZonedDateTime.now().minusDays(1)
doc.alfrescoId = alfrescoId
doc.name = name
doc.personId = personId
doc.primaryKeyId = primaryKeyId
doc.type = documentType
return doc
}

fun generateEventDocument(
personId: Long,
alfrescoId: String,
name: String,
documentType: String,
primaryKeyId: Long? = null
): EventDocument {
val doc = EventDocument()
doc.id = IdGenerator.getAndIncrement()
doc.lastUpdated = ZonedDateTime.now().minusDays(3)
doc.alfrescoId = alfrescoId
doc.name = name
doc.personId = personId
doc.primaryKeyId = primaryKeyId
doc.type = documentType
return doc
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.OffenderManager
import java.time.LocalDate

object OffenderManagerGenerator {

val OFFENDER_MANAGER_ACTIVE =
OffenderManager(IdGenerator.getAndIncrement(), PersonGenerator.OVERVIEW, null, 1234, null)
val OFFENDER_MANAGER_INACTIVE =
OffenderManager(IdGenerator.getAndIncrement(), PersonGenerator.OVERVIEW, null, 1234, LocalDate.now())
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ object PersonGenerator {
val DEFAULT_DISPOSAL_TYPE = generateDisposalType("DFS", "Default Sentence Type", "NP", 0)
val ACTIVE_ORDER = generateDisposal(EVENT_1, length = 12)

val INACTIVE_ORDER_1 = generateDisposal(INACTIVE_EVENT_1)
val INACTIVE_ORDER_2 = generateDisposal(INACTIVE_EVENT_2)
val INACTIVE_ORDER_1 = generateDisposal(INACTIVE_EVENT_1, LocalDate.of(2023, 4, 8))
val INACTIVE_ORDER_2 = generateDisposal(INACTIVE_EVENT_2, LocalDate.of(2023, 4, 9))

val ADD_OFF_1 = generateOffence("Burglary", "ADD1")
val ADDITIONAL_OFFENCE_1 = generateAdditionalOffence(
Expand Down Expand Up @@ -284,6 +284,7 @@ object PersonGenerator {

fun generateDisposal(
event: Event,
terminationDate: LocalDate? = null,
date: LocalDate = LocalDate.now().minusDays(14),
length: Long? = null,
type: DisposalType = DEFAULT_DISPOSAL_TYPE,
Expand All @@ -292,7 +293,19 @@ object PersonGenerator {
active: Boolean = true,
softDeleted: Boolean = false,
id: Long = IdGenerator.getAndIncrement()
) = Disposal(event, date, length, type, null, enteredEndDate, notionalEndDate, active, softDeleted, id)
) = Disposal(
event,
date,
length,
type,
null,
enteredEndDate,
notionalEndDate,
terminationDate,
active,
softDeleted,
id
)

fun generateOffence(
description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import uk.gov.justice.digital.hmpps.data.generator.IdGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
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.personalDetails.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.PersonalContactEntity
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import java.time.LocalDate
import java.time.ZonedDateTime
Expand Down Expand Up @@ -117,6 +120,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 = PersonalContactEntity(
IdGenerator.getAndIncrement(),
Expand All @@ -129,6 +133,7 @@ object PersonDetailsGenerator {
"0897676554",
LocalDate.now(),
LocalDate.now(),
LocalDate.now(),
RELATIONSHIP_TYPE,
CONTACT_ADDRESS,
USER
Expand Down Expand Up @@ -197,22 +202,6 @@ object PersonDetailsGenerator {
val DOCUMENT_1 = generateDocument(PERSONAL_DETAILS.id, "A001", "induction.doc", "DOCUMENT")
val DOCUMENT_2 = generateDocument(PERSONAL_DETAILS.id, "A002", "other.doc", "DOCUMENT")

val COURT_DOCUMENT = generateCourtDocument(
PersonGenerator.OVERVIEW.id,
"A003",
"court report",
"DOCUMENT",
COURT_REPORT.courtReportId
)

val EVENT_DOCUMENT = generateEventDocument(
PersonGenerator.OVERVIEW.id,
"A004",
"event report",
"DOCUMENT",
PersonGenerator.EVENT_1.id
)

fun generateContactAddress(
addressNumber: String,
streetName: String,
Expand Down Expand Up @@ -320,42 +309,6 @@ object PersonDetailsGenerator {
return doc
}

fun generateCourtDocument(
personId: Long,
alfrescoId: String,
name: String,
documentType: String,
primaryKeyId: Long? = null
): CourtReportDocument {
val doc = CourtReportDocument()
doc.id = IdGenerator.getAndIncrement()
doc.lastUpdated = ZonedDateTime.now().minusDays(1)
doc.alfrescoId = alfrescoId
doc.name = name
doc.personId = personId
doc.primaryKeyId = primaryKeyId
doc.type = documentType
return doc
}

fun generateEventDocument(
personId: Long,
alfrescoId: String,
name: String,
documentType: String,
primaryKeyId: Long? = null
): EventDocument {
val doc = EventDocument()
doc.id = IdGenerator.getAndIncrement()
doc.lastUpdated = ZonedDateTime.now().minusDays(3)
doc.alfrescoId = alfrescoId
doc.name = name
doc.personId = personId
doc.primaryKeyId = primaryKeyId
doc.type = documentType
return doc
}

fun generateAlias(forename: String, secondName: String, surname: String, personId: Long) = Alias(
id = IdGenerator.getAndIncrement(),
forename = forename,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.overview.Order
import uk.gov.justice.digital.hmpps.api.model.overview.Rar
import uk.gov.justice.digital.hmpps.api.model.sentence.*
import uk.gov.justice.digital.hmpps.data.generator.CourtReportGenerator.COURT_DOCUMENT
import uk.gov.justice.digital.hmpps.data.generator.CourtReportGenerator.EVENT_DOCUMENT
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.COURT_DOCUMENT
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.EVENT_DOCUMENT
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken
import java.time.LocalDate
Expand All @@ -33,7 +34,7 @@ class SentenceIntegrationTest {
.andReturn().response.contentAsJson<SentenceOverview>()

val expected = SentenceOverview(
Name("Caroline", "Louise", "Bloggs"), listOf()
Name("Caroline", "Louise", "Bloggs"), listOf(), ProbationHistory(0, null, 0, 0)
)

assertEquals(expected, response)
Expand All @@ -44,6 +45,7 @@ class SentenceIntegrationTest {
val response = mockMvc
.perform(MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}").withToken())
.andExpect(MockMvcResultMatchers.status().isOk)
.andDo(print())
.andReturn().response.contentAsJson<SentenceOverview>()

val expected = SentenceOverview(
Expand Down Expand Up @@ -86,7 +88,8 @@ class SentenceIntegrationTest {
listOf(),
listOf()
)
)
),
ProbationHistory(2, LocalDate.of(2023, 4, 9), 2, 1)
)

assertEquals(expected, response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class SentenceController(private val sentenceService: SentenceService) {

@GetMapping
@Operation(summary = "Display the most recent ‘Active Event’ ")
fun getOverview(@PathVariable crn: String) = sentenceService.getMostRecentActiveEvent(crn)
fun getOverview(@PathVariable crn: String) = sentenceService.getEvents(crn)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.gov.justice.digital.hmpps.api.model.sentence

import java.time.LocalDate

data class ProbationHistory(
val numberOfTerminatedEvents: Int,
val dateOfMostRecentTerminatedEvent: LocalDate?,
val numberOfTerminatedEventBreaches: Int,
val numberOfProfessionalContacts: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import uk.gov.justice.digital.hmpps.api.model.Name
data class SentenceOverview(
val name: Name,
val sentences: List<Sentence>,
val probationHistory: ProbationHistory,
)
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class Disposal(
@Column(name = "notional_end_date")
val notionalEndDate: LocalDate? = null,

@Column(name = "termination_date")
val terminationDate: LocalDate? = null,

@Column(name = "active_flag", columnDefinition = "number")
val active: Boolean,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class PersonalContactEntity(
@Column(name = "start_date")
val startDate: LocalDate?,

@Column(name = "end_date")
val endDate: LocalDate?,

@Column(name = "last_updated_datetime")
val lastUpdated: LocalDate,

Expand Down Expand Up @@ -81,4 +84,3 @@ interface PersonalContactRepository : JpaRepository<PersonalContactEntity, Long>
fun PersonalContactRepository.getContact(crn: String, id: Long): PersonalContactEntity =
findById(crn, id) ?: throw NotFoundException("PersonalContact", "id", id)


Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class ReferenceData(
val code: String,

@Column(name = "code_description", length = 500, nullable = false)
val description: String
val description: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity

import jakarta.persistence.*
import org.hibernate.annotations.Immutable
import java.io.Serializable

@Entity
@Table(name = "r_linked_list")
@Immutable
class ReferenceDataLinkedList(
@Id
val id: ReferenceDataLinkedListId
)

@Embeddable
class ReferenceDataLinkedListId(
@Column(name = "STANDARD_REFERENCE_DATA1")
val data1: Long,

@Column(name = "STANDARD_REFERENCE_DATA2")
val data2: Long
) : Serializable
Loading

0 comments on commit 2dd1f93

Please sign in to comment.