Skip to content

Conversation

thomasleese
Copy link
Contributor

@thomasleese thomasleese commented Mar 24, 2025

This introduces a new model, Patient::TriageStatus, which stores the triage status of a patient-programme pair in the database so it can queried and rendered quickly. Locally, I'm seeing the triage tab on sessions 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 #3263 which applies the same to the consents.

@thomasleese thomasleese added the performance Improving performance label Mar 24, 2025
@thomasleese thomasleese force-pushed the cache-consent-status branch from ee5b2fe to 66c5a13 Compare March 24, 2025 10:05
@thomasleese thomasleese force-pushed the cache-triage-status branch from 9f3f489 to 7e59956 Compare March 24, 2025 10:05
@thomasleese thomasleese added this to the v2.1.2 milestone Mar 24, 2025
@thomasleese thomasleese force-pushed the cache-consent-status branch from 66c5a13 to 1995557 Compare March 24, 2025 11:59
@thomasleese thomasleese force-pushed the cache-triage-status branch from 7e59956 to 5647c6b Compare March 24, 2025 12:20
@thomasleese thomasleese force-pushed the cache-consent-status branch 4 times, most recently from 462a6de to 1013b56 Compare March 24, 2025 18:50
@thomasleese thomasleese force-pushed the cache-triage-status branch from 5647c6b to 14fec04 Compare March 24, 2025 19:20
@thomasleese thomasleese marked this pull request as ready for review March 24, 2025 19:21
@thomasleese thomasleese force-pushed the cache-consent-status branch from 1013b56 to 592ed46 Compare March 24, 2025 19:26
@thomasleese thomasleese force-pushed the cache-triage-status branch from 14fec04 to 1c9a3f0 Compare March 24, 2025 19:26
@thomasleese thomasleese force-pushed the cache-consent-status branch from 592ed46 to 61a6085 Compare March 24, 2025 21:00
@thomasleese thomasleese force-pushed the cache-triage-status branch from 1c9a3f0 to d851bf4 Compare March 24, 2025 21:05
@thomasleese thomasleese force-pushed the cache-consent-status branch 2 times, most recently from 5a20b9f to 8a82523 Compare March 25, 2025 22:01
@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-consent-status branch 3 times, most recently from 2ed3092 to a6037bf Compare March 26, 2025 07:52
@thomasleese thomasleese force-pushed the cache-consent-status branch 3 times, most recently from ebb2e85 to 55b5484 Compare March 28, 2025 16:22
@thomasleese thomasleese force-pushed the cache-triage-status branch from 2592c40 to ad2058b Compare March 28, 2025 16:23
@thomasleese thomasleese force-pushed the cache-triage-status branch from ad2058b to 16ff865 Compare March 28, 2025 16:25
@thomasleese thomasleese force-pushed the cache-consent-status branch from 55b5484 to 921f83b Compare March 28, 2025 16:29
@thomasleese thomasleese force-pushed the cache-triage-status branch from 16ff865 to 827a407 Compare March 28, 2025 16:30
@thomasleese thomasleese force-pushed the cache-consent-status branch from 921f83b to c497667 Compare March 28, 2025 17:03
@thomasleese thomasleese force-pushed the cache-triage-status branch from 827a407 to dbb76a7 Compare March 28, 2025 17:03
Base automatically changed from cache-consent-status to v2.1.2-wip March 28, 2025 17:11
This removes any usage of the `all` method on the `TriageOutcome` class
in preparation for the removal of the `TriageOutcome` class. I think it
also simplifies the code by avoiding the need to go through another
class to fetch all the triage records.
This removes usage of the `latest` method on the `TriageOutcome` class
in preparation for the removal of this class.
This creates a new model that will represent the triage 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 `TriageOutcome` class, although the logic
itself should be the same.
This updates the factories to create instances of the new
`Patient::TriageStatus` model to ensure the tests are running in
representative database.
This updates the various parts of the code that relied on the
`TriageOutcome` class to determine the consent status of a patient to
instead use the new `Patient::TriageStatus` model with the status
cached.
This can be safely removed as it's no longer being used and has been
replaced with the `Patient::TriageStatus` model.
This removes the column from the `Patient::ConsentStatus` model as it's
no longer being used. Instead, the triage status is calculated using the
values from the consent directly meaning the consent status and triage
status can be updated independently.
@thomasleese thomasleese force-pushed the cache-triage-status branch from dbb76a7 to b815421 Compare March 28, 2025 17:12
@tvararu tvararu temporarily deployed to mavis-pr-3268 March 28, 2025 17:12 Inactive
Copy link

@thomasleese thomasleese merged commit 0ef0327 into v2.1.2-wip Mar 31, 2025
11 checks passed
@thomasleese thomasleese deleted the cache-triage-status branch March 31, 2025 13:23
thomasleese added a commit that referenced this pull request Mar 31, 2025
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.
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