Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions app/jobs/process_patient_changesets_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def steps
too_many_matches: :no_fuzzy_without_history
},
no_fuzzy_without_history: {
no_matches: :fuzzy,
no_matches: :give_up,
one_match: :save_nhs_number_if_unique,
too_many_matches: :give_up,
format_query: ->(query) { query.merge(history: false) }
Expand All @@ -98,22 +98,11 @@ def steps
format_query: ->(query) { query[:given_name][3..] = "*" }
},
no_fuzzy_with_wildcard_family_name: {
no_matches: :fuzzy,
one_match: :fuzzy,
too_many_matches: :fuzzy,
skip_step: :fuzzy,
format_query: ->(query) { query[:family_name][3..] = "*" }
},
fuzzy: {
no_matches: :give_up,
no_matches: :save_nhs_number_if_unique,
one_match: :save_nhs_number_if_unique,
too_many_matches: :save_nhs_number_if_unique,
format_query: ->(query) do
query[:fuzzy] = true
# For fuzzy searches, history is the default. We get an error if we
# try to set it to true explicitly
query[:history] = nil
end
skip_step: :save_nhs_number_if_unique,
format_query: ->(query) { query[:family_name][3..] = "*" }
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/patient_changesets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{
child: {
"given_name" => "John",
"family_name" => "Doe",
"family_name" => "Dover",
"date_of_birth" => "2010-01-01",
"address_postcode" => "SW1A 1AA",
"nhs_number" => nil
Expand Down
12 changes: 2 additions & 10 deletions spec/features/import_child_pds_lookup_extravaganza_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def and_pds_lookup_during_import_is_enabled
address_postcode: "B1 1AA",
steps: {
wildcard_postcode: "1111111111",
fuzzy: "9435726097"
wildcard_family_name: "9435726097"
}
)
end
Expand Down Expand Up @@ -387,13 +387,6 @@ def stub_pds_cascading_search(
"given" => given_name,
"birthdate" => birthdate,
"address-postalcode" => address_postcode
},
fuzzy: {
"family" => family_name,
"given" => given_name,
"birthdate" => birthdate,
"address-postalcode" => address_postcode,
"_fuzzy-match" => "true"
}
}.each do |step, query|
if steps[step]
Expand Down Expand Up @@ -827,14 +820,13 @@ def then_maia_has_the_uploaded_nhs_number

def and_maia_has_multiple_pds_search_results
maia = Patient.find_by(given_name: "Maia", family_name: "Smith")
expect(maia.pds_search_results.count).to eq(5)
expect(maia.pds_search_results.count).to eq(4)
expect(maia.pds_search_results.pluck(:step)).to eq(
%w[
no_fuzzy_with_history
no_fuzzy_with_wildcard_postcode
no_fuzzy_with_wildcard_given_name
no_fuzzy_with_wildcard_family_name
fuzzy
]
)
end
Expand Down
9 changes: 5 additions & 4 deletions spec/jobs/process_patient_changesets_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
end
end

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

before do
patient_changeset["pending_changes"]["search_results"] = [
Expand All @@ -94,8 +94,8 @@
end
end

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

before do
patient_changeset["pending_changes"]["search_results"] = [
Expand All @@ -115,6 +115,7 @@
perform

expect(patient_changeset.child_attributes["nhs_number"]).to be_blank
expect(patient_changeset.pds_nhs_number).to be_nil
end
end

Expand Down