Skip to content

Commit

Permalink
Merge branch 'feature/PI-1939-mas-sentence-card' of github.com:minist…
Browse files Browse the repository at this point in the history
…ryofjustice/hmpps-probation-integration-services into feature/PI-1939-mas-sentence-card
  • Loading branch information
achimber-moj committed Mar 28, 2024
2 parents c66e945 + c6c8d7d commit 64001ea
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SentenceIntegrationTest {
listOf(AdditionalSentence(3, null, null, "Disqualified from Driving"))
),
Order("Default Sentence Type", 12, null, LocalDate.now().minusDays(14)),
listOf(Requirement("Main", "High Intensity", 12, "my notes", Rar(1,0, 1)))
listOf(Requirement("Main", "High Intensity", 12, "my notes", Rar(1, 0, 1)))
),
Sentence(
OffenceDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ interface RequirementRepository : JpaRepository<Requirement, Long> {
AND e.active_flag = 1
""", nativeQuery = true
)
fun getRequirements(crn: String, eventNumber: String) : List<RequirementDetails>
fun getRequirements(crn: String, eventNumber: String): List<RequirementDetails>
}

@Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class OverviewService(
return Rar(completed = completedDays, scheduled = scheduledDays)
}

fun Disposal.toOrder() = Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate())
fun Disposal.toOrder() =
Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate())

fun Event.toSentence() = mainOffence?.offence?.let { offence ->
Sentence(
mainOffence = offence.toOffence(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,37 @@ class SentenceService(
})
}

fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List<ExtraSentence>, crn: String) = Sentence(
OffenceDetails(
eventNumber = eventNumber,
offence = mainOffence?.let { Offence(it.offence.description, it.offenceCount) },
dateOfOffence = mainOffence?.date,
notes = notes,
additionalOffences = additionalOffences.map {
Offence(description = it.offence.description, count = it.offenceCount ?: 0)
}
),
Conviction(
sentencingCourt = courtAppearance?.court?.name,
responsibleCourt = court?.name,
convictionDate = convictionDate,
additionalSentences.map { it.toAdditionalSentence() }
),
order = disposal?.toOrder(),
requirements = disposal.let { requirementRepository.getRequirements(crn, eventNumber).map { it.toRequirement() } },
)
fun Event.toSentence(courtAppearance: CourtAppearance?, additionalSentences: List<ExtraSentence>, crn: String) =
Sentence(
OffenceDetails(
eventNumber = eventNumber,
offence = mainOffence?.let { Offence(it.offence.description, it.offenceCount) },
dateOfOffence = mainOffence?.date,
notes = notes,
additionalOffences = additionalOffences.map {
Offence(description = it.offence.description, count = it.offenceCount ?: 0)
}
),
Conviction(
sentencingCourt = courtAppearance?.court?.name,
responsibleCourt = court?.name,
convictionDate = convictionDate,
additionalSentences.map { it.toAdditionalSentence() }
),
order = disposal?.toOrder(),
requirements = disposal.let {
requirementRepository.getRequirements(crn, eventNumber).map { it.toRequirement() }
},
)

fun ExtraSentence.toAdditionalSentence(): AdditionalSentence =
AdditionalSentence(length, amount, notes, type.description)

fun PersonSummaryEntity.toName() =
Name(forename, secondName, surname)

fun Disposal.toOrder() = Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate())
fun Disposal.toOrder() =
Order(description = type.description, length = length, startDate = date, endDate = expectedEndDate())

fun RequirementDetails.toRequirement() = Requirement(
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ class SentenceServiceTest {
whenever(requirementRepository.getRequirements(PersonGenerator.OVERVIEW.crn, event.eventNumber))
.thenReturn(listOf(requirement))

whenever(requirementRepository.getRarDaysByRequirementId(requirement._id)).thenReturn(listOf(completedRarDays, scheduledRarDays))
whenever(requirementRepository.getRarDaysByRequirementId(requirement._id)).thenReturn(
listOf(
completedRarDays,
scheduledRarDays
)
)

val response = service.getMostRecentActiveEvent(PersonGenerator.OVERVIEW.crn)

Expand All @@ -138,7 +143,15 @@ class SentenceServiceTest {
)
),
Order("Default Sentence Type", 12, null, LocalDate.now().minusDays(14)),
listOf(Requirement(requirement._description, requirement._codeDescription, requirement._length, requirement._notes, Rar(completedRarDays._days, scheduledRarDays._days, 3)))
listOf(
Requirement(
requirement._description,
requirement._codeDescription,
requirement._length,
requirement._notes,
Rar(completedRarDays._days, scheduledRarDays._days, 3)
)
)
)
)
)
Expand Down Expand Up @@ -174,6 +187,5 @@ class SentenceServiceTest {

override val notes: String?
get() = _notes

}
}

0 comments on commit 64001ea

Please sign in to comment.