Skip to content

Commit

Permalink
PI-2031 Handle null OSP I/C scores (#3535)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Mar 25, 2024
1 parent 891d726 commit ca872f6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ object MessageGenerator {
val RSR_SCORES_DETERMINED = ResourceLoader.message<HmppsDomainEvent>("rsr-scores-determined")
val RSR_SCORES_DETERMINED_WITHOUT_OSPIIC_OSPDC =
ResourceLoader.message<HmppsDomainEvent>("rsr-scores-determined-null-osp")
val RSR_SCORES_DETERMINED_WITH_OSPII_OSPDC =
ResourceLoader.message<HmppsDomainEvent>("rsr-scores-determined-osp-ii-dc")
val OGRS_SCORES_DETERMINED = ResourceLoader.message<HmppsDomainEvent>("ogrs-scores-determined")
val OGRS_SCORES_DETERMINED_UPDATE = ResourceLoader.message<HmppsDomainEvent>("ogrs-scores-determined-update")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Type": "Notification",
"MessageId": "b04098df-3d67-416f-87eb-f63782f713fb",
"TopicArn": "",
"Message": "{\"eventType\":\"risk-assessment.scores.rsr.determined\",\"version\":1,\"description\":\"Risk assessment scores have been determined\",\"detailUrl\":\"https://some-url-where-we-can-get-more-info-this-might-not-exist\",\"occurredAt\":\"2022-09-22T12:16:04+01:00\",\"additionalInformation\":{\"RSRScore\":45.33,\"RSRBand\":\"H\",\"RSRStaticOrDynamic\":\"STATIC\",\"OSPIndirectIndecentScore\":5.79,\"OSPIndirectIndecentBand\":\"H\",\"OSPDirectContactScore\":38.7,\"OSPDirectContactBand\":\"V\",\"OSPIndecentScore\":null,\"OSPIndecentBand\":null,\"OSPContactScore\":null,\"OSPContactBand\":null,\"EventNumber\":1,\"AssessmentDate\":\"2022-09-22T12:16:04+01:00\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"X552020\"}]}}",
"Timestamp": "2022-05-04T08:06:46.704Z",
"SignatureVersion": "1",
"Signature": "",
"SigningCertURL": "",
"UnsubscribeURL": "",
"MessageAttributes": {
"eventType": {
"Type": "String",
"Value": "risk-assessment.scores.determined"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class IntegrationTest {
}

@Test
fun `handles null OSP-IIC and OSP-DC bands`() {
fun `handles old OSP scores`() {
val notification = Notification(
message = MessageGenerator.RSR_SCORES_DETERMINED_WITHOUT_OSPIIC_OSPDC,
attributes = MessageAttributes("risk-assessment.scores.determined")
Expand All @@ -74,6 +74,16 @@ internal class IntegrationTest {
verify(telemetryService).trackEvent("RsrScoresUpdated", notification.message.telemetryProperties())
}

@Test
fun `handles new OSP scores`() {
val notification = Notification(
message = MessageGenerator.RSR_SCORES_DETERMINED_WITH_OSPII_OSPDC,
attributes = MessageAttributes("risk-assessment.scores.determined")
)
channelManager.getChannel(queueName).publishAndWait(notification)
verify(telemetryService).trackEvent("RsrScoresUpdated", notification.message.telemetryProperties())
}

@Test
@Order(1)
fun `successfully add OGRS assessment`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class RiskScoreService(jdbcTemplate: JdbcTemplate, val featureFlags: FeatureFlag
eventNumber: Int?,
assessmentDate: ZonedDateTime,
rsr: RiskAssessment,
ospIndecent: RiskAssessment,
ospIndecent: RiskAssessment?,
ospIndirectIndecent: RiskAssessment?,
ospContact: RiskAssessment,
ospContact: RiskAssessment?,
ospDirectContact: RiskAssessment?,
) {
try {
Expand All @@ -53,10 +53,10 @@ class RiskScoreService(jdbcTemplate: JdbcTemplate, val featureFlags: FeatureFlag
.addValue("p_rsr_assessor_date", assessmentDate)
.addValue("p_rsr_score", rsr.score)
.addValue("p_rsr_level_code", rsr.band)
.addValue("p_osp_score_i", ospIndecent.score)
.addValue("p_osp_score_c", ospContact.score)
.addValue("p_osp_level_i_code", ospIndecent.band)
.addValue("p_osp_level_c_code", ospContact.band)
.addValue("p_osp_score_i", ospIndecent?.score)
.addValue("p_osp_score_c", ospContact?.score)
.addValue("p_osp_level_i_code", ospIndecent?.band)
.addValue("p_osp_level_c_code", ospContact?.band)

if (featureFlags.enabled("osp-indirect-indecent-and-direct-contact")) {
updateRsrAndOspScoresProcedure.withIndirectIndecentAndDirectContact.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ fun HmppsDomainEvent.rsr() = RiskAssessment(
additionalInformation["RSRBand"] as String
)

fun HmppsDomainEvent.ospIndecent() = RiskAssessment(
additionalInformation["OSPIndecentScore"] as Double,
additionalInformation["OSPIndecentBand"] as String,
)
fun HmppsDomainEvent.ospIndecent() = additionalInformation["OSPIndecentScore"]?.let {
RiskAssessment(
additionalInformation["OSPIndecentScore"] as Double,
additionalInformation["OSPIndecentBand"] as String,
)
}

fun HmppsDomainEvent.ospIndirectIndecent() = additionalInformation["OSPIndecentIndirectBand"]?.let {
RiskAssessment(
Expand All @@ -107,10 +109,12 @@ fun HmppsDomainEvent.ospIndirectIndecent() = additionalInformation["OSPIndecentI
)
}

fun HmppsDomainEvent.ospContact() = RiskAssessment(
additionalInformation["OSPContactScore"] as Double,
additionalInformation["OSPContactBand"] as String,
)
fun HmppsDomainEvent.ospContact() = additionalInformation["OSPContactScore"]?.let {
RiskAssessment(
additionalInformation["OSPContactScore"] as Double,
additionalInformation["OSPContactBand"] as String,
)
}

fun HmppsDomainEvent.ospDirectContact() = additionalInformation["OSPDirectContactBand"]?.let {
RiskAssessment(
Expand Down

0 comments on commit ca872f6

Please sign in to comment.