(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 BaseActiveRecord
 public function afterValidate()
 {
     if (!$this->reading_id && !$this->qualitative_reading_id) {
         $this->addError('reading_id', 'Either a numerical reading or a qualitative reading must be specified.');
     }
     return parent::afterValidate();
 }
Beispiel #2
0
 public function beforeSave()
 {
     if (!$this->end_date) {
         $this->stop_reason_id = null;
     }
     return parent::beforeSave();
 }
 protected function beforeValidate()
 {
     if (!$this->isAllowed()) {
         $this->addError('recipient_email', 'Recipient email is not in the list of allowed domains');
     }
     return parent::beforeValidate();
 }
 protected function beforeSave()
 {
     if (!parent::beforeSave() || !$this->getPatientMeasurement()->save()) {
         return false;
     }
     $this->patient_measurement_id = $this->getPatientMeasurement()->id;
     return true;
 }
 protected function beforeSave()
 {
     foreach ($this->findAll('patient_measurement_id = ?', array($this->patient_measurement_id)) as $existing) {
         if ($this->episode_id && $this->episode_id == $existing->episode_id) {
             throw new Exception("Measurement reference already exists from episode {$this->episode_id} to patient measurement {$this->patient_measurement_id}");
         }
         if ($this->event_id && $this->event_id == $existing->event_id) {
             throw new Exception("Measurement reference already exists from event {$this->event_id} to patient measurement {$this->patient_measurement_id}");
         }
         if ($this->origin && $existing->origin) {
             throw new Exception("Origin reference already exists for patient measurement {$this->patient_measurement_id}");
         }
     }
     return parent::beforeSave();
 }
 /**
  * set a default display order for a new record.
  */
 protected function afterConstruct()
 {
     parent::afterConstruct();
     if (!$this->display_order) {
         $criteria = new CDbCriteria();
         $criteria->order = 'display_order desc';
         $criteria->limit = 1;
         $model = get_class($this);
         $bottom = $model::model()->find($criteria);
         if ($bottom) {
             $this->display_order = $bottom->display_order + 1;
         } else {
             $this->display_order = 1;
         }
     }
 }
 /**
  * ensures file is removed from filesystem when deleting
  *
  */
 public function afterDelete()
 {
     unlink($this->_stored_path);
     return parent::afterDelete();
 }
Beispiel #8
0
 /**
  * @param string $prop
  * @return bool
  */
 public function __isset($prop)
 {
     $method = "get_" . $prop;
     if (method_exists($this, $method)) {
         return true;
     }
     return parent::__isset($prop);
 }
Beispiel #9
0
 public function delete()
 {
     if ($this->children) {
         foreach ($this->children as $child) {
             if (!$child->delete()) {
                 return false;
             }
         }
     }
     return parent::delete();
 }
 protected function beforeSave()
 {
     if ($this->start_date && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $this->start_date)) {
         $this->start_date = date('Y-m-d', strtotime($this->start_date));
     }
     if ($this->end_date && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $this->end_date)) {
         $this->end_date = date('Y-m-d', strtotime($this->end_date));
     }
     $this->default_admission_time = $this->setDefaultAdmissionTime($this->default_admission_time, $this->start_time);
     return parent::beforeSave();
 }
Beispiel #11
0
 protected function beforeValidate()
 {
     return parent::beforeValidate();
 }
Beispiel #12
0
 /**
  * @return bool
  */
 public function beforeSave()
 {
     if ($this->subspecialty_id) {
         $this->service_subspecialty_assignment_id = ServiceSubspecialtyAssignment::model()->find('subspecialty_id=?', array($this->subspecialty_id))->id;
     }
     return parent::beforeSave();
 }
Beispiel #13
0
 /**
  * assignment field validation.
  */
 public function afterValidate()
 {
     // validate any widget fields in the assignment_fields attribute
     foreach ($this->getAssignmentFieldDefinitions() as $i => $fld) {
         if (!($id = @$fld['id'])) {
             $this->addError('assignment_fields', 'ID required for assignment field ' . ($i + 1));
             continue;
         }
         if (@$fld['type'] == 'widget') {
             if (!@$fld['widget_name']) {
                 $this->addError('assignment_fields', 'Widget Name missing for ' . $id);
             } elseif (!is_file(\Yii::getPathOfAlias('application.modules.PatientTicketing.widgets.' . $fld['widget_name']) . '.php')) {
                 $this->addError('assignment_fields', 'Widget with name ' . $fld['widget_name'] . ' for ' . $id . ' not defined');
             }
         }
     }
     parent::afterValidate();
 }
Beispiel #14
0
 /**
  * Override to allow us to have classes defined outside of core that store the data in a different way
  *
  * @param array $attributes
  * @return CActiveRecord
  */
 protected function instantiate($attributes)
 {
     if (isset($attributes['patient_measurement_id'])) {
         if ($pm = PatientMeasurement::model()->findByPk($attributes['patient_measurement_id'])) {
             $origin = $pm->originReference;
             if ($origin && $origin->event) {
                 $api = Yii::app()->moduleAPI->getForEventId($origin->event_id);
                 if ($api) {
                     OELog::log("we have an api");
                     return $api->getMeasurementClassForEventId($origin->event_id);
                 }
             }
         }
     }
     return parent::instantiate($attributes);
 }
 /**
  * check the time entry is valid.
  *
  * @return bool
  */
 public function beforeValidate()
 {
     if (!preg_match('/^(([01]?[0-9])|(2[0-3])):?[0-5][0-9]$/', $this->measurement_timestamp)) {
         $this->addError('measurement_timestamp', 'Invalid ' . $this->getAttributeLabel('measurement_timestamp'));
     }
     return parent::beforeValidate();
 }
Beispiel #16
0
 /**
  * Extend parent behaviour to enforce a transaction so that we don't lose commissioning
  * body assignments if the delete fails part way through.
  *
  * @return bool
  *
  * @throws Exception
  */
 public function delete()
 {
     // perform this process in a transaction if one has not been created
     $transaction = Yii::app()->db->getCurrentTransaction() === null ? Yii::app()->db->beginTransaction() : false;
     try {
         if (parent::delete()) {
             if ($transaction) {
                 $transaction->commit();
             }
             return true;
         } else {
             if ($transaction) {
                 $transaction->rollback();
             }
             return false;
         }
     } catch (Exception $e) {
         if ($transaction) {
             $transaction->rollback();
         }
         throw $e;
     }
 }
Beispiel #17
0
 /**
  * Only set when for scheduled worklist entries.
  */
 public function afterValidate()
 {
     if ($this->worklist->scheduled) {
         if (empty($this->when)) {
             $this->addError('when', $this->getAttributeLabel('when') . ' is required when the Worklist is scheduled.');
         }
     } else {
         if (!empty($this->when)) {
             $this->addError('when', $this->getAttributeLabel('when') . ' cannot be set when the Worklist not scheduled.');
         }
     }
     parent::afterValidate();
 }
 /**
  * Dissociate the session from cancelled bookings and ERODs before deletion.
  */
 protected function beforeDelete()
 {
     OphTrOperationbooking_Operation_Booking::model()->updateAll(array('session_id' => null), 'session_id = :session_id and booking_cancellation_date is not null', array(':session_id' => $this->id));
     OphTrOperationbooking_Operation_EROD::model()->updateAll(array('session_id' => null), 'session_id = :session_id', array(':session_id' => $this->id));
     return parent::beforeDelete();
 }
 protected function afterSave()
 {
     return parent::afterSave();
 }
Beispiel #20
0
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord && !$this->address_type_id) {
             // make correspondence the default address type
             $this->address_type_id = AddressType::CORRESPOND;
         }
         return true;
     }
     return false;
 }
Beispiel #21
0
 public function beforeValidate()
 {
     if (!preg_match('/^[0-9a-f]{32}$/', $this->password)) {
         if ($this->password != $this->password_repeat) {
             $this->addError('password', 'Password confirmation must match exactly');
         }
         $this->salt = $this->randomSalt();
     }
     if ($this->getIsNewRecord() && !$this->password) {
         $this->addError('password', 'Password is required');
     }
     return parent::beforeValidate();
 }
 public function afterFind()
 {
     // strip out the seconds from the time field
     foreach (array('start_time', 'end_time') as $time_attr) {
         $this->{$time_attr} = substr($this->{$time_attr}, 0, 5);
     }
     parent::afterFind();
 }
Beispiel #23
0
 /**
  * Pass through use_pas flag to allow pas supression
  * @see CActiveRecord::instantiate()
  */
 protected function instantiate($attributes)
 {
     $model = parent::instantiate($attributes);
     $model->use_pas = $this->use_pas;
     return $model;
 }
Beispiel #24
0
 public function beforeSave()
 {
     switch ($this->type) {
         case 'site':
             $this->firm_id = null;
             $this->subspecialty = null;
             break;
         case 'subspecialty':
             $this->firm_id = null;
             $this->site_id = null;
             break;
         case 'firm':
             $this->subspecialty_id = null;
             $this->site_id = null;
             break;
     }
     return parent::beforeSave();
 }
Beispiel #25
0
 public function afterDelete()
 {
     $this->removePatientAdherence();
     return parent::afterDelete();
 }
Beispiel #26
0
 /**
  * Raise event to allow external data sources to update gp
  * @see CActiveRecord::afterFind()
  */
 protected function afterFind()
 {
     parent::afterFind();
     Yii::app()->event->dispatch('gp_after_find', array('gp' => $this));
 }
Beispiel #27
0
 /**
  * Sets various default properties for audit calls on this event.
  *
  * @param $target
  * @param $action
  * @param null $data
  * @param bool $log
  * @param array $properties
  */
 public function audit($target, $action, $data = null, $log = false, $properties = array())
 {
     $properties['event_id'] = $this->id;
     $properties['episode_id'] = $this->episode_id;
     $properties['patient_id'] = $this->episode->patient_id;
     parent::audit($target, $action, $data, $log, $properties);
 }
 public function beforeValidate()
 {
     $whereParams = array();
     if ($this->id) {
         $where = 'id != :id and ';
         $whereParams[':id'] = $this->id;
     } else {
         $where = '';
     }
     if (!$this->subspecialty_id) {
         $where .= ' subspecialty_id is null and ';
     } else {
         $where .= ' subspecialty_id = :subspecialty_id and ';
         $whereParams[':subspecialty_id'] = $this->subspecialty_id;
     }
     if (!$this->episode_status_id) {
         $where .= ' episode_status_id is null';
     } else {
         $where .= ' episode_status_id = :episode_status_id';
         $whereParams[':episode_status_id'] = $this->episode_status_id;
     }
     if (self::model()->find($where, $whereParams)) {
         //$this->addError('id','There is already a rule for this subspecialty and episode status combination');
     }
     return parent::beforeValidate();
 }
Beispiel #29
0
 /**
  * Returns the static model of the specified AR class.
  *
  * @return FamilyHistory the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 protected function afterSave()
 {
     Yii::app()->event->dispatch('OphTrOperationbooking_booking_after_save', array('patient' => $this->operation->event->episode->patient, 'admission_date' => $this->session->date, 'admission_time' => $this->admission_time, 'firm' => $this->session->firm, 'site' => $this->ward->site, 'ward_code' => $this->ward->code, 'theatre_code' => $this->session->theatre ? $this->session->theatre->code : null, 'cancellation_date' => $this->booking_cancellation_date, 'new' => $this->isNewRecord));
     parent::afterSave();
 }