diff --git a/app/components/app_outcome_banner_component.rb b/app/components/app_outcome_banner_component.rb
index 0304438bf..1d54338e1 100644
--- a/app/components/app_outcome_banner_component.rb
+++ b/app/components/app_outcome_banner_component.rb
@@ -56,7 +56,7 @@ def show_location?
end
def vaccine_summary
- type = I18n.t("vaccines.#{vaccination_record.vaccine.type}")
+ type = vaccination_record.programme.name
brand = vaccination_record.vaccine.brand
batch = vaccination_record.batch.name
"#{type} (#{brand}, #{batch})"
diff --git a/app/components/app_vaccinate_form_component.html.erb b/app/components/app_vaccinate_form_component.html.erb
index 09150be4f..1198ba22b 100644
--- a/app/components/app_vaccinate_form_component.html.erb
+++ b/app/components/app_vaccinate_form_component.html.erb
@@ -15,7 +15,7 @@
<%= f.govuk_radio_buttons_fieldset(:administered, legend: nil) do %>
<%= f.govuk_radio_button(
:administered, true,
- label: { text: t("vaccinations.form.label.#{@vaccination_record.vaccine.type}") },
+ label: { text: t("vaccinations.form.label.#{@vaccination_record.programme.type}") },
link_errors: true,
checked: @vaccination_record.persisted? && @vaccination_record.administered?,
) do %>
diff --git a/app/controllers/import_issues_controller.rb b/app/controllers/import_issues_controller.rb
index 8691a0cc0..88638034c 100644
--- a/app/controllers/import_issues_controller.rb
+++ b/app/controllers/import_issues_controller.rb
@@ -37,11 +37,11 @@ def set_import_issues
.with_pending_changes
.distinct
.includes(
- :vaccine,
:batch,
:patient_session,
session: :location,
- patient: %i[cohort school]
+ patient: %i[cohort school],
+ vaccine: :programme
)
.strict_loading
end
diff --git a/app/controllers/vaccination_records_controller.rb b/app/controllers/vaccination_records_controller.rb
index 81e7cf31e..ddb661fff 100644
--- a/app/controllers/vaccination_records_controller.rb
+++ b/app/controllers/vaccination_records_controller.rb
@@ -41,9 +41,9 @@ def vaccination_records
:immunisation_imports,
:performed_by_user,
:programme,
- :vaccine,
patient: [:cohort, :school, { parent_relationships: :parent }],
- session: %i[dates location]
+ session: %i[dates location],
+ vaccine: :programme
)
.where(programme:)
.order(:recorded_at)
diff --git a/app/helpers/vaccines_helper.rb b/app/helpers/vaccines_helper.rb
index 640987e93..107547959 100644
--- a/app/helpers/vaccines_helper.rb
+++ b/app/helpers/vaccines_helper.rb
@@ -2,6 +2,6 @@
module VaccinesHelper
def vaccine_heading(vaccine)
- sprintf("%s (%s)", vaccine.brand, t(vaccine.type, scope: "vaccines"))
+ "#{vaccine.brand} (#{vaccine.programme.name})"
end
end
diff --git a/app/models/dps_export.rb b/app/models/dps_export.rb
index af32ab665..139ed372e 100644
--- a/app/models/dps_export.rb
+++ b/app/models/dps_export.rb
@@ -41,7 +41,7 @@ def csv
:performed_by_user,
:session,
:team,
- :vaccine
+ vaccine: :programme
)
.order(:recorded_at)
.strict_loading
diff --git a/app/models/immunisation_import_row.rb b/app/models/immunisation_import_row.rb
index 6665e4be3..a7e54afac 100644
--- a/app/models/immunisation_import_row.rb
+++ b/app/models/immunisation_import_row.rb
@@ -358,11 +358,11 @@ def maximum_dose_sequence
end
def requires_care_setting?
- vaccine&.hpv?
+ @programme.hpv?
end
def requires_performed_by?
- vaccine&.flu?
+ administered && @programme.flu?
end
def parse_date(key)
diff --git a/app/models/vaccine.rb b/app/models/vaccine.rb
index a8e8a9809..1f72a01d7 100644
--- a/app/models/vaccine.rb
+++ b/app/models/vaccine.rb
@@ -14,7 +14,6 @@
# nivs_name :text not null
# snomed_product_code :string not null
# snomed_product_term :string not null
-# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# programme_id :bigint not null
@@ -51,18 +50,17 @@ class Vaccine < ApplicationRecord
validates :snomed_product_term, presence: true, uniqueness: true
enum :method, %i[injection nasal], validate: true
- enum :type, { flu: "flu", hpv: "hpv" }, validate: true
scope :active, -> { where(discontinued: false) }
delegate :first_health_question, to: :health_questions
def contains_gelatine?
- flu? && nasal?
+ programme.flu? && nasal?
end
def common_delivery_sites
- if hpv?
+ if programme.hpv?
%w[left_arm_upper_position right_arm_upper_position]
else
raise NotImplementedError,
@@ -71,10 +69,12 @@ def common_delivery_sites
end
def maximum_dose_sequence
- { "flu" => 1, "hpv" => 3 }.fetch(type)
+ { "flu" => 1, "hpv" => 3 }.fetch(programme.type)
end
- alias_method :seasonal?, :flu?
+ def seasonal?
+ programme.flu?
+ end
AVAILABLE_DELIVERY_SITES_BY_METHOD = {
"injection" =>
@@ -93,7 +93,7 @@ def available_delivery_sites
}.freeze
def available_delivery_methods
- AVAILABLE_DELIVERY_METHODS_BY_TYPE.fetch(type)
+ AVAILABLE_DELIVERY_METHODS_BY_TYPE.fetch(programme.type)
end
SNOMED_PROCEDURE_CODE_AND_TERM_BY_TYPE = {
@@ -105,6 +105,6 @@ def available_delivery_methods
}.freeze
def snomed_procedure_code_and_term
- SNOMED_PROCEDURE_CODE_AND_TERM_BY_TYPE.fetch(type)
+ SNOMED_PROCEDURE_CODE_AND_TERM_BY_TYPE.fetch(programme.type)
end
end
diff --git a/app/views/vaccines/show.html.erb b/app/views/vaccines/show.html.erb
index 05364262c..4690c3791 100644
--- a/app/views/vaccines/show.html.erb
+++ b/app/views/vaccines/show.html.erb
@@ -23,7 +23,7 @@
Vaccine
- <%= t("vaccines.#{@vaccine.type}") %>
+ <%= @vaccine.programme.name %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8942f3e91..5578af396 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -652,8 +652,6 @@ en:
given: Vaccination recorded for
not_given: Record updated for
vaccines:
- flu: Flu
- hpv: HPV
index:
title: Vaccines
wicked:
diff --git a/db/migrate/20240927142305_remove_type_from_vaccines.rb b/db/migrate/20240927142305_remove_type_from_vaccines.rb
new file mode 100644
index 000000000..8b26ed96e
--- /dev/null
+++ b/db/migrate/20240927142305_remove_type_from_vaccines.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class RemoveTypeFromVaccines < ActiveRecord::Migration[7.2]
+ def change
+ remove_column :vaccines, :type, :string, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index b14d47a88..f0bdcc26c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.2].define(version: 2024_09_27_134753) do
+ActiveRecord::Schema[7.2].define(version: 2024_09_27_142305) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -587,7 +587,6 @@
end
create_table "vaccines", force: :cascade do |t|
- t.string "type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "brand", null: false
diff --git a/erd.pdf b/erd.pdf
index 466e23d8e..310b97d17 100644
Binary files a/erd.pdf and b/erd.pdf differ
diff --git a/lib/tasks/add_health_questions.rake b/lib/tasks/add_health_questions.rake
index b524f4535..7df1565cc 100644
--- a/lib/tasks/add_health_questions.rake
+++ b/lib/tasks/add_health_questions.rake
@@ -21,7 +21,7 @@ task :add_health_questions,
team = Team.find(args[:team_id])
vaccine = team.programme.vaccines.find(args[:vaccine_id])
existing_health_questions = vaccine.health_questions.in_order
- puts "Existing health questions for #{team.name}'s #{vaccine.type} vaccine #{vaccine.brand}"
+ puts "Existing health questions for #{team.name}'s #{vaccine.programme.name} vaccine #{vaccine.brand}"
if existing_health_questions.any?
existing_health_questions.each do |health_question|
puts Rainbow(" #{health_question.title}").yellow
@@ -60,7 +60,7 @@ task :add_health_questions,
next
end
- puts "\nThese will be the health questions for #{team.name}'s #{vaccine.type} vaccine #{vaccine.brand}:"
+ puts "\nThese will be the health questions for #{team.name}'s #{vaccine.programme.name} vaccine #{vaccine.brand}:"
unless replace
existing_health_questions.each do |health_question|
puts Rainbow(" [old] #{health_question.title}").black
diff --git a/lib/tasks/vaccines.rake b/lib/tasks/vaccines.rake
index b19f8c507..9e1114eb9 100644
--- a/lib/tasks/vaccines.rake
+++ b/lib/tasks/vaccines.rake
@@ -24,12 +24,11 @@ namespace :vaccines do
vaccine.method = data["method"]
vaccine.nivs_name = data["nivs_name"]
vaccine.snomed_product_term = data["snomed_product_term"]
- vaccine.type = data["type"]
vaccine.programme = programme
vaccine.save!
- next if vaccine.flu? || vaccine.health_questions.exists?
+ next if programme.flu? || vaccine.health_questions.exists?
vaccine.health_questions.create!(
title: "Does your child have any severe allergies?",
diff --git a/spec/components/app_vaccination_record_summary_component_spec.rb b/spec/components/app_vaccination_record_summary_component_spec.rb
index d1dcd6d15..ab3d7a48e 100644
--- a/spec/components/app_vaccination_record_summary_component_spec.rb
+++ b/spec/components/app_vaccination_record_summary_component_spec.rb
@@ -116,9 +116,7 @@
end
describe "dose number row" do
- context "for HPV vaccine" do
- let(:vaccine) { create(:vaccine, :hpv) }
-
+ context "for an HPV programme" do
before { vaccination_record.dose_sequence = 2 }
it do
@@ -129,8 +127,8 @@
end
end
- context "for a seasonal vaccine (e.g. flu)" do
- let(:vaccine) { create(:vaccine, :flu) }
+ context "for a seasonal programme" do
+ let(:programme) { create(:programme, :flu) }
it do
expect(subject).not_to have_css(
diff --git a/spec/factories/programmes.rb b/spec/factories/programmes.rb
index 4edc4b56c..08cd6a346 100644
--- a/spec/factories/programmes.rb
+++ b/spec/factories/programmes.rb
@@ -18,9 +18,7 @@
transient { batch_count { 1 } }
type { %w[flu hpv].sample }
- vaccines do
- [association(:vaccine, type:, batch_count:, programme: instance)]
- end
+ vaccines { [association(:vaccine, batch_count:, programme: instance)] }
trait :hpv do
type { "hpv" }
diff --git a/spec/factories/vaccines.rb b/spec/factories/vaccines.rb
index c93da192b..c65a3ee6e 100644
--- a/spec/factories/vaccines.rb
+++ b/spec/factories/vaccines.rb
@@ -14,7 +14,6 @@
# nivs_name :text not null
# snomed_product_code :string not null
# snomed_product_term :string not null
-# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# programme_id :bigint not null
@@ -34,10 +33,12 @@
#
FactoryBot.define do
factory :vaccine do
- transient { batch_count { 1 } }
+ transient do
+ batch_count { 1 }
+ type { %w[flu hpv].sample }
+ end
- type { %w[flu hpv].sample }
- programme { Programme.find_or_create_by!(type:) }
+ programme { association :programme, type: }
brand { Faker::Commerce.product_name }
manufacturer { Faker::Company.name }
diff --git a/spec/models/health_question_spec.rb b/spec/models/health_question_spec.rb
index f2b08fc9b..56f731677 100644
--- a/spec/models/health_question_spec.rb
+++ b/spec/models/health_question_spec.rb
@@ -58,7 +58,7 @@
end
it "ignores health questions outside of the scoped collection" do
- create :health_question
+ create(:health_question, vaccine:)
hqs.first.update! next_question: hqs.second
hqs.second.update! next_question: hqs.third
@@ -78,7 +78,7 @@
end
it "ignores health questions outside of the scoped collection" do
- create :health_question
+ create(:health_question, vaccine:)
hqs.first.update! next_question: hqs.second
hqs.second.update! next_question: hqs.third
diff --git a/spec/models/vaccination_record_spec.rb b/spec/models/vaccination_record_spec.rb
index f67846c77..8c4229b6d 100644
--- a/spec/models/vaccination_record_spec.rb
+++ b/spec/models/vaccination_record_spec.rb
@@ -60,7 +60,7 @@
let(:patient_session) { create(:patient_session, programme:) }
let(:vaccine) { programme.vaccines.first }
- let(:different_vaccine) { create(:vaccine) }
+ let(:different_vaccine) { create(:vaccine, programme:) }
let(:batch) { create(:batch, vaccine: different_vaccine) }
it "has an error" do
diff --git a/spec/models/vaccine_spec.rb b/spec/models/vaccine_spec.rb
index 142505923..c9c8de27c 100644
--- a/spec/models/vaccine_spec.rb
+++ b/spec/models/vaccine_spec.rb
@@ -14,7 +14,6 @@
# nivs_name :text not null
# snomed_product_code :string not null
# snomed_product_term :string not null
-# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# programme_id :bigint not null
@@ -36,7 +35,6 @@
describe Vaccine, type: :model do
describe "validation" do
it { should validate_inclusion_of(:method).in_array(%w[injection nasal]) }
- it { should validate_inclusion_of(:type).in_array(%w[flu hpv]) }
end
describe "#contains_gelatine?" do