Skip to content

Commit e3e2486

Browse files
committed
Allow MMR triage delay for any future date before first dose
Previously, the validation for delayed MMR triage incorrectly checked the minimum delay period even when the patient hadn't received their first dose yet. This prevented nurses from scheduling triage delays more than 28 days in the future for unvaccinated patients. Now, the 28-day minimum delay validation only applies when the patient has already received their first MMR dose and is awaiting their second. For patients without any doses, any future date within the academic year is accepted.
1 parent 39efdea commit e3e2486

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

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/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)