Skip to content

Commit dcc1471

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 0d81782 commit dcc1471

6 files changed

Lines changed: 119 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
@@ -66,6 +66,8 @@ def status
6666
:needs_consent_no_response
6767
elsif should_be_cannot_vaccinate_delay_vaccination?
6868
:cannot_vaccinate_delay_vaccination
69+
elsif should_be_review_vaccination_history?
70+
:review_vaccination_history
6971
elsif should_be_due?
7072
:due
7173
elsif should_be_needs_triage?
@@ -218,6 +220,13 @@ def should_be_cannot_vaccinate_delay_vaccination?
218220
is_eligible? && triage_generator.status == :delay_vaccination
219221
end
220222

223+
def should_be_review_vaccination_history?
224+
is_eligible? && triage_generator.status == :safe_to_vaccinate &&
225+
vaccination_records.any? do |r|
226+
r.created_at > triage_generator.created_at
227+
end
228+
end
229+
221230
def should_be_due? = is_due?
222231

223232
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
@@ -51,6 +51,10 @@ def without_gelatine
5151
latest_triage&.without_gelatine if status_should_be_safe_to_vaccinate?
5252
end
5353

54+
def created_at
55+
latest_triage&.created_at
56+
end
57+
5458
delegate :disease_types, to: :consent_generator
5559

5660
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
@@ -85,6 +85,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
8585
needs_consent
8686
has_refusal
8787
needs_triage
88+
review_vaccination_history
8889
due
8990
cannot_vaccinate
9091
vaccinated
@@ -108,6 +109,10 @@ class Patient::ProgrammeStatus < ApplicationRecord
108109

109110
NEEDS_TRIAGE_STATUSES = { "needs_triage" => 30 }.freeze
110111

112+
REVIEW_VACCINATION_HISTORY_STATUSES = {
113+
"review_vaccination_history" => 35
114+
}.freeze
115+
111116
DUE_STATUSES = { "due" => 40 }.freeze
112117

113118
CANNOT_VACCINATE_STATUSES = {
@@ -130,6 +135,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
130135
**NEEDS_CONSENT_STATUSES,
131136
**HAS_REFUSAL_STATUSES,
132137
**NEEDS_TRIAGE_STATUSES,
138+
**REVIEW_VACCINATION_HISTORY_STATUSES,
133139
**DUE_STATUSES,
134140
**CANNOT_VACCINATE_STATUSES,
135141
**VACCINATED_STATUSES

config/locales/status.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ en:
6868
needs_consent_no_contact_details: Needs consent
6969
needs_triage: Needs triage
7070
not_eligible: Not eligible
71+
review_vaccination_history: Review vaccs history
7172
vaccinated: Vaccinated
7273
vaccinated_already: Vaccinated
7374
vaccinated_fully: Vaccinated
@@ -96,6 +97,7 @@ en:
9697
needs_consent_no_contact_details: blue
9798
needs_triage: blue
9899
not_eligible: grey
100+
review_vaccination_history: blue
99101
vaccinated: white
100102
vaccinated_already: white
101103
vaccinated_fully: white

spec/lib/status_generator/programme_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,32 @@
499499
end
500500
end
501501

502+
context "when a vaccination record was added after a safe to vaccinate triage" do
503+
let(:programme) { Programme.mmr }
504+
505+
before do
506+
create(:consent, :given, patient:, programme:)
507+
create(
508+
:triage,
509+
:safe_to_vaccinate,
510+
patient:,
511+
programme:,
512+
created_at: 1.day.ago
513+
)
514+
create(:vaccination_record, :yesterday, patient:, programme:)
515+
end
516+
517+
its(:consent_status) { should be(:given) }
518+
its(:consent_vaccine_methods) { should contain_exactly("injection") }
519+
its(:date) { should eq(Date.yesterday) }
520+
its(:disease_types) { should be_empty }
521+
its(:dose_sequence) { should eq(2) }
522+
its(:location_id) { should be_nil }
523+
its(:status) { should be(:review_vaccination_history) }
524+
its(:vaccine_methods) { should contain_exactly("injection") }
525+
its(:without_gelatine) { should be(false) }
526+
end
527+
502528
context "when not eligible" do
503529
let(:patient) { create(:patient, year_group: 12, parents:) }
504530

spec/lib/status_generator/triage_spec.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,78 @@
366366
end
367367
end
368368

369+
describe "#created_at" do
370+
subject { generator.created_at }
371+
372+
context "with no triage" do
373+
it { should be_nil }
374+
end
375+
376+
context "with a safe to vaccinate triage" do
377+
let!(:triage) do
378+
create(:triage, :safe_to_vaccinate, patient:, programme:)
379+
end
380+
381+
it { should eq(triage.created_at) }
382+
end
383+
384+
context "with a safe to vaccinate triage and vaccinated" do
385+
let!(:triage) do
386+
create(:triage, :safe_to_vaccinate, patient:, programme:)
387+
end
388+
389+
before { create(:vaccination_record, patient:, programme:) }
390+
391+
it { should eq(triage.created_at) }
392+
end
393+
394+
context "with a do not vaccinate triage" do
395+
let!(:triage) { create(:triage, :do_not_vaccinate, patient:, programme:) }
396+
397+
it { should eq(triage.created_at) }
398+
end
399+
400+
context "with multiple triages" do
401+
let(:current_academic_year) { AcademicYear.current }
402+
let!(:latest_triage) do
403+
create(
404+
:triage,
405+
:safe_to_vaccinate,
406+
patient:,
407+
programme:,
408+
created_at: latest_created_at
409+
)
410+
end
411+
412+
let(:older_created_at) do
413+
Date.new(current_academic_year, 10, 15).in_time_zone
414+
end
415+
416+
let(:latest_created_at) { older_created_at + 2.days }
417+
418+
before do
419+
create(
420+
:triage,
421+
:safe_to_vaccinate,
422+
patient:,
423+
programme:,
424+
created_at: older_created_at
425+
)
426+
end
427+
428+
429+
it { should eq(latest_triage.created_at) }
430+
end
431+
432+
context "with an invalidated safe to vaccinate triage" do
433+
before do
434+
create(:triage, :safe_to_vaccinate, :invalidated, patient:, programme:)
435+
end
436+
437+
it { should be_nil }
438+
end
439+
end
440+
369441
describe "#without_gelatine" do
370442
subject { generator.without_gelatine }
371443

0 commit comments

Comments
 (0)