Skip to content

Commit

Permalink
MAN-113: Return MAPPA and OPD in risks
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcphee77 committed Dec 17, 2024
1 parent 214ba62 commit c59f75c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.api.model.Name
import uk.gov.justice.digital.hmpps.api.model.risk.*
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import uk.gov.justice.digital.hmpps.integrations.delius.compliance.NsiRepository
import uk.gov.justice.digital.hmpps.integrations.delius.compliance.NsiType
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.getPerson
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.getSummary
import uk.gov.justice.digital.hmpps.integrations.delius.risk.DeRegistration
import uk.gov.justice.digital.hmpps.integrations.delius.risk.RiskFlagRepository
Expand Down Expand Up @@ -49,13 +47,6 @@ class RiskService(
removedRiskFlags = riskFlags.filter { it.deRegistered }.map { it.toRiskFlag() }
)
}

fun getMappaDetail(crn: String): MappaDetail {
val person = personRepository.getPerson(crn)
return riskFlagRepository.findActiveMappaRegistrationByOffenderId(person.id, PageRequest.of(0, 1))
.firstOrNull()
?.toMappa() ?: throw NotFoundException("MAPPA details for offender not found")
}
}

enum class MappaLevel(val communityValue: Int, val deliusValue: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
import org.mockito.kotlin.whenever
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageImpl
import uk.gov.justice.digital.hmpps.data.generator.IdGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.MAPPA_TYPE
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.generateRegistration
import uk.gov.justice.digital.hmpps.data.generator.personalDetails.PersonDetailsGenerator.PERSONAL_DETAILS
import uk.gov.justice.digital.hmpps.integrations.delius.compliance.NsiRepository
import uk.gov.justice.digital.hmpps.integrations.delius.overview.entity.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.delius.referencedata.entity.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.risk.RiskFlagRepository
import uk.gov.justice.digital.hmpps.utils.Summary

Expand Down Expand Up @@ -65,6 +70,35 @@ internal class RiskServiceTest {
assertThat(res.riskFlags, equalTo(expectedRiskFlags.map { it.toRiskFlag() }))
}

@Test
fun `returns nominal community level and category for mappa`() {
val crn = "X000005"
val expectedRiskFlags = listOf(
PersonGenerator.REGISTRATION_1,
PersonGenerator.REGISTRATION_2
)

val otherMappaLevel = ReferenceData(IdGenerator.getAndIncrement(), "OT", "Other Desc")
val otherMappaCategory = ReferenceData(IdGenerator.getAndIncrement(), "OT", "Other Desc")
val mappaRegistration =
generateRegistration(MAPPA_TYPE, otherMappaCategory, 1L, "Notes", level = otherMappaLevel)

whenever(personRepository.findSummary(crn)).thenReturn(personSummary)
whenever(riskFlagRepository.findByPersonId(any())).thenReturn(expectedRiskFlags)
whenever(nsiRepository.findByPersonIdAndTypeCode(any(), any())).thenReturn(emptyList())
whenever(riskFlagRepository.findActiveMappaRegistrationByOffenderId(any(), any())).thenReturn(
PageImpl(
listOf(
mappaRegistration
)
)
)

val res = service.getPersonRiskFlags(crn)
assertThat(res.mappa?.level, equalTo(MappaLevel.NOMINAL.communityValue))
assertThat(res.mappa?.category, equalTo(MappaLevel.NOMINAL.communityValue))
}

@Test
fun `calls get risk function`() {
val crn = "X000005"
Expand Down

0 comments on commit c59f75c

Please sign in to comment.