Skip to content

Commit 345cbad

Browse files
authored
Merge pull request #3955 from nhsuk/filter-vaccine-method-on-safe-to-vaccinate
Filter on patients with approriate vaccine method
2 parents 791a477 + 0a07ade commit 345cbad

5 files changed

Lines changed: 100 additions & 21 deletions

File tree

app/controllers/sessions/record_controller.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ def show
2525
)
2626
.has_registration_status(%w[attending completed])
2727

28-
scope = @form.apply(scope)
29-
3028
patient_sessions =
31-
scope.select do |patient_session|
32-
@form.programmes.any? do |programme|
33-
patient_session.patient.consent_given_and_safe_to_vaccinate?(
34-
programme:
35-
)
36-
end
37-
end
29+
@form.apply(scope).consent_given_and_ready_to_vaccinate(
30+
programmes: @form.programmes,
31+
vaccine_method: @form.vaccine_method
32+
)
3833

3934
@pagy, @patient_sessions = pagy_array(patient_sessions)
4035

app/models/patient.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,23 @@ def vaccination_status(programme:)
327327
vaccination_statuses.build(programme:)
328328
end
329329

330-
def consent_given_and_safe_to_vaccinate?(programme:)
330+
def consent_given_and_safe_to_vaccinate?(programme:, vaccine_method: nil)
331331
return false if vaccination_status(programme:).vaccinated?
332332

333-
consent_status(programme:).given? &&
334-
(
335-
triage_status(programme:).safe_to_vaccinate? ||
336-
triage_status(programme:).delay_vaccination? ||
337-
triage_status(programme:).not_required?
338-
)
333+
return false unless consent_status(programme:).given?
334+
335+
unless triage_status(programme:).safe_to_vaccinate? ||
336+
triage_status(programme:).delay_vaccination? ||
337+
triage_status(programme:).not_required?
338+
return false
339+
end
340+
341+
if vaccine_method &&
342+
!approved_vaccine_methods(programme:).include?(vaccine_method)
343+
return false
344+
end
345+
346+
true
339347
end
340348

341349
def approved_vaccine_methods(programme:)

app/models/patient_session.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ class PatientSession < ApplicationRecord
179179
)
180180
end
181181

182+
scope :consent_given_and_ready_to_vaccinate,
183+
->(programmes:, vaccine_method:) do
184+
select do |patient_session|
185+
patient = patient_session.patient
186+
187+
programmes.any? do |programme|
188+
patient.consent_given_and_safe_to_vaccinate?(
189+
programme:,
190+
vaccine_method:
191+
)
192+
end
193+
end
194+
end
195+
182196
scope :destroy_all_if_safe,
183197
-> do
184198
includes(

spec/features/flu_vaccination_administered_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
1111

1212
when_i_go_to_the_nasal_only_patient
13-
then_i_see_the_vacciantion_form_for_nasal_spray
13+
then_i_see_the_vaccination_form_for_nasal_spray
1414

1515
when_i_record_that_the_patient_has_been_vaccinated_with_nasal_spray
1616
then_i_see_the_check_and_confirm_page_for_nasal_spray
@@ -28,7 +28,7 @@
2828
and_there_are_nasal_and_injection_batches
2929

3030
when_i_go_to_the_injection_only_patient
31-
then_i_see_the_vacciantion_form_for_injection
31+
then_i_see_the_vaccination_form_for_injection
3232

3333
when_i_record_that_the_patient_has_been_vaccinated_with_injection
3434
then_i_see_the_check_and_confirm_page_for_injection
@@ -45,7 +45,7 @@
4545
and_there_are_nasal_and_injection_batches
4646

4747
when_i_go_to_the_nasal_only_patient
48-
then_i_see_the_vacciantion_form_for_nasal_spray
48+
then_i_see_the_vaccination_form_for_nasal_spray
4949

5050
when_i_record_that_the_patient_has_been_vaccinated_with_nasal_spray
5151
then_i_see_the_check_and_confirm_page_for_nasal_spray
@@ -124,14 +124,14 @@ def when_i_go_to_the_injection_only_patient
124124
click_link @patient.full_name
125125
end
126126

127-
def then_i_see_the_vacciantion_form_for_nasal_spray
127+
def then_i_see_the_vaccination_form_for_nasal_spray
128128
expect(page).to have_content("Record flu vaccination with nasal spray")
129129
expect(page).to have_content(
130130
"Is #{@patient.given_name} ready for their flu nasal spray?"
131131
)
132132
end
133133

134-
def then_i_see_the_vacciantion_form_for_injection
134+
def then_i_see_the_vaccination_form_for_injection
135135
expect(page).to have_content("Record flu vaccination with injection")
136136
expect(page).to have_content(
137137
"Is #{@patient.given_name} ready for their flu injection?"

spec/models/patient_session_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,68 @@
4040
end
4141
end
4242

43+
describe "scopes" do
44+
describe "#consent_given_and_ready_to_vaccinate" do
45+
subject(:scope) do
46+
described_class.consent_given_and_ready_to_vaccinate(
47+
programmes:,
48+
vaccine_method:
49+
)
50+
end
51+
52+
let(:programmes) { [create(:programme, :flu), create(:programme, :hpv)] }
53+
let(:vaccine_method) { nil }
54+
55+
it { should be_empty }
56+
57+
context "with a patient eligible for vaccination" do
58+
let(:patient_session) do
59+
create(
60+
:patient_session,
61+
:consent_given_triage_not_needed,
62+
programmes:
63+
)
64+
end
65+
66+
it { should include(patient_session) }
67+
end
68+
69+
context "when filtering on nasal spray" do
70+
let(:vaccine_method) { "nasal" }
71+
72+
context "with a patient eligible for vaccination" do
73+
let(:patient_session) do
74+
create(
75+
:patient_session,
76+
:consent_given_triage_not_needed,
77+
programmes:
78+
)
79+
end
80+
81+
before do
82+
patient_session
83+
.patient
84+
.consent_status(programme: programmes.first)
85+
.update!(vaccine_methods: %w[nasal injection])
86+
end
87+
88+
it { should include(patient_session) }
89+
90+
context "when the patient has been vaccinated for flu" do
91+
before do
92+
patient_session
93+
.patient
94+
.vaccination_status(programme: programmes.first)
95+
.vaccinated!
96+
end
97+
98+
it { should_not include(patient_session) }
99+
end
100+
end
101+
end
102+
end
103+
end
104+
43105
describe "#safe_to_destroy?" do
44106
subject(:safe_to_destroy?) { patient_session.safe_to_destroy? }
45107

0 commit comments

Comments
 (0)