Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ClinicSessionInvitationsJob < ApplicationJob
class EnqueueClinicSessionInvitationsJob < ApplicationJob
queue_as :notifications

def perform
Expand All @@ -9,7 +9,7 @@ def perform
.includes(:programmes)
.joins(:location)
.merge(Location.clinic)
.each do |session|
.find_each do |session|
# We're only inviting patients who don't have a school.
# Patients who have a school are sent invitations manually by the
# nurse when they're finished at a school.
Expand Down
14 changes: 14 additions & 0 deletions app/jobs/enqueue_school_consent_reminders_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class EnqueueSchoolConsentRemindersJob < ApplicationJob
queue_as :notifications

def perform
sessions =
Session.send_consent_reminders.joins(:location).merge(Location.school)

sessions.find_each do |session|
SendSchoolConsentRemindersJob.perform_later(session)
end
end
end
14 changes: 14 additions & 0 deletions app/jobs/enqueue_school_consent_requests_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class EnqueueSchoolConsentRequestsJob < ApplicationJob
queue_as :notifications

def perform
sessions =
Session.send_consent_requests.joins(:location).merge(Location.school)

sessions.find_each do |session|
SendSchoolConsentRequestsJob.perform_later(session)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class BulkUpdatePatientsFromPDSJob < ApplicationJob
class EnqueueUpdatePatientsFromPDSJob < ApplicationJob
include GoodJob::ActiveJobExtensions::Concurrency

queue_as :pds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# frozen_string_literal: true

class SchoolConsentRemindersJob < ApplicationJob
class SendSchoolConsentRemindersJob < ApplicationJob
queue_as :notifications

def perform
sessions =
Session
.send_consent_reminders
.joins(:location)
.includes(:session_dates, :programmes, :patient_sessions, :location)
.merge(Location.school)
def perform(session)
return unless session.school? && session.open_for_consent?

sessions.find_each(batch_size: 1) do |session|
next unless session.open_for_consent?

session.patient_sessions.each do |patient_session|
session
.patient_sessions
.includes_programmes
.includes(patient: %i[consent_notifications consents vaccination_records])
.find_each do |patient_session|
ProgrammeGrouper
.call(patient_session.programmes)
.each_value do |programmes|
Expand All @@ -39,7 +35,6 @@ def perform
)
end
end
end
end

def should_send_notification?(patient_session:, programmes:)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# frozen_string_literal: true

class SchoolConsentRequestsJob < ApplicationJob
class SendSchoolConsentRequestsJob < ApplicationJob
queue_as :notifications

def perform
sessions =
Session
.send_consent_requests
.joins(:location)
.includes(:session_dates, :programmes, :patient_sessions, :location)
.merge(Location.school)
def perform(session)
return unless session.school? && session.open_for_consent?

sessions.find_each(batch_size: 1) do |session|
next unless session.open_for_consent?

session.patient_sessions.each do |patient_session|
session
.patient_sessions
.includes_programmes
.includes(patient: %i[consent_notifications consents vaccination_records])
.find_each do |patient_session|
ProgrammeGrouper
.call(patient_session.programmes)
.each_value do |programmes|
Expand All @@ -30,7 +26,6 @@ def perform
)
end
end
end
end

def should_send_notification?(patient:, programmes:)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class SchoolSessionRemindersJob < ApplicationJob
class SendSchoolSessionRemindersJob < ApplicationJob
queue_as :notifications

def perform
Expand All @@ -16,7 +16,7 @@ def perform
.merge(Session.has_date(date))
.notification_not_sent(date)

patient_sessions.each do |patient_session|
patient_sessions.find_each do |patient_session|
next unless should_send_notification?(patient_session:)

SessionNotification.create_and_send!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class VaccinationConfirmationsJob < ApplicationJob
class SendVaccinationConfirmationsJob < ApplicationJob
include VaccinationMailerConcern

queue_as :notifications
Expand Down
28 changes: 14 additions & 14 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,20 @@

config.good_job.enable_cron = true
config.good_job.cron = {
bulk_update_patients_from_pds: {
cron: "every day at 6:00 and 18:00",
class: "BulkUpdatePatientsFromPDSJob",
description: "Keep patient details up to date with PDS."
},
clinic_invitation: {
clinic_session_invitations: {
cron: "every day at 9am",
class: "ClinicSessionInvitationsJob",
class: "EnqueueClinicSessionInvitationsJob",
description: "Send school clinic invitation emails to parents"
},
consent_request: {
school_consent_requests: {
cron: "every day at 4pm",
class: "SchoolConsentRequestsJob",
class: "EnqueueSchoolConsentRequestsJob",
description:
"Send school consent request emails to parents for each session"
},
consent_reminder: {
cron: "every day at 4pm",
class: "SchoolConsentRemindersJob",
cron: "every day at 9am",
class: "SendSchoolConsentReminderJob",
description:
"Send school consent reminder emails to parents for each session"
},
Expand All @@ -125,9 +120,9 @@
description:
"Invalidate all self-consents and associated triage for the previous day"
},
session_reminder: {
school_session_reminders: {
cron: "every day at 9am",
class: "SchoolSessionRemindersJob",
class: "SendSchoolSessionRemindersJob",
description: "Send school session reminder emails to parents"
},
remove_import_csv: {
Expand All @@ -145,9 +140,14 @@
class: "TrimActiveRecordSessionsJob",
description: "Remove ActiveRecord sessions older than 30 days"
},
update_patients_from_pds: {
cron: "every day at 6:00 and 18:00",
class: "EnqueueUpdatePatientsFromPDSJob",
description: "Keep patient details up to date with PDS."
},
vaccination_confirmations: {
cron: "every day at 7pm",
class: "VaccinationConfirmationsJob",
class: "SendVaccinationConfirmationsJob",
description: "Send vaccination confirmation emails to parents"
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec/features/doubles_vaccination_administered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def then_i_see_the_patient_is_vaccinated_for_td_ipv
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccinations
Expand Down
2 changes: 1 addition & 1 deletion spec/features/hpv_vaccination_administered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def then_i_see_the_patient
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccination
Expand Down
2 changes: 1 addition & 1 deletion spec/features/hpv_vaccination_already_had_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def then_i_see_that_the_status_is_vaccinated
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_saying_the_vaccination_didnt_happen
Expand Down
2 changes: 1 addition & 1 deletion spec/features/hpv_vaccination_clinic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def then_i_see_that_the_status_is_vaccinated
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccination
Expand Down
2 changes: 1 addition & 1 deletion spec/features/hpv_vaccination_delayed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def then_i_see_the_patient_has_no_outcome_yet
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_delay
Expand Down
2 changes: 1 addition & 1 deletion spec/features/hpv_vaccination_offline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def and_the_clinic_location_is_displayed
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccination
Expand Down
2 changes: 1 addition & 1 deletion spec/features/menacwy_vaccination_administered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def and_i_see_the_vaccination_details
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccination
Expand Down
6 changes: 4 additions & 2 deletions spec/features/scheduled_consent_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ def when_1_more_day_passes
end

def then_no_consent_requests_have_been_sent
SchoolConsentRequestsJob.perform_now
EnqueueSchoolConsentRequestsJob.perform_now
perform_enqueued_jobs

expect(email_deliveries).to be_empty
expect(sms_deliveries).to be_empty
end

def then_all_four_parents_received_consent_requests
SchoolConsentRequestsJob.perform_now
EnqueueSchoolConsentRequestsJob.perform_now
perform_enqueued_jobs

expect_email_to(
"parent1.child1@example.com",
Expand Down
3 changes: 2 additions & 1 deletion spec/features/td_ipv_already_had_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def and_i_cannot_record_the_patient_as_already_vaccinated
end

def and_the_consent_requests_are_sent
SchoolConsentRequestsJob.perform_now
EnqueueSchoolConsentRequestsJob.perform_now
perform_enqueued_jobs
end

def then_the_parent_doesnt_receive_a_consent_request
Expand Down
2 changes: 1 addition & 1 deletion spec/features/td_ipv_vaccination_administered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def and_i_see_the_vaccination_details
end

def when_vaccination_confirmations_are_sent
VaccinationConfirmationsJob.perform_now
SendVaccinationConfirmationsJob.perform_now
end

def then_an_email_is_sent_to_the_parent_confirming_the_vaccination
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe ClinicSessionInvitationsJob do
describe EnqueueClinicSessionInvitationsJob do
subject(:perform_now) { described_class.perform_now }

let(:programmes) { [create(:programme, :hpv)] }
Expand Down
75 changes: 75 additions & 0 deletions spec/jobs/enqueue_school_consent_reminders_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

describe EnqueueSchoolConsentRemindersJob do
subject(:perform_now) { described_class.perform_now }

let(:programmes) { [create(:programme)] }
let(:organisation) { create(:organisation, programmes:) }
let(:location) { create(:school, organisation:) }

let(:dates) { [Date.new(2024, 1, 12), Date.new(2024, 1, 15)] }

let!(:session) do
create(
:session,
dates:,
send_consent_requests_at: dates.first - 3.weeks,
days_before_consent_reminders: 7,
location:,
programmes:,
organisation:
)
end

around { |example| travel_to(today) { example.run } }

context "two weeks before the first session" do
let(:today) { dates.first - 2.weeks }

it "doesn't queue any jobs" do
expect { perform_now }.not_to have_enqueued_job(
SendSchoolConsentRemindersJob
)
end
end

context "one week before the first session" do
let(:today) { dates.first - 1.week }

it "queues a job for the session" do
expect { perform_now }.to have_enqueued_job(
SendSchoolConsentRemindersJob
).with(session)
end

context "when location is a generic clinic" do
let(:location) { create(:generic_clinic, organisation:) }

it "doesn't queue any jobs" do
expect { perform_now }.not_to have_enqueued_job(
SendSchoolConsentRemindersJob
)
end
end
end

context "one week before the second session" do
let(:today) { dates.last - 1.week }

it "queues a job for the session" do
expect { perform_now }.to have_enqueued_job(
SendSchoolConsentRemindersJob
).with(session)
end

context "when location is a generic clinic" do
let(:location) { create(:generic_clinic, organisation:) }

it "doesn't queue any jobs" do
expect { perform_now }.not_to have_enqueued_job(
SendSchoolConsentRemindersJob
)
end
end
end
end
Loading
Loading