Skip to content

Commit 1efae8f

Browse files
committed
Make PDS cascading steps a constant
Since it doesn't need to be dynamic. Jira-Issue: MAV-7288
1 parent 7de67c7 commit 1efae8f

1 file changed

Lines changed: 53 additions & 55 deletions

File tree

app/jobs/pds_cascading_search_job.rb

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
3737

3838
searchable.save!
3939

40-
next_step = steps[step_name][result]
40+
next_step = STEPS[step_name][result]
4141

4242
if result == :error || next_step.nil? || next_step == :give_up ||
4343
multiple_nhs_numbers_found?(search_results) ||
@@ -48,7 +48,7 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
4848
else
4949
PatientUpdateFromPDSJob.perform_later(searchable, search_results)
5050
end
51-
elsif next_step.in?(steps.keys)
51+
elsif next_step.in?(STEPS.keys)
5252
raise "Recursive step detected: #{next_step}" if next_step == step_name
5353
enqueue_next_search(searchable, next_step, search_results, queue)
5454
else
@@ -59,6 +59,55 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
5959

6060
private
6161

62+
STEPS = {
63+
no_fuzzy_with_history: {
64+
no_matches: :no_fuzzy_with_wildcard_postcode,
65+
one_match: :save_nhs_number_if_unique,
66+
too_many_matches: :no_fuzzy_without_history
67+
},
68+
no_fuzzy_without_history: {
69+
no_matches: :give_up,
70+
one_match: :save_nhs_number_if_unique,
71+
too_many_matches: :give_up,
72+
format_query: ->(query) { query.merge(history: false) }
73+
},
74+
no_fuzzy_with_wildcard_postcode: {
75+
no_matches: :no_fuzzy_with_wildcard_given_name,
76+
one_match: :no_fuzzy_with_wildcard_given_name,
77+
too_many_matches: :no_fuzzy_with_wildcard_given_name,
78+
format_query:
79+
lambda do |query|
80+
query[:address_postcode] = query[:address_postcode].dup
81+
query[:address_postcode][2..] = "*"
82+
query
83+
end
84+
},
85+
no_fuzzy_with_wildcard_given_name: {
86+
no_matches: :no_fuzzy_with_wildcard_family_name,
87+
one_match: :no_fuzzy_with_wildcard_family_name,
88+
too_many_matches: :no_fuzzy_with_wildcard_family_name,
89+
skip_step: :no_fuzzy_with_wildcard_family_name,
90+
format_query:
91+
lambda do |query|
92+
query[:given_name] = query[:given_name].dup
93+
query[:given_name][3..] = "*"
94+
query
95+
end
96+
},
97+
no_fuzzy_with_wildcard_family_name: {
98+
no_matches: :save_nhs_number_if_unique,
99+
one_match: :save_nhs_number_if_unique,
100+
too_many_matches: :save_nhs_number_if_unique,
101+
skip_step: :save_nhs_number_if_unique,
102+
format_query:
103+
lambda do |query|
104+
query[:family_name] = query[:family_name].dup
105+
query[:family_name][3..] = "*"
106+
query
107+
end
108+
}
109+
}.freeze
110+
62111
def search_for_patient(
63112
family_name:,
64113
given_name:,
@@ -84,8 +133,8 @@ def search_for_patient(
84133
fuzzy: false
85134
}
86135

87-
if steps[step_name][:format_query].respond_to?(:call)
88-
result = steps[step_name][:format_query].call(query)
136+
if STEPS[step_name][:format_query].respond_to?(:call)
137+
result = STEPS[step_name][:format_query].call(query)
89138
query = result if result.is_a?(Hash)
90139
end
91140

@@ -107,57 +156,6 @@ def search_for_patient(
107156
[:error, nil]
108157
end
109158

110-
def steps
111-
{
112-
no_fuzzy_with_history: {
113-
no_matches: :no_fuzzy_with_wildcard_postcode,
114-
one_match: :save_nhs_number_if_unique,
115-
too_many_matches: :no_fuzzy_without_history
116-
},
117-
no_fuzzy_without_history: {
118-
no_matches: :give_up,
119-
one_match: :save_nhs_number_if_unique,
120-
too_many_matches: :give_up,
121-
format_query: ->(query) { query.merge(history: false) }
122-
},
123-
no_fuzzy_with_wildcard_postcode: {
124-
no_matches: :no_fuzzy_with_wildcard_given_name,
125-
one_match: :no_fuzzy_with_wildcard_given_name,
126-
too_many_matches: :no_fuzzy_with_wildcard_given_name,
127-
format_query:
128-
lambda do |query|
129-
query[:address_postcode] = query[:address_postcode].dup
130-
query[:address_postcode][2..] = "*"
131-
query
132-
end
133-
},
134-
no_fuzzy_with_wildcard_given_name: {
135-
no_matches: :no_fuzzy_with_wildcard_family_name,
136-
one_match: :no_fuzzy_with_wildcard_family_name,
137-
too_many_matches: :no_fuzzy_with_wildcard_family_name,
138-
skip_step: :no_fuzzy_with_wildcard_family_name,
139-
format_query:
140-
lambda do |query|
141-
query[:given_name] = query[:given_name].dup
142-
query[:given_name][3..] = "*"
143-
query
144-
end
145-
},
146-
no_fuzzy_with_wildcard_family_name: {
147-
no_matches: :save_nhs_number_if_unique,
148-
one_match: :save_nhs_number_if_unique,
149-
too_many_matches: :save_nhs_number_if_unique,
150-
skip_step: :save_nhs_number_if_unique,
151-
format_query:
152-
lambda do |query|
153-
query[:family_name] = query[:family_name].dup
154-
query[:family_name][3..] = "*"
155-
query
156-
end
157-
}
158-
}
159-
end
160-
161159
def enqueue_next_search(searchable, step_name, search_results, queue)
162160
searchable.save!
163161

0 commit comments

Comments
 (0)