@@ -19,12 +19,7 @@ def render? = rows.any?
1919 delegate :govuk_summary_list , to : :helpers
2020 delegate :academic_year , :programmes , to : :session
2121
22- def patient_sessions
23- session
24- . patient_sessions
25- . joins ( :patient , :session )
26- . appear_in_programmes ( programmes )
27- end
22+ def patients = session . patients
2823
2924 def rows
3025 @rows ||= [
@@ -38,16 +33,15 @@ def rows
3833 end
3934
4035 def no_nhs_number_row
41- count = patient_sessions . merge ( Patient . without_nhs_number ) . count
36+ count = patients . without_nhs_number . count
4237 href = session_patients_path ( session , missing_nhs_number : true )
4338
4439 generate_row ( :children_without_nhs_number , count :, href :)
4540 end
4641
4742 def no_consent_response_row
4843 status = "no_response"
49- count =
50- patient_sessions . has_consent_status ( status , programme : programmes ) . count
44+ count = session . patients_with_no_consent_response_count
5145 href = session_consent_path ( session , consent_statuses : [ status ] )
5246 actions = [
5347 {
@@ -61,7 +55,11 @@ def no_consent_response_row
6155 def conflicting_consent_row
6256 status = "conflicts"
6357 count =
64- patient_sessions . has_consent_status ( status , programme : programmes ) . count
58+ patients . has_consent_status (
59+ status ,
60+ programme : programmes ,
61+ academic_year :
62+ ) . count
6563 href = session_consent_path ( session , consent_statuses : [ status ] )
6664
6765 generate_row ( :children_with_conflicting_consent_response , count :, href :)
@@ -70,7 +68,11 @@ def conflicting_consent_row
7068 def triage_required_row
7169 status = "required"
7270 count =
73- patient_sessions . has_triage_status ( status , programme : programmes ) . count
71+ patients . has_triage_status (
72+ status ,
73+ programme : programmes ,
74+ academic_year :
75+ ) . count
7476 href = session_triage_path ( session , triage_status : status )
7577
7678 generate_row ( :children_requiring_triage , count :, href :)
@@ -80,7 +82,7 @@ def register_attendance_row
8082 return nil unless session . requires_registration? && session . today?
8183
8284 status = "unknown"
83- count = patient_sessions . has_registration_status ( status ) . count
85+ count = patients . has_registration_status ( status , session : ) . count
8486 href = session_register_path ( session , register_status : status )
8587
8688 generate_row ( :children_to_register , count :, href :)
@@ -91,13 +93,11 @@ def ready_for_vaccinator_row
9193
9294 counts_by_programme =
9395 session . programmes . index_with do |programme |
94- patient_sessions
95- . has_registration_status ( %w[ attending completed ] )
96- . includes (
97- patient : %i[ consent_statuses triage_statuses vaccination_statuses ]
98- )
99- . count do |patient_session |
100- patient_session . patient . consent_given_and_safe_to_vaccinate? (
96+ patients
97+ . has_registration_status ( %w[ attending completed ] , session :)
98+ . includes ( :consent_statuses , :triage_statuses , :vaccination_statuses )
99+ . count do |patient |
100+ patient . consent_given_and_safe_to_vaccinate? (
101101 programme :,
102102 academic_year :
103103 )
0 commit comments