The followings are the available columns in table:
Inheritance: extends BaseActiveRecordVersioned
 public function testCanValidateWithItem()
 {
     $test = new OphTrOperationbooking_Operation_EROD_Rule();
     $test->subspecialty_id = $this->subspecialties('subspecialty1')->id;
     $item = new OphTrOperationbooking_Operation_EROD_Rule_Item();
     $item->item_type = 'firm';
     $item->item_id = $this->firms('firm1')->id;
     $test->items = array($item);
     $this->assertTrue($test->validate());
 }
Example #2
0
 public function actionDeleteERODRules()
 {
     if (!empty($_POST['erod'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             foreach ($_POST['erod'] as $erod_id) {
                 if ($_erod = OphTrOperationbooking_Operation_EROD_Rule::model()->findByPk($erod_id)) {
                     foreach ($_erod->items as $item) {
                         if (!$item->delete()) {
                             throw new Exception('Unable to delete rule item: ' . print_r($item->getErrors(), true));
                         }
                     }
                     if (!$_erod->delete()) {
                         throw new Exception('Unable to delete erod rule: ' . print_r($_erod->getErrors(), true));
                     }
                 } else {
                     throw new Exception('EROD Rule not found for id ' . $erod_id);
                 }
             }
             Audit::add('admin', 'delete', null, null, array('module' => 'OphTrOperationbooking', 'model' => 'OphTrOperationbooking_Operation_EROD_Rule'));
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollback();
             echo $e->getMessage();
             Yii::app()->end();
         }
     }
     echo '1';
 }
Example #3
0
<div class="box admin">
	<h2>EROD rules</h2>
	<form id="erod_rules">
		<table class="grid">
			<thead>
				<tr>
					<th><input type="checkbox" id="checkall" class="erod_rules" /></th>
					<th>Subspecialty</th>
					<th>Firms</th>
				</tr>
			</thead>
			<tbody>
				<?php 
$criteria = new CDbCriteria();
$criteria->order = 'display_order asc';
foreach (OphTrOperationbooking_Operation_EROD_Rule::model()->findAll() as $i => $erod) {
    ?>
					<tr class="clickable sortable" data-id="<?php 
    echo $erod->id;
    ?>
?>" data-uri="OphTrOperationbooking/admin/editerodrule/<?php 
    echo $erod->id;
    ?>
">
						<td><input type="checkbox" name="erod[]" value="<?php 
    echo $erod->id;
    ?>
" class="erod_rules" /></td>
						<td><?php 
    echo $erod->subspecialty->name;
    ?>
 /**
  * Calculate the EROD for this operation - the firm used to determine the service can be overridden by providing a firm.
  * (Note that this handles the emergency list by having a firm placeholder object that does not have an id - at this time,
  * no sessions are assigned to A&E firms, having the effect that no EROD can be calculated for emergency bookings).
  *
  * @param Firm $firm
  *
  * @return OphTrOperationbooking_Operation_EROD|null
  *
  * @throws Exception
  */
 public function calculateEROD($firm = null)
 {
     $criteria = new CDbCriteria();
     $criteria->params[':one'] = 1;
     //consultant required
     if ($this->consultant_required) {
         $criteria->addCondition('`t`.consultant = :one');
     }
     //anaesthetic requirements
     if ($this->anaesthetist_required || $this->anaesthetic_type->code == 'GA') {
         $criteria->addCondition('`t`.anaesthetist = :one and `t`.general_anaesthetic = :one');
     }
     // child conditions
     $patient = $this->getPatient();
     if ($patient->isChild()) {
         // need to get the point at which patient becomes an adult. All sessions up to that point need the pediatric flag
         $criteria->params[':adult_date'] = $patient->getBecomesAdultDate();
         $criteria->addCondition('(`t`.date < :adult_date AND `t`.paediatric = :one) OR `t`.date >= :adult_date');
     }
     // if their are firms that are set for the subspecialty of the episode, use their sessions
     if ($rule = OphTrOperationbooking_Operation_EROD_Rule::model()->find('subspecialty_id=?', array($this->getFirm()->getSubspecialtyID()))) {
         $firm_ids = array();
         foreach ($rule->items as $item) {
             if ($item->item_type == 'firm') {
                 $firm_ids[] = $item->item_id;
             }
         }
         $criteria->addInCondition('firm.id', $firm_ids);
     } else {
         // otherwise, use the given firm to define the set of valid sessions by subspecialty
         if (!$firm) {
             $firm = $this->event->episode->firm;
         }
         if (!$firm->id) {
             // booking into the emergency list
             if (!($subspecialty = Subspecialty::model()->find('ref_spec=?', array('AE')))) {
                 throw new Exception('A&E subspecialty not found');
             }
             if (!($service_subspecialty_assignment = ServiceSubspecialtyAssignment::model()->find('subspecialty_id=?', array($subspecialty->id)))) {
                 throw new Exception('A&E service_subspecialty_assignment not found');
             }
             $service_subspecialty_assignment_id = $service_subspecialty_assignment->id;
         } else {
             if (!($service_subspecialty_assignment_id = $firm->service_subspecialty_assignment_id)) {
                 throw new Exception('Firm must have service_subspecialty_assignment for EROD calculation');
             }
         }
         $criteria->addCondition('service_subspecialty_assignment_id = :serviceSubspecialtyAssignmentId');
         $criteria->params[':serviceSubspecialtyAssignmentId'] = $service_subspecialty_assignment_id;
     }
     // session must be available
     $criteria->addCondition('`t`.available = :one');
     // work out the lead date
     $lead_decision_date = strtotime($this->decision_date);
     if ($lead_weeks = Yii::app()->params['erod_lead_time_weeks']) {
         $lead_decision_date += 86400 * 7 * $lead_weeks;
     }
     $lead_current_date = time();
     if ($lead_days = Yii::app()->params['erod_lead_current_date_days']) {
         $lead_current_date += 86400 * $lead_days;
     }
     $lead_time_date = $lead_decision_date > $lead_current_date ? date('Y-m-d', $lead_decision_date) : date('Y-m-d', $lead_current_date);
     $criteria->addCondition('`t`.date > :leadTimeDate');
     $criteria->params[':leadTimeDate'] = $lead_time_date;
     $criteria->order = '`t`.date, `t`.start_time';
     foreach (OphTrOperationbooking_Operation_Session::model()->with(array('firm' => array('joinType' => 'JOIN')))->findAll($criteria) as $session) {
         $available_time = $session->availableMinutes;
         if ($available_time < $this->total_duration) {
             continue;
         }
         if ($session->max_procedures > 0 && $this->getProcedureCount() > $session->getAvailableProcedureCount()) {
             continue;
         }
         $erod = new OphTrOperationbooking_Operation_EROD();
         $erod->session_id = $session->id;
         $erod->session_date = $session->date;
         $erod->session_start_time = $session->start_time;
         $erod->session_end_time = $session->end_time;
         $erod->firm_id = $session->firm_id;
         $erod->consultant = $session->consultant;
         $erod->paediatric = $session->paediatric;
         $erod->anaesthetist = $session->anaesthetist;
         $erod->general_anaesthetic = $session->general_anaesthetic;
         $erod->session_duration = $session->duration;
         $erod->total_operations_time = $session->bookedMinutes;
         // Note that I have not subtracted the duration of this operation from the available time when storing this
         // as it is now being generated before the booking is made. When the booking is made, it will have been saved
         // before the EROD is calculated, so the available time will reflect the same value as in the prior calculations
         $erod->available_time = $available_time;
         return $erod;
     }
 }