The followings are the available columns in table 'service_subspecialty_assignment':
Inheritance: extends BaseActiveRecordVersioned
コード例 #1
0
ファイル: Firm.php プロジェクト: code-4-england/OpenEyes
 /**
  * @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();
 }
コード例 #2
0
 protected function buildTicketFilterCriteria($filter_options, services\PatientTicketing_QueueSet $queueset)
 {
     $patient_filter = null;
     // build criteria
     $criteria = new \CDbCriteria();
     $qs_svc = Yii::app()->service->getService(self::$QUEUESET_SERVICE);
     if (@$_GET['patient_id']) {
         // this is a simple way of handling this for the sake of demo-ing functionality
         $criteria->addColumnCondition(array('patient_id' => $_GET['patient_id']));
         $patient_filter = \Patient::model()->findByPk($_GET['patient_id']);
     } else {
         // TODO: we probably don't want to have such a gnarly approach to this, we might want to denormalise so that we are able to do eager loading
         // That being said, we might get away with setting together false on the with to do this filtering (multiple query eager loading).
         $criteria->join = 'JOIN ' . models\TicketQueueAssignment::model()->tableName() . ' cqa ON cqa.ticket_id = t.id and cqa.id = (SELECT id from ' . models\TicketQueueAssignment::model()->tableName() . ' qa2 WHERE qa2.ticket_id = t.id order by qa2.created_date desc limit 1)';
         // build queue id list
         $queue_ids = array();
         if (@$filter_options['queue-ids']) {
             $queue_ids = $filter_options['queue-ids'];
             if (@$filter_options['closed-tickets']) {
                 // get all closed tickets regardless of whether queue is active or not
                 foreach (models\Queue::model()->closing()->findAll() as $closed_queue) {
                     $queue_ids[] = $closed_queue->id;
                 }
             }
         } else {
             if ($qs_svc->isQueueSetPermissionedForUser($queueset, Yii::app()->user->id)) {
                 foreach ($qs_svc->getQueueSetQueues($queueset, @$filter_options['closed-tickets'] ? true : false) as $queue) {
                     $queue_ids[] = $queue->id;
                 }
             }
         }
         if (@$filter_options['my-tickets']) {
             $criteria->addColumnCondition(array('assignee_user_id' => Yii::app()->user->id));
         }
         if (@$filter_options['priority-ids']) {
             $criteria->addInCondition('priority_id', $filter_options['priority-ids']);
         }
         if (count($queue_ids)) {
             $criteria->addInCondition('cqa.queue_id', $queue_ids);
         }
         if (@$filter_options['firm-id']) {
             $criteria->addColumnCondition(array('cqa.assignment_firm_id' => $filter_options['firm-id']));
         } elseif (@$filter_options['subspecialty-id']) {
             $criteria->join .= 'JOIN ' . \Firm::model()->tableName() . ' f ON f.id = cqa.assignment_firm_id JOIN ' . \ServiceSubspecialtyAssignment::model()->tableName() . ' ssa ON ssa.id = f.service_subspecialty_assignment_id';
             $criteria->addColumnCondition(array('ssa.subspecialty_id' => $filter_options['subspecialty-id']));
         }
     }
     $criteria->order = 't.created_date desc';
     return array($criteria, $patient_filter);
 }
コード例 #3
0
 /**
  * Generates a firm list based on a subspecialty id provided via POST
  * echoes form option tags for display.
  */
 public function actionFilterFirms()
 {
     if (@$_POST['empty']) {
         echo CHtml::tag('option', array('value' => ''), CHtml::encode('- Firm -'), true);
     } else {
         echo CHtml::tag('option', array('value' => ''), CHtml::encode('All firms'), true);
     }
     if (!empty($_POST['subspecialty_id'])) {
         $subspecialty_id = $_POST['subspecialty_id'];
     } elseif (!empty($_POST['service_id'])) {
         $subspecialty_id = ServiceSubspecialtyAssignment::model()->find('service_id=?', array($_POST['service_id']))->subspecialty_id;
     }
     if (isset($subspecialty_id)) {
         $firms = $this->getFilteredFirms($subspecialty_id);
         foreach ($firms as $id => $name) {
             echo CHtml::tag('option', array('value' => $id), CHtml::encode($name), true);
         }
     }
 }
コード例 #4
0
 /**
  * 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;
     }
 }