| Class | Client |
| In: |
app/models/client.rb
|
| Parent: | ActiveRecord::Base |
A client can make a Booking to see a Clinician. Currently there is only a small amount of information in the Client object. This is likely to be expanded.
Clients are mainly controlled through the ClientController
Finds a client record from a string either in format: name (record number) OR record_number
# File app/models/client.rb, line 40
40: def Client.find_by_full_name(client_name)
41: # Try to extract record number
42: if client_record_number = /\((.)*\)/.match(client_name).to_s
43: client_record_number = client_record_number.to_s[1, client_record_number.length-2]
44: end
45:
46: # If can't find client, try using whole string as record_number
47: if !client = Client.find_by_record_number(client_record_number)
48: client = Client.find_by_record_number(client_name)
49: end
50:
51: return client
52: end
Method to determine whether a particular client has and bookings. Returns true if there is at least one either past or future.
Usage
clients_with_bookings << client if client.has_bookings?
# File app/models/client.rb, line 60
60: def has_bookings?
61: has_bookings = false
62: self.bookings.each do |b|
63: has_bookings = true
64: end
65: return has_bookings
66: end
Method to determine whether a client is booked during a time period. Optionally takes a param to ignore a specific session
Usage
make_booking unless client.is_booked?(session.start, session.finish)
# File app/models/client.rb, line 74
74: def is_booked?(start, finish, ignore_session = 0)
75: isbooked = false
76:
77: if cs = ClinicalSession.find(:all, :conditions => "start <= '#{start.to_s(:db)}' AND '#{start.to_s(:db)}' < finish AND id <> #{ignore_session}")
78: cs.each do | session |
79: if session.booked?
80: isbooked = true if session.client_booked_in?(self)
81: end
82: end
83: end
84:
85: if cs = ClinicalSession.find(:all, :conditions => "start < '#{finish.to_s(:db)}' AND '#{finish.to_s(:db)}' <= finish AND id <> #{ignore_session}")
86: cs.each do | session |
87: if session.booked?
88: isbooked = true if session.client_booked_in?(self)
89: end
90: end
91: end
92:
93: # Test for (1)
94: if cs = ClinicalSession.find(:all, :conditions => "start > '#{start.to_s(:db)} ' AND '#{finish.to_s(:db)}' > finish AND id <> #{ignore_session}")
95: cs.each do | session |
96: if session.booked?
97: isbooked = true if session.client_booked_in?(self)
98: end
99: end
100: end
101:
102: return isbooked
103: end