@@ -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