Inheritance: extends BaseActiveRecordVersioned
Example #1
0
 /**
  * Generates an HTML list layout of the given Queue and its Outcome Queues.
  *
  * @param $id
  *
  * @throws \CHttpException
  */
 public function actionLoadQueueNav($id)
 {
     if (!($queue = models\Queue::model()->findByPk((int) $id))) {
         throw new \CHttpException(404, "Queue not found with id {$id}");
     }
     $root = $queue->getRootQueue();
     if (is_array($root)) {
         throw new \CHttpException(501, "Don't currently support queues with multiple roots");
     }
     $queueset = models\QueueSet::model()->findByAttributes(array('initial_queue_id' => $root->id));
     $resp = array('rootid' => $root->id, 'queuesetid' => $queueset->id, 'nav' => $this->renderPartial('queue_nav_item', array('queueset' => $queueset, 'queue' => $root), true));
     echo \CJSON::encode($resp);
 }
Example #2
0
 /**
  * Handles the moving of a ticket to a new Queue.
  *
  * @param $id
  *
  * @throws \CHttpException
  */
 public function actionMoveTicket($id)
 {
     if (!($ticket = models\Ticket::model()->with('current_queue')->findByPk($id))) {
         throw new \CHttpException(404, 'Invalid ticket id.');
     }
     $qs_svc = Yii::app()->service->getService(self::$QUEUESET_SERVICE);
     $queueset = $qs_svc->getQueueSetForTicket($ticket->id);
     if (!$this->checkQueueSetProcessAccess($queueset)) {
         throw new \CHttpException(403, 'Not authorised to take ticket');
     }
     foreach (array('from_queue_id', 'to_queue_id') as $required_field) {
         if (!@$_POST[$required_field]) {
             throw new \CHttpException(400, "Missing required form field {$required_field}");
         }
     }
     if ($ticket->current_queue->id != $_POST['from_queue_id']) {
         throw new \CHttpException(409, 'Ticket has already moved to a different queue');
     }
     if (!($to_queue = models\Queue::model()->active()->findByPk($_POST['to_queue_id']))) {
         throw new \CHttpException(404, "Cannot find queue with id {$_POST['to_queue_id']}");
     }
     $api = Yii::app()->moduleAPI->get('PatientTicketing');
     list($data, $errs) = $api->extractQueueData($to_queue, $_POST, true);
     if (count($errs)) {
         echo json_encode(array('errors' => array_values($errs)));
         Yii::app()->end();
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         if ($to_queue->addTicket($ticket, Yii::app()->user, $this->firm, $data)) {
             if ($ticket->assignee) {
                 $ticket->assignee_user_id = null;
                 $ticket->assignee_date = null;
                 $ticket->save();
             }
             $ticket->audit('ticket', 'move', $ticket->id);
             $transaction->commit();
             $t_svc = Yii::app()->service->getService('PatientTicketing_Ticket');
             AutoSaveTicket::clear();
             $flsh_id = 'patient-ticketing-';
             $flsh_id .= $queueset->getId();
             if ($to_queue->outcomes) {
                 Yii::app()->user->setFlash($flsh_id, $t_svc->getCategoryForTicket($ticket)->name . ' - ' . $ticket->patient->getHSCICName() . ' moved to ' . $to_queue->name);
             } else {
                 Yii::app()->user->setFlash($flsh_id, $t_svc->getCategoryForTicket($ticket)->name . ' - ' . $ticket->patient->getHSCICName() . ' completed');
             }
         } else {
             throw new Exception('unable to assign ticket to queue');
         }
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
     $queueset_id = $queueset->getId();
     $queueset_model = models\QueueSet::model()->findByPk($queueset_id);
     $queueset_category_id = $queueset_model->category_id;
     echo json_encode(array('redirectURL' => "/PatientTicketing/default/?queueset_id={$queueset_id}&cat_id={$queueset_category_id}"));
 }
 /**
  * @param \Firm $firm
  *
  * @return array
  */
 public function getQueueSetsForFirm(\Firm $firm = null)
 {
     $res = array();
     foreach (models\QueueSet::model()->active()->findAll() as $qs) {
         $res[] = $this->modelToResource($qs);
     }
     return $res;
 }