Skip to content

Commit 69da9c6

Browse files
authored
Merge pull request #3673 from nhsuk/consent-preferred-method
Store vaccine methods on consent forms
2 parents 9671035 + a2d5ed8 commit 69da9c6

14 files changed

+158
-46
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ gem "stackprof"
2424
gem "activerecord-import"
2525
gem "activerecord-session_store"
2626
gem "amazing_print"
27+
gem "array_enum"
2728
gem "audited", git: "https://github.com/tvararu/audited", branch: "encryption"
2829
gem "caxlsx"
2930
gem "charlock_holmes"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ GEM
102102
aes_key_wrap (1.1.0)
103103
amazing_print (1.7.2)
104104
annotaterb (4.14.0)
105+
array_enum (1.6.0)
106+
activemodel
105107
asciidoctor (2.0.23)
106108
asciidoctor-diagram (3.0.0)
107109
asciidoctor (>= 1.5.7, < 3.x)
@@ -713,6 +715,7 @@ DEPENDENCIES
713715
activerecord-session_store
714716
amazing_print
715717
annotaterb
718+
array_enum
716719
asciidoctor
717720
asciidoctor-diagram
718721
audited!

app/controllers/patient_sessions/consents_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def create_params
123123
{
124124
patient_session: @patient_session,
125125
programme: @programme,
126-
recorded_by: current_user
126+
recorded_by: current_user,
127+
vaccine_methods: %w[injection]
127128
}
128129
end
129130

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module HasVaccineMethods
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
extend ArrayEnum
8+
9+
array_enum vaccine_methods: { injection: 0, nasal: 1 }
10+
11+
validates :vaccine_methods, subset: %w[injection nasal]
12+
end
13+
end

app/models/consent.rb

Lines changed: 38 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_methods :integer default([]), not null, is an Array
1617
# withdrawn_at :datetime
1718
# created_at :datetime not null
1819
# updated_at :datetime not null
@@ -42,6 +43,7 @@
4243
class Consent < ApplicationRecord
4344
include Invalidatable
4445
include HasHealthAnswers
46+
include HasVaccineMethods
4547

4648
audited associated_with: :patient
4749

@@ -99,6 +101,8 @@ class Consent < ApplicationRecord
99101
presence: true,
100102
unless: -> { via_self_consent? || via_website? }
101103

104+
validates :vaccine_methods, presence: true, if: :response_given?
105+
102106
def self.verbal_routes = routes.except("website", "self_consent")
103107

104108
def name
@@ -158,42 +162,43 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
158162
parent =
159163
consent_form.find_or_create_parent_with_relationship_to!(patient:)
160164

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
165+
consents =
166+
consent_form
167+
.consent_form_programmes
168+
.includes(:programme)
169+
.map do |consent_form_programme|
170+
notes =
171+
if consent_form_programme.response_given?
172+
""
173+
else
174+
consent_form.reason_notes.presence || ""
175+
end
176+
reason_for_refusal =
177+
if consent_form_programme.response_given?
178+
nil
179+
else
180+
consent_form.reason
181+
end
182+
183+
patient.consents.create!(
184+
consent_form:,
185+
health_answers: consent_form.health_answers,
186+
notes:,
187+
organisation: consent_form.organisation,
188+
parent:,
189+
programme: consent_form_programme.programme,
190+
reason_for_refusal:,
191+
recorded_by: current_user,
192+
response: consent_form_programme.response,
193+
route: "website",
194+
submitted_at: consent_form.recorded_at,
195+
vaccine_methods: consent_form_programme.vaccine_methods
196+
)
197+
end
193198

194199
StatusUpdater.call(patient:)
195200

196-
consent_given + consent_refused
201+
consents
197202
end
198203
end
199204

app/models/consent_form.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ def home_educated_changed?
454454
def update_programme_responses
455455
case response
456456
when "given"
457-
consent_form_programmes.each { it.response = "given" }
457+
consent_form_programmes.each do
458+
it.response = "given"
459+
it.vaccine_methods = %w[injection]
460+
end
458461
when "given_one"
459462
consent_form_programmes.each do |consent_form_programme|
460463
consent_form_programme.response =
@@ -463,6 +466,7 @@ def update_programme_responses
463466
else
464467
"refused"
465468
end
469+
consent_form_programme.vaccine_methods = %w[injection]
466470
end
467471
when "refused"
468472
consent_form_programmes.each { it.response = "refused" }

app/models/consent_form_programme.rb

Lines changed: 3 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_methods :integer default([]), not null, is an Array
910
# consent_form_id :bigint not null
1011
# programme_id :bigint not null
1112
#
@@ -20,6 +21,8 @@
2021
# fk_rails_... (programme_id => programmes.id)
2122
#
2223
class ConsentFormProgramme < ApplicationRecord
24+
include HasVaccineMethods
25+
2326
belongs_to :consent_form
2427
belongs_to :programme
2528

app/models/draft_consent.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def self.request_session_key
3333
attribute :route, :string
3434
attribute :triage_notes, :string
3535
attribute :triage_status, :string
36+
attribute :vaccine_methods, array: true, default: []
3637

3738
def wizard_steps
3839
[
@@ -333,6 +334,7 @@ def writable_attribute_names
333334
response
334335
route
335336
organisation_id
337+
vaccine_methods
336338
]
337339
end
338340

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+
class AddVaccineMethodsToConsentAndConsentForms < ActiveRecord::Migration[8.0]
4+
def change
5+
add_column :consent_form_programmes,
6+
:vaccine_methods,
7+
:integer,
8+
null: false,
9+
array: true,
10+
default: []
11+
12+
add_column :consents,
13+
:vaccine_methods,
14+
:integer,
15+
null: false,
16+
array: true,
17+
default: []
18+
19+
# We don't support getting consent for nasal spray yet.
20+
reversible do |dir|
21+
dir.up do
22+
ConsentFormProgramme.response_given.update_all(
23+
vaccine_methods: %w[injection]
24+
)
25+
Consent.response_given.update_all(vaccine_methods: %w[injection])
26+
end
27+
end
28+
end
29+
end

db/schema.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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_methods", default: [], null: false, array: true
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_methods", default: [], null: false, array: true
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"

0 commit comments

Comments
 (0)