| Class | CalendarController |
| In: |
app/controllers/calendar_controller.rb
|
| Parent: | ApplicationController |
The main controller allowing an overview of all sessions and bookings by presenting them in a calendar format. Currently only displays in week format (7 days), but this _may_ be expanded in the future.
This action is a redirector to allow a route that selects clinician by full name.
Usage
/2006-10-4/swift, jarrod
would map to the calendar for October 4, 2006 showing clinician named jarrod swift. If no Clinician matches this name, it will just be the first clinician.
# File app/controllers/calendar_controller.rb, line 155
155: def clinician_schedule
156: id = if clinician = Clinician.find_by_full_name(params[:full_name])
157: clinician.id
158: else
159: Clinician.find(:first).id
160: end
161:
162: redirect_to :action => :week, :date => params[:date], :clinician => id
163: end
Control the week displayed
# File app/controllers/calendar_controller.rb, line 117
117: def date_picker
118: # Filter
119: @filter = @params["show"] || "all"
120:
121: # Get selected date
122: @selected_date = @params["selected_date"]
123: @date = @params["date"] || Time.now.at_beginning_of_week.yesterday.strftime("%Y-%m-%d")
124:
125: month_begins = @date.to_time.at_beginning_of_month
126: if month_begins.tomorrow == month_begins.tomorrow.at_beginning_of_week
127: @date = month_begins.tomorrow.strftime("%Y-%m-%d")
128: else
129: @date = month_begins
130: end
131:
132:
133: # Get selected clinician
134: @selected_clinician = @params["clinician"] || Clinician.find(:first).id
135: @selected_clinician = Clinician.find(@selected_clinician)
136:
137: # Get list of all clinicians
138: @clinicians = Clinician.find(:all, :conditions => "discipline_id = #{@selected_clinician.discipline.id}")
139:
140: #generate hash
141: @display = {:date => @date,
142: :clinician => @selected_clinician,
143: :clinicians => @clinicians,
144: :show => @filter}
145: end
The default display of the calendar controller is the week action
This action is not currently used as the routing directly loads the week action.
# File app/controllers/calendar_controller.rb, line 14
14: def index
15: if Clinician.find(:first)
16: redirect_to :action => 'week'
17: else
18: flash[:notice] = 'Please add a clinician'
19: redirect_to :controller => 'clinician', :action => 'new'
20: end
21: end
Creates a list of clinicians for the selected discipline
# File app/controllers/calendar_controller.rb, line 95
95: def list_clinicians
96: @clinicians = Clinician.find(:all, :conditions => "discipline_id = #{params[:discipline]}")
97:
98: # Filter
99: @filter = @params["show"] || "all"
100:
101: # Set date to display (this needs to be added to the links
102: # to ensure the consistency of operation
103: @date = @params["date"] || Time.now.at_beginning_of_week.yesterday.strftime("%Y-%m-%d")
104:
105: # Set the selected clinician
106: @selected_clinician = @params["clinician"] || Clinician.find(:first).id
107: @selected_clinician = Clinician.find(@selected_clinician)
108:
109: # Generate hash object to pass to partial
110: @display = {:date => @date,
111: :clinician => @selected_clinician,
112: :clinicians => @clinicians,
113: :show => @filter}
114: end
Display a week view of sessions. This view shows all the sessions for a single Clinician over a week. Most day to day actions can be performed from here.
Clicking on a blank space in the calendar will begin the process of creating a new ClinicalSession for the selected Clinician at the selected time.
# File app/controllers/calendar_controller.rb, line 31
31: def week
32: if first_clinician = Clinician.find(:first)
33: # Check to see if a particular clinical session has been requested,
34: # otherwise show this week
35: if params[:clinical_session]
36: clinical_session = ClinicalSession.find(params[:clinical_session])
37: end
38:
39: # Get list of all disciplines
40: @disciplines = Discipline.find(:all)
41:
42: # Get date to show
43: if clinical_session
44: @date = clinical_session.start.strftime("%Y-%m-%d")
45: else
46: @date = @params["date"] || Time.now.strftime("%Y-%m-%d")
47: end
48: @date = @date.to_time
49:
50: @date = if @date.tomorrow.at_beginning_of_week == @date.at_beginning_of_week
51: @date.at_beginning_of_week.yesterday.strftime("%Y-%m-%d")
52: else
53: @date.strftime("%Y-%m-%d")
54: end
55:
56: # Get clinician to display (and their discipline)
57: if clinical_session
58: @clinician = clinical_session.clinician
59: c_id = @clinician.id
60: @discipline = @clinician.discipline
61: else
62: c_id = @params["clinician"] || first_clinician.id
63: @clinician = Clinician.find(c_id)
64: @discipline = @clinician.discipline
65: end
66:
67: # Get list of all clinicians
68: @clinicians = Clinician.find(:all, :conditions => "discipline_id = #{@discipline.id}")
69:
70: # Get list of clinical sessions for this week
71: week_start = @date.to_time
72: @clinical_sessions =[]
73:
74: for i in 0..6
75: @clinical_sessions[i] = ClinicalSession.find(:all,
76: :conditions => "clinician_id = #{c_id} AND start > '#{week_start.advance(:days => i).to_s(:db)}' AND start < '#{week_start.advance(:days => i+1).to_s(:db)}'")
77: end
78:
79: # Filter
80: @filter = @params["show"] || "all"
81:
82: # Generate hash object to pass to partials
83: @display = {:date => @date,
84: :clinician => @clinician,
85: :clinicians => @clinicians,
86: :clinical_sessions => @clinical_sessions,
87: :show => @filter}
88: else
89: flash[:notice] = 'Please add a clinician'
90: redirect_to :controller => 'clinician', :action => 'new'
91: end
92: end