-
Notifications
You must be signed in to change notification settings - Fork 0
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
VB-5220 - Migrate a prisoner balance #50
Conversation
Initial migration to onboard a prisoner from NOMIS to dps. This PR includes a new service, handling migrating a balance of both positive and negative values. In the current system design, negative VOs are represented as their own model with unique status and types. Add integration tests to cover new migration logic.
After discussions, we believe it would be simpler to have a status limited to "available" or actively being used ("used"). In cases of visits being cancelled, we could move the state back to available as we would have from scheduled. This smaller enum set will help when calculating the balance in the future as well, as we don't need to account for an additional state.
Add ability to track prisoners last allocated date regardless of their balance size. This will allow us to simplify the allocation logic, to not care about the vo / negative_vo tables and instead go directly to the prisoner_details table to get the last allocated date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments added
src/main/kotlin/uk/gov/justice/digital/hmpps/visitallocationapi/enums/NegativeVisitOrderType.kt
Show resolved
Hide resolved
src/main/kotlin/uk/gov/justice/digital/hmpps/visitallocationapi/service/NomisSyncService.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/uk/gov/justice/digital/hmpps/visitallocationapi/service/NomisSyncService.kt
Outdated
Show resolved
Hide resolved
src/main/resources/db/migration/V1_5__create_negative_visit_order_table.sql
Outdated
Show resolved
Hide resolved
src/main/resources/db/migration/V1_8__create_prisoner_details_table.sql
Outdated
Show resolved
Hide resolved
src/main/kotlin/uk/gov/justice/digital/hmpps/visitallocationapi/service/ChangeLogService.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -59,7 +59,7 @@ interface VisitOrderRepository : JpaRepository<VisitOrder, Long> { | |||
WHERE prisoner_id = :prisonerId | |||
AND type = 'PVO' | |||
AND status = 'AVAILABLE' | |||
AND created_date < CURRENT_DATE - INTERVAL '28 days' | |||
AND created_timestamp < CURRENT_TIMESTAMP - INTERVAL '28 days' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created_timestamp::date < CURRENT_TIMESTAMP::date will set the time to start of day before doing this comparison or the time element might come into play. Might be worth adding a test to confirm.
expiryDate = null, | ||
) | ||
|
||
private fun isDueVO(prisonerId: String): Boolean { | ||
val lastVODate = visitOrderRepository.findLastAllocatedDate(prisonerId, VisitOrderType.VO) | ||
return lastVODate == null || lastVODate <= LocalDate.now().minusDays(14) | ||
return lastVODate == null || lastVODate <= LocalDateTime.now().minusDays(14) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this still be LocalDate.now()?
@@ -133,7 +132,7 @@ class AllocationService( | |||
return isDueVO(prisonerId) | |||
} | |||
|
|||
return lastPVODate <= LocalDate.now().minusDays(28) | |||
return lastPVODate <= LocalDateTime.now().minusDays(28) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
CREATE INDEX idx_visit_order_last_allocated | ||
ON visit_order (prisoner_id, type, created_timestamp DESC); | ||
|
||
COMMIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it be easier updating the existing script as this is not Live?
@@ -76,7 +76,7 @@ interface VisitOrderRepository : JpaRepository<VisitOrder, Long> { | |||
WHERE prisoner_id = :prisonerId | |||
AND type = :#{#type.name()} | |||
AND status = 'AVAILABLE' | |||
AND created_date < CURRENT_DATE - INTERVAL '28 days' | |||
AND created_timestamp < CURRENT_TIMESTAMP - INTERVAL '28 days' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
...tlin/uk/gov/justice/digital/hmpps/visitallocationapi/repository/PrisonerDetailsRepository.kt
Outdated
Show resolved
Hide resolved
...tlin/uk/gov/justice/digital/hmpps/visitallocationapi/repository/PrisonerDetailsRepository.kt
Outdated
Show resolved
Hide resolved
...ain/kotlin/uk/gov/justice/digital/hmpps/visitallocationapi/service/PrisonerDetailsService.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this PR do?
Initial migration to onboard a prisoner from NOMIS to dps.
This PR includes a new service, handling migrating a balance of both positive and negative values.
In the current system design, negative VOs are represented as their own model with unique status and types.
We also capture the prisoner's details (currently, lastAllocatedDate) to help us with allocations on our service.
Add integration tests to cover new migration logic.
JIRA Link
https://dsdmoj.atlassian.net/browse/VB-5220