From ca872f6112106aff66e9e2b48809b9adbb35ed2b Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Mon, 25 Mar 2024 11:44:57 +0000 Subject: [PATCH] PI-2031 Handle null OSP I/C scores (#3535) --- .../justice/digital/hmpps/MessageGenerator.kt | 2 ++ .../rsr-scores-determined-osp-ii-dc.json | 17 ++++++++++++++++ .../justice/digital/hmpps/IntegrationTest.kt | 12 ++++++++++- .../integrations/delius/RiskScoreService.kt | 12 +++++------ .../digital/hmpps/messaging/Handler.kt | 20 +++++++++++-------- 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 projects/risk-assessment-scores-to-delius/src/dev/resources/messages/rsr-scores-determined-osp-ii-dc.json diff --git a/projects/risk-assessment-scores-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/MessageGenerator.kt b/projects/risk-assessment-scores-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/MessageGenerator.kt index cb1d3372b9..d886eabc44 100644 --- a/projects/risk-assessment-scores-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/MessageGenerator.kt +++ b/projects/risk-assessment-scores-to-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/MessageGenerator.kt @@ -7,6 +7,8 @@ object MessageGenerator { val RSR_SCORES_DETERMINED = ResourceLoader.message("rsr-scores-determined") val RSR_SCORES_DETERMINED_WITHOUT_OSPIIC_OSPDC = ResourceLoader.message("rsr-scores-determined-null-osp") + val RSR_SCORES_DETERMINED_WITH_OSPII_OSPDC = + ResourceLoader.message("rsr-scores-determined-osp-ii-dc") val OGRS_SCORES_DETERMINED = ResourceLoader.message("ogrs-scores-determined") val OGRS_SCORES_DETERMINED_UPDATE = ResourceLoader.message("ogrs-scores-determined-update") } diff --git a/projects/risk-assessment-scores-to-delius/src/dev/resources/messages/rsr-scores-determined-osp-ii-dc.json b/projects/risk-assessment-scores-to-delius/src/dev/resources/messages/rsr-scores-determined-osp-ii-dc.json new file mode 100644 index 0000000000..bf41a84751 --- /dev/null +++ b/projects/risk-assessment-scores-to-delius/src/dev/resources/messages/rsr-scores-determined-osp-ii-dc.json @@ -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" + } + } +} \ No newline at end of file diff --git a/projects/risk-assessment-scores-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/risk-assessment-scores-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 65e06e8991..0273f8214d 100644 --- a/projects/risk-assessment-scores-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/risk-assessment-scores-to-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -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") @@ -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`() { diff --git a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt index c5dc88b7bc..2a89bf65fb 100644 --- a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt +++ b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/RiskScoreService.kt @@ -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 { @@ -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( diff --git a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt index bb31366f05..7d339c32fc 100644 --- a/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt +++ b/projects/risk-assessment-scores-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt @@ -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( @@ -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(