Skip to content

Commit

Permalink
Merge branch 'main' into PI-2781-new-api-to-show-previous-orders
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj authored Jan 30, 2025
2 parents ac603a6 + a5c238b commit 9b6fde3
Show file tree
Hide file tree
Showing 12 changed files with 2,337 additions and 326 deletions.
6 changes: 3 additions & 3 deletions projects/assessment-summary-and-delius/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Assessment summary relies on the OASys ORDS API for retrieving the assessment su
## Assessment summary produced workflow
The assessment summary is recorded in Delius. The risks are evaluated and stored as registrations.

| Business Event | Message Event Type / Filter |
| --------------------- | ---------------------------- |
| Assessment submitted | assessment.summary.produced |
| Business Event | Message Attribute Event Type | Message Event Type |
| --------------------- | --------------------------------- | --------------------------- |
| Assessment submitted | risk-assessment.scores.determined | assessment.summary.produced |

### Record assessment
The previous assessment summary is deleted and replaced with the new assessment summary. The full assessment can be retrieved from OASys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.audit.service.AuditableService
import uk.gov.justice.digital.hmpps.audit.service.AuditedInteractionService
import uk.gov.justice.digital.hmpps.enum.RiskOfSeriousHarmType
import uk.gov.justice.digital.hmpps.enum.RiskType
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode.SUBMIT_ASSESSMENT_SUMMARY
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode.UPDATE_RISK_DATA
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository
Expand All @@ -26,8 +28,11 @@ class AssessmentSubmitted(
"crn" to crn,
"dateCompleted" to summary.dateCompleted.toString(),
"assessmentType" to summary.assessmentType,
"assessmentId" to summary.assessmentPk.toString()
)
"assessmentId" to summary.assessmentPk.toString(),
"ROSH" to summary.riskFlags.mapNotNull(RiskOfSeriousHarmType::of).maxByOrNull { it.ordinal }.toString(),
) + RiskType.entries.map {
it.name to it.riskLevel(summary)?.name.toString()
}

val person = personRepository.getByCrn(crn)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assessment-submitted: Assessment Summary {
assessment_summary_produced: Assessment summary produced
}

domain_event: "assessment-summary\n.assessment.summary.produced" {
domain_event: "assessment-summary-and-delius\n.risk-assessment.scores.determined" {
style.font-size: 12
shape: queue
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
{
"description": "Split text into chunks and generate embeddings",
"processors": [
{
"append": {
"field": "text",
"value": [
"{{{date}}}",
"{{{startTime}}}",
"{{{typeDescription}}}",
"{{{typeShortDescription}}}",
"{{{outcomeDescription}}}",
"{{{description}}}",
"{{{notes}}}"
]
}
},
{
"join": {
"field": "text",
"separator": "\n"
}
},
{
"text_chunking": {
"algorithm": {
Expand All @@ -31,10 +11,21 @@
}
},
"field_map": {
"text": "textChunks"
"notes": "textChunks"
}
}
},
{
"append": {
"field": "textChunks",
"value": [
"{{{date}}} {{{startTime}}}",
"{{{typeDescription}}} {{{typeShortDescription}}}",
"{{{outcomeDescription}}}",
"{{{description}}}"
]
}
},
{
"text_embedding": {
"model_id": "${model_id}",
Expand Down
53 changes: 45 additions & 8 deletions projects/risk-assessment-scores-to-delius/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
# Risk Assessment Scores to Delius

This integration listens for domain events generated by the OASys Offender Assessment System, and stores changes to the
RSR (Risk of Serious Recidivism) and OSP (OASys Sexual reoffending Predictor) scores in the Delius probation case
management system.
This integration service listens for domain events generated by the OASys Offender Assessment system and updates Delius with changes to the following risk scores:

* Risk of serious recidivism (RSR)
* OASys sexual reoffending predictor (OSP)
* Offender group reconviction scale (OGRS)

The scores are updated when an OASys risk assessment is submitted for a **Person on Probation**.

## Business need
Helps the business users understand the actuarial risk predictors within the Delius user interface.

## Data dependencies
This integration service is used to update the RSR and OSP risk scores in Delius. The service will also add/update scores from OGRS risk assessments for a **Person on Probation** and an **Event** in Delius.

### Context map - Risk Assessment Data

![](./tech-docs/source/img/risk-assessment-context-map.svg)

## Workflows

| Business Event | Message Event Type/Filter |
| ------------------- | -------------------------------------- |
| Risk scores updated | risk-assessment.scores.rsr.determined |
| Risk assessment | risk-assessment.scores.ogrs.determined |

### Risk Score Workflow
Two types of scores are provided in the risk score data: risk of serious recidivism (RAR) and OASys sexual reoffending predictor (OSP). The scores are updated in Delius.

![](./tech-docs/source/img/risk-assessment-scores-workflow.svg)

### OGRS Risk Assessment Workflow
An OGRS risk assessment is conducted for a **Person on Probation** for a specific **Event**. The offender group reconviction scale (OGRS) score is stored or updated in Delius when the risk assessment is submitted.

![](./tech-docs/source/img/risk-assessment-workflow.svg)

## Interfaces

### Message Formats

The service responds to HMPPS Domain Event messages via the
[Risk Assessment Scores and Delius Queue](https://github.com/ministryofjustice/cloud-platform-environments/blob/main/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-probation-integration-services-prod/resources/risk-assessment-scores-to-delius-queue.tf).

Example [messages](./src/dev/resources/messages/) are in the development source tree.

Incoming messages are filtered on `eventType` by the [SQS queue policy](https://github.com/ministryofjustice/cloud-platform-environments/blob/main/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-probation-integration-services-prod/resources/risk-assessment-scores-to-delius-queue.tf)

## OASys Domain Event

Expand Down Expand Up @@ -36,8 +78,3 @@ Sample message:
}
}
```

## Delius Integration

A stored procedure is provided in the Delius database. Details of the procedure can be found in the NDST
Jira: [DST-12572](https://jira.engineering-dev.probation.hmpps.dsd.io/browse/DST-12572).
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

style { ...@../../../../script/style.style }
vars { ...@../../../../script/style.vars }
** { ...@../../../../script/style.all-style }

context-oasys: OASys Context {
entities: Entities {
grid-columns: 3
pop: Person on Probation
rsr: RSR
osp: OSP
ogrs: OGRS score
date: Assessment date
event: Event number
}
}

context-delius: Delius Context {

interface: Risk Assessment\n and Delius {
type: Anti-Corruption\nLayer
}

entities: Entities {
grid-columns: 2
event: Event
mte: Management tier event
contact: Contact
pop: Person on Probation
pm: Person manager
staff: Staff
team: Team
ogrs-assessment: OGRS Assessment
}
}

context-oasys--context-delius.interface: Upstream\n\n\nDownstream
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Risk Scores Workflow: Risk Scores Updated

direction: right

style { ...@../../../../script/style.style }
vars { ...@../../../../script/style.vars }
** { ...@../../../../script/style.all-style }

# What triggers the workflow?
risk-scores: Risk Scores Updated {
style.font-size: 24

explanation: |md
## Risk Scores Updated
- RSR and OSP scores are\
updated in the OASys system
|

risk_scores_updated: Risk Scores Updated
}

domain_event: "risk-assessment\n.scores.rsr.determined" {
style.font-size: 12
shape: queue
}

# What happens in Delius?
delius: Delius {
style.font-size: 24

explanation: |md
## Update Risk Scores
- Update the risk/
scores in Delius
|

}

risk-scores -> domain_event -> delius
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Risk Assessment Workflow: Risk Assessment Submitted

direction: right

style { ...@../../../../script/style.style }
vars { ...@../../../../script/style.vars }
** { ...@../../../../script/style.all-style }

# What triggers the workflow?
assessment-submitted: Risk Assessment Submitted {
style.font-size: 24

explanation: |md
## Risk Assessment Submitted
- A risk assessment is\
produced in OASys
|

risk_assessment_produced: Risk Assessment Submitted
}

domain_event: "risk-assessment\n.scores.ogrs.determined" {
style.font-size: 12
shape: queue
}

# What happens in Delius?
delius: Delius {
style.font-size: 24
grid-columns: 2

d_store_scores: Add/Update risk assessment scores
d_contact: Create Contact
d_create_mte: Create management tier event

d_store_scores -> d_contact -> d_create_mte

explanation: |md
## Risk Assessment Submitted
- Check for an existing\
risk assessment
- Add/Update the risk\
assessment scores
- Create a new contact
- Create a new management\
tier event
|

}

assessment-submitted -> domain_event -> delius
Loading

0 comments on commit 9b6fde3

Please sign in to comment.