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.
- Loading branch information
1 parent
b3fdb81
commit 8407425
Showing
16 changed files
with
319 additions
and
108 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
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
11 changes: 11 additions & 0 deletions
11
projects/prison-case-notes-to-probation/src/dev/resources/messages/noms-number-added.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,11 @@ | ||
{ | ||
"Type": "Notification", | ||
"Message": "{\"eventType\":\"probation-case.prison-identifier.added\",\"version\":1,\"occurredAt\":\"2025-01-15T09:47:39+01:00\",\"publishedAt\":\"2025-01-15T09:47:39+01:00\",\"description\":\"A prisoner identifier has been added\",\"personReference\":{\"identifiers\":[{\"type\":\"NOMS\",\"value\":\"A4578BX\"}]}}", | ||
"Timestamp": "2025-01-15T09:47:39+01:00", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "probation-case.prison-identifier.added" | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...-notes-to-probation/src/dev/resources/simulations/__files/migrate-for-new-identifier.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,69 @@ | ||
{ | ||
"content": [ | ||
{ | ||
"caseNoteId": "ff0cfa55-3193-41c9-9332-7766c03a06ff", | ||
"eventId": 77701, | ||
"offenderIdentifier": "A4578BX", | ||
"type": "GEN", | ||
"subType": "OSE", | ||
"creationDateTime": "2025-01-12T11:22:33+01:00", | ||
"occurrenceDateTime": "2025-01-11T10:11:22+01:00", | ||
"authorName": "Some Name", | ||
"text": "note content", | ||
"locationId": "LEI", | ||
"amendments": [] | ||
}, | ||
{ | ||
"caseNoteId": "2dd32070-4af0-4d3c-ad8d-5108a43a9322", | ||
"eventId": 77702, | ||
"offenderIdentifier": "A4578BX", | ||
"type": "ALERT", | ||
"subType": "ACTIVE", | ||
"creationDateTime": "2025-01-12T11:22:33+01:00", | ||
"occurrenceDateTime": "2025-01-11T10:11:22+01:00", | ||
"authorName": "Some Name", | ||
"text": "note content", | ||
"locationId": "LEI", | ||
"amendments": [] | ||
}, | ||
{ | ||
"caseNoteId": "7f283166-2c7e-404e-9b0c-fa21cfbd338e", | ||
"eventId": 77704, | ||
"offenderIdentifier": "A4578BX", | ||
"type": "KA", | ||
"subType": "KS", | ||
"creationDateTime": "2025-01-12T11:22:33+01:00", | ||
"occurrenceDateTime": "2025-01-11T10:11:22+01:00", | ||
"authorName": "Some Name", | ||
"text": "note content", | ||
"locationId": "LEI", | ||
"amendments": [] | ||
}, | ||
{ | ||
"caseNoteId": "d9e02743-3e8a-4ab8-923b-01d4214afeaf", | ||
"eventId": 77705, | ||
"offenderIdentifier": "A4578BX", | ||
"type": "PRISON", | ||
"subType": "RELEASE", | ||
"creationDateTime": "2025-01-12T11:22:33+01:00", | ||
"occurrenceDateTime": "2025-01-11T10:11:22+01:00", | ||
"authorName": "Some Name", | ||
"text": "note content", | ||
"locationId": "LEI", | ||
"amendments": [] | ||
}, | ||
{ | ||
"caseNoteId": "bdc8b4af-01a3-44b5-9160-23c4d289f9a2", | ||
"eventId": 77703, | ||
"offenderIdentifier": "A4578BX", | ||
"type": "TRANSFER", | ||
"subType": "FROMTOL", | ||
"creationDateTime": "2025-01-12T11:22:33+01:00", | ||
"occurrenceDateTime": "2025-01-11T10:11:22+01:00", | ||
"authorName": "Some Name", | ||
"text": "note content", | ||
"locationId": "TRN", | ||
"amendments": [] | ||
} | ||
] | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/prison/PrisonCaseNotesClient.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 |
---|---|---|
@@ -1,9 +1,44 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.prison | ||
|
||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.service.annotation.GetExchange | ||
import org.springframework.web.service.annotation.PostExchange | ||
import java.net.URI | ||
import java.time.LocalDateTime | ||
|
||
interface PrisonCaseNotesClient { | ||
@GetExchange | ||
fun getCaseNote(baseUrl: URI): PrisonCaseNote? | ||
|
||
@PostExchange | ||
fun searchCaseNotes( | ||
uri: URI, | ||
@RequestBody searchCaseNotes: SearchCaseNotes | ||
): CaseNotesResults | ||
} | ||
|
||
data class SearchCaseNotes( | ||
val typeSubTypes: Set<TypeSubTypeRequest>, | ||
val occurredFrom: LocalDateTime? = null, | ||
val occurredTo: LocalDateTime? = null, | ||
val includeSensitive: Boolean = true, | ||
val page: Int = 1, | ||
val size: Int = Int.MAX_VALUE, | ||
val sort: String = "occurredAt,desc", | ||
) { | ||
companion object { | ||
val TYPES_OF_INTEREST = setOf( | ||
TypeSubTypeRequest("PRISON", setOf("RELEASE")), | ||
TypeSubTypeRequest("TRANSFER", setOf("FROMTOL")), | ||
TypeSubTypeRequest("GEN", setOf("OSE")), | ||
TypeSubTypeRequest("ALERT"), | ||
TypeSubTypeRequest("OMIC"), | ||
TypeSubTypeRequest("OMIC_OPD"), | ||
TypeSubTypeRequest("KA"), | ||
) | ||
} | ||
} | ||
|
||
data class TypeSubTypeRequest(val type: String, val subTypes: Set<String> = setOf()) | ||
|
||
data class CaseNotesResults(val content: List<PrisonCaseNote>) |
87 changes: 87 additions & 0 deletions
87
...-to-probation/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/CaseNotePublished.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,87 @@ | ||
package uk.gov.justice.digital.hmpps.messaging | ||
|
||
import org.springframework.http.HttpStatus | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.client.HttpStatusCodeException | ||
import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter | ||
import uk.gov.justice.digital.hmpps.exceptions.OffenderNotFoundException | ||
import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService | ||
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNote | ||
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNoteFilters | ||
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNotesClient | ||
import uk.gov.justice.digital.hmpps.integrations.prison.toDeliusCaseNote | ||
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
import java.net.URI | ||
|
||
@Service | ||
class CaseNotePublished( | ||
private val prisonCaseNotesClient: PrisonCaseNotesClient, | ||
private val deliusService: DeliusService, | ||
private val telemetryService: TelemetryService, | ||
) { | ||
fun handle(event: HmppsDomainEvent) { | ||
val caseNoteId = event.additionalInformation["caseNoteId"] | ||
if (caseNoteId == null) { | ||
telemetryService.trackEvent( | ||
"MissingCaseNoteId", | ||
mapOf( | ||
"eventType" to event.eventType, | ||
"nomsNumber" to event.personReference.findNomsNumber()!! | ||
) | ||
) | ||
return | ||
} | ||
|
||
val prisonCaseNote = try { | ||
prisonCaseNotesClient.getCaseNote(URI.create(event.detailUrl!!)) | ||
} catch (ex: HttpStatusCodeException) { | ||
when (ex.statusCode) { | ||
HttpStatus.NOT_FOUND -> { | ||
telemetryService.trackEvent("CaseNoteNotFound", mapOf("detailUrl" to event.detailUrl!!)) | ||
return | ||
} | ||
|
||
else -> throw ex | ||
} | ||
} | ||
|
||
val reasonToIgnore: Lazy<String?> = lazy { | ||
PrisonCaseNoteFilters.filters.firstOrNull { it.predicate.invoke(prisonCaseNote!!) }?.reason | ||
} | ||
|
||
if (prisonCaseNote == null || reasonToIgnore.value != null) { | ||
val reason = if (prisonCaseNote == null) { | ||
"case note was not able to be retrieved" | ||
} else { | ||
reasonToIgnore.value!! | ||
} | ||
telemetryService.trackEvent( | ||
"CaseNoteIgnored", | ||
(prisonCaseNote?.properties() ?: emptyMap()) + ("reason" to reason) | ||
) | ||
return | ||
} | ||
|
||
try { | ||
deliusService.mergeCaseNote(prisonCaseNote.toDeliusCaseNote(event.occurredAt)) | ||
telemetryService.trackEvent("CaseNoteMerged", prisonCaseNote.properties()) | ||
} catch (e: Exception) { | ||
telemetryService.trackEvent( | ||
"CaseNoteMergeFailed", | ||
prisonCaseNote.properties() + ("exception" to (e.message ?: "")) | ||
) | ||
if (e !is OffenderNotFoundException) throw e | ||
} | ||
} | ||
|
||
private fun PrisonCaseNote.properties() = mapOf( | ||
"caseNoteId" to id, | ||
"type" to type, | ||
"subType" to subType, | ||
"eventId" to eventId.toString(), | ||
"created" to DeliusDateTimeFormatter.format(creationDateTime), | ||
"occurrence" to DeliusDateTimeFormatter.format(occurrenceDateTime), | ||
"location" to locationId | ||
) | ||
} |
Oops, something went wrong.