Skip to content
Merged
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
45 changes: 38 additions & 7 deletions app/models/draft_vaccination_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,43 @@ def identity_check=(identity_check)
end

def vaccine_method_matches_consent_and_triage?
return true if delivery_method.blank? || !administered?
if delivery_method.blank? || !administered? || academic_year.nil?
return true
end

# We can't use `patient.approved_vaccine_methods` because once vaccinated
# a patient no longer has an approved list of vaccine methods (they don't
# need the vaccine).

consent_generator =
StatusGenerator::Consent.new(
programme:,
academic_year:,
patient:,
consents: patient.consents,
vaccination_records: []
)

triage_generator =
StatusGenerator::Triage.new(
programme:,
academic_year:,
patient:,
consents: patient.consents,
triages: patient.triages,
vaccination_records: []
)

approved_vaccine_methods =
if triage_generator.status == :not_required
consent_generator.vaccine_methods
else
[triage_generator.vaccine_method].compact
end

academic_year = session&.academic_year || performed_at.academic_year
approved_methods =
patient.approved_vaccine_methods(programme:, academic_year:)
vaccine_method = Vaccine.delivery_method_to_vaccine_method(delivery_method)

approved_methods.include?(vaccine_method)
approved_vaccine_methods.include?(vaccine_method)
end

private
Expand Down Expand Up @@ -321,13 +350,15 @@ def reset_unused_attributes
end
end

def academic_year = session&.academic_year

def earliest_possible_value
session.academic_year.to_academic_year_date_range.first.beginning_of_day
academic_year.to_academic_year_date_range.first.beginning_of_day
end

def latest_possible_value
[
session.academic_year.to_academic_year_date_range.last.end_of_day,
academic_year.to_academic_year_date_range.last.end_of_day,
Time.current
].min
end
Expand Down
13 changes: 0 additions & 13 deletions spec/factories/patients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,6 @@
end
end

trait :triage_safe_to_vaccinate_nasal do
triage_statuses do
programmes.map do |programme|
association(
:patient_triage_status,
:safe_to_vaccinate_nasal,
patient: instance,
programme:
)
end
end
end

trait :triage_required do
triage_statuses do
programmes.map do |programme|
Expand Down
3 changes: 3 additions & 0 deletions spec/features/edit_vaccination_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def when_i_click_on_edit_vaccination_record

def then_i_see_the_edit_vaccination_record_page
expect(page).to have_content("Edit vaccination record")
expect(page).not_to have_content(
"The vaccine given does not match that determined by the child’s consent or triage outcome"
)
end

def when_i_click_back
Expand Down
78 changes: 39 additions & 39 deletions spec/models/draft_vaccination_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
context "when vaccination is not administered" do
let(:attributes) { valid_not_administered_attributes }

it { should be true }
it { should be(true) }
end

context "when delivery method is nasal_spray" do
Expand All @@ -367,41 +367,39 @@
end

context "when consent is given for nasal" do
let(:patient) do
create(
:patient,
:consent_given_nasal_only_triage_not_needed,
session:
)
end
before { create(:consent, :given_nasal, patient:, programme:) }

it { should be true }
it { should be(true) }
end

context "when consent is given for injection" do
let(:patient) do
create(
:patient,
:consent_given_injection_only_triage_needed,
session:
)
end
before { create(:consent, :given_injection, patient:, programme:) }

it { should be false }
it { should be(false) }
end

context "when triage is safe for nasal" do
let(:patient) do
create(:patient, :triage_safe_to_vaccinate_nasal, session:)
before do
create(:consent, :given_nasal, patient:, programme:)
create(
:triage,
:ready_to_vaccinate,
patient:,
programme:,
vaccine_method: "nasal"
)
end

it { should be true }
it { should be(true) }
end

context "when triage is safe for injection" do
let(:patient) { create(:patient, :triage_safe_to_vaccinate, session:) }
before do
create(:consent, :given_injection, patient:, programme:)
create(:triage, :ready_to_vaccinate, patient:, programme:)
end

it { should be false }
it { should be(false) }
end
end

Expand All @@ -411,37 +409,39 @@
end

context "when consent is given for injection" do
let(:patient) do
create(
:patient,
:consent_given_injection_only_triage_not_needed,
session:
)
end
before { create(:consent, :given_injection, patient:, programme:) }

it { should be true }
it { should be(true) }
end

context "when consent is given for nasal" do
let(:patient) do
create(:patient, :consent_given_nasal_only_triage_needed, session:)
end
before { create(:consent, :given_nasal, patient:, programme:) }

it { should be false }
it { should be(false) }
end

context "when triage is safe for injection" do
let(:patient) { create(:patient, :triage_safe_to_vaccinate, session:) }
before do
create(:consent, :given_injection, patient:, programme:)
create(:triage, :ready_to_vaccinate, patient:, programme:)
end

it { should be true }
it { should be(true) }
end

context "when triage is safe for nasal" do
let(:patient) do
create(:patient, :triage_safe_to_vaccinate_nasal, session:)
before do
create(:consent, :given_nasal, patient:, programme:)
create(
:triage,
:ready_to_vaccinate,
patient:,
programme:,
vaccine_method: "nasal"
)
end

it { should be false }
it { should be(false) }
end
end
end
Expand Down