Skip to content

Commit 7d3390f

Browse files
committed
Add disease_types column to ConsentFormProgramme model
This allows us to determine the disease types for the consent form in the controller and set that when creating the consent form, which will eventually determine which questions the parent sees. This is required now becasue we are adding a new consent flow for MMRV which is a "variant" of the programme MMR. Hence the programme type alone is insufficient to determine which consent journey is displayed.
1 parent 3ce8b7a commit 7d3390f

6 files changed

Lines changed: 43 additions & 3 deletions

File tree

app/models/consent_form_programme.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: consent_form_programmes
66
#
77
# id :bigint not null, primary key
8+
# disease_types :enum is an Array
89
# notes :text default(""), not null
910
# programme_type :enum not null
1011
# reason_for_refusal :integer
@@ -36,7 +37,11 @@ class ConsentFormProgramme < ApplicationRecord
3637
delegate :flu?, :hpv?, :menacwy?, :mmr?, :td_ipv?, to: :programme
3738

3839
def disease_types
39-
# TODO: Update this when we allow parents to submit consent for MMRV.
40+
# Use database column if populated, otherwise fall back to default logic
41+
# for records created before disease_types column was added
42+
db_value = super
43+
return db_value if db_value.present?
44+
4045
if programme_type == "mmr"
4146
Programme::Variant::DISEASE_TYPES["mmr"]
4247
else
@@ -46,7 +51,7 @@ def disease_types
4651

4752
def vaccines
4853
VaccineCriteria.from_consentable(self).apply(
49-
Vaccine.active.where(programme_type:)
54+
Vaccine.active.where(programme_type:, disease_types:)
5055
)
5156
end
5257

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class AddDiseaseTypesToConsentFormProgrammes < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :consent_form_programmes,
6+
:disease_types,
7+
:enum,
8+
enum_type: :disease_type,
9+
array: true
10+
end
11+
end

db/schema.rb

Lines changed: 2 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.1].define(version: 2026_02_17_111256) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_02_18_163043) 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"
@@ -202,6 +202,7 @@
202202

203203
create_table "consent_form_programmes", force: :cascade do |t|
204204
t.bigint "consent_form_id", null: false
205+
t.enum "disease_types", array: true, enum_type: "disease_type"
205206
t.text "notes", default: "", null: false
206207
t.enum "programme_type", null: false, enum_type: "programme_type"
207208
t.integer "reason_for_refusal"

spec/factories/consent_form_programmes.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: consent_form_programmes
66
#
77
# id :bigint not null, primary key
8+
# disease_types :enum is an Array
89
# notes :text default(""), not null
910
# programme_type :enum not null
1011
# reason_for_refusal :integer
@@ -26,6 +27,13 @@
2627
factory :consent_form_programme do
2728
consent_form
2829
programme { Programme.sample }
30+
disease_types do
31+
if programme.mmr?
32+
programme.variants.sample.disease_types
33+
else
34+
Programme::DISEASE_TYPES[programme.type]
35+
end
36+
end
2937

3038
trait :given do
3139
response { "given" }

spec/factories/consent_forms.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@
146146
evaluator.programmes.each do |programme|
147147
consent_form.consent_form_programmes.build(
148148
programme:,
149+
disease_types:
150+
(
151+
if programme.mmr?
152+
programme.variants.sample.disease_types
153+
else
154+
Programme::DISEASE_TYPES[programme.type]
155+
end
156+
),
149157
response: evaluator.response
150158
)
151159
end

spec/models/consent_form_programme_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Table name: consent_form_programmes
66
#
77
# id :bigint not null, primary key
8+
# disease_types :enum is an Array
89
# notes :text default(""), not null
910
# programme_type :enum not null
1011
# reason_for_refusal :integer
@@ -30,6 +31,12 @@
3031

3132
describe "#vaccines" do
3233
context "when there are MMR and MMRV vaccines" do
34+
before do
35+
consent_form_programme.update!(
36+
disease_types: Programme::Variant::DISEASE_TYPES[programme.type]
37+
)
38+
end
39+
3340
it "only returns MMR vaccines" do
3441
# Ensure that the MMRV vaccines do actually exist!
3542
expect(Vaccine.where(brand: %w[ProQuad Priorix-Tetra]).count).to eq(2)

0 commit comments

Comments
 (0)