Class Clinician
In: app/models/clinician.rb
Parent: ActiveRecord::Base

Clinician

A clinician may have ClinicalSessions to see Clients. Each ClinicalSession is for only 1 Client.

Clinicians are controlled through the ClinicianController

Rules

  • A clinician belongs to a Discipline
  • A clinician must have a first_name
  • A clinician must have a last_name
  • A clinician may have many ClinicalSessions
  • A clinician must have a valid email address (as the feature may be used as a contact point in future versions)
  • Clinician names may only consist of letters, numbers and spaces
  • A phone number may only consist of numbers, brackets and spaces

Methods

Public Class methods

Class method Returns clinician if clinician can be found matching last_name, first_name

Usage

  clinician = Clinician.find_by_full_name( fn )

Note: This is a class method, not an instance method.

[Source]

     # File app/models/clinician.rb, line 126
126:   def Clinician.find_by_full_name( fullname )
127:     names = fullname.scan(/\w+/)
128: 
129:     if clinician = Clinician.find(:first, 
130:                     :conditions => "last_name = '#{names[0]}' AND first_name = '#{names[1]}'")
131:       return clinician
132:     else
133:       return false
134:     end
135:   end

Public Instance methods

Returns a list of Clients who have booked to see sessions owned by this clinician.

Usage

  my_clients = clinician.clients

[Source]

     # File app/models/clinician.rb, line 102
102:   def clients
103:     client_list = []
104:     client_ids  = []  # This is to ensure unique list
105: 
106:     self.clinical_sessions.each do |clinical_session|
107:       clinical_session.bookings.each do |booking|
108:         unless client_ids.include?( booking.client.id )
109:           client_ids  << booking.client.id
110:           client_list << booking.client
111:         end
112:       end
113:     end
114:     
115:     return client_list
116:   end

Returns the full name of the clinician in the form last_name, first_name

Usage

  clinician_name = clinician.full_name

[Source]

    # File app/models/clinician.rb, line 93
93:   def full_name
94:     return "#{self.last_name}, #{self.first_name}"
95:   end

Checks to see if a clinician has bookings on a particular date. Similar to is_available? . Returns true if there is at least one booking on the given date.

Usage

    display_booked if clinician.has_bookings?("2006-05-05 12:55:00".to_time)

[Source]

    # File app/models/clinician.rb, line 55
55:   def has_bookings? (date)
56:     hasBooking = false
57:     
58:     if cs = ClinicalSession.find(:all,
59:                                  :conditions => "clinician_id = #{self.id} AND start > '#{date.at_beginning_of_day.to_s(:db)}' AND start < '#{date.tomorrow.at_beginning_of_day.to_s(:db)}'")
60:       cs.each do |clinical_session|
61:         hasBooking = !clinical_session.bookings.empty?
62:       end
63:     end
64:      
65:     return hasBooking
66:   end

Checks whether the clinician has available (unbooked) sessions on a given day (as time). Returns false if there are none, true if there are.

Usage:

    display_available if clinician.is_available?("2006-05-05 12:55:00".to_time)

[Source]

    # File app/models/clinician.rb, line 37
37:   def is_available? (date)
38:     isAvailable = false
39:     if cs = ClinicalSession.find(:all,
40:                                  :conditions => "clinician_id = #{self.id} AND start > '#{date.at_beginning_of_day.to_s(:db)}' AND start < '#{date.tomorrow.at_beginning_of_day.to_s(:db)}'")
41:       cs.each do |clinical_session|
42:         isAvailable = true if !clinical_session.booked?
43:       end
44:     end
45:     
46:     return isAvailable
47:   end

Returns (first) ClinicalSession that occurs during specified start and finish times. Will return null if there is none.

Usage

  clash = clinician.session_during(new_session.start, new_session.finish)

[Source]

    # File app/models/clinician.rb, line 83
83:   def session_during( start, finish )
84:     return ClinicalSession.find(:first, 
85:             :conditions => "clinician_id = #{self.id} AND start < '#{finish.to_s(:db)}' AND finish > '#{start.to_s(:db)}'")
86:   end

Returns ClinicalSession array for a specific day

Usage

   today = clinician.sessions_for( Time.now )

[Source]

    # File app/models/clinician.rb, line 72
72:   def sessions_for( date )
73:     sessions = ClinicalSession.find(:all,
74:                   :conditions => "clinician_id = #{self.id} AND start > '#{date.at_beginning_of_day.to_s(:db)}' AND start < '#{date.tomorrow.at_beginning_of_day.to_s(:db)}'")
75:   end

[Validate]