Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/immunisation_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ def parse_row(data)
end

def process_row(row)
patient = row.set_patient(candidates: @patients_batch)
patient = row.set_patient(candidates: @all_patients)
vaccination_record = row.to_vaccination_record

count_column_to_increment = count_column(vaccination_record)
return count_column_to_increment unless vaccination_record

@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)
Expand All @@ -100,6 +101,7 @@ 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

Expand Down
31 changes: 16 additions & 15 deletions app/models/immunisation_import_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,23 +480,24 @@ def existing_patients(candidates: nil)
return
end

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 database_matches if database_matches.present?
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
)

return if candidates.blank?
return candidate_matches if candidate_matches.present?
end

PatientMatcher.from_enumerable(
candidates,
PatientMatcher.from_relation(
Patient,
nhs_number: patient_nhs_number_value,
given_name: patient_first_name.to_s,
family_name: patient_last_name.to_s,
Expand Down