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

VB-5220 - Migrate a prisoner balance #50

Merged
merged 13 commits into from
Mar 12, 2025

Conversation

adaviesMOJ
Copy link
Contributor

@adaviesMOJ adaviesMOJ commented Mar 7, 2025

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

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.
Copy link
Contributor

@dhirajshettymoj dhirajshettymoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments added

Copy link
Contributor

@dhirajshettymoj dhirajshettymoj left a 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'
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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;
Copy link
Contributor

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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

@dhirajshettymoj dhirajshettymoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adaviesMOJ adaviesMOJ merged commit 5791055 into main Mar 12, 2025
6 of 7 checks passed
@adaviesMOJ adaviesMOJ deleted the VB-5220-initial-migration-service branch March 12, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants