@@ -504,24 +504,23 @@ def existing_patients(candidates: nil)
504504 return
505505 end
506506
507- if candidates . present?
508- # Match against the in-memory list of patients so far in this upload, before matching against the database
509- candidate_matches =
510- PatientMatcher . from_enumerable (
511- candidates ,
512- nhs_number : patient_nhs_number_value ,
513- given_name : patient_first_name . to_s ,
514- family_name : patient_last_name . to_s ,
515- date_of_birth : patient_date_of_birth . to_date ,
516- address_postcode : patient_postcode &.to_postcode ,
517- include_3_out_of_4_matches : false
518- )
507+ database_matches =
508+ PatientMatcher . from_relation (
509+ Patient ,
510+ nhs_number : patient_nhs_number_value ,
511+ given_name : patient_first_name . to_s ,
512+ family_name : patient_last_name . to_s ,
513+ date_of_birth : patient_date_of_birth . to_date ,
514+ address_postcode : patient_postcode &.to_postcode ,
515+ include_3_out_of_4_matches : false
516+ )
519517
520- return candidate_matches if candidate_matches . present?
521- end
518+ return database_matches if database_matches . present?
519+
520+ return if candidates . blank?
522521
523- PatientMatcher . from_relation (
524- Patient ,
522+ PatientMatcher . from_enumerable (
523+ candidates ,
525524 nhs_number : patient_nhs_number_value ,
526525 given_name : patient_first_name . to_s ,
527526 family_name : patient_last_name . to_s ,
0 commit comments