From c718f556c3bc9b1100880515b6c5a274680acb2a Mon Sep 17 00:00:00 2001
From: Thomas Leese
Date: Tue, 24 Sep 2024 15:23:40 +0100
Subject: [PATCH] Update following programme/session change
The relationship between programmes and sessions has been changed to a
many-to-many relationship (effectively a session can administer vaccines
for multiple programmes).
This commit updates all the code paths that relate to session and
programmes to use the new relationship in most cases, and continuing the
current assumption around sessions where it's necessary, which will be
fixed in follow up work.
---
...pp_session_summary_card_component.html.erb | 4 +-
.../app_session_summary_card_component.rb | 4 +-
.../app_vaccinate_form_component.html.erb | 2 +-
.../app_vaccinate_form_component.rb | 4 +-
app/controllers/consents_controller.rb | 8 +++-
app/controllers/dev_controller.rb | 10 ++--
app/controllers/manage_consents_controller.rb | 11 +++--
.../consent_forms/base_controller.rb | 2 +-
.../consent_forms_controller.rb | 8 +++-
app/controllers/sessions/edit_controller.rb | 2 +-
app/controllers/sessions_controller.rb | 9 ++--
app/controllers/triage_controller.rb | 4 +-
app/controllers/vaccinations_controller.rb | 4 +-
app/helpers/sessions_helper.rb | 4 --
app/lib/govuk_notify_personalisation.rb | 17 +++++--
app/mailers/application_mailer.rb | 13 +++--
app/models/consent.rb | 2 +-
app/models/immunisation_import_row.rb | 18 ++++---
app/models/patient_session.rb | 10 ++--
app/models/session.rb | 13 ++---
app/policies/consent_form_policy.rb | 6 +--
app/policies/patient_session_policy.rb | 2 +-
.../unmatched_responses.html.erb | 2 +-
app/views/consents/index.html.erb | 2 +-
app/views/manage_consents/agree.html.erb | 2 +-
.../_confirmation_agreed.html.erb | 2 +-
.../_confirmation_injection.html.erb | 2 +-
.../_confirmation_needs_triage.html.erb | 2 +-
.../_confirmation_refused.html.erb | 2 +-
.../cannot_consent_responsibility.html.erb | 6 +--
.../cannot_consent_school.html.erb | 6 +--
.../consent_forms/confirm.html.erb | 4 +-
.../consent_forms/deadline_passed.html.erb | 2 +-
.../consent_forms/edit/consent.html.erb | 6 +--
.../consent_forms/start.html.erb | 4 +-
app/views/sessions/edit.html.erb | 2 +-
app/views/sessions/index.html.erb | 47 +++++++++----------
app/views/sessions/show.html.erb | 6 +--
app/views/triage/index.html.erb | 2 +-
app/views/vaccinations/edit/confirm.html.erb | 2 +-
app/views/vaccinations/edit/reason.html.erb | 2 +-
app/views/vaccinations/index.html.erb | 2 +-
.../app_outcome_banner_component_spec.rb | 2 +-
.../app_patient_page_component_spec.rb | 2 +-
...app_session_summary_card_component_spec.rb | 2 +-
.../app_vaccinate_form_component_spec.rb | 17 +++++--
.../concerns/patient_tabs_concern_spec.rb | 35 +++++++++-----
spec/factories/example_campaigns.rb | 30 +++++++++++-
spec/factories/patient_sessions.rb | 34 +++++++-------
spec/factories/patients.rb | 2 +-
spec/factories/sessions.rb | 4 +-
spec/features/e2e_journey_spec.rb | 2 +-
spec/features/parental_consent_spec.rb | 2 +-
.../features/triage_delay_vaccination_spec.rb | 7 ++-
...sent_given_when_previously_refused_spec.rb | 18 +++++--
spec/helpers/sessions_helper_spec.rb | 12 -----
spec/jobs/consent_reminders_job_spec.rb | 15 +++---
spec/lib/govuk_notify_personalisation_spec.rb | 1 +
spec/mailers/consent_mailer_spec.rb | 5 +-
spec/mailers/session_mailer_spec.rb | 5 +-
spec/models/consent_form_spec.rb | 10 ++--
spec/models/dps_export_row_spec.rb | 4 +-
spec/models/session_stats_spec.rb | 34 ++++++++++----
spec/models/vaccination_record_spec.rb | 12 +++--
spec/policies/patient_session_policy_spec.rb | 21 +++++----
65 files changed, 317 insertions(+), 221 deletions(-)
diff --git a/app/components/app_session_summary_card_component.html.erb b/app/components/app_session_summary_card_component.html.erb
index 6fe0ebe24..5de6239fd 100644
--- a/app/components/app_session_summary_card_component.html.erb
+++ b/app/components/app_session_summary_card_component.html.erb
@@ -7,8 +7,8 @@
end
summary_list.with_row do |row|
- row.with_key { "Vaccine" }
- row.with_value { vaccine }
+ row.with_key { "Vaccines" }
+ row.with_value { vaccines }
end
summary_list.with_row do |row|
diff --git a/app/components/app_session_summary_card_component.rb b/app/components/app_session_summary_card_component.rb
index 6e2672d3a..682557214 100644
--- a/app/components/app_session_summary_card_component.rb
+++ b/app/components/app_session_summary_card_component.rb
@@ -11,8 +11,8 @@ def school
helpers.session_location(@session)
end
- def vaccine
- @session.programme.name
+ def vaccines
+ @session.programmes.map(&:name)
end
def date
diff --git a/app/components/app_vaccinate_form_component.html.erb b/app/components/app_vaccinate_form_component.html.erb
index de26ff798..09150be4f 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.downcase}") },
+ label: { text: t("vaccinations.form.label.#{@vaccination_record.vaccine.type}") },
link_errors: true,
checked: @vaccination_record.persisted? && @vaccination_record.administered?,
) do %>
diff --git a/app/components/app_vaccinate_form_component.rb b/app/components/app_vaccinate_form_component.rb
index 6e839a799..cdc816f42 100644
--- a/app/components/app_vaccinate_form_component.rb
+++ b/app/components/app_vaccinate_form_component.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class AppVaccinateFormComponent < ViewComponent::Base
- def initialize(patient_session:, section:, tab:, vaccination_record: nil)
+ def initialize(patient_session:, section:, tab:, vaccination_record:)
super
@patient_session = patient_session
@@ -35,7 +35,7 @@ def session
end
def programme_name
- @patient_session.programme.name
+ @vaccination_record.programme.name
end
def vaccine
diff --git a/app/controllers/consents_controller.rb b/app/controllers/consents_controller.rb
index f60925126..53a89ea48 100644
--- a/app/controllers/consents_controller.rb
+++ b/app/controllers/consents_controller.rb
@@ -13,7 +13,7 @@ def index
.active
.strict_loading
.includes(
- :programme,
+ :programmes,
:gillick_assessment,
{ consents: :parent },
:patient,
@@ -48,7 +48,11 @@ def index
end
def show
- @consent = @session.programme.consents.recorded.find(params[:consent_id])
+ @consent =
+ Consent
+ .where(programme: @session.programmes)
+ .recorded
+ .find(params[:consent_id])
end
private
diff --git a/app/controllers/dev_controller.rb b/app/controllers/dev_controller.rb
index ea3b5df2e..fcdc1c540 100644
--- a/app/controllers/dev_controller.rb
+++ b/app/controllers/dev_controller.rb
@@ -19,14 +19,10 @@ def reset
def random_consent_form
Faker::Config.locale = "en-GB"
@session = Session.find(params.fetch(:session_id))
- @vaccine = @session.programme.vaccines.first
+ programme = @session.programmes.first
+ @vaccine = programme.vaccines.first
@consent_form =
- FactoryBot.build(
- :consent_form,
- :draft,
- programme: @session.programme,
- session: @session
- )
+ FactoryBot.build(:consent_form, :draft, programme:, session: @session)
@consent_form.health_answers = @vaccine.health_questions.to_health_answers
@consent_form.save!
@consent_form.each_health_answer do |health_answer|
diff --git a/app/controllers/manage_consents_controller.rb b/app/controllers/manage_consents_controller.rb
index f1a088dcc..0dd8aaa97 100644
--- a/app/controllers/manage_consents_controller.rb
+++ b/app/controllers/manage_consents_controller.rb
@@ -31,7 +31,7 @@ class ManageConsentsController < ApplicationController
if: -> { wizard_value(step).present? }
def create
- @consent = Consent.create! create_params
+ @consent = Consent.create!(create_params)
set_steps # The wizard_steps can change after certain attrs change
setup_wizard_translated # Next/previous steps can change after steps change
@@ -157,8 +157,11 @@ def handle_agree
response_was_given = @consent.response_given?
@consent.assign_attributes(update_params)
+ programme = @session.programmes.first # TODO: handle multiple programmes
+
if !response_was_given && @consent.response_given?
- @consent.health_answers = @session.health_questions.to_health_answers
+ @consent.health_answers =
+ programme.vaccines.first.health_questions.to_health_answers
@consent.reason_for_refusal = nil
elsif response_was_given && !@consent.response_given?
@consent.health_answers = []
@@ -227,7 +230,7 @@ def set_patient_session
def set_triage
@triage =
Triage.find_or_initialize_by(
- programme: @session.programme,
+ programme: @session.programmes.first, # TODO: handle multiple programmes
patient_session: @patient_session
)
end
@@ -235,7 +238,7 @@ def set_triage
def create_params
{
patient: @patient,
- programme: @session.programme,
+ programme: @session.programmes.first, # TODO: handle multiple programmes
recorded_by: current_user
}.tap do |attrs|
attrs[:route] = :self_consent if @patient_session.gillick_competent?
diff --git a/app/controllers/parent_interface/consent_forms/base_controller.rb b/app/controllers/parent_interface/consent_forms/base_controller.rb
index f8932df77..5b4dd37b0 100644
--- a/app/controllers/parent_interface/consent_forms/base_controller.rb
+++ b/app/controllers/parent_interface/consent_forms/base_controller.rb
@@ -39,7 +39,7 @@ def set_secondary_navigation
end
def set_privacy_policy_url
- @privacy_policy_url = @session.programme.team.privacy_policy_url
+ @privacy_policy_url = @session.team.privacy_policy_url
end
end
end
diff --git a/app/controllers/parent_interface/consent_forms_controller.rb b/app/controllers/parent_interface/consent_forms_controller.rb
index bc3fa6c12..10b6bfe63 100644
--- a/app/controllers/parent_interface/consent_forms_controller.rb
+++ b/app/controllers/parent_interface/consent_forms_controller.rb
@@ -12,11 +12,15 @@ class ConsentFormsController < ConsentForms::BaseController
before_action :check_if_past_deadline, except: %i[deadline_passed]
def start
+ # TODO: handle multiple programmes
+ @programme = @session.programmes.first
end
def create
- consent_form =
- @session.consent_forms.create!(programme: @session.programme)
+ # TODO: handle multiple programmes
+ programme = @session.programmes.first
+
+ consent_form = @session.consent_forms.create!(programme:)
session[:consent_form_id] = consent_form.id
diff --git a/app/controllers/sessions/edit_controller.rb b/app/controllers/sessions/edit_controller.rb
index 60bae0b79..16a79df1b 100644
--- a/app/controllers/sessions/edit_controller.rb
+++ b/app/controllers/sessions/edit_controller.rb
@@ -112,7 +112,7 @@ def set_patients
Session
.joins(:patient_sessions)
.active
- .where(programme: @session.programme)
+ .where(team: @session.team)
.where("patient_sessions.patient_id = patients.id")
.arel
.exists
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 6c21f069f..ca0637270 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -6,17 +6,16 @@ class SessionsController < ApplicationController
def create
skip_policy_scope
- programme = current_user.team.programmes.first
+ team = current_user.team
@session =
- Session.create!(active: false, team: current_user.team, programme:)
+ Session.create!(active: false, team:, programmes: team.programmes)
redirect_to session_edit_path(@session, :location)
end
def index
- @sessions_by_type =
- policy_scope(Session).active.in_progress.group_by(&:type)
+ @sessions = policy_scope(Session).active.in_progress
render layout: "full"
end
@@ -24,7 +23,7 @@ def index
def show
@patient_sessions =
@session.patient_sessions.strict_loading.includes(
- :programme,
+ :programmes,
:gillick_assessment,
{ consents: :parent },
:triage,
diff --git a/app/controllers/triage_controller.rb b/app/controllers/triage_controller.rb
index 578002699..69ff1c119 100644
--- a/app/controllers/triage_controller.rb
+++ b/app/controllers/triage_controller.rb
@@ -20,7 +20,7 @@ def index
.active
.strict_loading
.includes(
- :programme,
+ :programmes,
:gillick_assessment,
:patient,
:triage,
@@ -84,7 +84,7 @@ def set_patient_session
def set_triage
@triage =
Triage.new(
- programme: @session.programme,
+ programme: @session.programmes.first, # TODO: handle multiple programmes
patient_session: @patient_session
)
end
diff --git a/app/controllers/vaccinations_controller.rb b/app/controllers/vaccinations_controller.rb
index 6c0b78ef1..b90c23ed4 100644
--- a/app/controllers/vaccinations_controller.rb
+++ b/app/controllers/vaccinations_controller.rb
@@ -22,7 +22,7 @@ def index
.active
.strict_loading
.includes(
- :programme,
+ :programmes,
:gillick_assessment,
:patient,
:triage,
@@ -161,7 +161,7 @@ def set_todays_batch
end
def set_batches
- @batches = @session.programme.batches.order(expiry: :asc, name: :asc)
+ @batches = @session.batches.order(expiry: :asc, name: :asc)
end
def set_section_and_tab
diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb
index 94853cf7a..4c60642c0 100644
--- a/app/helpers/sessions_helper.rb
+++ b/app/helpers/sessions_helper.rb
@@ -8,8 +8,4 @@ def session_location(session, part_of_sentence: false)
part_of_sentence ? "unknown location" : "Unknown location"
end
end
-
- def session_name(session)
- "#{session.programme.name} session at #{session_location(session, part_of_sentence: true)}"
- end
end
diff --git a/app/lib/govuk_notify_personalisation.rb b/app/lib/govuk_notify_personalisation.rb
index ce76f56f6..e616b7126 100644
--- a/app/lib/govuk_notify_personalisation.rb
+++ b/app/lib/govuk_notify_personalisation.rb
@@ -9,6 +9,7 @@ def initialize(
parent: nil,
patient: nil,
patient_session: nil,
+ programme: nil,
session: nil,
vaccination_record: nil
)
@@ -18,7 +19,13 @@ def initialize(
@consent_form = consent_form
@parent = parent || consent&.parent
@patient = patient || consent&.patient || patient_session&.patient
+ @programme =
+ programme || vaccination_record&.programme || consent_form&.programme ||
+ consent&.programme
@session = session || consent_form&.session || patient_session&.session
+ @team =
+ programme&.team || session&.team || patient_session&.team ||
+ consent_form&.team || consent&.team || vaccination_record&.team
@vaccination_record = vaccination_record
end
@@ -61,7 +68,9 @@ def self.call(*args, **kwargs)
:consent_form,
:parent,
:patient,
+ :programme,
:session,
+ :team,
:vaccination_record
def batch_name
@@ -111,7 +120,7 @@ def parent_name
end
def programme_name
- session.programme.name
+ programme&.name
end
def reason_did_not_vaccinate
@@ -168,15 +177,15 @@ def survey_deadline_date
end
def team_email
- session.programme.team.email
+ team.email
end
def team_name
- session.programme.team.name
+ team.name
end
def team_phone
- session.programme.team.phone
+ team.phone
end
def today_or_date_of_vaccination
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 070f0d4a1..a99d1ac97 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -36,6 +36,10 @@ def parent
@parent ||= params[:parent]
end
+ def programme
+ @programme ||= params[:programme]
+ end
+
def session
@session ||= params[:session]
end
@@ -45,11 +49,11 @@ def to
end
def reply_to_id
- programme =
- session&.programme || consent&.programme ||
- consent_form&.session&.programme || patient_session&.programme
+ team =
+ programme&.team || session&.team || patient_session&.team ||
+ consent_form&.team || consent&.team || vaccination_record&.team
- programme.team.reply_to_id
+ team.reply_to_id
end
def personalisation
@@ -59,6 +63,7 @@ def personalisation
parent:,
patient:,
patient_session:,
+ programme:,
session:,
vaccination_record:
)
diff --git a/app/models/consent.rb b/app/models/consent.rb
index 6e0e7bc68..927cdd13d 100644
--- a/app/models/consent.rb
+++ b/app/models/consent.rb
@@ -58,7 +58,7 @@ class Consent < ApplicationRecord
optional: true,
foreign_key: :recorded_by_user_id
- scope :submitted_for_programme, ->(programme) { recorded.where(programme:) }
+ has_one :team, through: :programme
enum :response, %w[given refused not_provided], prefix: true
enum :reason_for_refusal,
diff --git a/app/models/immunisation_import_row.rb b/app/models/immunisation_import_row.rb
index dbe36c89c..8bd93c07e 100644
--- a/app/models/immunisation_import_row.rb
+++ b/app/models/immunisation_import_row.rb
@@ -118,13 +118,17 @@ def session
return unless valid?
@session ||=
- Session.create_with(active: false).find_or_create_by!(
- team:,
- programme: @programme,
- date: session_date,
- location:,
- time_of_day: :all_day
- )
+ Session
+ .create_with(active: false)
+ .find_or_create_by!(
+ team:,
+ date: session_date,
+ location:,
+ time_of_day: :all_day
+ )
+ .tap do
+ _1.programmes << @programme unless _1.programmes.include?(@programme)
+ end
end
def patient_session
diff --git a/app/models/patient_session.rb b/app/models/patient_session.rb
index 636f3823d..9e2d605a5 100644
--- a/app/models/patient_session.rb
+++ b/app/models/patient_session.rb
@@ -45,11 +45,13 @@ class PatientSession < ApplicationRecord
class_name: "GillickAssessment"
has_one :team, through: :session
+ has_many :programmes, through: :session
+
has_many :triage, -> { order(:updated_at) }
has_many :vaccination_records
has_many :consents,
->(patient_session) do
- submitted_for_programme(patient_session.programme).includes(
+ recorded.where(programme: patient_session.programmes).includes(
:parent
)
end,
@@ -69,10 +71,12 @@ def draft_vaccination_record
# HACK: this code will need to be revisited in future as it only really works for HPV, where we only have one
# vaccine. It is likely to fail for the Doubles programme as that has 2 vaccines. It is also likely to fail for
# the flu programme for the SAIS teams that offer both nasal and injectable vaccines.
- vaccine = programme&.vaccines&.first
+
+ programme = programmes.first
+
vaccination_records
.draft
- .create_with(programme:, vaccine:)
+ .create_with(programme:, vaccine: programme.vaccines.first)
.find_or_initialize_by(recorded_at: nil)
end
diff --git a/app/models/session.rb b/app/models/session.rb
index c5a8e1af4..f2332a621 100644
--- a/app/models/session.rb
+++ b/app/models/session.rb
@@ -41,11 +41,14 @@ class Session < ApplicationRecord
has_many :consent_forms
has_many :patient_sessions
- has_many :patients, through: :patient_sessions
has_and_belongs_to_many :immunisation_imports
has_and_belongs_to_many :programmes
+ has_many :patients, through: :patient_sessions
+ has_many :vaccines, through: :programmes
+ has_many :batches, through: :vaccines
+
enum :time_of_day, %w[morning afternoon all_day], validate: { if: :active? }
scope :past, -> { where(date: ..Time.zone.yesterday) }
@@ -98,14 +101,6 @@ class Session < ApplicationRecord
if: -> { close_consent_on == "custom" }
end
- def health_questions
- programme.vaccines.first.health_questions
- end
-
- def type
- programme.name
- end
-
def in_progress?
date.to_date == Time.zone.today
end
diff --git a/app/policies/consent_form_policy.rb b/app/policies/consent_form_policy.rb
index 4575f0d5c..71e8ddc5a 100644
--- a/app/policies/consent_form_policy.rb
+++ b/app/policies/consent_form_policy.rb
@@ -8,11 +8,7 @@ def initialize(user, scope)
end
def resolve
- @scope.joins(session: :programme).where(
- programme: {
- team_id: @user.teams.ids
- }
- )
+ @scope.joins(:programme).where(programme: { team_id: @user.teams.ids })
end
end
end
diff --git a/app/policies/patient_session_policy.rb b/app/policies/patient_session_policy.rb
index 18f87bb76..c0156ad9c 100644
--- a/app/policies/patient_session_policy.rb
+++ b/app/policies/patient_session_policy.rb
@@ -8,7 +8,7 @@ def initialize(user, scope)
end
def resolve
- @scope.joins(:programme).where(programme: { team_id: @user.teams.ids })
+ @scope.joins(:session).where(session: { team_id: @user.teams.ids })
end
end
end
diff --git a/app/views/consent_forms/unmatched_responses.html.erb b/app/views/consent_forms/unmatched_responses.html.erb
index b8e7560e5..e465b9812 100644
--- a/app/views/consent_forms/unmatched_responses.html.erb
+++ b/app/views/consent_forms/unmatched_responses.html.erb
@@ -3,7 +3,7 @@
<% content_for :before_main do %>
<%= render AppBreadcrumbComponent.new(items: [
- { text: session_name(@session), href: session_path(@session) },
+ { text: session_location(@session), href: session_path(@session) },
{ text: "Check consent responses", href: session_consents_path(@session) },
{ text: page_title },
]) %>
diff --git a/app/views/consents/index.html.erb b/app/views/consents/index.html.erb
index a254add03..4f8c870fe 100644
--- a/app/views/consents/index.html.erb
+++ b/app/views/consents/index.html.erb
@@ -4,7 +4,7 @@
<%= render AppBreadcrumbComponent.new(items: [
{ text: "Home", href: dashboard_path },
{ text: t("sessions.index.title"), href: sessions_path },
- { text: session_name(@session), href: session_path(@session) },
+ { text: session_location(@session), href: session_path(@session) },
]) %>
<% end %>
diff --git a/app/views/manage_consents/agree.html.erb b/app/views/manage_consents/agree.html.erb
index 7208b950e..4605d17e8 100644
--- a/app/views/manage_consents/agree.html.erb
+++ b/app/views/manage_consents/agree.html.erb
@@ -5,7 +5,7 @@
) %>
<% end %>
-<% title = t("consents.edit_consent.title.#{@session.type.downcase}") %>
+<% title = t("consents.edit_consent.title.#{@consent.programme.type}") %>
<% content_for :page_title, title %>
<%= form_with model: @consent, url: form_path_for(@consent), method: form_method_for(@consent) do |f| %>
diff --git a/app/views/parent_interface/consent_forms/_confirmation_agreed.html.erb b/app/views/parent_interface/consent_forms/_confirmation_agreed.html.erb
index 1514d37ad..8156bf54c 100644
--- a/app/views/parent_interface/consent_forms/_confirmation_agreed.html.erb
+++ b/app/views/parent_interface/consent_forms/_confirmation_agreed.html.erb
@@ -1,4 +1,4 @@
-<% title = t("consent_forms.confirmation_agreed.title.#{@session.type.downcase}",
+<% title = t("consent_forms.confirmation_agreed.title.#{@consent_form.programme.type}",
full_name: @consent_form.full_name,
date: @session.date.to_fs(:long)) %>
<% content_for :page_title, title %>
diff --git a/app/views/parent_interface/consent_forms/_confirmation_injection.html.erb b/app/views/parent_interface/consent_forms/_confirmation_injection.html.erb
index 4b64bc1b6..3d58f78e9 100644
--- a/app/views/parent_interface/consent_forms/_confirmation_injection.html.erb
+++ b/app/views/parent_interface/consent_forms/_confirmation_injection.html.erb
@@ -1,3 +1,3 @@
-<%= h1 t("consent_forms.confirmation_injection.title.#{@session.type.downcase}") %>
+<%= h1 t("consent_forms.confirmation_injection.title.#{@consent_form.programme.type}") %>
Someone will be in touch to discuss them having an injection instead.
diff --git a/app/views/parent_interface/consent_forms/_confirmation_needs_triage.html.erb b/app/views/parent_interface/consent_forms/_confirmation_needs_triage.html.erb
index e5614df95..ff6e2403a 100644
--- a/app/views/parent_interface/consent_forms/_confirmation_needs_triage.html.erb
+++ b/app/views/parent_interface/consent_forms/_confirmation_needs_triage.html.erb
@@ -1,4 +1,4 @@
-<%= h1 t("consent_forms.confirmation_needs_triage.title.#{@session.type.downcase}") %>
+<%= h1 t("consent_forms.confirmation_needs_triage.title.#{@consent_form.programme.type}") %>
As you answered ‘yes’ to some of the health questions, we need to check the
diff --git a/app/views/parent_interface/consent_forms/_confirmation_refused.html.erb b/app/views/parent_interface/consent_forms/_confirmation_refused.html.erb
index aca8a1e0c..f5433fa0c 100644
--- a/app/views/parent_interface/consent_forms/_confirmation_refused.html.erb
+++ b/app/views/parent_interface/consent_forms/_confirmation_refused.html.erb
@@ -1 +1 @@
-<%= h1 t("consent_forms.confirmation_refused.title.#{@session.type.downcase}") %>
+<%= h1 t("consent_forms.confirmation_refused.title.#{@consent_form.programme.type}") %>
diff --git a/app/views/parent_interface/consent_forms/cannot_consent_responsibility.html.erb b/app/views/parent_interface/consent_forms/cannot_consent_responsibility.html.erb
index b0234e792..764e382a7 100644
--- a/app/views/parent_interface/consent_forms/cannot_consent_responsibility.html.erb
+++ b/app/views/parent_interface/consent_forms/cannot_consent_responsibility.html.erb
@@ -13,7 +13,7 @@
If you have any questions, please contact the local health team by calling
- <%= @session.programme.team.phone %>, or email
-
- <%= @session.programme.team.email %>.
+ <%= @session.team.phone %>, or email
+
+ <%= @session.team.email %>.
diff --git a/app/views/parent_interface/consent_forms/cannot_consent_school.html.erb b/app/views/parent_interface/consent_forms/cannot_consent_school.html.erb
index 019aaf2da..deff2917b 100644
--- a/app/views/parent_interface/consent_forms/cannot_consent_school.html.erb
+++ b/app/views/parent_interface/consent_forms/cannot_consent_school.html.erb
@@ -12,7 +12,7 @@ parents whose children attend participating schools.
- Contact <% govuk_link_to @session.programme.team.email, "mailto:#{@session.programme.team.email}" %> to book a clinic appointment.
+ Contact <% govuk_link_to @session.team.email, "mailto:#{@session.team.email}" %> to book a clinic appointment.
diff --git a/app/views/parent_interface/consent_forms/edit/consent.html.erb b/app/views/parent_interface/consent_forms/edit/consent.html.erb
index a0e7806a2..8be41f720 100644
--- a/app/views/parent_interface/consent_forms/edit/consent.html.erb
+++ b/app/views/parent_interface/consent_forms/edit/consent.html.erb
@@ -5,7 +5,7 @@
) %>
<% end %>
-<% title = t("consent_forms.consent.title.#{@session.type.downcase}") %>
+<% title = t("consent_forms.consent.title.#{@consent_form.programme.type}") %>
<% content_for :page_title, title %>
<%= form_with model: @consent_form, url: wizard_path, method: :put do |f| %>
@@ -13,9 +13,9 @@
<%= f.govuk_radio_buttons_fieldset(:response,
legend: { size: "l", text: title, tag: "h1" },
- hint: { text: t("consent_forms.consent.hint.#{@session.type.downcase}") }) do %>
+ hint: { text: t("consent_forms.consent.hint.#{@consent_form.programme.type}") }) do %>
<%= f.govuk_radio_button :response, "given",
- label: { text: t("consent_forms.consent.i_agree.#{@session.type.downcase}") },
+ label: { text: t("consent_forms.consent.i_agree.#{@consent_form.programme.type}") },
link_errors: true %>
<%= f.govuk_radio_button :response, "refused",
label: { text: "No" } %>
diff --git a/app/views/parent_interface/consent_forms/start.html.erb b/app/views/parent_interface/consent_forms/start.html.erb
index ea6fd7b93..00a250c8b 100644
--- a/app/views/parent_interface/consent_forms/start.html.erb
+++ b/app/views/parent_interface/consent_forms/start.html.erb
@@ -1,6 +1,6 @@
-<%= h1 t("consent_forms.start.title.#{@session.type.downcase}") %>
+<%= h1 t("consent_forms.start.title.#{@programme.type}") %>
-<% t("consent_forms.start.paragraphs.#{@session.type.downcase}").each do |paragraph| %>
+<% t("consent_forms.start.paragraphs.#{@programme.type}").each do |paragraph| %>
There are no sessions scheduled for today.
-<% end %>
-
-<% @sessions_by_type.each do |programme_type, sessions| %>
+<% else %>
-
<%= programme_type %>
+
<%= pluralize(@sessions.count, "sessions") %>
+
<%= govuk_table(html_attributes: { class: "nhsuk-table-responsive" }) do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
@@ -20,26 +19,24 @@
<% end %>
<% table.with_body do |body| %>
- <% @sessions_by_type.each do |programme_type, sessions| %>
- <% sessions.each do |session| %>
- <% body.with_row do |row| %>
- <% row.with_cell do %>
-
Time
- <%= session.time_of_day.humanize %>
- <% end %>
- <% row.with_cell do %>
-
Location
-
- <%= link_to session_location(session), session_path(session) %>
- <% if (location = session.location)&.has_address? %>
-
<%= format_address_single_line(location) %>
- <% end %>
-
- <% end %>
- <% row.with_cell do %>
-
Cohort
- <%= session.patients.count %>
- <% end %>
+ <% @sessions.each do |session| %>
+ <% body.with_row do |row| %>
+ <% row.with_cell do %>
+
Time
+ <%= session.time_of_day.humanize %>
+ <% end %>
+ <% row.with_cell do %>
+
Location
+
+ <%= link_to session_location(session), session_path(session) %>
+ <% if (location = session.location)&.has_address? %>
+
<%= format_address_single_line(location) %>
+ <% end %>
+
+ <% end %>
+ <% row.with_cell do %>
+
Cohort
+ <%= session.patients.count %>
<% end %>
<% end %>
<% end %>
diff --git a/app/views/sessions/show.html.erb b/app/views/sessions/show.html.erb
index 67185dac3..34909b767 100644
--- a/app/views/sessions/show.html.erb
+++ b/app/views/sessions/show.html.erb
@@ -1,10 +1,10 @@
-<% page_title = session_name(@session) %>
+<% page_title = session_location(@session) %>
<% content_for :before_main do %>
<%= render AppBreadcrumbComponent.new(items: [
{ text: "Home", href: dashboard_path },
- { text: t("programmes.index.title"), href: programmes_path },
- { text: @session.programme.name, href: programme_path(@session.programme) },
+ { text: t("sessions.index.title"), href: sessions_path },
+ { text: session_location(@session), href: session_path(@session) },
]) %>
<% end %>
diff --git a/app/views/triage/index.html.erb b/app/views/triage/index.html.erb
index b4faaf3cc..2a3e8df4f 100644
--- a/app/views/triage/index.html.erb
+++ b/app/views/triage/index.html.erb
@@ -4,7 +4,7 @@
<%= render AppBreadcrumbComponent.new(items: [
{ text: "Home", href: dashboard_path },
{ text: t("sessions.index.title"), href: sessions_path },
- { text: session_name(@session), href: session_path(@session) },
+ { text: session_location(@session), href: session_path(@session) },
]) %>
<% end %>
diff --git a/app/views/vaccinations/edit/confirm.html.erb b/app/views/vaccinations/edit/confirm.html.erb
index 17b32be58..0e77e5035 100644
--- a/app/views/vaccinations/edit/confirm.html.erb
+++ b/app/views/vaccinations/edit/confirm.html.erb
@@ -22,7 +22,7 @@
if @draft_vaccination_record.administered?
summary_list.with_row do |row|
row.with_key { "Vaccine" }
- row.with_value { @session.type }
+ row.with_value { @draft_vaccination_record.programme.name }
end
summary_list.with_row do |row|
diff --git a/app/views/vaccinations/edit/reason.html.erb b/app/views/vaccinations/edit/reason.html.erb
index 2d6fa417f..dfa0b329d 100644
--- a/app/views/vaccinations/edit/reason.html.erb
+++ b/app/views/vaccinations/edit/reason.html.erb
@@ -5,7 +5,7 @@
) %>
<% end %>
-<% title = t("vaccinations.reason.title.#{@session.type.downcase}") %>
+<% title = t("vaccinations.reason.title.#{@draft_vaccination_record.programme.type}") %>
<% content_for :page_title, title %>
<%= form_with model: @draft_vaccination_record,
diff --git a/app/views/vaccinations/index.html.erb b/app/views/vaccinations/index.html.erb
index 6ccf76dc9..db57c0d8b 100644
--- a/app/views/vaccinations/index.html.erb
+++ b/app/views/vaccinations/index.html.erb
@@ -3,7 +3,7 @@
items: [
{ text: "Home", href: dashboard_path },
{ text: t("sessions.index.title"), href: sessions_path },
- { text: session_name(@session), href: session_path(@session) },
+ { text: session_location(@session), href: session_path(@session) },
],
) %>
<% end %>
diff --git a/spec/components/app_outcome_banner_component_spec.rb b/spec/components/app_outcome_banner_component_spec.rb
index 6d834a1f1..e2a78c2f1 100644
--- a/spec/components/app_outcome_banner_component_spec.rb
+++ b/spec/components/app_outcome_banner_component_spec.rb
@@ -33,7 +33,7 @@
create(:patient_session, :vaccinated, created_by: user, programme:)
end
let(:vaccination_record) { patient_session.vaccination_records.first }
- let(:vaccine) { patient_session.session.programme.vaccines.first }
+ let(:vaccine) { programme.vaccines.first }
let(:location) { patient_session.session.location }
let(:batch) { vaccine.batches.first }
let(:date) { vaccination_record.recorded_at.to_date.to_fs(:long) }
diff --git a/spec/components/app_patient_page_component_spec.rb b/spec/components/app_patient_page_component_spec.rb
index c8ebdec21..cd1fd93bc 100644
--- a/spec/components/app_patient_page_component_spec.rb
+++ b/spec/components/app_patient_page_component_spec.rb
@@ -17,7 +17,7 @@
let(:component) do
described_class.new(
patient_session:,
- vaccination_record: VaccinationRecord.new(vaccine:),
+ vaccination_record: VaccinationRecord.new(programme:, vaccine:),
section: "triage",
tab: "needed",
triage: nil
diff --git a/spec/components/app_session_summary_card_component_spec.rb b/spec/components/app_session_summary_card_component_spec.rb
index 25e9b0d4f..55582e62b 100644
--- a/spec/components/app_session_summary_card_component_spec.rb
+++ b/spec/components/app_session_summary_card_component_spec.rb
@@ -48,7 +48,7 @@
let(:session) do
Session.new(
location: create(:location, :school),
- programme: create(:programme, :hpv),
+ programmes: [create(:programme, :hpv)],
date:,
time_of_day: "all_day"
)
diff --git a/spec/components/app_vaccinate_form_component_spec.rb b/spec/components/app_vaccinate_form_component_spec.rb
index 685ab6c06..4c6895f92 100644
--- a/spec/components/app_vaccinate_form_component_spec.rb
+++ b/spec/components/app_vaccinate_form_component_spec.rb
@@ -9,9 +9,15 @@
let(:session) { create(:session, :in_progress, programme:) }
let(:vaccine) { programme.vaccines.first }
let(:patient_session) do
- create :patient_session, :consent_given_triage_not_needed, session:
+ create(
+ :patient_session,
+ :consent_given_triage_not_needed,
+ programme:,
+ session:
+ )
end
- let(:vaccination_record) { VaccinationRecord.new(programme:, vaccine:) }
+ let(:vaccination_record) { build(:vaccination_record, programme:, vaccine:) }
+
let(:component) do
described_class.new(
patient_session:,
@@ -35,7 +41,12 @@
context "patient has unrecorded vaccination record" do
let(:patient_session) do
- create :patient_session, :consent_given_triage_not_needed, session:
+ create(
+ :patient_session,
+ :consent_given_triage_not_needed,
+ programme:,
+ session:
+ )
end
let(:vaccination_record) do
create(:vaccination_record, :not_recorded, programme:, patient_session:)
diff --git a/spec/controllers/concerns/patient_tabs_concern_spec.rb b/spec/controllers/concerns/patient_tabs_concern_spec.rb
index 75d116318..f21a27020 100644
--- a/spec/controllers/concerns/patient_tabs_concern_spec.rb
+++ b/spec/controllers/concerns/patient_tabs_concern_spec.rb
@@ -3,44 +3,55 @@
describe PatientTabsConcern do
subject { Class.new { include PatientTabsConcern }.new }
- let(:session) { create(:session) }
+ let(:programme) { create(:programme) }
+ let(:session) { create(:session, programme:) }
let(:added_to_session) do
- create(:patient_session, :added_to_session, session:)
+ create(:patient_session, :added_to_session, programme:, session:)
end
let(:consent_conflicts) do
- create(:patient_session, :consent_conflicting, session:)
+ create(:patient_session, :consent_conflicting, programme:, session:)
end
let(:consent_given_triage_not_needed) do
- create(:patient_session, :consent_given_triage_not_needed, session:)
+ create(
+ :patient_session,
+ :consent_given_triage_not_needed,
+ programme:,
+ session:
+ )
end
let(:consent_given_triage_needed) do
- create(:patient_session, :consent_given_triage_needed, session:)
+ create(:patient_session, :consent_given_triage_needed, programme:, session:)
+ end
+ let(:consent_refused) do
+ create(:patient_session, :consent_refused, programme:, session:)
end
- let(:consent_refused) { create(:patient_session, :consent_refused, session:) }
let(:delay_vaccination) do
- create(:patient_session, :delay_vaccination, session:)
+ create(:patient_session, :delay_vaccination, programme:, session:)
end
let(:triaged_do_not_vaccinate) do
- create(:patient_session, :triaged_do_not_vaccinate, session:)
+ create(:patient_session, :triaged_do_not_vaccinate, programme:, session:)
end
let(:triaged_kept_in_triage) do
- create(:patient_session, :triaged_kept_in_triage, session:)
+ create(:patient_session, :triaged_kept_in_triage, programme:, session:)
end
let(:triaged_ready_to_vaccinate) do
- create(:patient_session, :triaged_ready_to_vaccinate, session:)
+ create(:patient_session, :triaged_ready_to_vaccinate, programme:, session:)
end
let(:unable_to_vaccinate) do
- create(:patient_session, :unable_to_vaccinate, session:)
+ create(:patient_session, :unable_to_vaccinate, programme:, session:)
end
let(:unable_to_vaccinate_not_gillick_competent) do
create(
:patient_session,
:unable_to_vaccinate_not_gillick_competent,
+ programme:,
session:
)
end
- let(:vaccinated) { create(:patient_session, :vaccinated, session:) }
+ let(:vaccinated) do
+ create(:patient_session, :vaccinated, programme:, session:)
+ end
let(:patient_sessions) do
[
diff --git a/spec/factories/example_campaigns.rb b/spec/factories/example_campaigns.rb
index 76a731cda..2d93ff648 100644
--- a/spec/factories/example_campaigns.rb
+++ b/spec/factories/example_campaigns.rb
@@ -30,12 +30,19 @@
location:
).tap do |session|
patients_without_consent =
- create_list(:patient_session, 4, session:, created_by: user)
+ create_list(
+ :patient_session,
+ 4,
+ programme:,
+ session:,
+ created_by: user
+ )
unmatched_patients = patients_without_consent.sample(2).map(&:patient)
unmatched_patients.each do |patient|
create(
:consent_form,
:recorded,
+ programme:,
first_name: patient.first_name,
last_name: patient.last_name,
session:
@@ -46,6 +53,7 @@
:patient_session,
4,
:consent_given_triage_not_needed,
+ programme:,
session:,
created_by: user
)
@@ -53,6 +61,7 @@
:patient_session,
4,
:consent_given_triage_needed,
+ programme:,
session:,
created_by: user
)
@@ -60,6 +69,7 @@
:patient_session,
4,
:triaged_ready_to_vaccinate,
+ programme:,
session:,
created_by: user
)
@@ -67,6 +77,7 @@
:patient_session,
4,
:consent_refused,
+ programme:,
session:,
created_by: user
)
@@ -74,6 +85,7 @@
:patient_session,
2,
:consent_conflicting,
+ programme:,
session:,
created_by: user
)
@@ -97,6 +109,7 @@
:patient_session,
4,
:vaccinated,
+ programme:,
session:,
created_by: user
)
@@ -104,6 +117,7 @@
:patient_session,
4,
:delay_vaccination,
+ programme:,
session:,
created_by: user
)
@@ -111,6 +125,7 @@
:patient_session,
4,
:unable_to_vaccinate,
+ programme:,
session:,
created_by: user
)
@@ -131,12 +146,19 @@
location:
).tap do |session|
patients_without_consent =
- create_list(:patient_session, 16, session:, created_by: user)
+ create_list(
+ :patient_session,
+ 16,
+ programme:,
+ session:,
+ created_by: user
+ )
unmatched_patients = patients_without_consent.sample(8).map(&:patient)
unmatched_patients.each do |patient|
create(
:consent_form,
:recorded,
+ programme:,
first_name: patient.first_name,
last_name: patient.last_name,
session:
@@ -146,6 +168,7 @@
:patient_session,
8,
:consent_given_triage_not_needed,
+ programme:,
session:,
created_by: user
)
@@ -153,6 +176,7 @@
:patient_session,
8,
:consent_given_triage_needed,
+ programme:,
session:,
created_by: user
)
@@ -160,6 +184,7 @@
:patient_session,
8,
:consent_refused,
+ programme:,
session:,
created_by: user
)
@@ -167,6 +192,7 @@
:patient_session,
4,
:consent_conflicting,
+ programme:,
session:,
created_by: user
)
diff --git a/spec/factories/patient_sessions.rb b/spec/factories/patient_sessions.rb
index aa2600a95..1904f157b 100644
--- a/spec/factories/patient_sessions.rb
+++ b/spec/factories/patient_sessions.rb
@@ -47,7 +47,7 @@
patient do
association :patient,
:consent_given_triage_not_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -56,7 +56,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -65,7 +65,7 @@
patient do
association :patient,
:consent_refused,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -74,7 +74,7 @@
patient do
association :patient,
:consent_refused_with_notes,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -83,7 +83,7 @@
patient do
association :patient,
:consent_conflicting,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -92,7 +92,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -112,7 +112,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -125,7 +125,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -138,7 +138,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -151,7 +151,7 @@
association(
:vaccination_record,
:not_administered,
- programme: session.programme,
+ programme:,
patient_session: instance,
performed_by: created_by,
reason: :absent_from_school
@@ -164,7 +164,7 @@
patient do
association :patient,
:consent_given_triage_not_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
end
@@ -173,7 +173,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -186,7 +186,7 @@
association(
:vaccination_record,
:not_administered,
- programme: session.programme,
+ programme:,
patient_session: instance,
performed_by: created_by,
reason: :already_had
@@ -201,7 +201,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -214,7 +214,7 @@
association(
:vaccination_record,
:not_administered,
- programme: session.programme,
+ programme:,
patient_session: instance,
performed_by: created_by,
reason: :already_had
@@ -227,7 +227,7 @@
patient do
association :patient,
:consent_given_triage_needed,
- programme: session.programme,
+ programme:,
school: session.location
end
@@ -239,7 +239,7 @@
[
association(
:vaccination_record,
- programme: session.programme,
+ programme:,
patient_session: instance,
performed_by: created_by
)
diff --git a/spec/factories/patients.rb b/spec/factories/patients.rb
index b12ba19d1..954703a69 100644
--- a/spec/factories/patients.rb
+++ b/spec/factories/patients.rb
@@ -41,7 +41,7 @@
factory :patient do
transient do
session { nil }
- programme { session&.programme }
+ programme { session&.programmes&.first }
team { programme&.team || association(:team) }
parents { [create(:parent, :recorded, last_name:)] }
diff --git a/spec/factories/sessions.rb b/spec/factories/sessions.rb
index 4882d7e17..3c6b99406 100644
--- a/spec/factories/sessions.rb
+++ b/spec/factories/sessions.rb
@@ -26,8 +26,10 @@
#
FactoryBot.define do
factory :session do
+ transient { programme { association :programme, team: } }
+
team
- programmes { [association(:programme, team:)] }
+ programmes { [programme] }
location { association :location, :school }
date { Time.zone.today }
diff --git a/spec/features/e2e_journey_spec.rb b/spec/features/e2e_journey_spec.rb
index 6190b5266..1afd3c8da 100644
--- a/spec/features/e2e_journey_spec.rb
+++ b/spec/features/e2e_journey_spec.rb
@@ -213,7 +213,7 @@ def then_i_should_see_that_the_patient_is_ready_for_vaccination
def when_i_click_on_the_vaccination_section
click_link "Back to consents page"
- click_link "HPV session at Pilot School"
+ click_link "Pilot School"
click_link "Record vaccinations"
click_link "Vaccinate ( 1 )"
end
diff --git a/spec/features/parental_consent_spec.rb b/spec/features/parental_consent_spec.rb
index 4f6904564..9954c72e9 100644
--- a/spec/features/parental_consent_spec.rb
+++ b/spec/features/parental_consent_spec.rb
@@ -196,7 +196,7 @@ def and_they_see_the_full_consent_form
end
def when_they_check_triage
- click_link "HPV session at Pilot School"
+ click_link "Pilot School"
click_on "Triage health questions"
click_on "No triage needed"
end
diff --git a/spec/features/triage_delay_vaccination_spec.rb b/spec/features/triage_delay_vaccination_spec.rb
index 4e1a088b1..f9d9f52ca 100644
--- a/spec/features/triage_delay_vaccination_spec.rb
+++ b/spec/features/triage_delay_vaccination_spec.rb
@@ -34,7 +34,12 @@ def given_a_programme_with_a_running_session
date: Time.zone.today
)
@patient =
- create(:patient_session, :consent_given_triage_needed, session:).patient
+ create(
+ :patient_session,
+ :consent_given_triage_needed,
+ programme:,
+ session:
+ ).patient
end
def and_i_am_signed_in
diff --git a/spec/features/verbal_consent_given_when_previously_refused_spec.rb b/spec/features/verbal_consent_given_when_previously_refused_spec.rb
index 9d712626c..6eb4ea933 100644
--- a/spec/features/verbal_consent_given_when_previously_refused_spec.rb
+++ b/spec/features/verbal_consent_given_when_previously_refused_spec.rb
@@ -14,14 +14,26 @@
def given_an_hpv_programme_is_underway
@team = create(:team, :with_one_nurse)
- programme = create(:programme, :hpv, team: @team)
+ @programme = create(:programme, :hpv, team: @team)
location = create(:location, :school, name: "Pilot School")
- @session = create(:session, :in_future, team: @team, programme:, location:)
+ @session =
+ create(
+ :session,
+ :in_future,
+ team: @team,
+ programme: @programme,
+ location:
+ )
end
def and_a_parent_has_refused_consent_for_their_child
@child =
- create(:patient_session, :consent_refused, session: @session).patient
+ create(
+ :patient_session,
+ :consent_refused,
+ programme: @programme,
+ session: @session
+ ).patient
end
def and_i_am_logged_in_as_a_nurse
diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb
index 37920eed2..3c098c1f8 100644
--- a/spec/helpers/sessions_helper_spec.rb
+++ b/spec/helpers/sessions_helper_spec.rb
@@ -24,16 +24,4 @@
end
end
end
-
- describe "#session_name" do
- subject(:session_name) { helper.session_name(session) }
-
- it { should eq("Flu session at Waterloo Road") }
-
- context "when location is nil" do
- let(:location) { nil }
-
- it { should eq("Flu session at unknown location") }
- end
- end
end
diff --git a/spec/jobs/consent_reminders_job_spec.rb b/spec/jobs/consent_reminders_job_spec.rb
index c0f8bf147..41c3dd624 100644
--- a/spec/jobs/consent_reminders_job_spec.rb
+++ b/spec/jobs/consent_reminders_job_spec.rb
@@ -6,12 +6,13 @@
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
end
+ let(:programme) { create(:programme) }
+
context "with draft and active sessions" do
it "enqueues ConsentRemindersSessionBatchJob for each active sessions" do
active_session =
- create(:session, send_consent_reminders_at: Time.zone.today)
- _draft_session =
- create(:session, :draft, programme: active_session.programme)
+ create(:session, programme:, send_consent_reminders_at: Time.zone.today)
+ _draft_session = create(:session, :draft, programme:)
described_class.perform_now
expect(ConsentRemindersSessionBatchJob).to have_been_enqueued.once
@@ -24,13 +25,9 @@
context "with sessions set to send consent today and in the future" do
it "enqueues ConsentRemindersSessionBatchJob for the session set to send consent today" do
active_session =
- create(:session, send_consent_reminders_at: Time.zone.today)
+ create(:session, programme:, send_consent_reminders_at: Time.zone.today)
_later_session =
- create(
- :session,
- send_consent_reminders_at: 2.days.from_now,
- programme: active_session.programme
- )
+ create(:session, programme:, send_consent_reminders_at: 2.days.from_now)
described_class.perform_now
expect(ConsentRemindersSessionBatchJob).to have_been_enqueued.once
diff --git a/spec/lib/govuk_notify_personalisation_spec.rb b/spec/lib/govuk_notify_personalisation_spec.rb
index 5bfbbd799..a31bb3865 100644
--- a/spec/lib/govuk_notify_personalisation_spec.rb
+++ b/spec/lib/govuk_notify_personalisation_spec.rb
@@ -8,6 +8,7 @@
consent:,
consent_form:,
parent:,
+ programme:,
vaccination_record:
)
end
diff --git a/spec/mailers/consent_mailer_spec.rb b/spec/mailers/consent_mailer_spec.rb
index 102f254d8..7407b6c54 100644
--- a/spec/mailers/consent_mailer_spec.rb
+++ b/spec/mailers/consent_mailer_spec.rb
@@ -41,13 +41,14 @@
context "with a consent record" do
subject(:mail) { described_class.with(consent:, session:).give_feedback }
- let(:session) { create(:session) }
+ let(:programme) { create(:programme) }
+ let(:session) { create(:session, programme:) }
let(:consent) do
create(
:consent,
:recorded,
recorded_at: Date.new(2021, 1, 1),
- programme: session.programme
+ programme:
)
end
diff --git a/spec/mailers/session_mailer_spec.rb b/spec/mailers/session_mailer_spec.rb
index de637de58..9647cbc78 100644
--- a/spec/mailers/session_mailer_spec.rb
+++ b/spec/mailers/session_mailer_spec.rb
@@ -3,11 +3,12 @@
describe SessionMailer do
describe "#reminder" do
subject(:mail) do
- described_class.with(session:, patient:, parent:).reminder
+ described_class.with(programme:, session:, patient:, parent:).reminder
end
+ let(:programme) { create(:programme) }
let(:patient) { create(:patient, common_name: "Joey") }
- let(:session) { create(:session, patients: [patient]) }
+ let(:session) { create(:session, programme:, patients: [patient]) }
let(:parent) { patient.parents.first }
it { should have_attributes(to: [patient.parents.first.email]) }
diff --git a/spec/models/consent_form_spec.rb b/spec/models/consent_form_spec.rb
index e4f73f486..825b6ec5f 100644
--- a/spec/models/consent_form_spec.rb
+++ b/spec/models/consent_form_spec.rb
@@ -563,8 +563,9 @@
end
describe "scope unmatched" do
- let(:session) { create(:session) }
- let(:consent) { create(:consent, programme: session.programme) }
+ let(:programme) { create(:programme) }
+ let(:session) { create(:session, programme:) }
+ let(:consent) { create(:consent, programme:) }
let(:unmatched_consent_form) do
create(:consent_form, consent: nil, session:)
end
@@ -577,8 +578,9 @@
end
describe "scope recorded" do
- let(:session) { create(:session) }
- let(:consent) { create(:consent, programme: session.programme) }
+ let(:programme) { create(:programme) }
+ let(:session) { create(:session, programme:) }
+ let(:consent) { create(:consent, programme:) }
let(:recorded_consent_form) do
create(:consent_form, :recorded, consent:, session:)
end
diff --git a/spec/models/dps_export_row_spec.rb b/spec/models/dps_export_row_spec.rb
index c0faec758..ccf0e8e60 100644
--- a/spec/models/dps_export_row_spec.rb
+++ b/spec/models/dps_export_row_spec.rb
@@ -13,7 +13,7 @@
let(:patient) do
create(:patient, date_of_birth: Date.new(2012, 12, 29), school:)
end
- let(:session) { create(:session, programme:, location:) }
+ let(:session) { create(:session, team:, programme:, location:) }
let(:patient_session) { create(:patient_session, patient:, session:) }
let(:performed_by) { create(:user, family_name: "Doe", given_name: "Jane") }
let(:performed_by_given_name) { nil }
@@ -71,7 +71,7 @@
end
it "has site_code" do
- expect(array[7]).to eq vaccination_record.programme.team.ods_code
+ expect(array[7]).to eq vaccination_record.team.ods_code
end
it "has site_code_type_uri" do
diff --git a/spec/models/session_stats_spec.rb b/spec/models/session_stats_spec.rb
index 4edfbddf3..7533c70e2 100644
--- a/spec/models/session_stats_spec.rb
+++ b/spec/models/session_stats_spec.rb
@@ -6,7 +6,8 @@
described_class.new(patient_sessions: session.patient_sessions, session:)
end
- let(:session) { create :session }
+ let(:programme) { create(:programme) }
+ let(:session) { create(:session, programme:) }
it "returns a hash of session stats" do
expect(subject.to_h).to eq(
@@ -24,15 +25,30 @@
context "with patient sessions" do
before do
- create(:patient_session, :consent_refused, session:) # consent refused
- create(:patient_session, :added_to_session, session:) # without a response
- create(:patient_session, :consent_given_triage_needed, session:) # needing triage, consent given
- create(:patient_session, :triaged_kept_in_triage, session:) # needing triage, consent given
- create(:patient_session, :triaged_ready_to_vaccinate, session:) # ready to vaccinate, consent given
- create(:patient_session, :consent_given_triage_not_needed, session:) # ready to vaccinate, consent given
+ create(:patient_session, :consent_refused, programme:, session:) # consent refused
+ create(:patient_session, :added_to_session, programme:, session:) # without a response
+ create(
+ :patient_session,
+ :consent_given_triage_needed,
+ programme:,
+ session:
+ ) # needing triage, consent given
+ create(:patient_session, :triaged_kept_in_triage, programme:, session:) # needing triage, consent given
+ create(
+ :patient_session,
+ :triaged_ready_to_vaccinate,
+ programme:,
+ session:
+ ) # ready to vaccinate, consent given
+ create(
+ :patient_session,
+ :consent_given_triage_not_needed,
+ programme:,
+ session:
+ ) # ready to vaccinate, consent given
- create(:consent_form, :recorded, session:, consent_id: nil) # => unmatched response
- create(:consent_form, :draft, session:, consent_id: nil) # => still draft, should not be counted
+ create(:consent_form, :recorded, programme:, session:, consent_id: nil) # => unmatched response
+ create(:consent_form, :draft, programme:, session:, consent_id: nil) # => still draft, should not be counted
end
it "returns a hash of session stats" do
diff --git a/spec/models/vaccination_record_spec.rb b/spec/models/vaccination_record_spec.rb
index 12a727cdf..f67846c77 100644
--- a/spec/models/vaccination_record_spec.rb
+++ b/spec/models/vaccination_record_spec.rb
@@ -49,11 +49,17 @@
describe "validations" do
context "vaccine and batch doesn't match" do
subject(:vaccination_record) do
- build(:vaccination_record, vaccine:, batch:, patient_session:)
+ build(
+ :vaccination_record,
+ programme:,
+ vaccine:,
+ batch:,
+ patient_session:
+ )
end
- let(:patient_session) { create(:patient_session) }
- let(:vaccine) { patient_session.programme.vaccines.first }
+ let(:patient_session) { create(:patient_session, programme:) }
+ let(:vaccine) { programme.vaccines.first }
let(:different_vaccine) { create(:vaccine) }
let(:batch) { create(:batch, vaccine: different_vaccine) }
diff --git a/spec/policies/patient_session_policy_spec.rb b/spec/policies/patient_session_policy_spec.rb
index cf543b316..4134ab77b 100644
--- a/spec/policies/patient_session_policy_spec.rb
+++ b/spec/policies/patient_session_policy_spec.rb
@@ -1,18 +1,23 @@
# frozen_string_literal: true
describe PatientSessionPolicy do
- let(:patient_session) { create :patient_session }
- let(:another_teams_patient_session) do
- create :patient_session,
- session: create(:session, programme: create(:programme, :flu))
+ let(:team) { create(:team) }
+ let(:user) { create(:user, teams: [team]) }
+
+ let(:programme) { create(:programme, team:) }
+ let(:patient_session) do
+ create(
+ :patient_session,
+ programme:,
+ session: create(:session, team:, programme:)
+ )
end
- let(:team) { patient_session.session.programme.team }
- let(:user) { create :user, teams: [team] }
+ let(:another_teams_patient_session) { create(:patient_session) }
describe "Scope#resolve" do
subject { PatientSessionPolicy::Scope.new(user, PatientSession).resolve }
- it { should include patient_session }
- it { should_not include another_teams_patient_session }
+ it { should include(patient_session) }
+ it { should_not include(another_teams_patient_session) }
end
end