Skip to content

Commit 1114e74

Browse files
committed
Add "Review vaccs history" status
* Adds new status that patients get for a programme when they have been triaged as "Safe to vaccinate" but a new vaccination record has appeared in their history. Jira-Issue: MAV-5582
1 parent a31551e commit 1114e74

6 files changed

Lines changed: 87 additions & 0 deletions

File tree

app/lib/status_generator/programme.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def status
5858
:needs_consent_no_response
5959
elsif should_be_cannot_vaccinate_delay_vaccination?
6060
:cannot_vaccinate_delay_vaccination
61+
elsif should_be_review_vaccination_history?
62+
:review_vaccination_history
6163
elsif should_be_due?
6264
:due
6365
elsif should_be_needs_triage?
@@ -202,6 +204,13 @@ def should_be_cannot_vaccinate_delay_vaccination?
202204
is_eligible? && triage_generator.status == :delay_vaccination
203205
end
204206

207+
def should_be_review_vaccination_history?
208+
is_eligible? && triage_generator.status == :safe_to_vaccinate &&
209+
vaccination_records.any? do |r|
210+
r.created_at > triage_generator.created_at
211+
end
212+
end
213+
205214
def should_be_due? = is_due?
206215

207216
def should_be_needs_triage?

app/lib/status_generator/triage.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def without_gelatine
4545
latest_triage&.without_gelatine if status_should_be_safe_to_vaccinate?
4646
end
4747

48+
def created_at
49+
latest_triage&.created_at
50+
end
51+
4852
delegate :disease_types, to: :consent_generator
4953

5054
def delay_vaccination_until_date

app/models/patient/programme_status.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
6868
needs_consent
6969
has_refusal
7070
needs_triage
71+
review_vaccination_history
7172
due
7273
cannot_vaccinate
7374
vaccinated
@@ -90,6 +91,10 @@ class Patient::ProgrammeStatus < ApplicationRecord
9091

9192
NEEDS_TRIAGE_STATUSES = { "needs_triage" => 30 }.freeze
9293

94+
REVIEW_VACCINATION_HISTORY_STATUSES = {
95+
"review_vaccination_history" => 35
96+
}.freeze
97+
9398
DUE_STATUSES = { "due" => 40 }.freeze
9499

95100
CANNOT_VACCINATE_STATUSES = {
@@ -112,6 +117,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
112117
**NEEDS_CONSENT_STATUSES,
113118
**HAS_REFUSAL_STATUSES,
114119
**NEEDS_TRIAGE_STATUSES,
120+
**REVIEW_VACCINATION_HISTORY_STATUSES,
115121
**DUE_STATUSES,
116122
**CANNOT_VACCINATE_STATUSES,
117123
**VACCINATED_STATUSES

config/locales/status.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ en:
5959
needs_consent_request_scheduled: Needs consent
6060
needs_triage: Needs triage
6161
not_eligible: Not eligible
62+
review_vaccination_history: Review vaccs history
6263
vaccinated: Vaccinated
6364
vaccinated_already: Vaccinated
6465
vaccinated_fully: Vaccinated
@@ -86,6 +87,7 @@ en:
8687
needs_consent_request_scheduled: blue
8788
needs_triage: blue
8889
not_eligible: grey
90+
review_vaccination_history: blue
8991
vaccinated: white
9092
vaccinated_already: white
9193
vaccinated_fully: white

spec/lib/status_generator/programme_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,32 @@
375375
end
376376
end
377377

378+
context "when a vaccination record was added after a safe to vaccinate triage" do
379+
let(:programme) { Programme.mmr }
380+
381+
before do
382+
create(:consent, :given, patient:, programme:)
383+
create(
384+
:triage,
385+
:safe_to_vaccinate,
386+
patient:,
387+
programme:,
388+
created_at: 1.day.ago
389+
)
390+
create(:vaccination_record, :yesterday, patient:, programme:)
391+
end
392+
393+
its(:consent_status) { should be(:given) }
394+
its(:consent_vaccine_methods) { should contain_exactly("injection") }
395+
its(:date) { should eq(Date.yesterday) }
396+
its(:disease_types) { should be_empty }
397+
its(:dose_sequence) { should eq(2) }
398+
its(:location_id) { should be_nil }
399+
its(:status) { should be(:review_vaccination_history) }
400+
its(:vaccine_methods) { should contain_exactly("injection") }
401+
its(:without_gelatine) { should be(false) }
402+
end
403+
378404
context "when not eligible" do
379405
let(:patient) { create(:patient, year_group: 20) }
380406

spec/lib/status_generator/triage_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,46 @@
363363
end
364364
end
365365

366+
describe "#created_at" do
367+
subject { generator.created_at }
368+
369+
context "with no triage" do
370+
it { should be_nil }
371+
end
372+
373+
context "with a safe to vaccinate triage" do
374+
let!(:triage) do
375+
create(:triage, :safe_to_vaccinate, patient:, programme:)
376+
end
377+
378+
it { should eq(triage.created_at) }
379+
end
380+
381+
context "with a safe to vaccinate triage and vaccinated" do
382+
let!(:triage) do
383+
create(:triage, :safe_to_vaccinate, patient:, programme:)
384+
end
385+
386+
before { create(:vaccination_record, patient:, programme:) }
387+
388+
it { should eq(triage.created_at) }
389+
end
390+
391+
context "with a do not vaccinate triage" do
392+
let!(:triage) { create(:triage, :do_not_vaccinate, patient:, programme:) }
393+
394+
it { should eq(triage.created_at) }
395+
end
396+
397+
context "with an invalidated safe to vaccinate triage" do
398+
before do
399+
create(:triage, :safe_to_vaccinate, :invalidated, patient:, programme:)
400+
end
401+
402+
it { should be_nil }
403+
end
404+
end
405+
366406
describe "#without_gelatine" do
367407
subject { generator.without_gelatine }
368408

0 commit comments

Comments
 (0)