| Class | ClinicianController |
| In: |
app/controllers/clinician_controller.rb
|
| Parent: | ApplicationController |
This action displays a list of unbooked sessions (similar to bookings)
# File app/controllers/clinician_controller.rb, line 164
164: def available
165: begin
166: @clinician = Clinician.find(params[:id])
167: @clinical_sessions = []
168:
169: @clinician.clinical_sessions.each do |clinical_session|
170: @clinical_sessions << clinical_session unless clinical_session.start < Time.now.at_beginning_of_day || clinical_session.booked?
171: end
172:
173: @clinical_sessions = @clinical_sessions.sort_by { |clinical_session| clinical_session[:start] }
174: rescue
175: flash[:notice] = "Clinician not found!"
176: redirect_to :action => :list
177: end
178: end
Show all bookings for sessions with this clinician
Should this *PAGINATE?*
# File app/controllers/clinician_controller.rb, line 146
146: def bookings
147: begin
148: @clinician = Clinician.find(params[:id])
149: @clinical_sessions = []
150:
151: @clinician.clinical_sessions.each do |clinical_session|
152: @clinical_sessions << clinical_session if clinical_session.start > Time.now.at_beginning_of_day && !clinical_session.bookings.empty?
153: end
154:
155: @clinical_sessions = @clinical_sessions.sort_by { |clinical_session| clinical_session[:start] }
156: rescue
157: flash[:notice] = "Clinician not found!"
158: redirect_to :action => :list
159: end
160: end
Returns an iCalendar for the selected clinician.
Currently this action is not protected by security!
# File app/controllers/clinician_controller.rb, line 185
185: def calendar
186: @clinician = Clinician.find(params[:id])
187: @cal = Icalendar::Calendar.new
188:
189: @clinician.clinical_sessions.find(:all).each do |cs|
190: event = Icalendar::Event.new
191: event.start = cs.start.strftime("%Y%m%dT%H%M%S")
192: event.end = cs.finish.strftime("%Y%m%dT%H%M%S")
193:
194: if cs.max_bookings > 1 && !cs.bookings.empty?
195: event.summary = "Group Session - #{cs.session_type.name} (#{cs.bookings.size} clients)"
196: event.description = cs.bookings.map {|b| b.client.last_name }.join(". ")
197: elsif cs.max_bookings > 1 && cs.bookings.empty?
198: event.summary = "Group Session (no bookings) - #{cs.session_type.name}"
199: elsif cs.booked?
200: event.summary = "#{cs.session_type.name} - #{cs.bookings[0].client.full_name}"
201: event.description = cs.bookings[0].client.full_name
202: else
203: event.summary = "#{cs.session_type.name} Available"
204: end
205:
206: @cal.add event
207: end
208:
209: headers['Content-Type'] = "text/calendar; charset=UTF-8"
210: render_without_layout :text => @cal.to_ical
211: end
Gets posted Clinician from the new method
Redirect to previous page or to the clinician list
# File app/controllers/clinician_controller.rb, line 54
54: def create
55: if params[:cancel]
56: if !params[:referer] || params[:referer].match(/new/) || params[:referer].match(/create/)
57: redirect_to :action => :list
58: else
59: redirect_to params[:referer]
60: end
61: else
62: @clinician = Clinician.new(params[:clinician])
63: if @clinician.save
64: flash[:notice] = 'Clinician succesfully created.'
65: redirect_to :action => :index
66: else
67: # unable to create Clinician
68: @disciplines = Discipline.find_all
69: render :action => :new
70: end
71: end
72: end
Delete clinician
This will delete all sessions for this clinician
Redirect to previous page or to the clinician list
# File app/controllers/clinician_controller.rb, line 111
111: def destroy
112: begin
113: @clinician = Clinician.find(params[:id])
114: @clinician.destroy
115: flash[:notice] = 'Clinician succesfully deleted.'
116: rescue
117: flash[:notice] = "Unable to delete: Clinician not found!"
118: end
119:
120: if request.env['HTTP_REFERER'].match(/clinician\/[a-zA-Z]*\/[0-9]*$/)
121: redirect_to :action => :list
122: else
123: redirect_to :back
124: end
125: end
Edit an exisiting Clinician
Sends form to the update method
# File app/controllers/clinician_controller.rb, line 27
27: def edit
28: begin
29: @clinician = Clinician.find(@params["id"])
30: @disciplines = Discipline.find_all
31: rescue
32: flash[:notice] = "Clinician not found!"
33: redirect_to :action => :list
34: end
35: end
The default action is to display the Clinician list.
# File app/controllers/clinician_controller.rb, line 12
12: def index
13: if !(@disciplines = Discipline.find(:all))
14: flash[:notice] = 'Please add a discipline'
15: redirect_to :controller => 'discipline', :action => 'new'
16: elsif !Clinician.find(:first)
17: flash[:notice] = 'Please add a clinician'
18: redirect_to :action => :new
19: else
20: render :action => :list
21: end
22: end
Display all Clinicians
# File app/controllers/clinician_controller.rb, line 128
128: def list
129: @disciplines = Discipline.find(:all)
130: end
Sends form to the create method
# File app/controllers/clinician_controller.rb, line 40
40: def new
41: if (@disciplines = Discipline.find(:all)).empty?
42: flash[:notice] = 'Please add a discipline'
43: redirect_to :controller => 'discipline',
44: :action => 'new'
45: else
46: @clinician = Clinician.new
47: @clinician.discipline = Discipline.find(params[:discipline_id]) if params[:discipline_id]
48: end
49: end
Show list of clients and details about this clinician
# File app/controllers/clinician_controller.rb, line 134
134: def show
135: begin
136: @clinician = Clinician.find(params[:id])
137: rescue
138: flash[:notice] = "Clinician not found!"
139: redirect_to :action => :list
140: end
141: end
Gets posted Clinician from the edit method
Redirect to previous page or to the clinician list
# File app/controllers/clinician_controller.rb, line 77
77: def update
78: if params[:cancel]
79: if !params[:referer] || params[:referer].match(/edit/) || params[:referer].match(/update/)
80: redirect_to :action => :show, :id => params[:id]
81: else
82: redirect_to params[:referer]
83: end
84: else
85: begin
86: @clinician = Clinician.find(params[:id])
87: if @clinician.update_attributes(params[:clinician])
88: flash[:notice] = 'Clinician succesfully updated.'
89: if !params[:referer] || params[:referer].match(/edit/) || params[:referer].match(/update/)
90: redirect_to :action => :show, :id => params[:id]
91: else
92: redirect_to params[:referer]
93: end
94: else
95: # unable to update Clinician
96: @disciplines = Discipline.find_all
97: render :action => :edit
98: end
99: rescue
100: flash[:notice] = "Unable to Update: Clinician not found!"
101: redirect_to :action => :list
102: end
103: end
104: end