Skip to content

Commit 9513cfe

Browse files
authored
Merge pull request #3914 from nhsuk/delivery-method-vaccine-side-effects
Limit side effects to vaccines approved for the patient
2 parents cf58321 + 0c83de4 commit 9513cfe

5 files changed

Lines changed: 98 additions & 17 deletions

File tree

app/components/app_vaccinate_form_component.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@ def url
1919
end
2020

2121
def delivery_method
22-
triage_status = patient.triage_status(programme:)
23-
24-
status =
25-
if triage_status.not_required?
26-
patient.consent_status(programme:)
27-
else
28-
triage_status
29-
end
30-
31-
status.vaccine_method_nasal? ? :nasal_spray : :intramuscular
22+
if patient.approved_vaccine_methods(programme:).include?("nasal")
23+
:nasal_spray
24+
else
25+
:intramuscular
26+
end
3227
end
3328

3429
def dose_sequence

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?

app/models/patient.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,16 @@ def consent_given_and_safe_to_vaccinate?(programme:)
338338
)
339339
end
340340

341+
def approved_vaccine_methods(programme:)
342+
triage_status = triage_status(programme:)
343+
344+
if triage_status.not_required?
345+
consent_status(programme:).vaccine_methods
346+
else
347+
[triage_status.vaccine_method].compact
348+
end
349+
end
350+
341351
def deceased?
342352
date_of_death != nil
343353
end

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

spec/models/patient_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,57 @@
321321
it { should eq("JD") }
322322
end
323323

324+
describe "#approved_vaccine_methods" do
325+
subject(:approved_vaccine_methods) do
326+
patient.approved_vaccine_methods(programme:)
327+
end
328+
329+
let(:patient) { create(:patient) }
330+
let(:programme) { create(:programme) }
331+
332+
it { should be_empty }
333+
334+
context "when consent given and triage not required" do
335+
before do
336+
create(
337+
:patient_consent_status,
338+
:given,
339+
patient:,
340+
programme:,
341+
vaccine_methods: %w[nasal injection]
342+
)
343+
end
344+
345+
it { should eq(%w[nasal injection]) }
346+
end
347+
348+
context "when consent given and triage required" do
349+
before do
350+
create(
351+
:patient_consent_status,
352+
:given,
353+
patient:,
354+
programme:,
355+
vaccine_methods: %w[nasal injection]
356+
)
357+
create(:patient_triage_status, :required, patient:, programme:)
358+
end
359+
360+
it { should be_empty }
361+
362+
context "and when triaged" do
363+
before do
364+
patient.triage_status(programme:).update!(
365+
status: "safe_to_vaccinate",
366+
vaccine_method: "nasal"
367+
)
368+
end
369+
370+
it { should eq(%w[nasal]) }
371+
end
372+
end
373+
end
374+
324375
describe "#update_from_pds!" do
325376
subject(:update_from_pds!) { patient.update_from_pds!(pds_patient) }
326377

0 commit comments

Comments
 (0)