Conversation
2cff41e to
d7ea6b3
Compare
c33b18d to
3276762
Compare
3276762 to
fae4447
Compare
| before_validation :set_nhs_number_first_added_at, | ||
| if: :will_save_change_to_nhs_number? |
There was a problem hiding this comment.
I don't think this will always work, particularly if we're importing patients in bulk via Patient.import (where callbacks won't typically be called).
I think we might need to add something to
manage-vaccinations-in-schools/app/models/immunisation_import_row.rb
Lines 553 to 564 in ea73635
In general we've tried to avoid callbacks where possible due to the fact that they don't always execute and instead set the values explicitly.
There was a problem hiding this comment.
I think I've added unit tests for each place where the nhs number can change. It looks like the callback works in almost all cases, but as you said it doesn't trigger during imports.
I was struggling to find a nice way to explicitly set nhs_number_added_at in all cases, since we'd need to do this for real changes, staged changes and bulk imports which would all be slightly different (plus we'd need to do this for any future mechanisms that set nhs numbers).
The callback does work in most cases, so any "standard" future mechanism that changes nhs numbers should be covered by it. If there are any new mechanisms that don't trigger callbacks, ideally we'd investigate and see that we need to update the nhs_number_first_added_at field as a part of the mechanism.
For now I've kept the callback and handled the bulk import case manually, but would be interested to hear what you think about it
2c6745e to
6f3d36a
Compare
| add_column :patients, :nhs_number_first_added_at, :datetime | ||
| add_index :patients, :nhs_number_first_added_at |
There was a problem hiding this comment.
Can we test how long this takes on data replication, as I believe it'll lock the table, particularly adding the index.
There was a problem hiding this comment.
Good point, we should definitely test this. I don't have DR access but I can find someone to test this with
There was a problem hiding this comment.
I've had another look and it seems we should be a bit more careful about this, so I've split the migrations up and moved the backfill column part to data - which will now be handled in batches and outside of a transaction
| existing_patient.public_send( | ||
| "#{attribute}=", | ||
| child_attributes[attribute.to_s] | ||
| ) |
There was a problem hiding this comment.
Is this change necessary because the callbacks don't execute without it?
There was a problem hiding this comment.
Yes, the callbacks didn't execute otherwise
8154b94 to
34bf138
Compare
* Will be used by Automated Careplus reports Jira-Issue: MAV-7091
* Will be used by Automated Careplus reports Jira-Issue: MAV-7091
* Include records for patients that gained an nhs number in the last day * Only include these records if they were created after the careplus integration was enabled Jira-Issue: MAV-7091
Jira-Issue: MAV-7091
34bf138 to
dec3d61
Compare
From the ticket:
We accomplish this by adding a
nhs_number_first_added_atfield toPatientand acareplus_integration_enabled_atfield toTeam. This allows us to extend the scope of the automated careplus reporter.Jira Issue - MAV-7091