diff --git a/app/models/immunisation_import.rb b/app/models/immunisation_import.rb index 6f085bb55e..cd0afa1d57 100644 --- a/app/models/immunisation_import.rb +++ b/app/models/immunisation_import.rb @@ -92,7 +92,7 @@ def parse_row(data) end def process_row(row) - patient = row.set_patient(candidates: @all_patients) + patient = row.set_patient(candidates: @patients_batch) vaccination_record = row.to_vaccination_record count_column_to_increment = count_column(vaccination_record) @@ -100,7 +100,6 @@ def process_row(row) @vaccination_records_batch.add(vaccination_record) @patients_batch.add(patient) - @all_patients.add(patient) if (patient_location = row.to_patient_location) @patient_locations_batch.add(patient_location) @@ -118,7 +117,6 @@ def process_import! @vaccination_records_batch = Set.new @patients_batch = Set.new - @all_patients = Set.new @patient_locations_batch = Set.new @archive_reasons_batch = Set.new diff --git a/app/models/immunisation_import_row.rb b/app/models/immunisation_import_row.rb index 2b38b2e3ab..92db1d9789 100644 --- a/app/models/immunisation_import_row.rb +++ b/app/models/immunisation_import_row.rb @@ -504,24 +504,23 @@ def existing_patients(candidates: nil) return end - if candidates.present? - # Match against the in-memory list of patients so far in this upload, before matching against the database - candidate_matches = - PatientMatcher.from_enumerable( - candidates, - nhs_number: patient_nhs_number_value, - given_name: patient_first_name.to_s, - family_name: patient_last_name.to_s, - date_of_birth: patient_date_of_birth.to_date, - address_postcode: patient_postcode&.to_postcode, - include_3_out_of_4_matches: false - ) + database_matches = + PatientMatcher.from_relation( + Patient, + nhs_number: patient_nhs_number_value, + given_name: patient_first_name.to_s, + family_name: patient_last_name.to_s, + date_of_birth: patient_date_of_birth.to_date, + address_postcode: patient_postcode&.to_postcode, + include_3_out_of_4_matches: false + ) - return candidate_matches if candidate_matches.present? - end + return database_matches if database_matches.present? + + return if candidates.blank? - PatientMatcher.from_relation( - Patient, + PatientMatcher.from_enumerable( + candidates, nhs_number: patient_nhs_number_value, given_name: patient_first_name.to_s, family_name: patient_last_name.to_s,