Skip to content

Commit

Permalink
Send multiple session dates to GOV.UK Notify
Browse files Browse the repository at this point in the history
This updates the GOV.UK Notify personalisation to include all the
session dates. I've already updated all the templates in GOV.UK Notify
to use these new personalisation variables.
  • Loading branch information
thomasleese committed Oct 1, 2024
1 parent 2eb84aa commit 03235b3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
43 changes: 31 additions & 12 deletions app/lib/govuk_notify_personalisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ def call
day_month_year_of_vaccination:,
full_and_preferred_patient_name:,
location_name:,
next_session_date:,
next_session_dates:,
next_session_dates_or:,
parent_name:,
programme_name:,
reason_did_not_vaccinate:,
reason_for_refusal:,
session_date:,
session_short_date:,
short_patient_name:,
short_patient_name_apos:,
show_additional_instructions:,
subsequent_session_dates_offered_message:,
survey_deadline_date:,
team_email:,
team_name:,
Expand Down Expand Up @@ -115,6 +117,24 @@ def location_name
session.location&.name
end

def next_session_date
session.today_or_future_dates.first&.to_fs(:short_day_of_week)
end

def next_session_dates
session
.today_or_future_dates
.map { _1.to_fs(:short_day_of_week) }
.to_sentence
end

def next_session_dates_or
session
.today_or_future_dates
.map { _1.to_fs(:short_day_of_week) }
.to_sentence(last_word_connector: ", or ", two_words_connector: " or ")
end

def parent_name
consent_form&.parent_name || parent&.name
end
Expand All @@ -140,16 +160,6 @@ def reason_for_refusal
I18n.t("mailers.consent_form_mailer.reasons_for_refusal.#{reason}")
end

def session_date
# TODO: Handle multiple dates.
session.dates.map(&:value).min.to_fs(:short_day_of_week)
end

def session_short_date
# TODO: Handle multiple dates.
session.dates.map(&:value).min.to_fs(:short)
end

def short_patient_name
[
consent_form&.common_name,
Expand All @@ -171,6 +181,15 @@ def show_additional_instructions
vaccination_record.already_had? ? "no" : "yes"
end

def subsequent_session_dates_offered_message
dates = session.today_or_future_dates.drop(1)
return if dates.empty?

"If they’re not seen, they’ll be offered the vaccination on #{
dates.map { _1.to_fs(:short_day_of_week) }.to_sentence
}."
end

def survey_deadline_date
recorded_at = consent_form&.recorded_at || consent&.recorded_at
return if recorded_at.nil?
Expand Down
27 changes: 22 additions & 5 deletions spec/lib/govuk_notify_personalisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
location:,
team:,
programme:,
close_consent_at: Date.new(2024, 1, 1),
date: Date.new(2024, 1, 1)
close_consent_at: Date.new(2026, 1, 1),
date: Date.new(2026, 1, 1)
)
end
let(:consent) { nil }
Expand All @@ -44,15 +44,16 @@
it do
expect(personalisation).to eq(
{
close_consent_date: "Monday 1 January",
close_consent_date: "Thursday 1 January",
close_consent_short_date: "1 January",
consent_link:
"http://localhost:4000/sessions/#{session.id}/consents/start",
full_and_preferred_patient_name: "John Smith",
location_name: "Hogwarts",
next_session_date: "Thursday 1 January",
next_session_dates: "Thursday 1 January",
next_session_dates_or: "Thursday 1 January",
programme_name: "Flu",
session_date: "Monday 1 January",
session_short_date: "1 January",
short_patient_name: "John",
short_patient_name_apos: "John’s",
team_email: "[email protected]",
Expand All @@ -63,6 +64,22 @@
)
end

context "with multiple dates" do
before { create(:session_date, session:, value: Date.new(2026, 1, 2)) }

it do
expect(personalisation).to match(
hash_including(
next_session_date: "Thursday 1 January",
next_session_dates: "Thursday 1 January and Friday 2 January",
next_session_dates_or: "Thursday 1 January or Friday 2 January",
subsequent_session_dates_offered_message:
"If they’re not seen, they’ll be offered the vaccination on Friday 2 January."
)
)
end
end

context "with a consent" do
let(:consent) do
create(:consent, :refused, programme:, recorded_at: Date.new(2024, 1, 1))
Expand Down

0 comments on commit 03235b3

Please sign in to comment.