Class Booking
In: app/models/booking.rb
Parent: ActiveRecord::Base

Booking

A booking for a client to see a Clinician in a specified ClinicalSession.

Bookings are controlled mainly through the SessionController

Rules

  • Each booking is for one ClinicalSession
  • Each booking belongs to one Client
  • A single client cannot have bookings that occur same time
  • A single session can have only 1 booking

Methods

validate  

Protected Instance methods

Additional Validation

Checks for clashes with existing bookings.

There are three types of possible clashes:

  1. Internal Conflict - Where an existing booked session is entirely inside the new booked session
  2. Start Time Conflict - Where the start time is inside a new booked session
  3. Finish Time Conflict - Where the finish time is inside a new booked session

If both 2 and 3 occur, the new booked session occurs entirely within a booked session. This is an external conflict.

Special Case Exemption

A booking may finish at the exact same time as another starts.

[Source]

    # File app/models/booking.rb, line 31
31:   def validate
32:     if clinical_session and client
33:       #Check to see if this session is already booked
34:       errors.add :clinical_session, "is already booked" if clinical_session.booked?
35:       
36:       errors.add :clinical_session, "is invalid. Client is already booked at this time" if client.is_booked?(clinical_session.start, clinical_session.finish)
37:       errors.add :clinical_session, "is already booked for this client" if clinical_session.booking_for(client_id)
38:     else
39:       errors.add :clinical_session, "is required" if !clinical_session_id
40:       errors.add :client, "is required" if !client_id
41:     end
42:   end

[Validate]