Skip to content

Commit 5894a03

Browse files
committed
Don't invalidate delay vaccination triages
When invalidating triages because the patient self-consented, we shouldn't invalidate any delay vaccination triages because they are likely to still be valid in that we need to wait some period of time before the patient can be vaccinated again. Jira-Issue: MAV-2771
1 parent c5d58e4 commit 5894a03

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

app/jobs/invalidate_self_consents_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def perform
3636

3737
ActiveRecord::Base.transaction do
3838
consents.invalidate_all
39-
triages.invalidate_all
39+
triages.safe_to_invalidate_automatically.invalidate_all
4040
end
4141
end
4242
end

app/models/triage.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Triage < ApplicationRecord
6060
if: :safe_to_vaccinate?
6161
}
6262

63+
scope :safe_to_invalidate_automatically, -> { not_delay_vaccination }
64+
6365
validates :delay_vaccination_until, absence: true, unless: :delay_vaccination?
6466

6567
with_options if: :safe_to_vaccinate? do

spec/jobs/invalidate_self_consents_job_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,44 @@
9696
end
9797
end
9898

99+
context "with an expired delay vaccination triage" do
100+
let(:triage) do
101+
create(
102+
:triage,
103+
:delay_vaccination,
104+
academic_year:,
105+
created_at: 1.day.ago,
106+
delay_vaccination_until: 1.day.ago,
107+
team:,
108+
programme:,
109+
patient:
110+
)
111+
end
112+
113+
it "doesn't invalidate the triage" do
114+
expect { perform_now }.not_to(change { triage.reload.invalidated? })
115+
end
116+
end
117+
118+
context "with a delay vaccination triage that's not expired" do
119+
let(:triage) do
120+
create(
121+
:triage,
122+
:delay_vaccination,
123+
academic_year:,
124+
created_at: 1.day.ago,
125+
delay_vaccination_until: 28.days.from_now,
126+
team:,
127+
programme:,
128+
patient:
129+
)
130+
end
131+
132+
it "doesn't invalidate the triage" do
133+
expect { perform_now }.not_to(change { triage.reload.invalidated? })
134+
end
135+
end
136+
99137
context "if the patient was vaccinated" do
100138
before do
101139
create(

0 commit comments

Comments
 (0)