@@ -4,6 +4,7 @@ class PatientSearchForm < SearchForm
44 attr_accessor :current_user
55 attr_writer :academic_year
66
7+ attribute :aged_out_of_programmes , :boolean
78 attribute :archived , :boolean
89 attribute :consent_statuses , array : true
910 attribute :date_of_birth_day , :integer
@@ -49,6 +50,7 @@ def programmes
4950 def apply ( scope )
5051 scope = filter_name ( scope )
5152 scope = filter_year_groups ( scope )
53+ scope = filter_aged_out_of_programmes ( scope )
5254 scope = filter_archived ( scope )
5355 scope = filter_date_of_birth_year ( scope )
5456 scope = filter_nhs_number ( scope )
@@ -82,6 +84,18 @@ def filter_year_groups(scope)
8284 end
8385 end
8486
87+ def filter_aged_out_of_programmes ( scope )
88+ if aged_out_of_programmes
89+ scope . not_appear_in_programmes ( team . programmes , academic_year :)
90+ elsif @session || archived
91+ scope
92+ else
93+ # Archived patients won't appear in programmes, so we need to
94+ # skip this check if we're trying to view archived patients.
95+ scope . appear_in_programmes ( team . programmes , academic_year :)
96+ end
97+ end
98+
8599 def filter_archived ( scope )
86100 if archived
87101 scope . archived ( team :)
0 commit comments