Skip to content

Commit f8c9bd4

Browse files
authored
Merge pull request #6581 from NHSDigital/MAV-6069-fix-mmrv-triage-email
Fix the "<Patient> needs another dose of MMR/MMRV" email so it doesn't always say MMR
2 parents f807fb4 + ac6752b commit f8c9bd4

8 files changed

Lines changed: 205 additions & 7 deletions

File tree

app/helpers/patients_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,14 @@ def patient_next_dose_label(patient, programme, academic_year)
8888
.dose_sequence
8989
&.ordinalize
9090
end
91+
92+
def patient_previous_dose_label(patient, programme, academic_year)
93+
dose = patient.programme_status(programme, academic_year:).dose_sequence
94+
(dose - 1).ordinalize if dose && dose > 1
95+
end
96+
97+
def patient_short_name_possessive(patient)
98+
name = patient.short_name
99+
name.ends_with?("s") ? "#{name}’" : "#{name}’s"
100+
end
91101
end

app/helpers/sessions_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ def session_title(session)
7373
def session_consent_style(session)
7474
session.outbreak ? "Outbreak request" : "Standard request"
7575
end
76+
77+
def session_future_dates(session)
78+
session.future_dates.map { it.to_fs(:short_day_of_week) }.to_sentence
79+
end
7680
end

app/lib/govuk_notify_personalisation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class GovukNotifyPersonalisation
66
include PatientsHelper
77
include PhoneHelper
88
include ProgrammesHelper
9+
include SessionsHelper
910
include TeamsHelper
1011
include VaccinationRecordsHelper
1112
include VaccinesHelper
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
template_id: "6fd910fd-120c-4e58-9ef3-15ffc5bd6edc"
33
template_name: triage_vaccination_will_happen_mmr_second_dose
4-
subject: "<%= short_patient_name %> needs another dose of the MMR vaccination"
4+
subject: "<%= patient.short_name %> needs another dose of the <%= programme_name_for_parents(mmr_programme.variant_for(patient:)) %> vaccination"
55
---
6-
We recently gave <%= short_patient_name %> their 1st dose of the MMR vaccination. To be fully vaccinated, they need 2 doses.
6+
<% variant = mmr_programme.variant_for(patient:) -%>
7+
<% previous_dose = patient_previous_dose_label(patient, mmr_programme, academic_year) -%>
8+
<% next_dose = patient_next_dose_label(patient, mmr_programme, academic_year) -%>
9+
We recently gave <%= patient.short_name %> their <%= previous_dose %> dose of the <%= programme_name_for_parents(variant) %> vaccination. To be fully vaccinated, they need <%= mmr_programme.maximum_dose_sequence %> doses.
710

8-
We’re coming to <%= location_name %> on <%= next_session_dates %> and plan to give <%= short_patient_name %> their 2nd dose then. Please let them know about this.
11+
We’re coming to <%= session.location.name %> on <%= session_future_dates(session) %> and plan to give <%= patient.short_name %> their <%= next_dose %> dose then. Please let them know about this.
912

10-
If <%= short_patient_name_apos %> health changes, or you arrange for them to get their 2nd dose somewhere else, contact us. You can email <%= subteam_email %> or phone <%= subteam_phone %>.
13+
If <%= patient_short_name_possessive(patient) %> health changes, or you arrange for them to get their <%= next_dose %> dose somewhere else, contact us. You can email <%= team_contact_email(session) %> or phone <%= team_contact_phone(session) %>.

spec/features/triage_required_spec.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,27 @@ def given_an_mmr_programme_with_a_running_session
481481

482482
def and_a_partially_vaccinated_patient_who_needs_triage_exists
483483
@patient_triage_needed =
484-
create(:patient, :partially_vaccinated_triage_needed, session: @session)
484+
create(
485+
:patient,
486+
:partially_vaccinated_triage_needed,
487+
date_of_birth: Date.new(2019, 6, 1), # before MMRV eligibility cutoff
488+
session: @session
489+
)
485490
end
486491

487492
def then_the_mmr_second_dose_will_happen_email_is_sent
493+
patient_name = @patient_triage_needed.short_name
494+
488495
@patient_triage_needed.parents.each do |parent|
489496
expect(email_deliveries).to include(
490497
matching_notify_email(
491498
to: parent.email,
492-
template: :triage_vaccination_will_happen_mmr_second_dose
493-
).with_content_including("We recently gave", "2nd dose")
499+
template: :triage_vaccination_will_happen_mmr_second_dose,
500+
subject: "#{patient_name} needs another dose of the MMR vaccination"
501+
).with_content_including(
502+
"We recently gave #{patient_name} their 1st dose of the MMR vaccination",
503+
"plan to give #{patient_name} their 2nd dose then"
504+
)
494505
)
495506
end
496507
end

spec/helpers/patients_helper_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,64 @@
177177
it { should eq("2nd") }
178178
end
179179
end
180+
181+
describe "#patient_previous_dose_label" do
182+
subject(:previous_dose_label) do
183+
helper.patient_previous_dose_label(
184+
patient,
185+
programme,
186+
session.academic_year
187+
)
188+
end
189+
190+
let(:programme) { Programme.mmr }
191+
let(:team) { create(:team, programmes: [programme]) }
192+
let(:session) do
193+
create(
194+
:session,
195+
team:,
196+
programmes: [programme],
197+
date: Date.new(2024, 10, 1)
198+
)
199+
end
200+
let(:patient) { create(:patient, session:, year_group: 9) }
201+
202+
context "with no vaccinations" do
203+
before { PatientStatusUpdater.call(patient:) }
204+
205+
it { should be_nil }
206+
end
207+
208+
context "with one vaccination" do
209+
before do
210+
create(
211+
:vaccination_record,
212+
:administered,
213+
programme:,
214+
patient:,
215+
session:,
216+
performed_at: Date.new(2024, 10, 1)
217+
)
218+
PatientStatusUpdater.call(patient:)
219+
end
220+
221+
it { should eq("1st") }
222+
end
223+
end
224+
225+
describe "#patient_short_name_possessive" do
226+
subject { helper.patient_short_name_possessive(patient) }
227+
228+
context "when the name does not end in s" do
229+
let(:patient) { build(:patient, given_name: "Filip") }
230+
231+
it { should eq("Filip’s") }
232+
end
233+
234+
context "when the name ends in s" do
235+
let(:patient) { build(:patient, given_name: "James") }
236+
237+
it { should eq("James’") }
238+
end
239+
end
180240
end

spec/helpers/sessions_helper_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@
107107
end
108108
end
109109

110+
describe "#session_future_dates" do
111+
subject { travel_to(today) { helper.session_future_dates(session) } }
112+
113+
let(:today) { Date.new(2025, 6, 1) }
114+
115+
context "with no future dates" do
116+
let(:session) { create(:session, dates: [Date.new(2025, 5, 30)]) }
117+
118+
it { should eq("") }
119+
end
120+
121+
context "with one future date" do
122+
let(:session) { create(:session, dates: [Date.new(2025, 6, 10)]) }
123+
124+
it { should eq("Tuesday 10 June") }
125+
end
126+
127+
context "with multiple future dates" do
128+
let(:session) do
129+
create(:session, dates: [Date.new(2025, 6, 10), Date.new(2025, 6, 17)])
130+
end
131+
132+
it { should eq("Tuesday 10 June and Tuesday 17 June") }
133+
end
134+
end
135+
110136
describe "#session_title" do
111137
subject(:session_title) { helper.session_title(session) }
112138

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# frozen_string_literal: true
2+
3+
describe "Notify email templates: triage_vaccination_will_happen_mmr_second_dose",
4+
type: :view do
5+
subject(:rendered) { render_template }
6+
7+
let(:programme) { Programme.mmr }
8+
let(:team) { create(:team, :with_one_nurse, programmes: [programme]) }
9+
let(:session) do
10+
create(
11+
:session,
12+
team:,
13+
programmes: [programme],
14+
date: Date.new(2025, 6, 10)
15+
)
16+
end
17+
let(:patient) do
18+
create(
19+
:patient,
20+
:partially_vaccinated_triage_needed,
21+
given_name: "Filip",
22+
date_of_birth: Date.new(2015, 6, 1),
23+
session:
24+
)
25+
end
26+
let(:consent) { patient.consents.first }
27+
28+
def render_template
29+
PatientStatusUpdater.call(patient:)
30+
patient.programme_statuses.reload
31+
personalisation = GovukNotifyPersonalisation.new(consent:, session:)
32+
NotifyTemplate.find(
33+
:triage_vaccination_will_happen_mmr_second_dose,
34+
channel: :email
35+
).render(personalisation)
36+
end
37+
38+
context "with an MMR programme" do
39+
it "includes the programme name in the subject" do
40+
expect(rendered[:subject]).to include("MMR vaccination")
41+
end
42+
43+
it "describes the first dose given" do
44+
expect(rendered[:body]).to include(
45+
"We recently gave Filip their 1st dose of the MMR vaccination"
46+
)
47+
end
48+
49+
it "describes the next dose" do
50+
expect(rendered[:body]).to include(
51+
"plan to give Filip their 2nd dose then"
52+
)
53+
end
54+
end
55+
56+
context "with an MMRV programme" do
57+
let(:patient) do
58+
create(
59+
:patient,
60+
:partially_vaccinated_triage_needed,
61+
given_name: "Filip",
62+
date_of_birth: Date.new(2020, 6, 1),
63+
session:
64+
)
65+
end
66+
67+
it "includes the programme name in the subject" do
68+
expect(rendered[:subject]).to include("MMRV vaccination")
69+
end
70+
71+
it "describes the first dose given" do
72+
expect(rendered[:body]).to include(
73+
"We recently gave Filip their 1st dose of the MMRV vaccination"
74+
)
75+
end
76+
77+
it "describes the next dose" do
78+
expect(rendered[:body]).to include(
79+
"plan to give Filip their 2nd dose then"
80+
)
81+
end
82+
end
83+
end

0 commit comments

Comments
 (0)