Skip to content

Commit 30568bf

Browse files
committed
Remove fuzzy-search from cascading PDS search algorithm
We have seen at least two cases where fuzzy matching in PDS returned a patient that was obviously wrong (first name and last name swapped around and spellings completely different, and postcode different). We think it is safest to remove the last search step (fuzzy step) from the cascading search
1 parent 6e80940 commit 30568bf

File tree

4 files changed

+12
-37
lines changed

4 files changed

+12
-37
lines changed

app/jobs/process_patient_changesets_job.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def steps
7979
too_many_matches: :no_fuzzy_without_history
8080
},
8181
no_fuzzy_without_history: {
82-
no_matches: :fuzzy,
82+
no_matches: :give_up,
8383
one_match: :save_nhs_number_if_unique,
8484
too_many_matches: :give_up,
8585
format_query: ->(query) { query.merge(history: false) }
@@ -98,22 +98,11 @@ def steps
9898
format_query: ->(query) { query[:given_name][3..] = "*" }
9999
},
100100
no_fuzzy_with_wildcard_family_name: {
101-
no_matches: :fuzzy,
102-
one_match: :fuzzy,
103-
too_many_matches: :fuzzy,
104-
skip_step: :fuzzy,
105-
format_query: ->(query) { query[:family_name][3..] = "*" }
106-
},
107-
fuzzy: {
108-
no_matches: :give_up,
101+
no_matches: :save_nhs_number_if_unique,
109102
one_match: :save_nhs_number_if_unique,
110103
too_many_matches: :save_nhs_number_if_unique,
111-
format_query: ->(query) do
112-
query[:fuzzy] = true
113-
# For fuzzy searches, history is the default. We get an error if we
114-
# try to set it to true explicitly
115-
query[:history] = nil
116-
end
104+
skip_step: :save_nhs_number_if_unique,
105+
format_query: ->(query) { query[:family_name][3..] = "*" }
117106
}
118107
}
119108
end

spec/factories/patient_changesets.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{
4747
child: {
4848
"given_name" => "John",
49-
"family_name" => "Doe",
49+
"family_name" => "Dover",
5050
"date_of_birth" => "2010-01-01",
5151
"address_postcode" => "SW1A 1AA",
5252
"nhs_number" => nil

spec/features/import_child_pds_lookup_extravaganza_spec.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def and_pds_lookup_during_import_is_enabled
350350
address_postcode: "B1 1AA",
351351
steps: {
352352
wildcard_postcode: "1111111111",
353-
fuzzy: "9435726097"
353+
wildcard_family_name: "9435726097"
354354
}
355355
)
356356
end
@@ -385,13 +385,6 @@ def stub_all_searches_to_return_no_patient(
385385
"birthdate" => birthdate,
386386
"address-postalcode" => "#{address_postcode[0..1]}*"
387387
)
388-
stub_pds_search_to_return_no_patients(
389-
"family" => family_name,
390-
"given" => given_name,
391-
"birthdate" => birthdate,
392-
"address-postalcode" => address_postcode,
393-
"_fuzzy-match" => "true"
394-
)
395388
end
396389

397390
def stub_pds_cascading_search(
@@ -426,13 +419,6 @@ def stub_pds_cascading_search(
426419
"given" => given_name,
427420
"birthdate" => birthdate,
428421
"address-postalcode" => address_postcode
429-
},
430-
fuzzy: {
431-
"family" => family_name,
432-
"given" => given_name,
433-
"birthdate" => birthdate,
434-
"address-postalcode" => address_postcode,
435-
"_fuzzy-match" => "true"
436422
}
437423
}.each do |step, query|
438424
if steps[step]
@@ -866,14 +852,13 @@ def then_maia_has_the_uploaded_nhs_number
866852

867853
def and_maia_has_multiple_pds_search_results
868854
maia = Patient.find_by(given_name: "Maia", family_name: "Smith")
869-
expect(maia.pds_search_results.count).to eq(5)
855+
expect(maia.pds_search_results.count).to eq(4)
870856
expect(maia.pds_search_results.pluck(:step)).to eq(
871857
%w[
872858
no_fuzzy_with_history
873859
no_fuzzy_with_wildcard_postcode
874860
no_fuzzy_with_wildcard_given_name
875861
no_fuzzy_with_wildcard_family_name
876-
fuzzy
877862
]
878863
)
879864
end

spec/jobs/process_patient_changesets_job_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
end
6969
end
7070

71-
context "when a later fuzzy search finds a match" do
72-
let(:step) { :fuzzy }
71+
context "when a later wildcard-family-name search finds a match" do
72+
let(:step) { :no_fuzzy_with_wildcard_family_name }
7373

7474
before do
7575
patient_changeset["pending_changes"]["search_results"] = [
@@ -94,8 +94,8 @@
9494
end
9595
end
9696

97-
context "when fuzzy search returns conflicting NHS numbers" do
98-
let(:step) { :fuzzy }
97+
context "when wildcard-family-name search returns conflicting NHS numbers" do
98+
let(:step) { :no_fuzzy_with_wildcard_family_name }
9999

100100
before do
101101
patient_changeset["pending_changes"]["search_results"] = [
@@ -115,6 +115,7 @@
115115
perform
116116

117117
expect(patient_changeset.child_attributes["nhs_number"]).to be_blank
118+
expect(patient_changeset.pds_nhs_number).to be_nil
118119
end
119120
end
120121

0 commit comments

Comments
 (0)