(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
 /**
  * @covers SplitEventTypeElement::setUpdateOptions
  * @todo   Implement testSetUpdateOptions().
  */
 public function testSetUpdateOptions()
 {
     $this->object->eye = $this->eye('eyeLeft');
     $this->object->setUpdateOptions();
     $this->assertEquals('NoName', $this->object->right_name);
     $this->assertEquals(0, $this->object->right_number);
 }
 /**
  * Returns the static model of the specified AR class.
  * @return Element_OphCiExamination_PupillaryAbnormalities the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 public function beforeDelete()
 {
     OphCiExamination_IntraocularPressure_Value::model()->deleteAll("element_id = ?", array($this->id));
     return parent::beforeDelete();
 }
 protected function beforeValidate()
 {
     return parent::beforeValidate();
 }
 /**
  * @see cleanUpSecondaryDiagnosis()
  * @see parent::delete()
  *
  * @return bool
  */
 public function delete()
 {
     $this->cleanUpSecondaryDiagnosis();
     return parent::delete();
 }
 /**
  * extends standard delete method to remove all the treatments.
  *
  * (non-PHPdoc)
  * @see CActiveRecord::delete()
  */
 public function delete()
 {
     $transaction = Yii::app()->db->getCurrentTransaction() === null ? Yii::app()->db->beginTransaction() : false;
     try {
         foreach ($this->readings as $reading) {
             if (!$reading->delete()) {
                 throw new Exception('Delete reading failed: ' . print_r($reading->getErrors(), true));
             }
         }
         if (parent::delete()) {
             if ($transaction) {
                 $transaction->commit();
             }
         } else {
             throw new \Exception('unable to delete');
         }
     } catch (\Exception $e) {
         if ($transaction) {
             $transaction->rollback();
         }
         throw $e;
     }
 }
 protected function afterSave()
 {
     return parent::afterSave();
 }
 public function afterValidate()
 {
     if ($this->scenario == 'formHasNoChildren') {
         $values = false;
         if ($this->hasLeft()) {
             if ($this->left_rapd || $this->left_comments) {
                 $values = true;
             }
         }
         if (!$values && $this->hasRight()) {
             if ($this->right_rapd || $this->right_comments) {
                 $values = true;
             }
         }
         if (!$values) {
             $this->addError(null, "Visual Function requires data");
         }
     }
     parent::afterValidate();
 }
 /**
  * clear out sided fields to prevent validation of irrelevant data.
  *
  * (non-PHPdoc)
  *
  * @see CModel::beforeValidate()
  */
 protected function beforeValidate()
 {
     // Need to clear any "sided" fields if that side isn't active to prevent
     if ($this->eye->name != 'Both') {
         foreach ($this->sidedFields() as $field_suffix) {
             if ($this->eye->name == 'Left') {
                 $clear_field = 'right_' . $field_suffix;
             } else {
                 // Right
                 $clear_field = 'left_' . $field_suffix;
             }
             $this->{$clear_field} = null;
         }
     }
     return parent::beforeValidate();
 }
 /**
  * Validate readings.
  */
 protected function afterValidate()
 {
     foreach (array('right', 'left') as $side) {
         foreach ($this->{$side . '_readings'} as $i => $reading) {
             if (!$reading->validate()) {
                 foreach ($reading->getErrors() as $fld => $err) {
                     $this->addError($side . '_reading', ucfirst($side) . ' reading (' . ($i + 1) . '): ' . implode(', ', $err));
                 }
             }
         }
     }
     return parent::afterValidate();
 }
 public function afterSave()
 {
     $complication_items = \Yii::app()->request->getParam('complication_items', false);
     $operation_note_id = \Yii::app()->request->getParam('OphCiExamination_postop_complication_operation_note_id', null);
     $elementData = \Yii::app()->request->getParam('OEModule_OphCiExamination_models_Element_OphCiExamination_PostOpComplications', null);
     $eye_id = isset($elementData['eye_id']) ? $elementData['eye_id'] : null;
     $model = new OphCiExamination_Et_PostOpComplications();
     $model->deleteAllByAttributes(array('element_id' => $this->id, 'operation_note_id' => $operation_note_id));
     if ($complication_items) {
         if (!isset($complication_items['R']) || $eye_id == \Eye::LEFT) {
             $complication_items['R'][0] = OphCiExamination_PostOpComplications::model()->findByAttributes(array('name' => 'none'))->id;
         }
         foreach ($complication_items['R'] as $cKey => $complication_id) {
             $et_Complication = new OphCiExamination_Et_PostOpComplications();
             $et_Complication->element_id = $this->id;
             $et_Complication->complication_id = $complication_id;
             $et_Complication->eye_id = \Eye::RIGHT;
             $et_Complication->operation_note_id = $operation_note_id;
             if (!$et_Complication->save()) {
                 throw new Exception('Unable to save post op complication: ' . print_r($et_Complication->getErrors(), true));
             }
         }
         $et_Complication = null;
         if (!isset($complication_items['L']) || $eye_id == \Eye::RIGHT) {
             $complication_items['L'][0] = OphCiExamination_PostOpComplications::model()->findByAttributes(array('name' => 'none'))->id;
         }
         foreach ($complication_items['L'] as $cKey => $complication_id) {
             $et_Complication = new OphCiExamination_Et_PostOpComplications();
             $et_Complication->element_id = $this->id;
             $et_Complication->complication_id = $complication_id;
             $et_Complication->eye_id = \Eye::LEFT;
             $et_Complication->operation_note_id = $operation_note_id;
             if (!$et_Complication->save()) {
                 throw new Exception('Unable to save post op complication: ' . print_r($et_Complication->getErrors(), true));
             }
         }
         $et_Complication = null;
     }
     parent::afterSave();
 }
 /**
  * extends standard delete method to remove any risk assignments made to it
  *
  * (non-PHPdoc)
  * @see CActiveRecord::delete()
  */
 public function delete()
 {
     $transaction = Yii::app()->db->getCurrentTransaction() === null ? Yii::app()->db->beginTransaction() : false;
     try {
         foreach ($this->risk_assignments as $riska) {
             $riska->delete();
         }
         foreach ($this->answers as $answer) {
             $answer->delete();
         }
         if (parent::delete()) {
             if ($transaction) {
                 $transaction->commit();
             }
         } else {
             throw new Exception('unable to delete');
         }
     } catch (Exception $e) {
         if ($transaction) {
             $transaction->rollback();
         }
         throw $e;
     }
 }
 public function setDefaultOptions()
 {
     // It is necessary to set these values to be an integer to prevent eyedraw
     // bound fields from breaking. See [ORB-340]
     $this->axial_length_left = 0;
     $this->axial_length_right = 0;
     parent::setDefaultOptions();
 }
 /**
  * Perform dependent validation for readings and flags.
  */
 protected function afterValidate()
 {
     $contra_flags = array('_unable_to_assess', '_eye_missing');
     foreach (array('left', 'right') as $side) {
         $check = 'has' . ucfirst($side);
         if ($this->{$check}()) {
             if ($this->{$side . '_readings'}) {
                 foreach ($this->{$side . '_readings'} as $i => $reading) {
                     if (!$reading->validate()) {
                         foreach ($reading->getErrors() as $fld => $err) {
                             $this->addError($side . '_readings', ucfirst($side) . ' reading(' . ($i + 1) . '): ' . implode(', ', $err));
                         }
                     }
                 }
                 foreach ($contra_flags as $f) {
                     if ($this->{$side . $f}) {
                         $this->addError($side . $f, 'Cannot be ' . $this->getAttributeLabel($side . $f) . ' with VA readings.');
                     }
                 }
             } else {
                 $valid = false;
                 foreach ($contra_flags as $f) {
                     if ($this->{$side . $f}) {
                         $valid = true;
                     }
                 }
                 if (!$valid) {
                     $this->addError($side, ucfirst($side) . ' side has no data.');
                 }
             }
         }
     }
     parent::afterValidate();
 }