Skip to content

Commit c92e786

Browse files
authored
Merge pull request #5109 from nhsuk/fix-mmr-delay-before-first-dose
Improves the MMR triage delay experience for patients who haven't received their first dose yet
2 parents 136bc05 + e3e2486 commit c92e786

4 files changed

Lines changed: 95 additions & 6 deletions

File tree

app/components/app_triage_form_component.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ def initialize(form, url:, method: :post, heading: true, continue: false)
1919
def builder = GOVUKDesignSystemFormBuilder::FormBuilder
2020

2121
def hint_text
22-
if programme.mmr? &&
23-
!patient.vaccination_status(
24-
programme:,
25-
academic_year: session.academic_year
26-
).vaccinated?
22+
if programme.mmr? && patient_eligible_for_additional_dose?
2723
"2nd dose is not due until #{form.next_mmr_dose_date.to_fs(:long)}"
2824
else
2925
"For example, #{hint_date.to_fs(:long)} "
@@ -54,4 +50,14 @@ def fieldset_options
5450
{ legend: { text: }, hint: { text: hint } }
5551
end
5652
end
53+
54+
def patient_eligible_for_additional_dose?
55+
next_dose =
56+
patient.vaccination_status(
57+
programme: programme,
58+
academic_year: session.academic_year
59+
).dose_sequence
60+
61+
next_dose == programme.maximum_dose_sequence
62+
end
5763
end

app/forms/triage_form.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def validate_delay_vaccination_until_date
239239
)
240240
end
241241

242-
if programme.mmr? && (delay_vaccination_until < next_mmr_dose_date)
242+
if programme.mmr? && patient_eligible_for_additional_dose? &&
243+
(delay_vaccination_until < next_mmr_dose_date)
243244
errors.add(
244245
:delay_vaccination_until,
245246
"The vaccination cannot take place before #{next_mmr_dose_date.to_fs(:long)}"
@@ -255,4 +256,14 @@ def associate_triage_with_vaccination_record(next_dose_delay_triage)
255256
vaccination_record.update!(next_dose_delay_triage:)
256257
end
257258
end
259+
260+
def patient_eligible_for_additional_dose?
261+
next_dose =
262+
patient.vaccination_status(
263+
programme: programme,
264+
academic_year: session.academic_year
265+
).dose_sequence
266+
267+
next_dose == programme.maximum_dose_sequence
268+
end
258269
end

spec/components/app_triage_form_component_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,28 @@
118118
expect(rendered).not_to have_text("The parent has consented to")
119119
end
120120
end
121+
122+
context "hint text for delayed triage when programme is MMR" do
123+
context "when the patient has not received any dose" do
124+
let(:programme) { create(:programme, :mmr) }
125+
126+
it "doesn't show the specific hint text about the 2nd dose" do
127+
expect(rendered).not_to have_text("2nd dose is not due until")
128+
end
129+
end
130+
131+
context "when the patient has received the 1st dose" do
132+
let(:programme) { create(:programme, :mmr) }
133+
134+
before do
135+
create(:vaccination_record, patient:, programme:, session:)
136+
137+
StatusUpdater.call(patient:)
138+
end
139+
140+
it "doesn't show the specific hint text about the 2nd dose" do
141+
expect(rendered).to have_text("2nd dose is not due until")
142+
end
143+
end
144+
end
121145
end

spec/forms/triage_form_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,52 @@
9494
expect(vaccination_record.reload.next_dose_delay_triage).to eq(triage)
9595
end
9696
end
97+
98+
context "programme is MMR" do
99+
let(:programme) { create(:programme, :mmr) }
100+
101+
describe "validation for delay_vaccination_until" do
102+
subject(:validation_errors) do
103+
form.save # rubocop:disable Rails/SaveBang
104+
form.errors.full_messages
105+
end
106+
107+
let(:delay_vaccination_until) { nil }
108+
109+
let(:form) do
110+
described_class.new(
111+
patient:,
112+
session:,
113+
programme:,
114+
delay_vaccination_until:,
115+
current_user: create(:user),
116+
status_option: "delay_vaccination"
117+
)
118+
end
119+
120+
context "patient hasn't received any doses" do
121+
let(:delay_vaccination_until) { Date.tomorrow }
122+
123+
it "doesn't produce any validation errors" do
124+
expect(validation_errors).to be_empty
125+
end
126+
end
127+
128+
context "patient has had their first dose" do
129+
let(:delay_vaccination_until) { Date.tomorrow }
130+
131+
before do
132+
create(:vaccination_record, patient:, programme:, session:)
133+
134+
StatusUpdater.call(patient:)
135+
end
136+
137+
it "doesn't produce any validation errors" do
138+
expect(validation_errors.join).to include(
139+
"The vaccination cannot take place before"
140+
)
141+
end
142+
end
143+
end
144+
end
97145
end

0 commit comments

Comments
 (0)