Skip to content

Commit 9b57a41

Browse files
thomasleesestevehook
authored andcommitted
Ignore time when matching vaccination records
When importing historical vaccination records, we should ignore the time component when trying to find an existing vaccination record. This should reduce the number of duplicates we end up importing as sometimes the time will already be set in the service but the time will be known in the import. Jira-Issue: MAV-3184
1 parent 059503d commit 9b57a41

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

app/jobs/search_vaccination_records_in_nhs_job.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def deduplicate_vaccination_records(incoming_vaccination_records)
110110
.includes(:team)
111111

112112
grouped_vaccination_records =
113-
vaccination_records.group_by do
114-
[it.performed_at.to_date, it.programme_type]
115-
end
113+
vaccination_records.group_by { [it.performed_at_date, it.programme_type] }
116114

117115
deduplicated_vaccination_records = []
118116

app/models/immunisation_import_row.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def to_vaccination_record
138138
outcome:,
139139
patient_id: patient.id,
140140
performed_at_date:,
141-
performed_at_time:,
142141
performed_by_user:,
143142
performed_ods_code: performed_ods_code&.to_s,
144143
programme_type: programme.type,
@@ -168,10 +167,11 @@ def to_vaccination_record
168167
attributes_to_stage_if_already_exists = {
169168
batch_number: batch_name&.to_s,
170169
batch_expiry: batch_expiry&.to_date,
171-
notes: notes&.to_s,
172-
vaccine_id: vaccine&.id,
173170
discarded_at: nil,
174-
source:
171+
notes: notes&.to_s,
172+
performed_at_time:,
173+
source:,
174+
vaccine_id: vaccine&.id
175175
}
176176

177177
vaccination_record =

spec/models/immunisation_import_row_spec.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@
13111311
end
13121312
end
13131313

1314-
context "with an existing vaccination record" do
1314+
context "with an existing vaccination record with the same UUID" do
13151315
let!(:existing_vaccination_record) do
13161316
create(
13171317
:vaccination_record,
@@ -1336,6 +1336,38 @@
13361336
end
13371337
end
13381338

1339+
context "with an existing vaccination record with the same programme and date" do
1340+
let(:vaccine) { Vaccine.find_by!(upload_name: "Gardasil9") }
1341+
let(:patient) do
1342+
create(
1343+
:patient,
1344+
given_name:,
1345+
family_name:,
1346+
date_of_birth: Date.parse(date_of_birth),
1347+
address_postcode:,
1348+
nhs_number:
1349+
)
1350+
end
1351+
1352+
let!(:existing_vaccination_record) do
1353+
create(
1354+
:vaccination_record,
1355+
location_name: "Waterloo Road",
1356+
patient:,
1357+
performed_at: Time.zone.local(2024, 1, 1, 12, 30),
1358+
performed_by_user: nil,
1359+
performed_ods_code: "ABC",
1360+
programme: programmes.first,
1361+
vaccine:
1362+
)
1363+
end
1364+
1365+
let(:data) { valid_data }
1366+
1367+
it { should_not be_nil }
1368+
it { should eq(existing_vaccination_record) }
1369+
end
1370+
13391371
describe "#batch_number" do
13401372
subject(:batch_number) { vaccination_record.batch_number }
13411373

0 commit comments

Comments
 (0)