Skip to content

Commit c371fd4

Browse files
committed
Use strings in PDSCascadingSearchJob
This is in preparation for converting this job to Sidekiq where all arguments need to be JSON serialisable, of which symbols are not. We also store these values in a JSON blob on the `PatientChangeset` model so I think it makes sense to use strings here since they will be serialised in to strings anyway. I've removed a `describe` block from the test to simplify the file, which has resulted in a whitespace change on each line as the code is de-indented. Jira-Issue: MAV-7288
1 parent f140549 commit c371fd4

3 files changed

Lines changed: 311 additions & 316 deletions

File tree

app/jobs/pds_cascading_search_job.rb

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ class PDSCascadingSearchJob < ApplicationJob
66
queue_as :pds
77
retry_on Faraday::ServerError, wait: :polynomially_longer
88

9-
def perform(searchable, step_name: nil, search_results: [], queue: :pds)
10-
step_name ||= :no_fuzzy_with_history
11-
9+
def perform(
10+
searchable,
11+
step_name: "no_fuzzy_with_history",
12+
search_results: [],
13+
queue: "pds"
14+
)
1215
SemanticLogger.tagged(
1316
searchable: "#{searchable.class.name}##{searchable.id}",
1417
step: step_name
@@ -19,15 +22,15 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
1922
given_name: searchable.given_name,
2023
date_of_birth: searchable.date_of_birth,
2124
address_postcode: searchable.address_postcode,
22-
step_name: step_name
25+
step_name:
2326
)
2427

2528
search_result = {
26-
step: step_name,
27-
result: result,
28-
nhs_number: pds_patient&.nhs_number,
29-
created_at: Time.current
30-
}.with_indifferent_access
29+
"step" => step_name,
30+
"result" => result.to_s,
31+
"nhs_number" => pds_patient&.nhs_number,
32+
"created_at" => Time.current.iso8601
33+
}
3134

3235
if searchable.is_a?(PatientChangeset)
3336
searchable.search_results << search_result
@@ -39,9 +42,9 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
3942

4043
next_step = STEPS[step_name][result]
4144

42-
if result == :error || next_step.nil? || next_step == :give_up ||
45+
if result == :error || next_step.nil? || next_step == "give_up" ||
4346
multiple_nhs_numbers_found?(search_results) ||
44-
next_step == :save_nhs_number_if_unique
47+
next_step == "save_nhs_number_if_unique"
4548
searchable.save!
4649
if searchable.is_a?(PatientChangeset)
4750
ProcessPatientChangesetJob.perform_later(searchable.id)
@@ -60,45 +63,45 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
6063
private
6164

6265
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
66+
"no_fuzzy_with_history" => {
67+
no_matches: "no_fuzzy_with_wildcard_postcode",
68+
one_match: "save_nhs_number_if_unique",
69+
too_many_matches: "no_fuzzy_without_history"
6770
},
68-
no_fuzzy_without_history: {
69-
no_matches: :give_up,
70-
one_match: :save_nhs_number_if_unique,
71-
too_many_matches: :give_up,
71+
"no_fuzzy_without_history" => {
72+
no_matches: "give_up",
73+
one_match: "save_nhs_number_if_unique",
74+
too_many_matches: "give_up",
7275
format_query: ->(query) { query.merge(history: false) }
7376
},
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,
77+
"no_fuzzy_with_wildcard_postcode" => {
78+
no_matches: "no_fuzzy_with_wildcard_given_name",
79+
one_match: "no_fuzzy_with_wildcard_given_name",
80+
too_many_matches: "no_fuzzy_with_wildcard_given_name",
7881
format_query:
7982
lambda do |query|
8083
query[:address_postcode] = query[:address_postcode].dup
8184
query[:address_postcode][2..] = "*"
8285
query
8386
end
8487
},
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,
88+
"no_fuzzy_with_wildcard_given_name" => {
89+
no_matches: "no_fuzzy_with_wildcard_family_name",
90+
one_match: "no_fuzzy_with_wildcard_family_name",
91+
too_many_matches: "no_fuzzy_with_wildcard_family_name",
92+
skip_step: "no_fuzzy_with_wildcard_family_name",
9093
format_query:
9194
lambda do |query|
9295
query[:given_name] = query[:given_name].dup
9396
query[:given_name][3..] = "*"
9497
query
9598
end
9699
},
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,
100+
"no_fuzzy_with_wildcard_family_name" => {
101+
no_matches: "save_nhs_number_if_unique",
102+
one_match: "save_nhs_number_if_unique",
103+
too_many_matches: "save_nhs_number_if_unique",
104+
skip_step: "save_nhs_number_if_unique",
102105
format_query:
103106
lambda do |query|
104107
query[:family_name] = query[:family_name].dup
@@ -118,9 +121,9 @@ def search_for_patient(
118121
return :no_postcode, nil if address_postcode.blank?
119122

120123
case step_name
121-
when :no_fuzzy_with_wildcard_given_name
124+
when "no_fuzzy_with_wildcard_given_name"
122125
return :skip_step, nil if given_name.length <= 3
123-
when :no_fuzzy_with_wildcard_family_name
126+
when "no_fuzzy_with_wildcard_family_name"
124127
return :skip_step, nil if family_name.length <= 3
125128
end
126129

app/models/patient_import.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def enqueue_pds_cascading_searches(changesets)
178178
changesets.find_each do |cs|
179179
PDSCascadingSearchJob.set(queue: :imports).perform_later(
180180
cs,
181-
queue: :imports
181+
queue: "imports"
182182
)
183183
end
184184
end

0 commit comments

Comments
 (0)