(C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011 (C) OpenEyes Foundation, 2011-2013 This file is part of OpenEyes. OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see .
Author: OpenEyes (info@openeyes.org.uk)
Inheritance: extends BaseEventTypeElement
 /**
  * Returns the static model of the specified AR class.
  *
  * @return ElementOperation the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * For new records, set the episode status and (if relevant) the operation status.
  *
  * @FIXME: abstraction of the episode and operation statuses
  *
  * @throws Exception
  */
 protected function afterSave()
 {
     if ($this->getIsNewRecord()) {
         $this->event->episode->episode_status_id = 4;
         if (!$this->event->episode->save()) {
             throw new Exception('Unable to change episode status for episode ' . $this->event->episode->id);
         }
         if ($this->booking_event_id && ($api = Yii::app()->moduleAPI->get('OphTrOperationbooking'))) {
             $api->setOperationStatus($this->booking_event_id, 'Completed');
         }
     }
     return parent::afterSave();
 }
 /**
  * Validate the witness field if it's turned on.
  *
  * @return bool
  */
 public function beforeValidate()
 {
     if ($this->witness_enabled) {
         if ($this->anaesthetist_id == 3) {
             if (!$this->anaesthetic_witness_id) {
                 $this->addError('anaesthetic_witness_id', 'Please select a witness');
             }
         }
     }
     return parent::beforeValidate();
 }
 /**
  * Need to delete associated records.
  *
  * @see CActiveRecord::beforeDelete()
  */
 protected function beforeDelete()
 {
     OphTrOperationnote_OperationDrug::model()->deleteAllByAttributes(array('ophtroperationnote_postop_drugs_id' => $this->id));
     return parent::beforeDelete();
 }