Skip to content

Commit 3341b7a

Browse files
committed
Persist all PDS search results for patient changesets
Previously, only the final PDS search result was persisted for a patient changeset. In-memory updates to `patient_changeset.search_results` will be lost between job executions if not explicitly saved. This commit ensures `patient_changeset.search_results` is saved after each PDS lookup, preserving the full history of search steps.
1 parent fe65298 commit 3341b7a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

app/jobs/process_patient_changesets_job.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ def perform(patient_changeset, step_name = nil)
1717
result, pds_patient =
1818
search_for_patient(patient_changeset.child_attributes, step_name)
1919
patient_changeset.search_results << {
20-
step: step_name,
21-
result: result,
20+
step: step_name.to_s,
21+
result: result.to_s,
2222
nhs_number: pds_patient&.nhs_number
23-
}
24-
25-
if multiple_nhs_numbers_found?(patient_changeset)
26-
finish_processing(patient_changeset)
27-
end
23+
}.with_indifferent_access
2824

2925
next_step = step[result]
3026

31-
if result == :error || next_step.nil? || next_step == :give_up
27+
if result == :error || next_step.nil? || next_step == :give_up ||
28+
multiple_nhs_numbers_found?(patient_changeset)
3229
finish_processing(patient_changeset)
3330
elsif next_step == :save_nhs_number_if_unique
3431
if nhs_number_is_unique_across_searches?(patient_changeset)
@@ -40,9 +37,11 @@ def perform(patient_changeset, step_name = nil)
4037
end
4138
finish_processing(patient_changeset)
4239
elsif next_step.in?(steps.keys)
40+
patient_changeset.save!
4341
raise "Recursive step detected: #{next_step}" if next_step == step_name
4442
enqueue_next_search(patient_changeset, next_step)
4543
else
44+
patient_changeset.save!
4645
raise "Unknown step: #{next_step}"
4746
end
4847
end

0 commit comments

Comments
 (0)