generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PI-2100: Added court report endpoint
- Loading branch information
Showing
13 changed files
with
212 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ourt-case-and-delius/src/dev/resources/simulations/__files/get_court_reports_C123456.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[ | ||
{ | ||
"courtReportId": 125, | ||
"offenderId": 65, | ||
"requestedDate": "2024-08-06T18:59:19.420309", | ||
"requiredDate": "2024-08-11T18:59:19.420318", | ||
"allocationDate": "2024-08-06T18:59:19.420326", | ||
"sentToCourtDate": "2024-08-06T18:59:19.420329", | ||
"receivedByCourtDate": "2024-08-06T18:59:19.420332", | ||
"courtReportType": { | ||
"code": "CR1", | ||
"description": "court report" | ||
}, | ||
"reportManagers": [ | ||
{ | ||
"staff": { | ||
"code": "N01ABBA", | ||
"forenames": "Bob Micheal", | ||
"surname": "Smith" | ||
}, | ||
"active": true | ||
} | ||
] | ||
} | ||
] |
13 changes: 13 additions & 0 deletions
13
projects/court-case-and-delius/src/dev/resources/simulations/mappings/get-convictions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/conviction/CourtReports.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package uk.gov.justice.digital.hmpps.api.model.conviction | ||
|
||
import uk.gov.justice.digital.hmpps.api.model.KeyValue | ||
import uk.gov.justice.digital.hmpps.api.model.StaffHuman | ||
import java.time.LocalDateTime | ||
|
||
data class CourtReportMinimal( | ||
val courtReportId: Long, | ||
val offenderId: Long, | ||
val requestedDate: LocalDateTime, | ||
val requiredDate: LocalDateTime, | ||
val allocationDate: LocalDateTime? = null, | ||
val completedDate: LocalDateTime? = null, | ||
val sentToCourtDate: LocalDateTime? = null, | ||
val receivedByCourtDate: LocalDateTime? = null, | ||
val courtReportType: KeyValue? = null, | ||
val reportManagers: List<ReportManager> = emptyList(), | ||
val deliveredCourtReportType: KeyValue? = null, | ||
|
||
) | ||
|
||
data class ReportManager( | ||
val staff: StaffHuman?, | ||
val active: Boolean | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ain/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/service/CourtReportService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.service | ||
|
||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.api.model.KeyValue | ||
import uk.gov.justice.digital.hmpps.api.model.StaffHuman | ||
import uk.gov.justice.digital.hmpps.api.model.conviction.CourtReportMinimal | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.entity.CourtReport | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.entity.CourtReportRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.courtappearance.entity.ReportManager | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.EventRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.event.entity.getByPersonAndEventNumber | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.getPerson | ||
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff | ||
|
||
@Service | ||
class CourtReportService( | ||
private val personRepository: PersonRepository, | ||
private val eventRepository: EventRepository, | ||
private val courtReportRepository: CourtReportRepository | ||
) { | ||
|
||
fun getCourtReportsFor(crn: String, eventId: Long): List<CourtReportMinimal> { | ||
val person = personRepository.getPerson(crn) | ||
val event = eventRepository.getByPersonAndEventNumber(person, eventId) | ||
return courtReportRepository.findByPersonIdAndEventId(person.id, event.id) | ||
.map { it.toCourtReport() } | ||
} | ||
} | ||
|
||
fun CourtReport.toCourtReport() = CourtReportMinimal( | ||
courtReportId = id, | ||
offenderId = personId, | ||
requestedDate = dateRequested, | ||
requiredDate = dateRequired, | ||
allocationDate = allocationDate, | ||
completedDate = dateCompleted, | ||
sentToCourtDate = sentToCourtDate, | ||
receivedByCourtDate = receivedByCourtDate, | ||
courtReportType = courtReportType?.let { KeyValue(it.code, it.description) }, | ||
reportManagers = reportManagers.filter { it.staff != null }.map { it.toReportManager() }, | ||
deliveredCourtReportType = deliveredCourtReportType?.let { KeyValue(it.code, it.description) } | ||
) | ||
|
||
fun Staff.toStaffHuman() = StaffHuman( | ||
forenames = listOfNotNull(forename, forename2).joinToString(" "), | ||
surname = surname, | ||
code = code | ||
) | ||
|
||
fun ReportManager.toReportManager() = uk.gov.justice.digital.hmpps.api.model.conviction.ReportManager( | ||
active = active, | ||
staff = staff?.toStaffHuman() | ||
) |