@@ -19,9 +19,7 @@ def render? = rows.any?
19
19
delegate :govuk_summary_list , to : :helpers
20
20
delegate :academic_year , :programmes , to : :session
21
21
22
- def patient_locations
23
- session . patient_locations . joins ( :patient ) . appear_in_programmes ( programmes )
24
- end
22
+ def patients = session . patients
25
23
26
24
def rows
27
25
@rows ||= [
@@ -35,7 +33,7 @@ def rows
35
33
end
36
34
37
35
def no_nhs_number_row
38
- count = patient_locations . merge ( Patient . without_nhs_number ) . count
36
+ count = patients . without_nhs_number . count
39
37
href = session_patients_path ( session , missing_nhs_number : true )
40
38
41
39
generate_row ( :children_without_nhs_number , count :, href :)
@@ -44,7 +42,11 @@ def no_nhs_number_row
44
42
def no_consent_response_row
45
43
status = "no_response"
46
44
count =
47
- patient_locations . has_consent_status ( status , programme : programmes ) . count
45
+ patients . has_consent_status (
46
+ status ,
47
+ programme : programmes ,
48
+ academic_year :
49
+ ) . count
48
50
href = session_consent_path ( session , consent_statuses : [ status ] )
49
51
actions = [
50
52
{
@@ -58,7 +60,11 @@ def no_consent_response_row
58
60
def conflicting_consent_row
59
61
status = "conflicts"
60
62
count =
61
- patient_locations . has_consent_status ( status , programme : programmes ) . count
63
+ patients . has_consent_status (
64
+ status ,
65
+ programme : programmes ,
66
+ academic_year :
67
+ ) . count
62
68
href = session_consent_path ( session , consent_statuses : [ status ] )
63
69
64
70
generate_row ( :children_with_conflicting_consent_response , count :, href :)
@@ -67,7 +73,11 @@ def conflicting_consent_row
67
73
def triage_required_row
68
74
status = "required"
69
75
count =
70
- patient_locations . has_triage_status ( status , programme : programmes ) . count
76
+ patients . has_triage_status (
77
+ status ,
78
+ programme : programmes ,
79
+ academic_year :
80
+ ) . count
71
81
href = session_triage_path ( session , triage_status : status )
72
82
73
83
generate_row ( :children_requiring_triage , count :, href :)
@@ -77,7 +87,7 @@ def register_attendance_row
77
87
return nil unless session . requires_registration? && session . today?
78
88
79
89
status = "unknown"
80
- count = patient_locations . has_registration_status ( status , session :) . count
90
+ count = patients . has_registration_status ( status , session :) . count
81
91
href = session_register_path ( session , register_status : status )
82
92
83
93
generate_row ( :children_to_register , count :, href :)
@@ -88,13 +98,11 @@ def ready_for_vaccinator_row
88
98
89
99
counts_by_programme =
90
100
session . programmes . index_with do |programme |
91
- patient_locations
101
+ patients
92
102
. has_registration_status ( %w[ attending completed ] , session :)
93
- . includes (
94
- patient : %i[ consent_statuses triage_statuses vaccination_statuses ]
95
- )
96
- . count do |patient_location |
97
- patient_location . patient . consent_given_and_safe_to_vaccinate? (
103
+ . includes ( :consent_statuses , :triage_statuses , :vaccination_statuses )
104
+ . count do |patient |
105
+ patient . consent_given_and_safe_to_vaccinate? (
98
106
programme :,
99
107
academic_year :
100
108
)
0 commit comments