Skip to content

Commit

Permalink
PI-2389 Use assessment completed date for contact (#4058)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Jul 24, 2024
1 parent 404407d commit 6dedce9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<HmppsDomainEvent>("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<HmppsDomainEvent>("assessment-summary-produced-${PersonGenerator.LOW_RISK.crn}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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
)
Expand Down Expand Up @@ -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}"
)
Expand Down

0 comments on commit 6dedce9

Please sign in to comment.