Skip to content

Commit 83d6a99

Browse files
committed
Ensure already vaccinated patients don't receive clinic invitations
This fixes an issue where patients who are invited to a clinic, and are vaccinated for some of the programmes but not all of them, were receiving an email/text for all the programmes they're eligible for rather than just the programmes they are eligible for and need a vaccination for. Jira-Issue: MAV-1994
1 parent 9a50dfe commit 83d6a99

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

app/models/session_notification.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ def self.create_and_send!(
102102
)
103103
end
104104
else
105-
session.programmes_for(patient:)
105+
session
106+
.programmes_for(patient:)
107+
.reject do |programme|
108+
patient.vaccination_status(programme:, academic_year:).vaccinated?
109+
end
106110
end
107111

108112
parents.each do |parent|

spec/models/session_notification_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,41 @@
173173
)
174174
end
175175

176+
context "when the session administers two programmes but the patient only needs one" do
177+
let(:programmes) do
178+
[create(:programme, :flu), create(:programme, :hpv)]
179+
end
180+
181+
before do
182+
create(:vaccination_record, patient:, programme: programmes.first)
183+
StatusUpdater.call(patient:)
184+
end
185+
186+
it "only sends emails for the remaining programme" do
187+
expect { create_and_send! }.to have_delivered_email(
188+
:session_clinic_initial_invitation
189+
).with(
190+
parent: parents.first,
191+
patient:,
192+
programmes: [programmes.second],
193+
session:,
194+
sent_by: current_user
195+
)
196+
end
197+
198+
it "enqueues a text per parent" do
199+
expect { create_and_send! }.to have_delivered_sms(
200+
:session_clinic_initial_invitation
201+
).with(
202+
parent: parents.first,
203+
patient:,
204+
programmes: [programmes.second],
205+
session:,
206+
sent_by: current_user
207+
)
208+
end
209+
end
210+
176211
context "when the team is Coventry & Warwickshire Partnership NHS Trust (CWPT)" do
177212
let(:team) { create(:team, ods_code: "RYG", programmes:) }
178213

0 commit comments

Comments
 (0)