Skip to content

Commit 606e36a

Browse files
committed
Store vaccine method on consent forms
This adds a new column on consent forms (per programme) allowing parents to express a preference regarding the vaccine method. In most cases this is irrelevant as injection is the only option, but for Flu there's the option of a nasal spray which is the preferred choice. Jira-Issue: MAV-1230
1 parent 8db08b2 commit 606e36a

9 files changed

+87
-47
lines changed

app/models/consent.rb

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# response :integer not null
1414
# route :integer not null
1515
# submitted_at :datetime not null
16+
# vaccine_method :integer
1617
# withdrawn_at :datetime
1718
# created_at :datetime not null
1819
# updated_at :datetime not null
@@ -69,6 +70,7 @@ class Consent < ApplicationRecord
6970
{ website: 0, phone: 1, paper: 2, in_person: 3, self_consent: 4 },
7071
prefix: "via",
7172
validate: true
73+
enum :vaccine_method, { injection: 0, nasal: 1 }, prefix: true
7274

7375
enum :reason_for_refusal,
7476
{
@@ -158,42 +160,44 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
158160
parent =
159161
consent_form.find_or_create_parent_with_relationship_to!(patient:)
160162

161-
consent_given =
162-
consent_form.given_programmes.map do |programme|
163-
patient.consents.create!(
164-
consent_form:,
165-
organisation: consent_form.organisation,
166-
programme:,
167-
parent:,
168-
notes: "",
169-
response: "given",
170-
route: "website",
171-
health_answers: consent_form.health_answers,
172-
recorded_by: current_user,
173-
submitted_at: consent_form.recorded_at
174-
)
175-
end
176-
177-
consent_refused =
178-
consent_form.refused_programmes.map do |programme|
179-
patient.consents.create!(
180-
consent_form:,
181-
organisation: consent_form.organisation,
182-
programme:,
183-
parent:,
184-
reason_for_refusal: consent_form.reason,
185-
notes: consent_form.reason_notes.presence || "",
186-
response: "refused",
187-
route: "website",
188-
health_answers: consent_form.health_answers,
189-
recorded_by: current_user,
190-
submitted_at: consent_form.recorded_at
191-
)
192-
end
163+
consents =
164+
consent_form
165+
.consent_form_programmes
166+
.includes(:programme)
167+
.map do |consent_form_programme|
168+
patient.consents.create!(
169+
consent_form:,
170+
health_answers: consent_form.health_answers,
171+
notes:
172+
(
173+
if consent_form_programme.response_given?
174+
""
175+
else
176+
consent_form.reason_notes.presence || ""
177+
end
178+
),
179+
organisation: consent_form.organisation,
180+
parent:,
181+
programme: consent_form_programme.programme,
182+
reason_for_refusal:
183+
(
184+
if consent_form_programme.response_given?
185+
nil
186+
else
187+
consent_form.reason
188+
end
189+
),
190+
recorded_by: current_user,
191+
response: consent_form_programme.response,
192+
route: "website",
193+
submitted_at: consent_form.recorded_at,
194+
vaccine_method: consent_form_programme.vaccine_method
195+
)
196+
end
193197

194198
StatusUpdater.call(patient:)
195199

196-
consent_given + consent_refused
200+
consents
197201
end
198202
end
199203

app/models/consent_form.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ class ConsentForm < ApplicationRecord
103103
through: :refused_consent_form_programmes,
104104
source: :programme
105105

106-
has_many :vaccines, through: :consent_form_programmes
107-
has_many :given_vaccines,
108-
through: :given_consent_form_programmes,
109-
source: :vaccines
110-
has_many :refused_vaccines,
111-
through: :refused_consent_form_programmes,
112-
source: :vaccines
113-
114106
has_one :team, through: :location
115107

116108
has_many :eligible_schools, through: :organisation, source: :schools
@@ -466,7 +458,10 @@ def home_educated_changed?
466458
def update_programme_responses
467459
case response
468460
when "given"
469-
consent_form_programmes.each { it.response = "given" }
461+
consent_form_programmes.each do
462+
it.response = "given"
463+
it.vaccine_method = "injection"
464+
end
470465
when "given_one"
471466
consent_form_programmes.each do |consent_form_programme|
472467
consent_form_programme.response =
@@ -475,6 +470,7 @@ def update_programme_responses
475470
else
476471
"refused"
477472
end
473+
consent_form_programme.vaccine_method = "injection"
478474
end
479475
when "refused"
480476
consent_form_programmes.each { it.response = "refused" }

app/models/consent_form_programme.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# id :bigint not null, primary key
88
# response :integer
9+
# vaccine_method :integer
910
# consent_form_id :bigint not null
1011
# programme_id :bigint not null
1112
#
@@ -28,4 +29,5 @@ class ConsentFormProgramme < ApplicationRecord
2829
scope :ordered, -> { joins(:programme).order(:"programme.type") }
2930

3031
enum :response, { given: 0, refused: 1 }, prefix: true
32+
enum :vaccine_method, { injection: 0, nasal: 1 }, prefix: true
3133
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
class AddVaccineMethodToConsentAndConsentForms < ActiveRecord::Migration[8.0]
4+
def change
5+
add_column :consent_form_programmes, :vaccine_method, :integer
6+
7+
add_column :consents, :vaccine_method, :integer
8+
9+
# We don't support getting consent for nasal spray yet.
10+
reversible do |dir|
11+
dir.up do
12+
ConsentFormProgramme.response_given.update_all(
13+
vaccine_method: "injection"
14+
)
15+
Consent.response_given.update_all(vaccine_method: "injection")
16+
end
17+
end
18+
19+
remove_column :consent_forms, :contact_injection, :boolean
20+
end
21+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2025_06_06_070424) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_06_06_083902) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pg_trgm"
@@ -156,6 +156,7 @@
156156
t.bigint "programme_id", null: false
157157
t.bigint "consent_form_id", null: false
158158
t.integer "response"
159+
t.integer "vaccine_method"
159160
t.index ["consent_form_id"], name: "index_consent_form_programmes_on_consent_form_id"
160161
t.index ["programme_id", "consent_form_id"], name: "idx_on_programme_id_consent_form_id_2113cb7f37", unique: true
161162
end
@@ -236,6 +237,7 @@
236237
t.datetime "invalidated_at"
237238
t.boolean "notify_parents"
238239
t.datetime "submitted_at", null: false
240+
t.integer "vaccine_method"
239241
t.index ["organisation_id"], name: "index_consents_on_organisation_id"
240242
t.index ["parent_id"], name: "index_consents_on_parent_id"
241243
t.index ["patient_id"], name: "index_consents_on_patient_id"

spec/factories/consent_form_programmes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# id :bigint not null, primary key
88
# response :integer
9+
# vaccine_method :integer
910
# consent_form_id :bigint not null
1011
# programme_id :bigint not null
1112
#

spec/factories/consents.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# response :integer not null
1414
# route :integer not null
1515
# submitted_at :datetime not null
16+
# vaccine_method :integer
1617
# withdrawn_at :datetime
1718
# created_at :datetime not null
1819
# updated_at :datetime not null

spec/models/consent_form_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
session:,
6868
programmes:,
6969
use_preferred_name:,
70-
wizard_step:,
70+
wizard_step:
7171
)
7272
end
7373

spec/models/consent_spec.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# response :integer not null
1414
# route :integer not null
1515
# submitted_at :datetime not null
16+
# vaccine_method :integer
1617
# withdrawn_at :datetime
1718
# created_at :datetime not null
1819
# updated_at :datetime not null
@@ -94,7 +95,7 @@
9495
end
9596

9697
describe "#from_consent_form!" do
97-
describe "the created consent object" do
98+
context "with on programme" do
9899
subject(:consent) do
99100
described_class.from_consent_form!(
100101
consent_form,
@@ -111,7 +112,7 @@
111112
expect(consent.recorded_by).to eq(current_user)
112113
end
113114

114-
it "copies over attributes from consent_form" do
115+
it "copies over attributes from consent form" do
115116
expect(consent).to(
116117
have_attributes(
117118
programme: consent_form.programmes.first,
@@ -160,9 +161,21 @@
160161
)
161162
end
162163
end
164+
165+
context "when consenting to nasal spray" do
166+
before do
167+
consent_form.consent_form_programmes.first.update!(
168+
vaccine_method: "nasal"
169+
)
170+
end
171+
172+
it "stores this preference on the consent" do
173+
expect(consent).to be_vaccine_method_nasal
174+
end
175+
end
163176
end
164177

165-
context "when only consenting to one programme" do
178+
context "with multiple programmes" do
166179
subject(:consents) do
167180
described_class.from_consent_form!(
168181
consent_form,

0 commit comments

Comments
 (0)