Skip to content

Commit

Permalink
Add PatientUpdateFromPDSJob
Browse files Browse the repository at this point in the history
This adds a new job which handles updating patient information from PDS
in the background, for patients where we already have their NHS number
so we don't need to perform a search for the patient first.
  • Loading branch information
thomasleese committed Oct 18, 2024
1 parent 86878d7 commit d395c4a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/jobs/patient_update_from_pds_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class PatientUpdateFromPDSJob < ApplicationJob
include NHSAPIConcurrencyConcern

queue_as :patients

def perform(patient)
raise MissingNHSNumber if patient.nhs_number.nil?

pds_patient = NHS::PDS.get_patient(patient.nhs_number).body
patient.update_from_pds!(pds_patient)
end

class MissingNHSNumber < StandardError
end
end
36 changes: 36 additions & 0 deletions spec/jobs/patient_update_from_pds_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

describe PatientUpdateFromPDSJob do
subject(:perform_now) { described_class.perform_now(patient) }

context "without an NHS number" do
let(:patient) { create(:patient, nhs_number: nil) }

it "raises an error" do
expect { perform_now }.to raise_error(
PatientUpdateFromPDSJob::MissingNHSNumber
)
end
end

context "with an NHS number" do
before do
stub_request(
:get,
"https://sandbox.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/0123456789"
).to_return(
body: file_fixture("pds/get-patient-response.json"),
headers: {
"Content-Type" => "application/fhir+json"
}
)
end

let(:patient) { create(:patient, nhs_number: "0123456789") }

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

0 comments on commit d395c4a

Please sign in to comment.