Element_OphTrOperationbooking_ScheduleOperation::isPatientAvailable PHP Method

isPatientAvailable() public method

Given a date (yyyy-mm-dd) check if the patient is available, and return true or false as appropriate.
public isPatientAvailable ( $date ) : boolean
$date
return boolean
    public function isPatientAvailable($date)
    {
        if (!$this->_unavailable_dates) {
            $this->_unavailable_dates = array();
            // cache the patient unavailable dates as we don't want to do this every time
            foreach ($this->patient_unavailables as $unavailable) {
                $dt = strtotime($unavailable->start_date);
                while ($dt <= strtotime($unavailable->end_date)) {
                    $this->_unavailable_dates[] = date('Y-m-d', $dt);
                    $dt += 86400;
                }
            }
        }
        if (empty($this->_unavailable_dates)) {
            return true;
        }
        return !in_array($date, $this->_unavailable_dates);
    }

Usage Example

 public function testIsPatientUnavailable()
 {
     $unavailables_data = array(array('start_date' => '2014-04-03', 'end_date' => '2014-04-03'), array('start_date' => '2014-04-12', 'end_date' => '2014-05-03'));
     $unavailables = array();
     foreach ($unavailables_data as $data) {
         $u = new OphTrOperationbooking_ScheduleOperation_PatientUnavailable();
         $u->attributes = $data;
         $unavailables[] = $u;
     }
     $test1 = new Element_OphTrOperationbooking_ScheduleOperation();
     $test1->patient_unavailables = array($unavailables[0]);
     $this->assertFalse($test1->isPatientAvailable('2014-04-03'));
     $this->assertTrue($test1->isPatientAvailable('2014-04-04'));
     $test2 = new Element_OphTrOperationbooking_ScheduleOperation();
     $test2->patient_unavailables = array($unavailables[0], $unavailables[1]);
     $this->assertTrue($test2->isPatientAvailable('2014-04-02'));
     $this->assertFalse($test2->isPatientAvailable('2014-04-03'));
     $this->assertTrue($test2->isPatientAvailable('2014-04-09'));
     $this->assertFalse($test2->isPatientAvailable('2014-04-12'));
     $this->assertFalse($test2->isPatientAvailable('2014-04-19'));
     $this->assertFalse($test2->isPatientAvailable('2014-05-03'));
     $this->assertTrue($test2->isPatientAvailable('2014-05-04'));
     // check it works when no unavailable data
     $test3 = new Element_OphTrOperationbooking_ScheduleOperation();
     $this->assertTrue($test3->isPatientAvailable('2041-04-02'));
 }
All Usage Examples Of Element_OphTrOperationbooking_ScheduleOperation::isPatientAvailable