Skip to content

Commit d05ded8

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 d05ded8

6 files changed

Lines changed: 119 additions & 2 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
subject(:generator) do
55
described_class.new(
66
programme_type: programme.type,
7-
academic_year: AcademicYear.current,
7+
academic_year: current_academic_year,
88
patient:,
99
consents: patient.consents,
1010
triages: patient.triages,
@@ -15,6 +15,7 @@
1515
)
1616
end
1717

18+
let(:current_academic_year) { AcademicYear.current }
1819
let(:patient) { create(:patient) }
1920
let(:programme) { Programme.hpv }
2021

@@ -212,7 +213,6 @@
212213
end
213214

214215
describe "academic year filtering" do
215-
let(:current_academic_year) { AcademicYear.current }
216216
let(:previous_academic_year) { current_academic_year - 1 }
217217
let(:patient) { create(:patient) }
218218
let(:programme) { Programme.sample }
@@ -366,6 +366,76 @@
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!(:latest_triage) do
402+
create(
403+
:triage,
404+
:safe_to_vaccinate,
405+
patient:,
406+
programme:,
407+
created_at: latest_created_at
408+
)
409+
end
410+
411+
let(:older_created_at) do
412+
Date.new(current_academic_year, 10, 15).in_time_zone
413+
end
414+
415+
let(:latest_created_at) { older_created_at + 2.days }
416+
417+
before do
418+
create(
419+
:triage,
420+
:safe_to_vaccinate,
421+
patient:,
422+
programme:,
423+
created_at: older_created_at
424+
)
425+
end
426+
427+
it { should eq(latest_triage.created_at) }
428+
end
429+
430+
context "with an invalidated safe to vaccinate triage" do
431+
before do
432+
create(:triage, :safe_to_vaccinate, :invalidated, patient:, programme:)
433+
end
434+
435+
it { should be_nil }
436+
end
437+
end
438+
369439
describe "#without_gelatine" do
370440
subject { generator.without_gelatine }
371441

0 commit comments

Comments
 (0)