Skip to content

Commit 7b99d8e

Browse files
committed
Add Patient#approved_vaccine_methods
This adds a method which encapsulates the logic related to determining the vaccine methods that are approved for a particular patient. This refactors existing the logic, but this method will then be used when generating personalisation variables for the emails and texts.
1 parent cf58321 commit 7b99d8e

3 files changed

Lines changed: 66 additions & 10 deletions

File tree

app/components/app_vaccinate_form_component.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@ def url
1919
end
2020

2121
def delivery_method
22-
triage_status = patient.triage_status(programme:)
23-
24-
status =
25-
if triage_status.not_required?
26-
patient.consent_status(programme:)
27-
else
28-
triage_status
29-
end
30-
31-
status.vaccine_method_nasal? ? :nasal_spray : :intramuscular
22+
if patient.approved_vaccine_methods(programme:).include?("nasal")
23+
:nasal_spray
24+
else
25+
:intramuscular
26+
end
3227
end
3328

3429
def dose_sequence

app/models/patient.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,16 @@ def consent_given_and_safe_to_vaccinate?(programme:)
338338
)
339339
end
340340

341+
def approved_vaccine_methods(programme:)
342+
triage_status = triage_status(programme:)
343+
344+
if triage_status.not_required?
345+
consent_status(programme:).vaccine_methods
346+
else
347+
[triage_status.vaccine_method].compact
348+
end
349+
end
350+
341351
def deceased?
342352
date_of_death != nil
343353
end

spec/models/patient_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,57 @@
321321
it { should eq("JD") }
322322
end
323323

324+
describe "#approved_vaccine_methods" do
325+
subject(:approved_vaccine_methods) do
326+
patient.approved_vaccine_methods(programme:)
327+
end
328+
329+
let(:patient) { create(:patient) }
330+
let(:programme) { create(:programme) }
331+
332+
it { should be_empty }
333+
334+
context "when consent given and triage not required" do
335+
before do
336+
create(
337+
:patient_consent_status,
338+
:given,
339+
patient:,
340+
programme:,
341+
vaccine_methods: %w[nasal injection]
342+
)
343+
end
344+
345+
it { should eq(%w[nasal injection]) }
346+
end
347+
348+
context "when consent given and triage required" do
349+
before do
350+
create(
351+
:patient_consent_status,
352+
:given,
353+
patient:,
354+
programme:,
355+
vaccine_methods: %w[nasal injection]
356+
)
357+
create(:patient_triage_status, :required, patient:, programme:)
358+
end
359+
360+
it { should be_empty }
361+
362+
context "and when triaged" do
363+
before do
364+
patient.triage_status(programme:).update!(
365+
status: "safe_to_vaccinate",
366+
vaccine_method: "nasal"
367+
)
368+
end
369+
370+
it { should eq(%w[nasal]) }
371+
end
372+
end
373+
end
374+
324375
describe "#update_from_pds!" do
325376
subject(:update_from_pds!) { patient.update_from_pds!(pds_patient) }
326377

0 commit comments

Comments
 (0)