Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/lib/status_generator/programme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def status
:needs_consent_no_response
elsif should_be_cannot_vaccinate_delay_vaccination?
:cannot_vaccinate_delay_vaccination
elsif should_be_review_vaccination_history?
:review_vaccination_history
elsif should_be_due?
:due
elsif should_be_needs_triage?
Expand Down Expand Up @@ -218,6 +220,13 @@ def should_be_cannot_vaccinate_delay_vaccination?
is_eligible? && triage_generator.status == :delay_vaccination
end

def should_be_review_vaccination_history?
is_eligible? && triage_generator.status == :safe_to_vaccinate &&
vaccination_records.any? do |r|
r.created_at > triage_generator.created_at
end
end

def should_be_due? = is_due?

def should_be_needs_triage?
Expand Down
4 changes: 4 additions & 0 deletions app/lib/status_generator/triage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def without_gelatine
latest_triage&.without_gelatine if status_should_be_safe_to_vaccinate?
end

def created_at
latest_triage&.created_at
end

delegate :disease_types, to: :consent_generator

def delay_vaccination_until_date
Expand Down
6 changes: 6 additions & 0 deletions app/models/patient/programme_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
needs_consent
has_refusal
needs_triage
review_vaccination_history
due
cannot_vaccinate
vaccinated
Expand All @@ -108,6 +109,10 @@ class Patient::ProgrammeStatus < ApplicationRecord

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

REVIEW_VACCINATION_HISTORY_STATUSES = {
"review_vaccination_history" => 35
}.freeze

DUE_STATUSES = { "due" => 40 }.freeze

CANNOT_VACCINATE_STATUSES = {
Expand All @@ -130,6 +135,7 @@ class Patient::ProgrammeStatus < ApplicationRecord
**NEEDS_CONSENT_STATUSES,
**HAS_REFUSAL_STATUSES,
**NEEDS_TRIAGE_STATUSES,
**REVIEW_VACCINATION_HISTORY_STATUSES,
**DUE_STATUSES,
**CANNOT_VACCINATE_STATUSES,
**VACCINATED_STATUSES
Expand Down
2 changes: 2 additions & 0 deletions config/locales/status.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ en:
needs_consent_no_contact_details: Needs consent
needs_triage: Needs triage
not_eligible: Not eligible
review_vaccination_history: Review vaccs history
vaccinated: Vaccinated
vaccinated_already: Vaccinated
vaccinated_fully: Vaccinated
Expand Down Expand Up @@ -96,6 +97,7 @@ en:
needs_consent_no_contact_details: blue
needs_triage: blue
not_eligible: grey
review_vaccination_history: blue
vaccinated: white
vaccinated_already: white
vaccinated_fully: white
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/status_generator/programme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,32 @@
end
end

context "when a vaccination record was added after a safe to vaccinate triage" do
let(:programme) { Programme.mmr }

before do
create(:consent, :given, patient:, programme:)
create(
:triage,
:safe_to_vaccinate,
patient:,
programme:,
created_at: 1.day.ago
)
create(:vaccination_record, :yesterday, patient:, programme:)
end

its(:consent_status) { should be(:given) }
its(:consent_vaccine_methods) { should contain_exactly("injection") }
its(:date) { should eq(Date.yesterday) }
its(:disease_types) { should be_empty }
its(:dose_sequence) { should eq(2) }
its(:location_id) { should be_nil }
its(:status) { should be(:review_vaccination_history) }
its(:vaccine_methods) { should contain_exactly("injection") }
its(:without_gelatine) { should be(false) }
end

context "when not eligible" do
let(:patient) { create(:patient, year_group: 12, parents:) }

Expand Down
74 changes: 72 additions & 2 deletions spec/lib/status_generator/triage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject(:generator) do
described_class.new(
programme_type: programme.type,
academic_year: AcademicYear.current,
academic_year: current_academic_year,
patient:,
consents: patient.consents,
triages: patient.triages,
Expand All @@ -15,6 +15,7 @@
)
end

let(:current_academic_year) { AcademicYear.current }
let(:patient) { create(:patient) }
let(:programme) { Programme.hpv }

Expand Down Expand Up @@ -212,7 +213,6 @@
end

describe "academic year filtering" do
let(:current_academic_year) { AcademicYear.current }
let(:previous_academic_year) { current_academic_year - 1 }
let(:patient) { create(:patient) }
let(:programme) { Programme.sample }
Expand Down Expand Up @@ -366,6 +366,76 @@
end
end

describe "#created_at" do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a scenario here where you've got multiple triage records and we want to be sure that created_at is the latest one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've amended the commit to include this

subject { generator.created_at }

context "with no triage" do
it { should be_nil }
end

context "with a safe to vaccinate triage" do
let!(:triage) do
create(:triage, :safe_to_vaccinate, patient:, programme:)
end

it { should eq(triage.created_at) }
end

context "with a safe to vaccinate triage and vaccinated" do
let!(:triage) do
create(:triage, :safe_to_vaccinate, patient:, programme:)
end

before { create(:vaccination_record, patient:, programme:) }

it { should eq(triage.created_at) }
end

context "with a do not vaccinate triage" do
let!(:triage) { create(:triage, :do_not_vaccinate, patient:, programme:) }

it { should eq(triage.created_at) }
end

context "with multiple triages" do
let!(:latest_triage) do
create(
:triage,
:safe_to_vaccinate,
patient:,
programme:,
created_at: latest_created_at
)
end

let(:older_created_at) do
Date.new(current_academic_year, 10, 15).in_time_zone
end

let(:latest_created_at) { older_created_at + 2.days }

before do
create(
:triage,
:safe_to_vaccinate,
patient:,
programme:,
created_at: older_created_at
)
end

it { should eq(latest_triage.created_at) }
end

context "with an invalidated safe to vaccinate triage" do
before do
create(:triage, :safe_to_vaccinate, :invalidated, patient:, programme:)
end

it { should be_nil }
end
end

describe "#without_gelatine" do
subject { generator.without_gelatine }

Expand Down
Loading