Skip to content

Commit

Permalink
Merge branch 'main' into MAN-109-schedule-multiple-appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj authored Nov 1, 2024
2 parents 1487088 + 15ac418 commit 22bb2e9
Show file tree
Hide file tree
Showing 113 changed files with 1,286 additions and 1,210 deletions.
1 change: 1 addition & 0 deletions .github/workflows/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ on:
- '["common-platform-and-delius"]'
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
- common-platform-and-delius
- ims-and-delius
- appointment-reminders-and-delius
- justice-email-and-delius
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ on:
- '["common-platform-and-delius"]'
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/service-catalogue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ on:
- '["common-platform-and-delius"]'
- '["ims-and-delius"]'
- '["appointment-reminders-and-delius"]'
- '["justice-email-and-delius"]'
# ^ add new projects here
# GitHub Actions doesn't support dynamic choices, we must add each project here to enable manual deployments
# See https://github.com/community/community/discussions/11795
Expand Down
12 changes: 12 additions & 0 deletions .idea/runConfigurations/justice_email_and_delius.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/tech-docs/source/services.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ weight: 20
* [Common Platform And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/common-platform-and-delius)
* [Ims And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/ims-and-delius)
* [Appointment Reminders And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/appointment-reminders-and-delius)
* [Justice Email And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/justice-email-and-delius)
<li style="display: none">^ add new projects here</li>
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,62 @@ interface UpwAppointmentRepository : JpaRepository<UpwAppointment, Long> {
"""
select
any_value(first_name) as "firstName",
any_value(mobile_number) as "mobileNumber",
any_value(formatted_mobile_number) as "mobileNumber",
any_value(to_char(appointment_date, 'DD/MM/YYYY')) as "appointmentDate",
-- for testing --
crn as "crn",
listagg(distinct event_number, ', ') as "eventNumbers",
listagg(distinct upw_appointment_id, ', ') as "upwAppointmentIds"
from (
with unique_mobile_numbers as (
select
replace(mobile_number, ' ', '') as formatted_mobile_number,
any_value(offender_id) as offender_id
from offender where soft_deleted = 0
-- no other cases with the same mobile number
group by replace(mobile_number, ' ', '') having count(*) = 1)
select
first_name,
replace(mobile_number, ' ', '') as mobile_number,
formatted_mobile_number,
upw_appointment.appointment_date as appointment_date,
crn,
event_number,
upw_appointment.upw_appointment_id
from offender
from unique_mobile_numbers
join offender on offender.offender_id = unique_mobile_numbers.offender_id
join event on event.offender_id = offender.offender_id and event.active_flag = 1 and event.soft_deleted = 0
join disposal on disposal.event_id = event.event_id and disposal.active_flag = 1 and disposal.soft_deleted = 0
join r_disposal_type on r_disposal_type.disposal_type_id = disposal.disposal_type_id
join upw_details on upw_details.disposal_id = disposal.disposal_id and upw_details.soft_deleted = 0
join upw_appointment on upw_appointment.upw_details_id = upw_details.upw_details_id and upw_appointment.soft_deleted = 0 and trunc(upw_appointment.appointment_date) = :date
left join r_contact_outcome_type on r_contact_outcome_type.contact_outcome_type_id = upw_appointment.contact_outcome_type_id
join upw_project on upw_project.upw_project_id = upw_appointment.upw_project_id
join r_standard_reference_list upw_project_type on upw_project_type.standard_reference_list_id = upw_project.project_type_id and upw_project_type.code_value in ('ES','ICP','NP1','NP2','PI','PIP','PIP2','PL','PS','PSP','WH1')
join probation_area on probation_area.probation_area_id = upw_project.probation_area_id and probation_area.code = :providerCode
left join exclusion on exclusion.offender_id = offender.offender_id and exclusion_date < current_date and (exclusion_end_date is null or current_date < exclusion_end_date)
left join restriction on restriction.offender_id = offender.offender_id and restriction_date < current_date and (restriction_end_date is null or current_date < restriction_end_date)
where offender.soft_deleted = 0
-- valid mobile number and sms allowed
and replace(mobile_number, ' ', '') like '07%'
and length(replace(mobile_number, ' ', '')) = 11
and validate_conversion(replace(mobile_number, ' ', '') as number) = 1
-- valid mobile number
where formatted_mobile_number like '07%' and length(formatted_mobile_number) = 11 and validate_conversion(formatted_mobile_number as number) = 1
-- sms is allowed
and (allow_sms is null or allow_sms = 'Y')
-- no other cases with the same mobile number
and not exists (
select 1 from offender duplicate where duplicate.soft_deleted = 0 and replace(duplicate.mobile_number, ' ', '') = replace(offender.mobile_number, ' ', '') and duplicate.offender_id <> offender.offender_id
)
-- no access limitations
and restriction_id is null and exclusion_id is null
-- appointment does not have an outcome
and upw_appointment.contact_outcome_type_id is null
-- not on remand
and (current_remand_status is null or (current_remand_status not in ('Warrant With Bail', 'Warrant Without Bail', 'Remanded In Custody', 'Unlawfully at Large') and current_remand_status not like 'UAL%'))
and not exists (select 1 from personal_circumstance
join r_circumstance_type on r_circumstance_type.circumstance_type_id = personal_circumstance.circumstance_type_id and r_circumstance_type.code_value = 'RIC'
where personal_circumstance.offender_id = offender.offender_id and personal_circumstance.soft_deleted = 0 and (personal_circumstance.end_date is null or personal_circumstance.end_date > current_date))
-- not in custody
and not exists (select 1 from custody
join disposal custody_disposal on custody_disposal.disposal_id = custody.disposal_id and custody_disposal.active_flag = 1 and custody_disposal.soft_deleted = 0
join event custody_event on custody_event.event_id = custody_disposal.event_id and custody_event.offender_id = offender.offender_id and custody_event.active_flag = 1 and custody_event.soft_deleted = 0
join r_standard_reference_list custodial_status on custodial_status.standard_reference_list_id = custody.custodial_status_id and custodial_status.code_value in ('A', 'C', 'D')
where custody.soft_deleted = 0)
-- not on warrant or unlawfully at large
and not exists (select 1 from registration
join r_register_type on r_register_type.register_type_id = registration.register_type_id and r_register_type.code in ('IWWO', 'IWWB', 'WRSM', 'HUAL')
where registration.offender_id = offender.offender_id and registration.deregistered = 0 and registration.soft_deleted = 0)
-- has an active unpaid work requirement
and exists (select 1 from rqmnt
join r_rqmnt_type_main_category on r_rqmnt_type_main_category.rqmnt_type_main_category_id = rqmnt.rqmnt_type_main_category_id and r_rqmnt_type_main_category.code in ('W', 'W0', 'W1', 'W2')
Expand All @@ -67,29 +87,6 @@ interface UpwAppointmentRepository : JpaRepository<UpwAppointment, Long> {
(select coalesce(sum(appts.minutes_credited), 0) from upw_appointment appts where appts.upw_details_id = upw_details.upw_details_id and appts.soft_deleted = 0)
as minutes_credited
from dual)) > 0
-- appointment does not have an outcome
and r_contact_outcome_type.description is null
-- not in custody
and not exists (select 1 from custody
join disposal custody_disposal on custody_disposal.disposal_id = custody.disposal_id and custody_disposal.active_flag = 1 and custody_disposal.soft_deleted = 0
join event custody_event on custody_event.event_id = custody_disposal.event_id and custody_event.offender_id = offender.offender_id and custody_event.active_flag = 1 and custody_event.soft_deleted = 0
join r_standard_reference_list custodial_status on custodial_status.standard_reference_list_id = custody.custodial_status_id and custodial_status.code_value in ('A', 'C', 'D')
where custody.soft_deleted = 0)
-- not on remand
and (current_remand_status is null or (current_remand_status not in ('Warrant With Bail', 'Warrant Without Bail', 'Remanded In Custody', 'Unlawfully at Large') and current_remand_status not like 'UAL%'))
and not exists (select 1 from personal_circumstance
join r_circumstance_type on r_circumstance_type.circumstance_type_id = personal_circumstance.circumstance_type_id and r_circumstance_type.code_value = 'RIC'
where personal_circumstance.offender_id = offender.offender_id and personal_circumstance.soft_deleted = 0 and (personal_circumstance.end_date is null or personal_circumstance.end_date > current_date))
-- not unlawfully at large
and not exists (select 1 from registration
join r_register_type on r_register_type.register_type_id = registration.register_type_id and r_register_type.code in ('HUAL')
where registration.offender_id = offender.offender_id and registration.deregistered = 0 and registration.soft_deleted = 0)
-- not on warrant
and not exists (select 1 from registration
join r_register_type on r_register_type.register_type_id = registration.register_type_id and r_register_type.code in ('IWWO', 'IWWB', 'WRSM')
where registration.offender_id = offender.offender_id and registration.deregistered = 0 and registration.soft_deleted = 0)
-- no access limitations
and restriction_id is null and exclusion_id is null
)
group by crn
order by crn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ spring.datasource.url: jdbc:h2:mem:./test;MODE=Oracle;DEFAULT_NULL_ORDERING=HIGH

---
spring.config.activate.on-profile: oracle
spring.datasource.url: 'jdbc:tc:oracle:slim-faststart:///XEPDB1'
spring:
datasource.url: 'jdbc:tc:oracle:slim-faststart:///XEPDB1'
jpa.hibernate.ddl-auto: create

---
spring.config.activate.on-profile: delius-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package uk.gov.justice.digital.hmpps.data

import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator
import uk.gov.justice.digital.hmpps.data.generator.DocumentGenerator.generate
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.ProbationCaseGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.DocumentRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.DocumentType
import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.getByCrn
import java.util.*

@Component
Expand All @@ -17,38 +18,51 @@ class DocumentDataLoader(
private val eventRepository: EventRepository
) {
fun loadData() {
documentRepository.save(DocumentGenerator.EVENT_DOC)
documentRepository.save(DocumentGenerator.PERSON_DOC)

val person = personRepository.findByCrnAndSoftDeletedIsFalse(ProbationCaseGenerator.CASE_X320741.crn)!!

documentRepository.save(
DocumentGenerator.generatePersonDoc(
person = person,
name = "Random offender document.pdf",
alfrescoId = UUID.randomUUID().toString(),
documentType = DocumentType.DOCUMENT
documentRepository.saveAll(
listOf(
DocumentGenerator.EVENT,
DocumentGenerator.PERSON,
DocumentGenerator.PREVIOUS_CONVICTIONS,
DocumentGenerator.CPS_PACK,
DocumentGenerator.ADDRESSASSESSMENT,
DocumentGenerator.PERSONALCONTACT,
DocumentGenerator.PERSONAL_CIRCUMSTANCE,
DocumentGenerator.OFFENDER_CONTACT,
DocumentGenerator.OFFENDER_NSI,
)
)

val personEvent = PersonGenerator.generateEvent(
"1",
person.id
).apply(eventRepository::save)
val person = personRepository.getByCrn(ProbationCaseGenerator.CASE_X320741.crn)
val personEvent = PersonGenerator.generateEvent("1", person.id)
.apply(eventRepository::save)

listOf(
Pair("CPS pack.pdf", DocumentType.CPS_PACK),
Pair("Conviction document.pdf", DocumentType.PREVIOUS_CONVICTION)
).forEach {
documentRepository.save(
DocumentGenerator.generateEventDoc(
person = person,
event = personEvent,
name = it.first,
alfrescoId = UUID.randomUUID().toString(),
documentType = it.second,
)
val personDocument = generate(
tableName = "OFFENDER",
person = person,
name = "Random offender document.pdf",
alfrescoId = UUID.randomUUID().toString()
)
val cpsPack = generate(
tableName = "EVENT",
type = "CPS_PACK",
name = "CPS pack.pdf",
person = person,
primaryKeyId = personEvent.id
)
val previousConvictions = generate(
tableName = "OFFENDER",
type = "PREVIOUS_CONVICTION",
name = "Conviction document.pdf",
person = person,
primaryKeyId = person.id
)

documentRepository.saveAll(
listOf(
personDocument,
cpsPack,
previousConvictions
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import uk.gov.justice.digital.hmpps.entity.Exclusion
import uk.gov.justice.digital.hmpps.entity.LimitedAccessPerson
import uk.gov.justice.digital.hmpps.entity.Restriction
import uk.gov.justice.digital.hmpps.integrations.delius.approvedpremises.referral.entity.EventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.PersonalCircumstanceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.PersonalCircumstanceSubType
import uk.gov.justice.digital.hmpps.integrations.delius.document.entity.PersonalCircumstanceType
import uk.gov.justice.digital.hmpps.integrations.delius.person.Ldu
import uk.gov.justice.digital.hmpps.integrations.delius.person.ProbationCaseRepository
import uk.gov.justice.digital.hmpps.integrations.delius.person.manager.probation.PersonManagerRepository
Expand All @@ -24,6 +21,9 @@ import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Ma
import uk.gov.justice.digital.hmpps.integrations.delius.person.offence.entity.Offence
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegisterType
import uk.gov.justice.digital.hmpps.integrations.delius.person.registration.entity.RegistrationRepository
import uk.gov.justice.digital.hmpps.integrations.delius.personalcircumstance.PersonalCircumstanceRepository
import uk.gov.justice.digital.hmpps.integrations.delius.personalcircumstance.entity.PersonalCircumstanceSubType
import uk.gov.justice.digital.hmpps.integrations.delius.personalcircumstance.entity.PersonalCircumstanceType
import uk.gov.justice.digital.hmpps.integrations.delius.staff.StaffRepository
import uk.gov.justice.digital.hmpps.integrations.delius.team.TeamRepository
import java.time.LocalDate
Expand Down
Loading

0 comments on commit 22bb2e9

Please sign in to comment.