Skip to content

Conversation

thomasleese
Copy link
Contributor

This introduces a new model, Patient::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 children 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 #3268 which applies the same to the triage.

@thomasleese thomasleese added the performance Improving performance label Mar 25, 2025
@thomasleese thomasleese added this to the v2.1.2 milestone Mar 25, 2025
@thomasleese thomasleese force-pushed the cache-programme-status branch from 1c1836c to a8e70b1 Compare March 25, 2025 18:09
@thomasleese thomasleese force-pushed the cache-programme-status branch from a8e70b1 to fb30f06 Compare March 25, 2025 18:10
@thomasleese thomasleese force-pushed the cache-programme-status branch from fb30f06 to 13adedc Compare March 25, 2025 20:00
@thomasleese thomasleese force-pushed the cache-triage-status branch from d851bf4 to 327c9b8 Compare March 25, 2025 22:02
@thomasleese thomasleese force-pushed the cache-programme-status branch from 13adedc to 63da35a Compare March 25, 2025 22:09
@thomasleese thomasleese force-pushed the cache-triage-status branch from 327c9b8 to 8b6224c Compare March 26, 2025 08:15
@thomasleese thomasleese force-pushed the cache-programme-status branch from 63da35a to 8df5d1f Compare March 26, 2025 08:30
@thomasleese thomasleese force-pushed the cache-triage-status branch from 8b6224c to ef1b470 Compare March 26, 2025 09:10
@thomasleese thomasleese force-pushed the cache-programme-status branch from 8df5d1f to 90754f0 Compare March 26, 2025 09:19
@thomasleese thomasleese force-pushed the cache-programme-status branch from 90754f0 to bb40682 Compare March 26, 2025 09:31
@thomasleese thomasleese force-pushed the cache-programme-status branch from bb40682 to 19bd43b Compare March 26, 2025 11:15
@thomasleese thomasleese force-pushed the cache-triage-status branch from ef1b470 to 124128f Compare March 26, 2025 17:26
@thomasleese thomasleese force-pushed the cache-programme-status branch from 19bd43b to 54fce39 Compare March 26, 2025 17:27
@thomasleese thomasleese force-pushed the cache-triage-status branch from 124128f to 2592c40 Compare March 28, 2025 09:45
@thomasleese thomasleese force-pushed the cache-programme-status branch from 54fce39 to bed9771 Compare March 28, 2025 09:46
@thomasleese thomasleese force-pushed the cache-programme-status branch from bed9771 to 956d6c8 Compare March 28, 2025 14:00
@thomasleese thomasleese force-pushed the cache-triage-status branch 3 times, most recently from 16ff865 to 827a407 Compare March 28, 2025 16:30
@thomasleese thomasleese force-pushed the cache-programme-status branch from 956d6c8 to 34c6886 Compare March 28, 2025 16:31
@thomasleese thomasleese force-pushed the cache-triage-status branch from 827a407 to dbb76a7 Compare March 28, 2025 17:03
@thomasleese thomasleese force-pushed the cache-programme-status branch from 34c6886 to e086f92 Compare March 28, 2025 17:03
@thomasleese thomasleese force-pushed the cache-triage-status branch from dbb76a7 to b815421 Compare March 28, 2025 17:12
@thomasleese thomasleese force-pushed the cache-programme-status branch from e086f92 to 45ae142 Compare March 28, 2025 17:12
Base automatically changed from cache-triage-status to v2.1.2-wip March 31, 2025 13:23
This removes any usage of the `all` method on the `ProgrammeOutcome` class
in preparation for the removal of the `ProgrammeOutcome` class. I think it
also simplifies the code by avoiding the need to go through another
class to fetch all the triage records.
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 `VaccinationOutcome` class, although the logic
itself should be the same.
This updates the factories to create instances of the new
`Patient::VaccinationStatus` model to ensure the tests are running
in representative database.
This updates the various parts of the code that relied on the
`ProgrammeOutcome` class to determine the consent status of a patient
to instead use the new `Patient::VaccinationStatus` model with the
status cached.
This can be safely removed as it's no longer being used and has been
replaced with the `Patient::VaccinationStatus` model.
This simplifies the next activity generation and moves it to a method on
to the `PatientSession` model since it's only used in once place.
@thomasleese thomasleese force-pushed the cache-programme-status branch from 45ae142 to 747650e Compare March 31, 2025 13:24
@tvararu tvararu temporarily deployed to mavis-pr-3272 March 31, 2025 13:24 Inactive
Copy link

@thomasleese thomasleese merged commit 7723722 into v2.1.2-wip Mar 31, 2025
11 checks passed
@thomasleese thomasleese deleted the cache-programme-status branch March 31, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improving performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants