Skip to content

Commit

Permalink
Update patients from PDS when looking up
Browse files Browse the repository at this point in the history
When looking up a patient from PDS, either when trying to find an NHS
number, or when matching with consent, we should update the patient
information from PDS to ensure our patient record is up to date.
  • Loading branch information
thomasleese committed Oct 17, 2024
1 parent 874527e commit 2aaf323
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/jobs/consent_form_matching_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def perform(consent_form)

# Search globally if we have an NHS number
if pds_patient && (patient = Patient.find_by(nhs_number: pds_patient["id"]))
patient.update_from_pds!(pds_patient)
consent_form.match_with_patient!(patient)
return
end
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/patient_nhs_number_lookup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def perform(patient)
).find_by(nhs_number:)
)
merge_patients!(existing_patient, patient)
existing_patient.update_from_pds!(pds_patient)
else
patient.update!(nhs_number:)
patient.update_from_pds!(pds_patient)
end
end

Expand Down
7 changes: 6 additions & 1 deletion spec/jobs/patient_nhs_number_lookup_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@
context "with a match" do
let(:response_file) { "pds/search-patients-response.json" }

it "changes the NHS number of the patient" do
it "sets the NHS number of the patient" do
expect { perform_now }.to change(patient, :nhs_number).from(nil).to(
"9449306168"
)
end

it "updates the patient details from PDS" do
expect(patient).to receive(:update_from_pds!)
perform_now
end
end

context "without a match" do
Expand Down

0 comments on commit 2aaf323

Please sign in to comment.