From 6dedce960310d8618c67abea413990f115b64a9c Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Wed, 24 Jul 2024 09:05:46 +0100 Subject: [PATCH] PI-2389 Use assessment completed date for contact (#4058) --- .../justice/digital/hmpps/IntegrationTest.kt | 23 ++++++++++++++++--- .../hmpps/service/AssessmentService.kt | 14 +++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 8d06d00dc1..c9305005c5 100644 --- a/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/assessment-summary-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -9,9 +9,7 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers -import org.mockito.kotlin.eq -import org.mockito.kotlin.timeout -import org.mockito.kotlin.verify +import org.mockito.kotlin.* import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.boot.test.context.SpringBootTest @@ -22,6 +20,7 @@ import uk.gov.justice.digital.hmpps.data.entity.IapsPersonRepository import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator import uk.gov.justice.digital.hmpps.data.generator.RegistrationGenerator +import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessmentRepository import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactRepository import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType @@ -67,11 +66,15 @@ internal class IntegrationTest { @MockBean lateinit var telemetryService: TelemetryService + @MockBean + lateinit var featureFlags: FeatureFlags + lateinit var transactionTemplate: TransactionTemplate @BeforeEach fun setUp() { transactionTemplate = TransactionTemplate(transactionManager) + whenever(featureFlags.enabled(any())).thenReturn(true) } @Test @@ -104,9 +107,23 @@ internal class IntegrationTest { val contact = contactRepository.findAll() .single { it.person.id == person.id && it.type.code == ContactType.Code.OASYS_ASSESSMENT.value } + assertThat(contact.date, equalTo(assessment?.date)) assertThat(contact.externalReference, equalTo("urn:uk:gov:hmpps:oasys:assessment:${assessment?.oasysId}")) } + @Test + fun `contact date is set to current date when flag is off`() { + whenever(featureFlags.enabled("assessment-summary-contact-date")).thenReturn(false) + val message = notification("assessment-summary-produced-${PersonGenerator.NO_RISK.crn}") + channelManager.getChannel(queueName).publishAndWait(prepNotification(message, wireMockServer.port())) + + val person = personRepository.getByCrn(PersonGenerator.NO_RISK.crn) + + val contact = contactRepository.findAll() + .single { it.person.id == person.id && it.type.code == ContactType.Code.OASYS_ASSESSMENT.value } + assertThat(contact.date, equalTo(LocalDate.now())) + } + @Test fun `an existing assessment is replaced, a new registration added and iaps is notified`() { val message = notification("assessment-summary-produced-${PersonGenerator.LOW_RISK.crn}") diff --git a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AssessmentService.kt b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AssessmentService.kt index 076224e2b1..857e283c87 100644 --- a/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AssessmentService.kt +++ b/projects/assessment-summary-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/AssessmentService.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service import uk.gov.justice.digital.hmpps.exception.IgnorableMessageException +import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessment import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.OasysAssessmentRepository import uk.gov.justice.digital.hmpps.integrations.delius.assessment.entity.SentencePlan @@ -25,7 +26,8 @@ class AssessmentService( private val offenceRepository: OffenceRepository, private val oasysAssessmentRepository: OasysAssessmentRepository, private val eventRepository: EventRepository, - private val contactService: ContactService + private val contactService: ContactService, + private val featureFlags: FeatureFlags, ) { fun recordAssessment(person: Person, summary: AssessmentSummary) { val previousAssessment = oasysAssessmentRepository.findByOasysId(summary.assessmentPk.toString()) @@ -34,12 +36,14 @@ class AssessmentService( ?: throw IgnorableMessageException("No Event Number provided") val event = eventRepository.getByNumber(person.id, eventNumber) val manager = checkNotNull(person.manager) { "Community Manager Not Found" } + val contactDate = + if (featureFlags.enabled("assessment-summary-contact-date")) summary.dateCompleted else LocalDate.now() val contact = previousAssessment?.contact?.withDateTeamAndStaff( - LocalDate.now(), + contactDate, manager.teamId, manager.staffId ) ?: contactService.createContact( - summary.contactDetail(), + summary.contactDetail(contactDate), person, event ) @@ -86,10 +90,10 @@ class AssessmentService( } } -private fun AssessmentSummary.contactDetail() = +private fun AssessmentSummary.contactDetail(contactDate: LocalDate) = ContactDetail( ContactType.Code.OASYS_ASSESSMENT, - LocalDate.now(), + contactDate, "Reason for Assessment: ${furtherInformation.pOAssessmentDesc}", "urn:uk:gov:hmpps:oasys:assessment:${assessmentPk}" )