Skip to content

Commit 0c83de4

Browse files
committed
Use Patient#approved_vaccine_methods
This ensures that when sending emails that list vaccine side effects, we're only include the side effects for the vaccines that the patient is approved for. In most cases this has no effect, but for Flu it's possible to be approved for either nasal or injection vaccines and therefore we should only show the approriate vaccine methods. Jira-Issue: MAV-1355
1 parent 7b99d8e commit 0c83de4

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

app/lib/govuk_notify_personalisation.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,18 @@ def vaccine_side_effects
293293
if vaccination_record
294294
vaccination_record.vaccine&.side_effects
295295
elsif programmes.present?
296-
Vaccine.where(programme: programmes).flat_map(&:side_effects)
296+
if patient
297+
programmes.flat_map do |programme|
298+
# We pick the first method as it's the one most likely to be used
299+
# to vaccinate the patient. For example, in the case of Flu, the
300+
# parents will approve nasal (and then optionally injection).
301+
method = patient.approved_vaccine_methods(programme:).first
302+
303+
Vaccine.where(programme:, method:).flat_map(&:side_effects)
304+
end
305+
else
306+
Vaccine.where(programme: programmes).flat_map(&:side_effects)
307+
end
297308
end
298309

299310
return if side_effects.nil?

spec/lib/govuk_notify_personalisation_spec.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,27 @@
248248
programmes.first.vaccines.first.update!(side_effects: %w[swelling unwell])
249249
end
250250

251-
it do
252-
expect(to_h).to match(
253-
hash_including(
254-
vaccine_side_effects:
255-
"- generally feeling unwell\n- swelling or pain where the injection was given"
251+
it { should include(vaccine_side_effects: "") }
252+
253+
context "with injection as an approved vaccine method" do
254+
before do
255+
create(
256+
:patient_triage_status,
257+
:safe_to_vaccinate,
258+
:injection,
259+
patient:,
260+
programme: programmes.first
256261
)
257-
)
262+
end
263+
264+
it do
265+
expect(to_h).to match(
266+
hash_including(
267+
vaccine_side_effects:
268+
"- generally feeling unwell\n- swelling or pain where the injection was given"
269+
)
270+
)
271+
end
258272
end
259273
end
260274
end

0 commit comments

Comments
 (0)