-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
86878d7
commit d395c4a
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |