Skip to content

Commit ace6e8f

Browse files
Match against patients in upload before DB in ImmsImports
This change caches all patients in the upload so far and re-orders the patient matching to match against in-memory cache before consulting the DB. Jira-Issue: MAV-3928
1 parent c48e358 commit ace6e8f

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

app/models/immunisation_import.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ def parse_row(data)
7575
end
7676

7777
def process_row(row)
78-
patient = row.set_patient(candidates: @patients_batch)
78+
patient = row.set_patient(candidates: @all_patients)
7979
vaccination_record = row.to_vaccination_record
8080

8181
count_column_to_increment = count_column(vaccination_record)
8282
return count_column_to_increment unless vaccination_record
8383

8484
@vaccination_records_batch.add(vaccination_record)
8585
@patients_batch.add(patient)
86+
@all_patients.add(patient)
8687

8788
if (patient_location = row.to_patient_location)
8889
@patient_locations_batch.add(patient_location)
@@ -100,6 +101,7 @@ def process_import!
100101

101102
@vaccination_records_batch = Set.new
102103
@patients_batch = Set.new
104+
@all_patients = Set.new
103105
@patient_locations_batch = Set.new
104106
@archive_reasons_batch = Set.new
105107

app/models/immunisation_import_row.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,23 +480,24 @@ def existing_patients(candidates: nil)
480480
return
481481
end
482482

483-
database_matches =
484-
PatientMatcher.from_relation(
485-
Patient,
486-
nhs_number: patient_nhs_number_value,
487-
given_name: patient_first_name.to_s,
488-
family_name: patient_last_name.to_s,
489-
date_of_birth: patient_date_of_birth.to_date,
490-
address_postcode: patient_postcode&.to_postcode,
491-
include_3_out_of_4_matches: false
492-
)
493-
494-
return database_matches if database_matches.present?
483+
if candidates.present?
484+
# Match against the in-memory list of patients so far in this upload, before matching against the database
485+
candidate_matches =
486+
PatientMatcher.from_enumerable(
487+
candidates,
488+
nhs_number: patient_nhs_number_value,
489+
given_name: patient_first_name.to_s,
490+
family_name: patient_last_name.to_s,
491+
date_of_birth: patient_date_of_birth.to_date,
492+
address_postcode: patient_postcode&.to_postcode,
493+
include_3_out_of_4_matches: false
494+
)
495495

496-
return if candidates.blank?
496+
return candidate_matches if candidate_matches.present?
497+
end
497498

498-
PatientMatcher.from_enumerable(
499-
candidates,
499+
PatientMatcher.from_relation(
500+
Patient,
500501
nhs_number: patient_nhs_number_value,
501502
given_name: patient_first_name.to_s,
502503
family_name: patient_last_name.to_s,

0 commit comments

Comments
 (0)