Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

APG-658 Capture override reason as part of referral update #777

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {
val springdocVersion = "2.6.0"
val sentryVersion = "8.0.0"
val jsonWebtokenVersion = "0.12.6"
val springSecurityVersion = "6.4.0"
val springSecurityVersion = "6.4.2"

implementation("uk.gov.justice.service.hmpps:hmpps-kotlin-spring-boot-starter:1.0.8")
// Override netty-common version to address https://osv.dev/vulnerability/GHSA-xq3w-v528-46rv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ data class ReferralEntity(
var primaryPomStaffId: BigInteger? = null,
@Column(name = "secondary_pom_staff_id")
var secondaryPomStaffId: BigInteger? = null,

var overrideReason: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class ReferralUpdate(
val additionalInformation: String?,
val oasysConfirmed: Boolean,
val hasReviewedProgrammeHistory: Boolean,
val overrideReason: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import uk.gov.justice.digital.hmpps.hmppsaccreditedprogrammesapi.restapi.model.S
* @param statusDescription The status description.
* @param statusColour The colour to display status description.
* @param submittedOn
* @param overrideReason
*/
data class Referral(

Expand Down Expand Up @@ -58,7 +59,9 @@ data class Referral(
@Schema(example = "null", description = "")
@get:JsonProperty("submittedOn") val submittedOn: String? = null,

@Schema(example = "The reason for going with the recommended course is...", description = "Reason for overriding the recommended course")
@get:JsonProperty("overrideReason") val overrideReason: String? = null,

@Schema(example = "null", description = "")
@get:JsonProperty("primaryPrisonOffenderManager") val primaryPrisonOffenderManager: PrisonOffenderManager? = null,

)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.media.Schema
* @param oasysConfirmed
* @param hasReviewedProgrammeHistory
* @param additionalInformation
* @param overrideReason
*/
data class ReferralUpdate(

Expand All @@ -19,4 +20,7 @@ data class ReferralUpdate(

@Schema(example = "null", description = "")
@get:JsonProperty("additionalInformation") val additionalInformation: String? = null,

@Schema(example = "The reason for going with the recommended course is...", description = "Reason for overriding the recommended course")
@get:JsonProperty("overrideReason") val overrideReason: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun ReferralEntity.toApi(status: ReferralStatusRefData, staffDetail: StaffDetail
statusColour = status.colour,
submittedOn = submittedOn?.toString(),
primaryPrisonOffenderManager = staffDetail,
overrideReason = overrideReason,
)

fun ReferralEntity.toApi(): ApiReferral = ApiReferral(
Expand All @@ -37,6 +38,7 @@ fun ReferralEntity.toApi(): ApiReferral = ApiReferral(
hasReviewedProgrammeHistory = hasReviewedProgrammeHistory,
additionalInformation = additionalInformation,
status = status,
overrideReason = overrideReason,
)

fun StaffEntity.toApi() = StaffDetail(
Expand All @@ -52,12 +54,14 @@ fun ApiReferralUpdate.toDomain() = ReferralUpdate(
additionalInformation = additionalInformation,
oasysConfirmed = oasysConfirmed,
hasReviewedProgrammeHistory = hasReviewedProgrammeHistory,
overrideReason = overrideReason,
)

fun ReferralUpdate.toApi() = ApiReferralUpdate(
additionalInformation = additionalInformation,
oasysConfirmed = oasysConfirmed,
hasReviewedProgrammeHistory = hasReviewedProgrammeHistory,
overrideReason = overrideReason,
)

fun ReferralViewEntity.toApi() = ReferralView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ constructor(
referral.additionalInformation = update.additionalInformation
referral.oasysConfirmed = update.oasysConfirmed
referral.hasReviewedProgrammeHistory = update.hasReviewedProgrammeHistory
referral.overrideReason = update.overrideReason
}

fun updateReferralStatusById(referralId: UUID, referralStatusUpdate: ReferralStatusUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data class SarReferral(
val hasReviewedProgrammeHistory: Boolean?,
val additionalInformation: String?,
val submittedOn: LocalDateTime?,
val overrideReason: String?,
val referrerUsername: String?,
val courseName: String?,
val audience: String?,
Expand Down Expand Up @@ -101,6 +102,7 @@ private fun List<ReferralEntity>.toSarReferral(): List<SarReferral> {
it.hasReviewedProgrammeHistory,
it.additionalInformation,
it.submittedOn,
it.overrideReason,
it.referrer.username,
it.offering.course.name,
it.offering.course.audience,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

ALTER TABLE referral
ADD COLUMN override_reason text;
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class PersistenceHelper {
.executeUpdate()
}

fun createReferral(referralId: UUID, offeringId: UUID, prisonNumber: String, referrerUsername: String, additionalInformation: String, oasysConfirmed: Boolean, hasReviewedProgrammeHistory: Boolean, status: String, submittedOn: LocalDateTime?, primaryPomStaffId: BigInteger = "1".toBigInteger(), secondaryPomStaffId: BigInteger = "2".toBigInteger()) {
entityManager.createNativeQuery("INSERT INTO referral (referral_id, offering_id, prison_number, referrer_username, additional_information, oasys_confirmed, has_reviewed_programme_history, status, submitted_on, primary_pom_staff_id, secondary_pom_staff_id) VALUES (:id, :offeringId, :prisonNumber, :referrerUsername, :additionalInformation, :oasysConfirmed, :hasReviewedProgrammeHistory, :status, :submittedOn, :primaryPomStaffId, :secondaryPomStaffId)")
fun createReferral(referralId: UUID, offeringId: UUID, prisonNumber: String, referrerUsername: String, additionalInformation: String, oasysConfirmed: Boolean, hasReviewedProgrammeHistory: Boolean, status: String, submittedOn: LocalDateTime?, primaryPomStaffId: BigInteger = "1".toBigInteger(), secondaryPomStaffId: BigInteger = "2".toBigInteger(), overrideReason: String? = null) {
entityManager.createNativeQuery("INSERT INTO referral (referral_id, offering_id, prison_number, referrer_username, additional_information, oasys_confirmed, has_reviewed_programme_history, status, submitted_on, primary_pom_staff_id, secondary_pom_staff_id, override_reason) VALUES (:id, :offeringId, :prisonNumber, :referrerUsername, :additionalInformation, :oasysConfirmed, :hasReviewedProgrammeHistory, :status, :submittedOn, :primaryPomStaffId, :secondaryPomStaffId, :overrideReason)")
.setParameter("id", referralId)
.setParameter("offeringId", offeringId)
.setParameter("prisonNumber", prisonNumber)
Expand All @@ -103,6 +103,7 @@ class PersistenceHelper {
.setParameter("submittedOn", submittedOn)
.setParameter("primaryPomStaffId", primaryPomStaffId)
.setParameter("secondaryPomStaffId", secondaryPomStaffId)
.setParameter("overrideReason", overrideReason)
.executeUpdate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
hasReviewedProgrammeHistory = false,
submittedOn = null,
primaryPrisonOffenderManager = null,
overrideReason = null,
)

val auditEntity = auditRepository.findAll()
Expand Down Expand Up @@ -211,6 +212,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
additionalInformation = "test",
overrideReason = "Scored higher in OSP, should go onto Kaizen",
),
)
submitReferral(referralCreated.id)
Expand Down Expand Up @@ -276,6 +278,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
oasysConfirmed = false,
hasReviewedProgrammeHistory = false,
submittedOn = null,
overrideReason = null,
)

val auditEntity = auditRepository.findAll()
Expand All @@ -295,6 +298,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
additionalInformation = "Additional information",
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
overrideReason = "Override reason",
)

updateReferral(referralCreated.id, referralUpdate)
Expand All @@ -314,6 +318,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
submittedOn = null,
overrideReason = "Override reason",
)
}

Expand All @@ -329,6 +334,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
additionalInformation = "Additional information",
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
overrideReason = "Override reason",
),
)
.exchange().expectStatus().isNotFound
Expand Down Expand Up @@ -380,6 +386,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
oasysConfirmed = false,
additionalInformation = null,
submittedOn = null,
overrideReason = null,
)
}

Expand Down Expand Up @@ -761,6 +768,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
additionalInformation = "Additional information",
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
overrideReason = "Override reason",
)

updateReferral(referralCreated.id, referralUpdate)
Expand Down Expand Up @@ -789,6 +797,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
additionalInformation = "Additional information",
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
overrideReason = "Override reason",
)

updateReferral(referralCreated.id, referralUpdate)
Expand Down Expand Up @@ -817,6 +826,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
additionalInformation = "Additional information",
oasysConfirmed = true,
hasReviewedProgrammeHistory = true,
overrideReason = null,
)

updateReferral(referralCreated.id, referralUpdate)
Expand Down Expand Up @@ -1564,6 +1574,7 @@ class ReferralControllerIntegrationTest : IntegrationTestBase() {
courseOrganisation shouldBe offering.organisationId
oasysConfirmed shouldBe referralEntity.oasysConfirmed
additionalInformation shouldBe referralEntity.additionalInformation
overrideReason shouldBe referralEntity.overrideReason
hasReviewedProgrammeHistory shouldBe referralEntity.hasReviewedProgrammeHistory
statusCode shouldBe referralEntity.status
referrerUsername shouldBe referralEntity.referrer.username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ReferralEntityFactory {
private var hasReviewedProgrammeHistory: Boolean = false
private var status: String = REFERRAL_STARTED
private var submittedOn: LocalDateTime? = null
private var overrideReason: String? = null

fun withId(id: UUID?) = apply { this.id = id }
fun withOffering(offering: OfferingEntity) = apply { this.offering = offering }
Expand All @@ -26,6 +27,7 @@ class ReferralEntityFactory {
fun withOasysConfirmed(oasysConfirmed: Boolean) = apply { this.oasysConfirmed = oasysConfirmed }
fun withHasReviewedProgrammeHistory(hasReviewedProgrammeHistory: Boolean) = apply { this.hasReviewedProgrammeHistory = hasReviewedProgrammeHistory }
fun withStatus(status: String) = apply { this.status = status }
fun withOverrideReason(overrideReason: String?) = apply { this.overrideReason = overrideReason }

fun produce() = ReferralEntity(
id = this.id,
Expand All @@ -37,5 +39,6 @@ class ReferralEntityFactory {
hasReviewedProgrammeHistory = this.hasReviewedProgrammeHistory,
status = this.status,
submittedOn = this.submittedOn,
overrideReason = this.overrideReason,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ constructor(
.withAdditionalInformation("Additional Info")
.withOasysConfirmed(true)
.withHasReviewedProgrammeHistory(true)
.withOverrideReason("Override Reason")
.produce()

every { referralService.getReferralById(referral.id!!) } returns referral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ class ReferralServiceTest {
.withAdditionalInformation("additional info")
.withId(referralId)
.withStatus(REFERRAL_STARTED)
.withOverrideReason("override reason")
.produce()

every { referralRepository.getReferenceById(referralId) } returns referral
Expand Down
Loading