Skip to content

Commit 829feef

Browse files
authored
Merge pull request #3785 from nhsuk/vaccine-side-effects
Add side effects to vaccines
2 parents 4625239 + 34f6328 commit 829feef

11 files changed

Lines changed: 156 additions & 3 deletions

File tree

app/lib/govuk_notify_personalisation.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def to_h
6565
team_name:,
6666
team_phone:,
6767
today_or_date_of_vaccination:,
68-
vaccination:
68+
vaccination:,
69+
vaccine_side_effects:
6970
}.compact
7071
end
7172

@@ -286,4 +287,20 @@ def vaccination
286287
programmes.count == 1 ? "vaccination" : "vaccinations"
287288
].join(" ")
288289
end
290+
291+
def vaccine_side_effects
292+
side_effects =
293+
if vaccination_record
294+
vaccination_record.vaccine&.side_effects
295+
elsif programmes.present?
296+
Vaccine.where(programme: programmes).flat_map(&:side_effects)
297+
end
298+
299+
return if side_effects.nil?
300+
301+
descriptions =
302+
side_effects.map { Vaccine.human_enum_name(:side_effect, it) }.sort.uniq
303+
304+
descriptions.map { "- #{it}" }.join("\n")
305+
end
289306
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module HasSideEffects
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
extend ArrayEnum
8+
9+
array_enum side_effects: {
10+
aching: 0,
11+
dizziness: 1,
12+
drowsy: 2,
13+
feeling_sick: 3,
14+
headache: 4,
15+
high_temperature: 5,
16+
irritable: 6,
17+
loss_of_appetite: 8,
18+
pain_in_arms: 9,
19+
raised_temperature: 10,
20+
rash: 11,
21+
runny_blocked_nose: 12,
22+
swelling: 13,
23+
tiredness: 14,
24+
unwell: 15
25+
}
26+
27+
validates :side_effects, subset: side_effects.keys
28+
end
29+
end

app/models/concerns/has_vaccine_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module HasVaccineMethods
88

99
array_enum vaccine_methods: { injection: 0, nasal: 1 }
1010

11-
validates :vaccine_methods, subset: %w[injection nasal]
11+
validates :vaccine_methods, subset: vaccine_methods.keys
1212
end
1313

1414
def vaccine_method_injection? = vaccine_methods.include?("injection")

app/models/vaccine.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# manufacturer :text not null
1212
# method :integer not null
1313
# nivs_name :text not null
14+
# side_effects :integer default([]), not null, is an Array
1415
# snomed_product_code :string not null
1516
# snomed_product_term :string not null
1617
# created_at :datetime not null
@@ -30,6 +31,8 @@
3031
# fk_rails_... (programme_id => programmes.id)
3132
#
3233
class Vaccine < ApplicationRecord
34+
include HasSideEffects
35+
3336
audited associated_with: :programme
3437
has_associated_audits
3538

config/locales/en.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ en:
231231
injection: Injection
232232
nasal: Nasal spray
233233
nasal_injection: Nasal spray (or injection)
234+
side_effects:
235+
aching: an aching body
236+
dizziness: dizziness
237+
drowsy: feeling drowsy
238+
feeling_sick: feeling sick
239+
headache: a headache
240+
high_temperature: a high temperature
241+
irritable: feeling irritable
242+
loss_of_appetite: loss of appetite
243+
pain_in_arms: pain in the arms, hands, fingers
244+
raised_temperature: a slightly raised temperature
245+
rash: a rash
246+
runny_blocked_nose: a runny or blocked nose
247+
swelling: swelling or pain where the injection was given
248+
tiredness: general tiredness
249+
unwell: generally feeling unwell
234250
errors:
235251
models:
236252
class_import:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
class AddSideEffectsToVaccines < ActiveRecord::Migration[8.0]
4+
def change
5+
add_column :vaccines,
6+
:side_effects,
7+
:integer,
8+
array: true,
9+
default: [],
10+
null: false
11+
end
12+
end

db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@
842842
t.text "nivs_name", null: false
843843
t.boolean "discontinued", default: false, null: false
844844
t.bigint "programme_id", null: false
845+
t.integer "side_effects", default: [], null: false, array: true
845846
t.index ["manufacturer", "brand"], name: "index_vaccines_on_manufacturer_and_brand", unique: true
846847
t.index ["nivs_name"], name: "index_vaccines_on_nivs_name", unique: true
847848
t.index ["programme_id"], name: "index_vaccines_on_programme_id"

lib/tasks/vaccines.rake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace :vaccines do
2626
vaccine.snomed_product_term = data["snomed_product_term"]
2727
vaccine.programme = programme
2828

29+
vaccine.side_effects = side_effects_for(programme, data["method"])
30+
2931
vaccine.save!
3032

3133
next if vaccine.health_questions.exists?
@@ -47,6 +49,61 @@ namespace :vaccines do
4749
end
4850
end
4951

52+
def side_effects_for(programme, method)
53+
if programme.flu?
54+
if method == "nasal"
55+
%w[runny_blocked_nose headache tiredness loss_of_appetite]
56+
else
57+
%w[
58+
swelling
59+
headache
60+
high_temperature
61+
feeling_sick
62+
irritable
63+
drowsy
64+
loss_of_appetite
65+
unwell
66+
]
67+
end
68+
elsif programme.hpv?
69+
%w[
70+
swelling
71+
headache
72+
high_temperature
73+
feeling_sick
74+
irritable
75+
drowsy
76+
loss_of_appetite
77+
unwell
78+
]
79+
elsif programme.menacwy?
80+
%w[
81+
drowsy
82+
feeling_sick
83+
headache
84+
high_temperature
85+
irritable
86+
loss_of_appetite
87+
rash
88+
swelling
89+
unwell
90+
]
91+
elsif programme.td_ipv?
92+
%w[
93+
drowsy
94+
feeling_sick
95+
headache
96+
high_temperature
97+
irritable
98+
loss_of_appetite
99+
swelling
100+
unwell
101+
]
102+
else
103+
raise UnsupportedProgramme, programme
104+
end
105+
end
106+
50107
def create_flu_health_questions(vaccine)
51108
asthma =
52109
if vaccine.nasal?

spec/factories/vaccines.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# manufacturer :text not null
1212
# method :integer not null
1313
# nivs_name :text not null
14+
# side_effects :integer default([]), not null, is an Array
1415
# snomed_product_code :string not null
1516
# snomed_product_term :string not null
1617
# created_at :datetime not null

spec/lib/govuk_notify_personalisation_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
team_email: "organisation@example.com",
7474
team_name: "Organisation",
7575
team_phone: "01234 567890 (option 1)",
76-
vaccination: "HPV vaccination"
76+
vaccination: "HPV vaccination",
77+
vaccine_side_effects: ""
7778
}
7879
)
7980
end
@@ -241,4 +242,19 @@
241242
)
242243
end
243244
end
245+
246+
context "with vaccine side effects" do
247+
before do
248+
programmes.first.vaccines.first.update!(side_effects: %w[swelling unwell])
249+
end
250+
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"
256+
)
257+
)
258+
end
259+
end
244260
end

0 commit comments

Comments
 (0)