File tree Expand file tree Collapse file tree 5 files changed +40
-71
lines changed Expand file tree Collapse file tree 5 files changed +40
-71
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,19 @@ def ready_for_vaccinator_row
119
119
120
120
counts_by_programme =
121
121
session . programmes . index_with do |programme |
122
- patient_sessions . count { it . ready_for_vaccinator? ( programme :) }
122
+ patient_sessions
123
+ . where (
124
+ PatientSession ::RegistrationStatus
125
+ . for_patient_session
126
+ . where ( status : %w[ attending completed ] )
127
+ . arel
128
+ . exists
129
+ )
130
+ . count do |patient_session |
131
+ patient_session . patient . consent_given_and_safe_to_vaccinate? (
132
+ programme :
133
+ )
134
+ end
123
135
end
124
136
125
137
return nil if counts_by_programme . values . all? ( &:zero? )
Original file line number Diff line number Diff line change @@ -16,20 +16,30 @@ class Sessions::RecordController < ApplicationController
16
16
17
17
def show
18
18
scope =
19
- @session . patient_sessions . preload_for_status . in_programmes (
20
- @session . programmes
21
- )
19
+ @session
20
+ . patient_sessions
21
+ . preload_for_status
22
+ . in_programmes ( @session . programmes )
23
+ . where (
24
+ PatientSession ::RegistrationStatus
25
+ . for_patient_session
26
+ . where ( status : %w[ attending completed ] )
27
+ . arel
28
+ . exists
29
+ )
30
+
31
+ scope = @form . apply ( scope )
22
32
23
33
patient_sessions =
24
- @form . apply ( scope ) do |filtered_scope |
25
- filtered_scope . select { it . ready_for_vaccinator? }
34
+ scope . select do |patient_session |
35
+ patient_session . programmes . any? do |programme |
36
+ patient_session . patient . consent_given_and_safe_to_vaccinate? (
37
+ programme :
38
+ )
39
+ end
26
40
end
27
41
28
- if patient_sessions . is_a? ( Array )
29
- @pagy , @patient_sessions = pagy_array ( patient_sessions )
30
- else
31
- @pagy , @patient_sessions = pagy ( patient_sessions )
32
- end
42
+ @pagy , @patient_sessions = pagy_array ( patient_sessions )
33
43
34
44
render layout : "full"
35
45
end
Original file line number Diff line number Diff line change @@ -40,10 +40,6 @@ def apply(scope, programme: nil)
40
40
41
41
scope = scope . search_by_nhs_number ( nil ) if missing_nhs_number . present?
42
42
43
- scope = scope . order_by_name
44
-
45
- scope = yield ( scope ) if block_given?
46
-
47
43
if ( status = consent_status ) . present?
48
44
scope =
49
45
scope . where (
@@ -91,6 +87,6 @@ def apply(scope, programme: nil)
91
87
)
92
88
end
93
89
94
- scope
90
+ scope . order_by_name
95
91
end
96
92
end
Original file line number Diff line number Diff line change @@ -148,19 +148,6 @@ def todays_attendance
148
148
end
149
149
end
150
150
151
- def ready_for_vaccinator? ( programme : nil )
152
- if registration_status . nil? || registration_status . unknown? ||
153
- registration_status . not_attending?
154
- return false
155
- end
156
-
157
- programmes_to_check = programme ? [ programme ] : programmes
158
-
159
- programmes_to_check . any? do
160
- patient . consent_given_and_safe_to_vaccinate? ( programme : it )
161
- end
162
- end
163
-
164
151
def next_activity ( programme :)
165
152
return :report if patient . vaccination_status ( programme :) . vaccinated?
166
153
@@ -176,6 +163,11 @@ def next_activity(programme:)
176
163
end
177
164
178
165
def outstanding_programmes
166
+ if registration_status . nil? || registration_status . unknown? ||
167
+ registration_status . not_attending?
168
+ return [ ]
169
+ end
170
+
179
171
# If this patient hasn't been seen yet by a nurse for any of the programmes,
180
172
# we don't want to show the banner.
181
173
all_programmes_none_yet =
@@ -185,7 +177,7 @@ def outstanding_programmes
185
177
186
178
programmes . select do |programme |
187
179
vaccination_status ( programme :) . none_yet? &&
188
- ready_for_vaccinator ?( programme :)
180
+ patient . consent_given_and_safe_to_vaccinate ?( programme :)
189
181
end
190
182
end
191
183
end
Original file line number Diff line number Diff line change 69
69
end
70
70
end
71
71
72
- describe "#ready_for_vaccinator?" do
73
- subject ( :ready_for_vaccinator? ) { patient_session . ready_for_vaccinator? }
74
-
75
- it { should be ( false ) }
76
-
77
- context "when attending the session" do
78
- let ( :patient_session ) do
79
- create ( :patient_session , :in_attendance , session :)
80
- end
81
-
82
- it { should be ( false ) }
83
- end
84
-
85
- context "when attending the session and consent given and triaged as safe to vaccinate" do
86
- let ( :patient_session ) do
87
- create (
88
- :patient_session ,
89
- :in_attendance ,
90
- :consent_given_triage_not_needed ,
91
- session :
92
- )
93
- end
94
-
95
- it { should be ( true ) }
96
-
97
- context "when already vaccinated" do
98
- let ( :patient_session ) do
99
- create (
100
- :patient_session ,
101
- :in_attendance ,
102
- :consent_given_triage_not_needed ,
103
- :vaccinated ,
104
- session :
105
- )
106
- end
107
-
108
- it { should be ( false ) }
109
- end
110
- end
111
- end
112
-
113
72
describe "#next_activity" do
114
73
subject { patient_session . next_activity ( programme :) }
115
74
You can’t perform that action at this time.
0 commit comments