From 2c1acf458547e51fbf3d250ede1512a39d77b61e Mon Sep 17 00:00:00 2001 From: Jake Benilov Date: Fri, 18 Oct 2024 16:26:22 +0100 Subject: [PATCH] Skip further PDS checks for invalidated patients, until invalidation cleared See https://digital.nhs.uk/developer/api-catalogue/personal-demographics-service-fhir/pds-fhir-technical-conformance---application-restricted-access-mode#invalidated-patient-records --- app/jobs/patient_update_from_pds_job.rb | 2 ++ spec/jobs/patient_update_from_pds_job_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/app/jobs/patient_update_from_pds_job.rb b/app/jobs/patient_update_from_pds_job.rb index b27ae8d1e..37bd991ac 100644 --- a/app/jobs/patient_update_from_pds_job.rb +++ b/app/jobs/patient_update_from_pds_job.rb @@ -9,6 +9,8 @@ class PatientUpdateFromPDSJob < ApplicationJob def perform(patient) raise MissingNHSNumber if patient.nhs_number.nil? + return if patient.invalidated? + pds_patient = PDS::Patient.find(patient.nhs_number) if pds_patient.nhs_number != patient.nhs_number diff --git a/spec/jobs/patient_update_from_pds_job_spec.rb b/spec/jobs/patient_update_from_pds_job_spec.rb index 16cfac0fb..86d590148 100644 --- a/spec/jobs/patient_update_from_pds_job_spec.rb +++ b/spec/jobs/patient_update_from_pds_job_spec.rb @@ -13,6 +13,15 @@ end end + context "invalidated patient" do + let!(:patient) { create(:patient, :invalidated) } + + it "doesn't update the patient" do + expect(patient).not_to receive(:update_from_pds!) + perform_now + end + end + context "with an NHS number" do context "when the patient is valid" do before do