diff --git a/app/jobs/patient_update_from_pds_job.rb b/app/jobs/patient_update_from_pds_job.rb index d960ba791..d2e342516 100644 --- a/app/jobs/patient_update_from_pds_job.rb +++ b/app/jobs/patient_update_from_pds_job.rb @@ -3,7 +3,7 @@ class PatientUpdateFromPDSJob < ApplicationJob include NHSAPIConcurrencyConcern - queue_as :patients + queue_as :imports def perform(patient) raise MissingNHSNumber if patient.nhs_number.nil? diff --git a/app/models/concerns/csv_importable.rb b/app/models/concerns/csv_importable.rb index f420d12a3..2e22178b0 100644 --- a/app/models/concerns/csv_importable.rb +++ b/app/models/concerns/csv_importable.rb @@ -104,12 +104,16 @@ def record! update_columns(recorded_at: Time.zone.now, status: :recorded, **counts) end - look_up_missing_nhs_numbers + update_from_pds end - def look_up_missing_nhs_numbers - patients.without_nhs_number.find_each do |patient| - PatientNHSNumberLookupJob.perform_later(patient) + def update_from_pds + patients.find_each do |patient| + if patient.nhs_number.nil? + PatientNHSNumberLookupJob.perform_later(patient) + else + PatientUpdateFromPDSJob.perform_later(patient) + end end end diff --git a/spec/features/dev_reset_team_spec.rb b/spec/features/dev_reset_team_spec.rb index b56dc69de..fea77eb53 100644 --- a/spec/features/dev_reset_team_spec.rb +++ b/spec/features/dev_reset_team_spec.rb @@ -7,7 +7,6 @@ scenario "Resetting a team deletes all associated data" do given_an_example_programme_exists - and_requests_can_be_made_to_pds and_patients_have_been_imported and_vaccination_records_have_been_imported @@ -28,13 +27,6 @@ def given_an_example_programme_exists @user = @team.users.first end - def and_requests_can_be_made_to_pds - stub_request( - :get, - "https://sandbox.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient" - ).with(query: hash_including({})).to_return_json(body: { total: 0 }) - end - def and_patients_have_been_imported sign_in @user visit "/dashboard" @@ -45,7 +37,6 @@ def and_patients_have_been_imported attach_file("cohort_import[csv]", "spec/fixtures/cohort_import/valid.csv") click_on "Continue" - perform_enqueued_jobs expect(@team.cohorts.flat_map(&:patients).size).to eq(3) expect(@team.cohorts.flat_map(&:patients).flat_map(&:parents).size).to eq(3) end @@ -62,7 +53,6 @@ def and_vaccination_records_have_been_imported ) click_on "Continue" - perform_enqueued_jobs expect(VaccinationRecord.count).to eq(11) end diff --git a/spec/features/e2e_journey_spec.rb b/spec/features/e2e_journey_spec.rb index 0e9410775..65c0d904c 100644 --- a/spec/features/e2e_journey_spec.rb +++ b/spec/features/e2e_journey_spec.rb @@ -94,7 +94,6 @@ def when_i_upload_the_cohort_import_containing_one_child click_on "Import child records" attach_file "cohort_import[csv]", csv_file.path click_on "Continue" - perform_enqueued_jobs visit programme_cohort_import_path(@programme, CohortImport.last) end diff --git a/spec/features/import_vaccination_records_with_duplicates_spec.rb b/spec/features/import_vaccination_records_with_duplicates_spec.rb index c60a0e596..079dd71d0 100644 --- a/spec/features/import_vaccination_records_with_duplicates_spec.rb +++ b/spec/features/import_vaccination_records_with_duplicates_spec.rb @@ -3,7 +3,6 @@ describe "Immunisation imports duplicates" do scenario "User reviews and selects between duplicate records" do given_i_am_signed_in - and_requests_can_be_made_to_pds and_an_hpv_programme_is_underway and_an_existing_patient_record_exists @@ -51,13 +50,6 @@ def given_i_am_signed_in sign_in @team.users.first end - def and_requests_can_be_made_to_pds - stub_request( - :get, - "https://sandbox.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient" - ).with(query: hash_including({})).to_return_json(body: { total: 0 }) - end - def and_an_hpv_programme_is_underway @programme = create(:programme, :hpv_all_vaccines) create(:team_programme, team: @team, programme: @programme) @@ -153,7 +145,6 @@ def and_i_upload_a_file_with_duplicate_records "spec/fixtures/immunisation_import/valid_hpv.csv" ) click_on "Continue" - perform_enqueued_jobs click_link ImmunisationImport.last.created_at.to_fs(:long), match: :first end diff --git a/spec/models/class_import_spec.rb b/spec/models/class_import_spec.rb index caa1f556b..23d6ddc51 100644 --- a/spec/models/class_import_spec.rb +++ b/spec/models/class_import_spec.rb @@ -257,6 +257,13 @@ ).once.on_queue(:imports) end + it "enqueues jobs to update from PDS" do + expect { record! }.to have_enqueued_job(PatientUpdateFromPDSJob) + .exactly(3) + .times + .on_queue(:imports) + end + context "with an existing patient matching the name" do before do create( diff --git a/spec/models/cohort_import_spec.rb b/spec/models/cohort_import_spec.rb index 4b0c36434..9714cf5c3 100644 --- a/spec/models/cohort_import_spec.rb +++ b/spec/models/cohort_import_spec.rb @@ -248,6 +248,12 @@ ).once.on_queue(:imports) end + it "enqueues jobs to update from PDS" do + expect { record! }.to have_enqueued_job( + PatientUpdateFromPDSJob + ).twice.on_queue(:imports) + end + context "with an existing patient matching the name" do before do create( diff --git a/spec/models/immunisation_import_spec.rb b/spec/models/immunisation_import_spec.rb index 76aa5d3c5..d1254bd06 100644 --- a/spec/models/immunisation_import_spec.rb +++ b/spec/models/immunisation_import_spec.rb @@ -184,6 +184,13 @@ PatientNHSNumberLookupJob ).once.on_queue(:imports) end + + it "enqueues jobs to update from PDS" do + expect { record! }.to have_enqueued_job(PatientUpdateFromPDSJob) + .exactly(6) + .times + .on_queue(:imports) + end end context "with valid HPV rows" do @@ -259,6 +266,13 @@ PatientNHSNumberLookupJob ).once.on_queue(:imports) end + + it "enqueues jobs to update from PDS" do + expect { record! }.to have_enqueued_job(PatientUpdateFromPDSJob) + .exactly(9) + .times + .on_queue(:imports) + end end context "with an existing patient matching the name" do