Skip to content

Commit c4963e6

Browse files
authored
Merge pull request #3916 from nhsuk/personalisation-vaccine-method
Add `vaccine_is_injection` and `vaccine_is_nasal`
2 parents 9513cfe + 78db476 commit c4963e6

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

app/lib/govuk_notify_personalisation.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
class GovukNotifyPersonalisation
44
include Rails.application.routes.url_helpers
5-
include PhoneHelper
65

6+
include PhoneHelper
77
include VaccinationRecordsHelper
88

99
def initialize(
@@ -66,6 +66,8 @@ def to_h
6666
team_phone:,
6767
today_or_date_of_vaccination:,
6868
vaccination:,
69+
vaccine_is_injection:,
70+
vaccine_is_nasal:,
6971
vaccine_side_effects:
7072
}.compact
7173
end
@@ -288,6 +290,30 @@ def vaccination
288290
].join(" ")
289291
end
290292

293+
def vaccine_is_injection = vaccine_is?("injection")
294+
295+
def vaccine_is_nasal = vaccine_is?("nasal")
296+
297+
def vaccine_is?(method)
298+
if vaccination_record
299+
vaccination_record.vaccine&.method == method ? "yes" : "no"
300+
elsif programmes.present?
301+
any_vaccines_with_method =
302+
if patient
303+
programmes.any? do |programme|
304+
# We pick the first method as it's the one most likely to be used
305+
# to vaccinate the patient. For example, in the case of Flu, the
306+
# parents will approve nasal (and then optionally injection).
307+
patient.approved_vaccine_methods(programme:).first == method
308+
end
309+
else
310+
Vaccine.where(programme: programmes, method:).exists?
311+
end
312+
313+
any_vaccines_with_method ? "yes" : "no"
314+
end
315+
end
316+
291317
def vaccine_side_effects
292318
side_effects =
293319
if vaccination_record
@@ -299,7 +325,6 @@ def vaccine_side_effects
299325
# to vaccinate the patient. For example, in the case of Flu, the
300326
# parents will approve nasal (and then optionally injection).
301327
method = patient.approved_vaccine_methods(programme:).first
302-
303328
Vaccine.where(programme:, method:).flat_map(&:side_effects)
304329
end
305330
else

spec/lib/govuk_notify_personalisation_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
team_name: "Organisation",
7575
team_phone: "01234 567890 (option 1)",
7676
vaccination: "HPV vaccination",
77+
vaccine_is_injection: "no",
78+
vaccine_is_nasal: "no",
7779
vaccine_side_effects: ""
7880
}
7981
)
@@ -243,6 +245,64 @@
243245
end
244246
end
245247

248+
context "with vaccine methods" do
249+
context "and an injection-only programme" do
250+
before do
251+
create(
252+
:patient_consent_status,
253+
:given,
254+
patient:,
255+
programme: programmes.first
256+
)
257+
end
258+
259+
it { should include(vaccine_is_injection: "yes", vaccine_is_nasal: "no") }
260+
end
261+
262+
context "and a nasal spray programme" do
263+
let(:programmes) { [create(:programme, :flu)] }
264+
265+
before do
266+
create(
267+
:patient_consent_status,
268+
:given,
269+
patient:,
270+
programme: programmes.first,
271+
vaccine_methods: %w[nasal injection]
272+
)
273+
end
274+
275+
it { should include(vaccine_is_injection: "no", vaccine_is_nasal: "yes") }
276+
end
277+
278+
context "and multiple programmes" do
279+
let(:programmes) { [create(:programme, :hpv), create(:programme, :flu)] }
280+
281+
before do
282+
create(
283+
:patient_consent_status,
284+
:given,
285+
patient:,
286+
programme: programmes.first,
287+
vaccine_methods: %w[nasal injection]
288+
)
289+
create(
290+
:patient_consent_status,
291+
:given,
292+
patient:,
293+
programme: programmes.second
294+
)
295+
end
296+
297+
it do
298+
expect(to_h).to include(
299+
vaccine_is_injection: "yes",
300+
vaccine_is_nasal: "yes"
301+
)
302+
end
303+
end
304+
end
305+
246306
context "with vaccine side effects" do
247307
before do
248308
programmes.first.vaccines.first.update!(side_effects: %w[swelling unwell])

0 commit comments

Comments
 (0)