Skip to content

Commit 361bf25

Browse files
committed
Limit programmes to those that are safe to vaccinate
When sending out the session reminder emails to parents, we should only include information (vaccine side effects) about programmes that the patient is going to be vaccinated for, specifically ignoring those where the patient has already been vaccinated or those that the parent didn't give consent for. Jira-Issue: MAV-1355
1 parent 652e1eb commit 361bf25

2 files changed

Lines changed: 81 additions & 11 deletions

File tree

app/models/session_notification.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,23 @@ def self.create_and_send!(
8282
sent_by: current_user
8383
)
8484

85+
programmes =
86+
if type == :school_reminder
87+
patient_session.programmes.select do |programme|
88+
patient.consent_given_and_safe_to_vaccinate?(programme:)
89+
end
90+
else
91+
patient_session.programmes
92+
end
93+
8594
parents.each do |parent|
86-
params = { parent:, patient:, session:, sent_by: current_user }
95+
params = {
96+
parent:,
97+
patient:,
98+
programmes:,
99+
session:,
100+
sent_by: current_user
101+
}
87102

88103
EmailDeliveryJob.perform_later(:"session_#{type}", **params)
89104

spec/models/session_notification_spec.rb

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@
4242
let(:parents) { create_list(:parent, 2) }
4343
let(:patient) { create(:patient, parents:, year_group: 10) }
4444
let(:programme) { create(:programme, :td_ipv) }
45-
let(:organisation) { create(:organisation, programmes: [programme]) }
45+
let(:programmes) { [programme] }
46+
let(:organisation) { create(:organisation, programmes:) }
4647
let(:location) { create(:school, organisation:) }
47-
let(:session) do
48-
create(:session, location:, programmes: [programme], organisation:)
49-
end
48+
let(:session) { create(:session, location:, programmes:, organisation:) }
5049
let(:session_date) { session.dates.min }
5150
let(:patient_session) { create(:patient_session, patient:, session:) }
5251
let(:current_user) { create(:user) }
@@ -58,7 +57,10 @@
5857

5958
let(:parent) { parents.first }
6059

61-
before { create(:consent, :given, patient:, parent:, programme:) }
60+
before do
61+
create(:consent, :given, patient:, parent:, programme:)
62+
create(:patient_consent_status, :given, patient:, programme:)
63+
end
6264

6365
it "creates a record" do
6466
expect { create_and_send! }.to change(described_class, :count).by(1)
@@ -73,22 +75,55 @@
7375
it "enqueues an email per parent who gave consent" do
7476
expect { create_and_send! }.to have_delivered_email(
7577
:session_school_reminder
76-
).with(parent:, patient:, session:, sent_by: current_user)
78+
).with(parent:, patient:, programmes:, session:, sent_by: current_user)
7779
end
7880

7981
it "enqueues a text per parent" do
8082
expect { create_and_send! }.to have_delivered_sms(
8183
:session_school_reminder
82-
).with(parent:, patient:, session:, sent_by: current_user)
84+
).with(parent:, patient:, programmes:, session:, sent_by: current_user)
8385
end
8486

8587
context "when parent doesn't want to receive updates by text" do
86-
before { parents.each { _1.update!(phone_receive_updates: false) } }
88+
before { parents.each { it.update!(phone_receive_updates: false) } }
8789

8890
it "doesn't enqueues a text" do
8991
expect { create_and_send! }.not_to have_delivered_sms
9092
end
9193
end
94+
95+
context "with multiple programmes but only one eligible for vaccination" do
96+
let(:consented_programmes) { [programme] }
97+
98+
# No consent for MenACWY
99+
let(:programmes) do
100+
consented_programmes + [create(:programme, :menacwy)]
101+
end
102+
103+
it "enqueues an email per parent who gave consent" do
104+
expect { create_and_send! }.to have_delivered_email(
105+
:session_school_reminder
106+
).with(
107+
parent:,
108+
patient:,
109+
programmes: consented_programmes,
110+
session:,
111+
sent_by: current_user
112+
)
113+
end
114+
115+
it "enqueues a text per parent" do
116+
expect { create_and_send! }.to have_delivered_sms(
117+
:session_school_reminder
118+
).with(
119+
parent:,
120+
patient:,
121+
programmes: consented_programmes,
122+
session:,
123+
sent_by: current_user
124+
)
125+
end
126+
end
92127
end
93128

94129
context "with an initial clinic invitation" do
@@ -110,11 +145,13 @@
110145
).with(
111146
parent: parents.first,
112147
patient:,
148+
programmes:,
113149
session:,
114150
sent_by: current_user
115151
).and have_delivered_email(:session_clinic_initial_invitation).with(
116152
parent: parents.second,
117153
patient:,
154+
programmes:,
118155
session:,
119156
sent_by: current_user
120157
)
@@ -126,11 +163,13 @@
126163
).with(
127164
parent: parents.first,
128165
patient:,
166+
programmes:,
129167
session:,
130168
sent_by: current_user
131169
).and have_delivered_sms(:session_clinic_initial_invitation).with(
132170
parent: parents.second,
133171
patient:,
172+
programmes:,
134173
session:,
135174
sent_by: current_user
136175
)
@@ -144,7 +183,13 @@
144183
it "still enqueues a text" do
145184
expect { create_and_send! }.to have_delivered_sms(
146185
:session_clinic_initial_invitation
147-
).with(parent:, patient:, session:, sent_by: current_user)
186+
).with(
187+
parent:,
188+
patient:,
189+
programmes:,
190+
session:,
191+
sent_by: current_user
192+
)
148193
end
149194
end
150195
end
@@ -168,11 +213,13 @@
168213
).with(
169214
parent: parents.first,
170215
patient:,
216+
programmes:,
171217
session:,
172218
sent_by: current_user
173219
).and have_delivered_email(:session_clinic_subsequent_invitation).with(
174220
parent: parents.second,
175221
patient:,
222+
programmes:,
176223
session:,
177224
sent_by: current_user
178225
)
@@ -184,11 +231,13 @@
184231
).with(
185232
parent: parents.first,
186233
patient:,
234+
programmes:,
187235
session:,
188236
sent_by: current_user
189237
).and have_delivered_sms(:session_clinic_subsequent_invitation).with(
190238
parent: parents.second,
191239
patient:,
240+
programmes:,
192241
session:,
193242
sent_by: current_user
194243
)
@@ -202,7 +251,13 @@
202251
it "still enqueues a text" do
203252
expect { create_and_send! }.to have_delivered_sms(
204253
:session_clinic_subsequent_invitation
205-
).with(parent:, patient:, session:, sent_by: current_user)
254+
).with(
255+
parent:,
256+
patient:,
257+
programmes:,
258+
session:,
259+
sent_by: current_user
260+
)
206261
end
207262
end
208263
end

0 commit comments

Comments
 (0)