Skip to content

Commit

Permalink
PI-1596 Added address processing (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister authored Oct 30, 2023
1 parent de750ab commit 1adf116
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"bookingId": "14c80733-4b6d-4f35-b724-66955aac320e",
"bookingUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/someURLtoTheBooking",
"departedAt": "2022-11-30T12:00:00",
"notes": "Person departed."
"notes": "Person departed.",
"reason": "Left of own accord | Other",
"reasonDetail": "",
"moveOnCategory": {
"description": "Friends and family",
"label": ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"bookingId": "14c80733-4b6d-4f35-b724-66955aac320e",
"bookingUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/someURLtoTheBooking",
"departedAt": "2022-11-30T12:00:00",
"notes": "Person departed."
"notes": "Person departed.",
"reason": "Left of own accord | Other",
"reasonDetail": "",
"moveOnCategory": {
"description": "Friends and family",
"label": ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ internal class CASIntegrationTest {
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EADP"))
val person = personRepository.findByCrnAndSoftDeletedIsFalse(event.message.crn())
val address = addressRepository.findAll().filter { it.personId == person?.id }[0]
MatcherAssert.assertThat(address!!.status.code, Matchers.equalTo("P"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ data class PersonDeparted(
val bookingId: String,
val bookingUrl: String,
val departedAt: ZonedDateTime,
val notes: String
val notes: String,
val reason: String,
val reasonDetail: String,
val moveOnCategory: Category

) : Cas3Event {
override val urn = "urn:hmpps:cas3:person-departed:$bookingId"
override val noteText = "${DeliusDateFormatter.format(departedAt)} $notes $bookingUrl"
override val noteText = "${DeliusDateFormatter.format(departedAt)} $notes $reason $reasonDetail ${moveOnCategory.description}"
override val contactTypeCode = ContactType.PERSON_DEPARTED
}

data class Category(
val description: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.integrations.delius

import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.PersonArrived
import uk.gov.justice.digital.hmpps.integrations.delius.entity.AddressTypeCode
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Person
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonAddress
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonAddressRepository
Expand All @@ -10,6 +11,7 @@ import uk.gov.justice.digital.hmpps.integrations.delius.entity.cas3AddressType
import uk.gov.justice.digital.hmpps.integrations.delius.entity.mainAddressStatus
import uk.gov.justice.digital.hmpps.integrations.delius.entity.previousAddressStatus
import java.time.LocalDate
import java.time.ZonedDateTime

@Service
class AddressService(
Expand All @@ -30,6 +32,18 @@ class AddressService(
}
}

fun endMainCAS3Address(person: Person, endDate: ZonedDateTime) {
val currentMain = personAddressRepository.findMainAddress(person.id)
currentMain?.apply {
if (currentMain.type.code == AddressTypeCode.CAS3.code) {
val previousStatus = referenceDataRepository.previousAddressStatus()
currentMain.status = previousStatus
currentMain.endDate = endDate.toLocalDate()
personAddressRepository.save(currentMain)
}
}
}

private fun toPersonAddress(person: Person, details: PersonArrived): PersonAddress {
val addressLines = details.premises.addressLines
return PersonAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ class Handler(
}

"accommodation.cas3.person.departed" -> {
contactService.createContact(event.crn()) {
cas3ApiClient.getPersonDeparted(event.url())
val person = personRepository.getByCrn(event.crn())
val detail = cas3ApiClient.getPersonDeparted(event.url())
contactService.createContact(event.crn(), person) {
detail
}
addressService.endMainCAS3Address(person, detail.eventDetails.departedAt)
telemetryService.trackEvent("PersonDeparted", event.telemetryProperties())
}

Expand Down

0 comments on commit 1adf116

Please sign in to comment.