File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -93,26 +93,28 @@ class PatientSession < ApplicationRecord
93
93
94
94
scope :appear_in_programmes ,
95
95
-> ( programmes ) do
96
+ # Are any of the programmes administered in the session?
97
+ programme_in_session =
98
+ SessionProgramme
99
+ . where ( programme : programmes )
100
+ . where ( "session_programmes.session_id = sessions.id" )
101
+ . arel
102
+ . exists
103
+
96
104
# Is the patient eligible for any of those programmes by year group?
97
- location_programme_year_groups =
105
+ patient_in_administered_year_groups =
98
106
LocationProgrammeYearGroup
99
- . where ( "programme_id = session_programmes.programme_id" )
107
+ . where ( programme : programmes )
100
108
. where ( "location_id = sessions.location_id" )
101
109
. where (
102
110
"year_group = sessions.academic_year " \
103
111
"- patients.birth_academic_year " \
104
112
"- #{ Integer ::AGE_CHILDREN_START_SCHOOL } "
105
113
)
106
-
107
- # Are any of the programmes administered in the session?
108
- where (
109
- SessionProgramme
110
- . where ( programme : programmes )
111
- . where ( "session_programmes.session_id = sessions.id" )
112
- . where ( location_programme_year_groups . arel . exists )
113
114
. arel
114
115
. exists
115
- )
116
+
117
+ where ( programme_in_session ) . where ( patient_in_administered_year_groups )
116
118
end
117
119
118
120
scope :search_by_name ,
You can’t perform that action at this time.
0 commit comments