Skip to content

Commit

Permalink
PI-2571 Ignore OPD assessments where NOMS number is not in Delius (#4281
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marcus-bcl authored Oct 7, 2024
1 parent cd3cb0d commit 66104ef
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactRepository
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType
import uk.gov.justice.digital.hmpps.integrations.delius.entity.*
import uk.gov.justice.digital.hmpps.message.PersonIdentifier
import uk.gov.justice.digital.hmpps.message.PersonReference
import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService

Expand Down Expand Up @@ -117,4 +119,24 @@ internal class OpdIntegrationTest {
.firstOrNull { it.personId == com.person.id && it.type.code == ContactType.Code.PENDING_CONSULTATION.value }
assertNotNull(opdContact!!)
}

@Test
fun `noms number not found`() {
val message = prepMessage("opd-assessment-new", wireMockServer.port())
.let {
it.copy(it.message.copy(personReference = PersonReference(listOf(PersonIdentifier("NOMS", "Z9999ZZ")))))
}

channelManager.getChannel(queueName).publishAndWait(message)

verify(telemetryService).trackEvent(
"OpdAssessmentIgnored",
mapOf(
"reason" to "PersonNotFound",
"noms" to "Z9999ZZ",
"date" to "30/10/2023 16:42:25",
"result" to "Screened In"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import jakarta.persistence.*
import org.hibernate.annotations.Immutable
import org.hibernate.annotations.SQLRestriction
import org.springframework.data.jpa.repository.JpaRepository
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.exception.NotFoundException

@Immutable
Expand Down Expand Up @@ -60,9 +61,8 @@ interface PersonManagerRepository : JpaRepository<PersonManager, Long> {
fun findByPersonNomsId(nomsId: String): PersonManager?
}

fun PersonManagerRepository.getByCrnOrNoms(crn: String?, nomsId: String?) =
crn?.let(::findByPersonCrn) ?: nomsId?.let(::findByPersonNomsId) ?: throw NotFoundException(
"Person",
crn?.let { "crn" } ?: nomsId?.let { "nomsId" } ?: "",
crn ?: nomsId ?: ""
)
fun PersonManagerRepository.getByCrnOrNoms(crn: String?, nomsId: String?) = when {
crn != null -> findByPersonCrn(crn) ?: throw NotFoundException("Manager for person", "crn", crn)
nomsId != null -> findByPersonNomsId(nomsId) ?: throw IgnorableMessageException("PersonNotFound")
else -> throw IllegalArgumentException("No CRN or NOMS number provided")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.openfolder.kotlinasyncapi.annotation.channel.Publish
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter
import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException
import uk.gov.justice.digital.hmpps.integrations.delius.entity.NsiSubType
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
Expand All @@ -28,13 +29,20 @@ class Handler(
override fun handle(notification: Notification<HmppsDomainEvent>) {
if (notification.message.eventType != OpdProduced) return
val opdAssessment = notification.message.opdAssessment()
when (opdAssessment.result) {
OpdAssessment.Result.SCREENED_IN, OpdAssessment.Result.SCREENED_IN_OVERRIDE -> {
opdService.processAssessment(notification.message.opdAssessment())
telemetryService.trackEvent("OpdAssessmentScreenedIn", opdAssessment.telemetryProperties())
}
try {
when (opdAssessment.result) {
OpdAssessment.Result.SCREENED_IN, OpdAssessment.Result.SCREENED_IN_OVERRIDE -> {
opdService.processAssessment(notification.message.opdAssessment())
telemetryService.trackEvent("OpdAssessmentScreenedIn", opdAssessment.telemetryProperties())
}

else -> telemetryService.trackEvent("OpdAssessmentScreenedOut", opdAssessment.telemetryProperties())
else -> telemetryService.trackEvent("OpdAssessmentScreenedOut", opdAssessment.telemetryProperties())
}
} catch (e: IgnorableMessageException) {
telemetryService.trackEvent(
"OpdAssessmentIgnored",
mapOf("reason" to e.message) + e.additionalProperties + opdAssessment.telemetryProperties()
)
}
}
}
Expand Down

0 comments on commit 66104ef

Please sign in to comment.