Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

APS-1752 - Filter out rejected referrals when importing delius bookings #2771

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Cas1ImportDeliusReferralsSeedJob(
"KEY_WORKER_FORENAME",
"KEY_WORKER_MIDDLE_NAME",
"KEY_WORKER_SURNAME",
"DECISION_CODE",
"DECISION_DESCRIPTION",
"DEPARTURE_REASON_CODE",
"MOVE_ON_CATEGORY_CODE",
"MOVE_ON_CATEGORY_DESCRIPTION",
Expand Down Expand Up @@ -65,6 +67,8 @@ class Cas1ImportDeliusReferralsSeedJob(
keyWorkerForename = seedColumns.getStringOrNull("KEY_WORKER_FORENAME"),
keyWorkerMiddleName = seedColumns.getStringOrNull("KEY_WORKER_MIDDLE_NAME"),
keyWorkerSurname = seedColumns.getStringOrNull("KEY_WORKER_SURNAME"),
decisionCode = seedColumns.getStringOrNull("DECISION_CODE")!!,
decisionDescription = seedColumns.getStringOrNull("DECISION_DESCRIPTION")!!,
departureReasonCode = seedColumns.getStringOrNull("DEPARTURE_REASON_CODE"),
moveOnCategoryCode = seedColumns.getStringOrNullMinus1IsNull("MOVE_ON_CATEGORY_CODE"),
moveOnCategoryDescription = seedColumns.getStringOrNull("MOVE_ON_CATEGORY_DESCRIPTION"),
Expand Down Expand Up @@ -100,6 +104,10 @@ class Cas1ImportDeliusReferralsSeedJob(
return
}

if (!isAccepted(row)) {
return
}

cas1DeliusBookingImportRepository.save(
Cas1DeliusBookingImportEntity(
id = UUID.randomUUID(),
Expand Down Expand Up @@ -129,6 +137,8 @@ class Cas1ImportDeliusReferralsSeedJob(
)
}

private fun isAccepted(row: Cas1DeliusBookingManagementDataRow) = row.decisionCode.startsWith("A")

override fun postSeed() {
log.info(
"""
Expand All @@ -147,6 +157,8 @@ data class Cas1DeliusBookingManagementDataRow(
val keyWorkerForename: String?,
val keyWorkerMiddleName: String?,
val keyWorkerSurname: String?,
val decisionCode: String,
val decisionDescription: String,
val departureReasonCode: String?,
val moveOnCategoryCode: String?,
val moveOnCategoryDescription: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.time.OffsetDateTime
import java.util.UUID

@TestInstance(TestInstance.Lifecycle.PER_METHOD)
class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
class SeedCas1ImportDeliusReferralsTest : SeedTestBase() {

@Autowired
lateinit var cas1DeliusBookingImportRepository: Cas1DeliusBookingImportRepository
Expand Down Expand Up @@ -44,6 +44,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
Cas1DeliusBookingManagementDataRowRaw(
crn = "CRN1",
eventNumber = "1",
decisionCode = "A1",
decisionDescription = "Accepted Code 1",
expectedArrivalDate = "2024-06-15 00:00:00",
hostelCode = "hostel code",
),
Expand Down Expand Up @@ -91,6 +93,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
keyWorkerForename = "kwForename",
keyWorkerMiddleName = "kwMiddle",
keyWorkerSurname = "kwSurname",
decisionCode = "A1",
decisionDescription = "Accepted Code 1",
departureReasonCode = "drc",
moveOnCategoryCode = "mocc",
moveOnCategoryDescription = "moccDescription",
Expand Down Expand Up @@ -134,6 +138,35 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
assertThat(bookingImport.premisesQcode).isEqualTo("hostel code")
}

@Test
fun `Only include accepted referrals`() {
val allDecisionCodes = listOf(
"AD", "ADA1", "ASA2", "ADA3", "AI", "A10", "AR", "DPAA", "-1",
"DP", "DR", "IR", "2", "3", "1", "8", "RJ", "9", "4", "6", "7", "5",
)

withCsv(
csvName = "valid-csv",
contents =
allDecisionCodes.map { decisionCode ->
Cas1DeliusBookingManagementDataRowRaw(
crn = decisionCode,
eventNumber = "1",
decisionCode = decisionCode,
decisionDescription = decisionCode,
expectedArrivalDate = "2024-06-15 00:00:00",
hostelCode = "hostel code",
)
}.toCsv(),
)

seedService.seedData(SeedFileType.approvedPremisesImportDeliusReferrals, "valid-csv.csv")

val bookingImport = cas1DeliusBookingImportRepository.findAll()

assertThat(bookingImport.map { it.crn }).containsExactlyInAnyOrder("AD", "ADA1", "ASA2", "ADA3", "AI", "A10", "AR")
}

@Test
fun `Fields containing invalid data are set to null`() {
val bookingId = UUID.randomUUID()
Expand All @@ -148,6 +181,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
expectedArrivalDate = "2024-06-15 00:00:00",
hostelCode = "hostel code",
keyWorkerStaffCode = "-1",
decisionCode = "A1",
decisionDescription = "Accepted Code 1",
moveOnCategoryCode = "-1",
nonArrivalReasonCode = "-1",
arrivalDate = "1900-01-01 00:00:00",
Expand Down Expand Up @@ -181,6 +216,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
"KEY_WORKER_FORENAME",
"KEY_WORKER_MIDDLE_NAME",
"KEY_WORKER_SURNAME",
"DECISION_CODE",
"DECISION_DESCRIPTION",
"DEPARTURE_REASON_CODE",
"MOVE_ON_CATEGORY_CODE",
"MOVE_ON_CATEGORY_DESCRIPTION",
Expand All @@ -206,6 +243,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
.withQuotedField(it.keyWorkerForename)
.withQuotedField(it.keyWorkerMiddleName)
.withQuotedField(it.keyWorkerSurname)
.withQuotedField(it.decisionCode)
.withQuotedField(it.decisionDescription)
.withQuotedField(it.departureReasonCode)
.withQuotedField(it.moveOnCategoryCode)
.withQuotedField(it.moveOnCategoryDescription)
Expand Down Expand Up @@ -233,6 +272,8 @@ class SeedCas1ImportDeliusReferralsSeedJobTest : SeedTestBase() {
val keyWorkerForename: String = "",
val keyWorkerMiddleName: String = "",
val keyWorkerSurname: String = "",
val decisionCode: String = "",
val decisionDescription: String = "",
val departureReasonCode: String = "",
val moveOnCategoryCode: String = "",
val moveOnCategoryDescription: String = "",
Expand Down
Loading