From e4ad71170dd1e94c7cbeb691854ca16f0227868c Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Tue, 14 May 2024 17:23:06 +0100 Subject: [PATCH] PI-2199 Only match if there is a single custodial sentence (#3797) --- .../digital/hmpps/PrisonMatchingIntegrationTest.kt | 13 +++---------- .../digital/hmpps/service/PrisonMatchingService.kt | 3 +++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PrisonMatchingIntegrationTest.kt b/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PrisonMatchingIntegrationTest.kt index 28ea617881..3563f038dc 100644 --- a/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PrisonMatchingIntegrationTest.kt +++ b/projects/prison-identifier-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/PrisonMatchingIntegrationTest.kt @@ -62,7 +62,7 @@ internal class PrisonMatchingIntegrationTest { @Test @Order(2) - fun `single match with existing noms number`() { + fun `no match with existing noms number if no custodial sentence in Delius`() { val crn = PersonGenerator.PERSON_WITH_NOMS.crn mockMvc @@ -70,17 +70,10 @@ internal class PrisonMatchingIntegrationTest { .andExpect(status().is2xxSuccessful) verify(telemetryService, timeout(5000)).trackEvent( - "MatchResultSuccess", mapOf( - "reason" to "Matched CRN A000001 to NOMS number E1234XS", + "MatchResultNoMatch", mapOf( + "reason" to "No single match found in prison system", "crn" to "A000001", "potentialMatches" to """[{"nomsNumber":"E1234XS"}]""", - "existingNomsNumber" to "E1234XS", - "matchedNomsNumber" to "E1234XS", - "nomsNumberChanged" to "false", - "matchedBookingNumber" to "76543A", - "bookingNumberChanged" to "false", - "totalCustodialEvents" to "1", - "matchingCustodialEvents" to "0", "dryRun" to "true" ) ) diff --git a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt index 4a19c85865..75f0c0d260 100644 --- a/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt +++ b/projects/prison-identifier-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/PrisonMatchingService.kt @@ -46,6 +46,9 @@ class PrisonMatchingService( val matchingCustodies = matchedPrisoner.sentenceStartDate ?.let { person.custodiesWithSentenceDateCloseTo(it) } ?: emptyList() val matchingCustody = matchingCustodies.singleOrNull() + val matchingPerson = matchingCustodies.map { it.disposal.event.person }.distinctBy { it.crn }.singleOrNull() + if (matchingPerson == null) + return NoMatch("No single match found in prison system", prisonerMatches.telemetry()) return Success( identifiers, person, matchingCustody, prisonerMatches.telemetry() + mapOf(