Skip to content

Commit e63a8bb

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 ac29422 commit e63a8bb

File tree

4 files changed

+12
-30
lines changed

4 files changed

+12
-30
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 & 10 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
@@ -387,13 +387,6 @@ def stub_pds_cascading_search(
387387
"given" => given_name,
388388
"birthdate" => birthdate,
389389
"address-postalcode" => address_postcode
390-
},
391-
fuzzy: {
392-
"family" => family_name,
393-
"given" => given_name,
394-
"birthdate" => birthdate,
395-
"address-postalcode" => address_postcode,
396-
"_fuzzy-match" => "true"
397390
}
398391
}.each do |step, query|
399392
if steps[step]
@@ -827,14 +820,13 @@ def then_maia_has_the_uploaded_nhs_number
827820

828821
def and_maia_has_multiple_pds_search_results
829822
maia = Patient.find_by(given_name: "Maia", family_name: "Smith")
830-
expect(maia.pds_search_results.count).to eq(5)
823+
expect(maia.pds_search_results.count).to eq(4)
831824
expect(maia.pds_search_results.pluck(:step)).to eq(
832825
%w[
833826
no_fuzzy_with_history
834827
no_fuzzy_with_wildcard_postcode
835828
no_fuzzy_with_wildcard_given_name
836829
no_fuzzy_with_wildcard_family_name
837-
fuzzy
838830
]
839831
)
840832
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)