22
33class SchoolsController < ApplicationController
44 include LocationSearchFormConcern
5- include PatientSearchFormConcern
65
7- before_action :set_location_search_form , only : :index
8- before_action :set_location , except : :index
9- before_action :set_programme_statuses ,
10- :set_patient_search_form ,
11- only : :patients
6+ before_action :set_location_search_form
127
138 layout "full"
149
@@ -25,7 +20,12 @@ def index
2520 @patient_count_by_school_id =
2621 Patient
2722 . joins ( :patient_locations )
28- . where ( patient_locations : { location : @locations , academic_year : } )
23+ . where (
24+ patient_locations : {
25+ location : @locations ,
26+ academic_year : AcademicYear . pending
27+ }
28+ )
2929 . distinct
3030 . group ( :school_id )
3131 . count
@@ -37,84 +37,5 @@ def index
3737 . group ( "team_location.location_id" )
3838 . where ( "date >= ?" , Date . current )
3939 . minimum ( :date )
40-
41- render layout : "full"
42- end
43-
44- def import
45- draft_import = DraftImport . new ( request_session : session , current_user :)
46-
47- draft_import . clear_attributes
48- draft_import . update! ( location : @location , type : "class" )
49-
50- steps = draft_import . wizard_steps
51- steps . delete ( :type )
52- steps . delete ( :location )
53-
54- redirect_to draft_import_path ( I18n . t ( steps . first , scope : :wicked ) )
55- end
56-
57- def patients
58- scope =
59- Patient
60- . joins ( :patient_locations )
61- . where ( patient_locations : { location : @location , academic_year : } )
62- . where ( school_id : @location . school_id )
63- . includes_statuses
64- . includes ( :clinic_notifications )
65-
66- patients = @form . apply ( scope )
67-
68- @pagy , @patients = pagy ( patients )
69- end
70-
71- def sessions
72- sessions =
73- policy_scope ( Session ) . for_academic_year ( academic_year ) . for_location (
74- @location
75- )
76-
77- @patient_count_by_session_id =
78- Patient
79- . joins_sessions
80- . joins_session_programme_year_groups
81- . where ( "sessions.id = ANY(ARRAY[?]::bigint[])" , sessions . pluck ( :id ) )
82- . group ( "sessions.id" )
83- . count ( "DISTINCT patients.id" )
84-
85- @unscheduled_sessions = sessions . unscheduled
86- @scheduled_sessions = sessions . scheduled
87- @completed_sessions = sessions . completed
88- end
89-
90- private
91-
92- def academic_year = AcademicYear . pending
93-
94- def set_location
95- urn_and_site = params [ :school_urn_and_site ]
96-
97- @location =
98- if urn_and_site . in? ( [ Location ::URN_UNKNOWN , Location ::URN_HOME_EDUCATED ] )
99- policy_scope ( Location ) . generic_clinic . sole
100- else
101- policy_scope ( Location ) . school . find_by_urn_and_site! (
102- params [ :school_urn_and_site ]
103- )
104- end
105-
106- authorize @location , policy_class : SchoolPolicy
107- end
108-
109- def set_programme_statuses
110- @programme_statuses =
111- Patient ::ProgrammeStatus . statuses . keys -
112- %w[
113- not_eligible
114- needs_consent_request_not_scheduled
115- needs_consent_request_scheduled
116- needs_consent_request_failed
117- needs_consent_follow_up_requested
118- ]
11940 end
12041end
0 commit comments