@@ -6,8 +6,10 @@ class PDSCascadingSearchJob < ApplicationJobActiveJob
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
9+ def perform ( searchable , step_name : nil , search_results : nil , queue : nil )
10+ step_name ||= "no_fuzzy_with_history"
11+ search_results ||= [ ]
12+ queue ||= "pds"
1113
1214 SemanticLogger . tagged (
1315 searchable : "#{ searchable . class . name } ##{ searchable . id } " ,
@@ -19,15 +21,15 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
1921 given_name : searchable . given_name ,
2022 date_of_birth : searchable . date_of_birth ,
2123 address_postcode : searchable . address_postcode ,
22- step_name : step_name
24+ step_name :
2325 )
2426
2527 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
28+ " step" => step_name ,
29+ " result" => result . to_s ,
30+ " nhs_number" => pds_patient &.nhs_number ,
31+ " created_at" => Time . current . iso8601
32+ }
3133
3234 if searchable . is_a? ( PatientChangeset )
3335 searchable . search_results << search_result
@@ -39,9 +41,9 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
3941
4042 next_step = STEPS [ step_name ] [ result ]
4143
42- if result == :error || next_step . nil? || next_step == : give_up ||
44+ if result == :error || next_step . nil? || next_step == " give_up" ||
4345 multiple_nhs_numbers_found? ( search_results ) ||
44- next_step == : save_nhs_number_if_unique
46+ next_step == " save_nhs_number_if_unique"
4547 searchable . save!
4648 if searchable . is_a? ( PatientChangeset )
4749 ProcessPatientChangesetJob . perform_later ( searchable . id )
@@ -60,45 +62,45 @@ def perform(searchable, step_name: nil, search_results: [], queue: :pds)
6062 private
6163
6264 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
65+ " no_fuzzy_with_history" => {
66+ no_matches : " no_fuzzy_with_wildcard_postcode" ,
67+ one_match : " save_nhs_number_if_unique" ,
68+ too_many_matches : " no_fuzzy_without_history"
6769 } ,
68- no_fuzzy_without_history : {
69- no_matches : : give_up,
70- one_match : : save_nhs_number_if_unique,
71- too_many_matches : : give_up,
70+ " no_fuzzy_without_history" => {
71+ no_matches : " give_up" ,
72+ one_match : " save_nhs_number_if_unique" ,
73+ too_many_matches : " give_up" ,
7274 format_query : -> ( query ) { query . merge ( history : false ) }
7375 } ,
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,
76+ " no_fuzzy_with_wildcard_postcode" => {
77+ no_matches : " no_fuzzy_with_wildcard_given_name" ,
78+ one_match : " no_fuzzy_with_wildcard_given_name" ,
79+ too_many_matches : " no_fuzzy_with_wildcard_given_name" ,
7880 format_query :
7981 lambda do |query |
8082 query [ :address_postcode ] = query [ :address_postcode ] . dup
8183 query [ :address_postcode ] [ 2 ..] = "*"
8284 query
8385 end
8486 } ,
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,
87+ " no_fuzzy_with_wildcard_given_name" => {
88+ no_matches : " no_fuzzy_with_wildcard_family_name" ,
89+ one_match : " no_fuzzy_with_wildcard_family_name" ,
90+ too_many_matches : " no_fuzzy_with_wildcard_family_name" ,
91+ skip_step : " no_fuzzy_with_wildcard_family_name" ,
9092 format_query :
9193 lambda do |query |
9294 query [ :given_name ] = query [ :given_name ] . dup
9395 query [ :given_name ] [ 3 ..] = "*"
9496 query
9597 end
9698 } ,
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,
99+ " no_fuzzy_with_wildcard_family_name" => {
100+ no_matches : " save_nhs_number_if_unique" ,
101+ one_match : " save_nhs_number_if_unique" ,
102+ too_many_matches : " save_nhs_number_if_unique" ,
103+ skip_step : " save_nhs_number_if_unique" ,
102104 format_query :
103105 lambda do |query |
104106 query [ :family_name ] = query [ :family_name ] . dup
@@ -118,9 +120,9 @@ def search_for_patient(
118120 return :no_postcode , nil if address_postcode . blank?
119121
120122 case step_name
121- when : no_fuzzy_with_wildcard_given_name
123+ when " no_fuzzy_with_wildcard_given_name"
122124 return :skip_step , nil if given_name . length <= 3
123- when : no_fuzzy_with_wildcard_family_name
125+ when " no_fuzzy_with_wildcard_family_name"
124126 return :skip_step , nil if family_name . length <= 3
125127 end
126128
0 commit comments