Skip to content

Commit 6eb1447

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 057e29d commit 6eb1447

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
@@ -63,6 +63,8 @@ def status
6363
:needs_consent_no_response
6464
elsif should_be_cannot_vaccinate_delay_vaccination?
6565
:cannot_vaccinate_delay_vaccination
66+
elsif should_be_review_vaccination_history?
67+
:review_vaccination_history
6668
elsif should_be_due?
6769
:due
6870
elsif should_be_needs_triage?
@@ -214,6 +216,13 @@ def should_be_cannot_vaccinate_delay_vaccination?
214216
is_eligible? && triage_generator.status == :delay_vaccination
215217
end
216218

219+
def should_be_review_vaccination_history?
220+
is_eligible? && triage_generator.status == :safe_to_vaccinate &&
221+
vaccination_records.any? do |r|
222+
r.created_at > triage_generator.created_at
223+
end
224+
end
225+
217226
def should_be_due? = is_due?
218227

219228
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
@@ -47,6 +47,10 @@ def without_gelatine
4747
latest_triage&.without_gelatine if status_should_be_safe_to_vaccinate?
4848
end
4949

50+
def created_at
51+
latest_triage&.created_at
52+
end
53+
5054
delegate :disease_types, to: :consent_generator
5155

5256
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
@@ -70,6 +70,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
7070
needs_consent
7171
has_refusal
7272
needs_triage
73+
review_vaccination_history
7374
due
7475
cannot_vaccinate
7576
vaccinated
@@ -93,6 +94,10 @@ class Patient::ProgrammeStatus < ApplicationRecord
9394

9495
NEEDS_TRIAGE_STATUSES = { "needs_triage" => 30 }.freeze
9596

97+
REVIEW_VACCINATION_HISTORY_STATUSES = {
98+
"review_vaccination_history" => 35
99+
}.freeze
100+
96101
DUE_STATUSES = { "due" => 40 }.freeze
97102

98103
CANNOT_VACCINATE_STATUSES = {
@@ -115,6 +120,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
115120
**NEEDS_CONSENT_STATUSES,
116121
**HAS_REFUSAL_STATUSES,
117122
**NEEDS_TRIAGE_STATUSES,
123+
**REVIEW_VACCINATION_HISTORY_STATUSES,
118124
**DUE_STATUSES,
119125
**CANNOT_VACCINATE_STATUSES,
120126
**VACCINATED_STATUSES

config/locales/status.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ en:
6464
needs_consent_no_contact_details: Needs consent
6565
needs_triage: Needs triage
6666
not_eligible: Not eligible
67+
review_vaccination_history: Review vaccs history
6768
vaccinated: Vaccinated
6869
vaccinated_already: Vaccinated
6970
vaccinated_fully: Vaccinated
@@ -92,6 +93,7 @@ en:
9293
needs_consent_no_contact_details: blue
9394
needs_triage: blue
9495
not_eligible: grey
96+
review_vaccination_history: blue
9597
vaccinated: white
9698
vaccinated_already: white
9799
vaccinated_fully: white

spec/lib/status_generator/programme_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,32 @@
405405
end
406406
end
407407

408+
context "when a vaccination record was added after a safe to vaccinate triage" do
409+
let(:programme) { Programme.mmr }
410+
411+
before do
412+
create(:consent, :given, patient:, programme:)
413+
create(
414+
:triage,
415+
:safe_to_vaccinate,
416+
patient:,
417+
programme:,
418+
created_at: 1.day.ago
419+
)
420+
create(:vaccination_record, :yesterday, patient:, programme:)
421+
end
422+
423+
its(:consent_status) { should be(:given) }
424+
its(:consent_vaccine_methods) { should contain_exactly("injection") }
425+
its(:date) { should eq(Date.yesterday) }
426+
its(:disease_types) { should be_empty }
427+
its(:dose_sequence) { should eq(2) }
428+
its(:location_id) { should be_nil }
429+
its(:status) { should be(:review_vaccination_history) }
430+
its(:vaccine_methods) { should contain_exactly("injection") }
431+
its(:without_gelatine) { should be(false) }
432+
end
433+
408434
context "when not eligible" do
409435
let(:patient) { create(:patient, year_group: 20, parents:) }
410436

spec/lib/status_generator/triage_spec.rb

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

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

0 commit comments

Comments
 (0)