-
Notifications
You must be signed in to change notification settings - Fork 9
Cache session status in database #3273
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a8e70b1
to
fb30f06
Compare
27c13ad
to
a55a184
Compare
a55a184
to
7f4d581
Compare
fb30f06
to
13adedc
Compare
7f4d581
to
44224ea
Compare
13adedc
to
63da35a
Compare
44224ea
to
10ab6c3
Compare
bb40682
to
19bd43b
Compare
10ab6c3
to
31f93ae
Compare
31f93ae
to
34f95c7
Compare
34f95c7
to
80cc26d
Compare
80cc26d
to
3cc744d
Compare
cf96582
to
3fe53b2
Compare
34c6886
to
e086f92
Compare
3fe53b2
to
e70bb04
Compare
e086f92
to
45ae142
Compare
e70bb04
to
fc8cf0b
Compare
45ae142
to
747650e
Compare
fc8cf0b
to
a2917e4
Compare
This removes usage of the `all` and `latest` methods of the `SessionOutcome` in preparation for the class being replaced with a model storing a cached version of the status.
a2917e4
to
7d03546
Compare
This creates a new model that will represent the vaccination status of a patient/programme pair so the value can be queried in the database directly rather than needing to generate the status on the fly each time.
This adds a method which refreshes the status of a patient-programme pair to be used in various other parts of the service. This is the main logic that replaces the `SessionOutcome` class, although the logic itself should be the same.
This updates the factories to create instances of the new `PatientSession::VaccinationStatus` model to ensure the tests are running in representative database.
This updates the various parts of the code that relied on the `SessionOutcome` class to determine the consent status of a patient to instead use the new `PatientSession::VaccinationStatus` model with the status cached.
This can be safely removed as it's no longer being used and has been replaced with the `PatientSession::VaccinationStatus` model.
This adds a job which handles the process of updating the status of patients in the background so we can run it on a schedule or for larger sessions.
Often the session can have lots of patients in and this can be slow. To ensure the user doesn't see this slowdown, we can queue the job to run in the background and the statuses will be updated shortly.
This is necessary as the registration status of a patient is tied to the current day and needs to reset the next day when there may no longer be a session date on that day.
7d03546
to
4fe227f
Compare
|
misaka
approved these changes
Apr 1, 2025
thomasleese
added a commit
that referenced
this pull request
Apr 1, 2025
This introduces a new model, `PatientSession::RegistrationStatus`, which stores the vaccination status of a patient-session date pair in the database so it can queried and rendered quickly. Locally, I'm seeing the register outcomes page on programmes with 50,000 patients load almost instantly even when filtering on statuses. The session overview page has a slight improvement, but that will only load quickly once the other statuses are cached. I've decided not to implement a state machine as had been previously discussed, but this could be built on top of this change to enhancement the functionality. For now, this effectively caches the existing logic that runs on the fly to the database. I've also decided not to implement this using Rails callbacks and instead be explicit where the status is refreshed. This allows us to optimise for bulk refreshes, as is necessary when adding new programmes to sessions, running the seeds, or generally updating the status of an entire session. This follows up from #3273 which applies the same to the session status.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces a new model,
PatientSession::VaccinationStatus
, which stores the vaccination status of a patient-programme pair in the database so it can queried and rendered quickly. Locally, I'm seeing the session outcomes page on programmes with 50,000 patients load almost instantly even when filtering on statuses. The session overview page has a slight improvement, but that will only load quickly once the other statuses are cached.I've decided not to implement a state machine as had been previously discussed, but this could be built on top of this change to enhancement the functionality. For now, this effectively caches the existing logic that runs on the fly to the database.
I've also decided not to implement this using Rails callbacks and instead be explicit where the status is refreshed. This allows us to optimise for bulk refreshes, as is necessary when adding new programmes to sessions, running the seeds, or generally updating the status of an entire session.
To support the vaccination status of the session changing each day (when the registration status of the patient changes), this introduces a nightly job which runs and updates the statuses to ensure they are up to date when the day changes. This introduces a potential risk in case the status updater job fails. There is one scenario to call out if this rare scenario happens:
If a patient is marked as absent, the session outcome for the patient will continue to show as "absent from session" the next day until either the nightly job runs again, another status of the patient changes, or the patient is marked as absent or present again.
This follows up from #3272 which applies the same to the programme status.