@@ -8,6 +8,7 @@ class PatientSearchForm < SearchForm
88 attribute :date_of_birth_day , :integer
99 attribute :date_of_birth_month , :integer
1010 attribute :date_of_birth_year , :integer
11+ attribute :invited_to_clinic , :boolean
1112 attribute :missing_nhs_number , :boolean
1213 attribute :patient_specific_direction_status , :string
1314 attribute :programme_status_group , :string
@@ -50,17 +51,18 @@ def programmes
5051 end
5152
5253 def apply ( scope )
53- scope = filter_name ( scope )
54- scope = filter_year_groups ( scope )
5554 scope = filter_aged_out_of_programmes ( scope )
5655 scope = filter_archived ( scope )
5756 scope = filter_date_of_birth_year ( scope )
57+ scope = filter_invited_to_clinic ( scope )
58+ scope = filter_name ( scope )
5859 scope = filter_nhs_number ( scope )
60+ scope = filter_patient_specific_direction_status ( scope )
61+ scope = filter_programme_statuses ( scope )
5962 scope = filter_programmes ( scope )
6063 scope = filter_registration_status ( scope )
61- scope = filter_programme_statuses ( scope )
6264 scope = filter_vaccine_criteria ( scope )
63- scope = filter_patient_specific_direction_status ( scope )
65+ scope = filter_year_groups ( scope )
6466
6567 scope . order_by_name
6668 end
@@ -79,18 +81,6 @@ def academic_year
7981
8082 def team = session &.team || current_user . selected_team
8183
82- def filter_name ( scope )
83- q . present? ? scope . search_by_name_or_nhs_number ( q ) : scope
84- end
85-
86- def filter_year_groups ( scope )
87- if year_groups . present?
88- scope . search_by_year_groups ( year_groups , academic_year :)
89- else
90- scope
91- end
92- end
93-
9484 def filter_aged_out_of_programmes ( scope )
9585 return scope if team . has_national_reporting_access?
9686
@@ -133,22 +123,22 @@ def filter_date_of_birth_year(scope)
133123 scope
134124 end
135125
136- def filter_nhs_number ( scope )
137- missing_nhs_number . present? ? scope . search_by_nhs_number ( nil ) : scope
138- end
139-
140- def filter_programmes ( scope )
141- if programme_types . present?
142- if session
143- scope . appear_in_programmes ( programmes , session :)
144- else
145- scope . appear_in_programmes ( programmes , academic_year :)
146- end
126+ def filter_invited_to_clinic ( scope )
127+ if invited_to_clinic
128+ scope . has_clinic_notification ( team :, academic_year :, programmes :)
147129 else
148130 scope
149131 end
150132 end
151133
134+ def filter_name ( scope )
135+ q . present? ? scope . search_by_name_or_nhs_number ( q ) : scope
136+ end
137+
138+ def filter_nhs_number ( scope )
139+ missing_nhs_number . present? ? scope . search_by_nhs_number ( nil ) : scope
140+ end
141+
152142 def filter_patient_specific_direction_status ( scope )
153143 return scope if ( status = patient_specific_direction_status &.to_sym ) . blank?
154144
@@ -208,6 +198,18 @@ def filter_programme_statuses(scope)
208198 or_scope
209199 end
210200
201+ def filter_programmes ( scope )
202+ if programme_types . present?
203+ if session
204+ scope . appear_in_programmes ( programmes , session :)
205+ else
206+ scope . appear_in_programmes ( programmes , academic_year :)
207+ end
208+ else
209+ scope
210+ end
211+ end
212+
211213 def filter_registration_status ( scope )
212214 if ( status = registration_status &.to_sym ) . present?
213215 scope . has_registration_status ( status , session :)
@@ -246,4 +248,12 @@ def filter_vaccine_criteria(scope)
246248
247249 or_scope
248250 end
251+
252+ def filter_year_groups ( scope )
253+ if year_groups . present?
254+ scope . search_by_year_groups ( year_groups , academic_year :)
255+ else
256+ scope
257+ end
258+ end
249259end
0 commit comments