Skip to content

Commit cda7428

Browse files
committed
Create PDSSearchResult from daily job
For data consistency, and to enable flaggind PDS info in the patient activity log, it would help to store any NHS numbers retrieved from the daily lookup job as well. This is unlikely to happen given that the dialy job is more restrictive than the import pds jobs. But int he event it does, we should have the info stored.
1 parent 8b163ce commit cda7428

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

app/jobs/patient_nhs_number_lookup_job.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@ def perform(patient)
2626
)
2727
PatientMerger.call(to_keep: existing_patient, to_destroy: patient)
2828
existing_patient.update_from_pds!(pds_patient)
29+
30+
PDSSearchResult.create!(
31+
patient_id: existing_patient.id,
32+
step: :no_fuzzy_with_history_daily,
33+
result: :one_match,
34+
nhs_number: pds_patient.nhs_number
35+
)
2936
else
3037
patient.nhs_number = pds_patient.nhs_number
3138
patient.update_from_pds!(pds_patient)
39+
PDSSearchResult.create!(
40+
patient_id: patient.id,
41+
step: :no_fuzzy_with_history_daily,
42+
result: :one_match,
43+
nhs_number: pds_patient.nhs_number
44+
)
3245
end
3346
end
3447
end

app/models/pds_search_result.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ class PDSSearchResult < ApplicationRecord
3131
enum :step,
3232
{
3333
no_fuzzy_with_history: 0,
34-
no_fuzzy_without_history: 1,
35-
no_fuzzy_with_wildcard_postcode: 2,
36-
no_fuzzy_with_wildcard_given_name: 3,
37-
no_fuzzy_with_wildcard_family_name: 4,
38-
fuzzy_without_history: 5,
39-
fuzzy_with_history: 6
34+
no_fuzzy_with_history_daily: 1,
35+
no_fuzzy_without_history: 2,
36+
no_fuzzy_with_wildcard_postcode: 3,
37+
no_fuzzy_with_wildcard_given_name: 4,
38+
no_fuzzy_with_wildcard_family_name: 5,
39+
fuzzy_without_history: 6,
40+
fuzzy_with_history: 7
4041
},
4142
validate: true
4243

spec/jobs/patient_nhs_number_lookup_job_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
expect(patient).to receive(:update_from_pds!)
6161
perform_now
6262
end
63+
64+
it "creates a PDSSearchResult" do
65+
expect { perform_now }.to change(PDSSearchResult, :count).by(1)
66+
expect(PDSSearchResult.last.step).to eq("no_fuzzy_with_history_daily")
67+
expect(PDSSearchResult.last.result).to eq("one_match")
68+
expect(PDSSearchResult.last.nhs_number).to eq("9449306168")
69+
end
6370
end
6471

6572
context "with a match and the patient already exists" do

0 commit comments

Comments
 (0)