Returns the static model of the specified AR class.
public static model ( $className = __CLASS__ ) : the | ||
return | the | static model class |
public function testSetOperationStatus_ScheduledOrRescheduled_Rescheduled() { $api = Yii::app()->moduleAPI->get('OphTrOperationbooking'); $eo = $this->el_o('eo12'); $api->setOperationStatus($eo->event_id, 'Scheduled or Rescheduled'); $this->assertEquals('Rescheduled', Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($eo->event_id))->status->name); }
/** * Collate the data and persist it to the table. * * @param $id * * @throws CHttpException * @throws Exception */ public function loadData($id) { $booking = Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($id)); $eye = Eye::model()->findByPk($booking->eye_id); if ($eye->name === 'Both') { throw new CHttpException(400, 'Can\'t display whiteboard for dual eye bookings'); } $eyeLabel = strtolower($eye->name); $event = Event::model()->findByPk($id); $episode = Episode::model()->findByPk($event->episode_id); $patient = Patient::model()->findByPk($episode->patient_id); $contact = Contact::model()->findByPk($patient->contact_id); $biometryCriteria = new CDbCriteria(); $biometryCriteria->addCondition('patient_id = :patient_id'); $biometryCriteria->params = array('patient_id' => $patient->id); $biometryCriteria->order = 'last_modified_date DESC'; $biometryCriteria->limit = 1; $biometry = Element_OphTrOperationnote_Biometry::model()->find($biometryCriteria); $examination = $event->getPreviousInEpisode(EventType::model()->findByAttributes(array('name' => 'Examination'))->id); //$management = new \OEModule\OphCiExamination\models\Element_OphCiExamination_Management(); //$anterior = new \OEModule\OphCiExamination\models\Element_OphCiExamination_AnteriorSegment(); $risks = new \OEModule\OphCiExamination\models\Element_OphCiExamination_HistoryRisk(); if ($examination) { //$management = $management->findByAttributes(array('event_id' => $examination->id)); //$anterior = $anterior->findByAttributes(array('event_id' => $examination->id)); $risks = $risks->findByAttributes(array('event_id' => $examination->id)); } $labResult = Element_OphInLabResults_Inr::model()->findPatientResultByType($patient->id, '1'); $allergies = Yii::app()->db->createCommand()->select('a.name as name')->from('patient_allergy_assignment pas')->leftJoin('allergy a', 'pas.allergy_id = a.id')->where("pas.patient_id = {$episode->patient_id}")->order('a.name')->queryAll(); $allergyString = 'None'; if ($allergies) { $allergyString = implode(',', array_column($allergies, 'name')); } $operation = Yii::app()->db->createCommand()->select('proc.term as term')->from('et_ophtroperationbooking_operation op')->leftJoin('ophtroperationbooking_operation_procedures_procedures opp', 'opp.element_id = op.id')->leftJoin('proc', 'opp.proc_id = proc.id')->where("op.event_id = {$id}")->queryAll(); $this->event_id = $id; $this->booking = $booking; $this->eye_id = $eye->id; $this->eye = $eye; $this->predicted_additional_equipment = $booking->special_equipment_details; $this->comments = ''; $this->patient_name = $contact['title'] . ' ' . $contact['first_name'] . ' ' . $contact['last_name']; $this->date_of_birth = $patient['dob']; $this->hos_num = $patient['hos_num']; $this->procedure = implode(',', array_column($operation, 'term')); $this->allergies = $allergyString; $this->iol_model = $biometry ? $biometry->attributes['lens_description_' . $eyeLabel] : 'Unknown'; $this->iol_power = $biometry ? $biometry->attributes['iol_power_' . $eyeLabel] : 'none'; $this->predicted_refractive_outcome = $biometry ? $biometry->attributes['predicted_refraction_' . $eyeLabel] : 'Unknown'; $this->alpha_blockers = $patient->hasRisk('Alpha blockers'); $this->anticoagulants = $patient->hasRisk('Anticoagulants'); $this->alpha_blocker_name = $risks ? $risks->alpha_blocker_name : ''; $this->anticoagulant_name = $risks ? $risks->anticoagulant_name : ''; $this->inr = $labResult ? $labResult : 'None'; $this->save(); }
protected function deceasedPatients() { echo 'Cancelling operations for deceased patients: '; // TODO: This needs to be made more robust $cancellation_reason = OphTrOperationbooking_Operation_Cancellation_Reason::model()->find("text = 'Patient has died'"); if (!$cancellation_reason) { throw new CException('Cannot find cancellation code for "patient has died"'); } $criteria = new CDbCriteria(); $criteria->addInCondition('`t`.status_id', array(1, 2, 3, 4)); $criteria->addCondition('is_deceased = 1 and session_date > :dateNow'); $criteria->params[':dateNow'] = date('Y-m-d'); foreach (Element_OphTrOperationbooking_Operation::model()->with(array('event' => array('with' => array('episode' => array('with' => 'patient'))), 'booking'))->findAll($criteria) as $operation) { $operation = Element_OphTrOperationbooking_Operation::model()->findByPk($operation['id']); $operation->cancel($cancellation_reason->id, 'Booking cancelled automatically', 1); echo '.'; } echo "\n"; }
/** * Cancel operation action. * * @param $id * * @throws CHttpException * @throws Exception */ public function actionCancel($id) { $operation = $this->operation; if ($operation->status->name == 'Cancelled') { return $this->redirect(array('default/view/' . $this->event->id)); } $errors = array(); if (isset($_POST['cancellation_reason']) && isset($_POST['operation_id'])) { $comment = isset($_POST['cancellation_comment']) ? strip_tags(@$_POST['cancellation_comment']) : ''; $result = $operation->cancel(@$_POST['cancellation_reason'], $comment); if ($result['result']) { $operation->event->deleteIssues(); $operation->event->audit('event', 'cancel'); die(json_encode(array())); } foreach ($result['errors'] as $form_errors) { foreach ($form_errors as $error) { $errors[] = $error; } } die(json_encode($errors)); } if (!($operation = Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($id)))) { throw new CHttpException(500, 'Operation not found'); } $this->patient = $operation->event->episode->patient; $this->title = 'Cancel operation'; $this->processJsVars(); $this->render('cancel', array('operation' => $operation, 'patient' => $operation->event->episode->patient, 'date' => $operation->minDate, 'errors' => $errors)); }
/** * Ajax method to check whether various attributes are required on a given session * (used to prevent them being turned off when they are needed on the session). * * @throws Exception */ public function actionCheckRequired() { if (!($session = OphTrOperationbooking_Operation_Session::model()->findByPk(@$_POST['session_id']))) { throw new Exception('Session not found: ' . $_POST['session_id']); } Yii::app()->event->dispatch('start_batch_mode'); switch (@$_POST['type']) { case 'consultant': $criteria = new CDbCriteria(); $criteria->addInCondition('`t`.status_id', array(2, 4)); $criteria->addCondition('session.id = :sessionId and booking.booking_cancellation_date is null and `t`.consultant_required = :required'); $criteria->params[':sessionId'] = $session->id; $criteria->params[':required'] = 1; if (Element_OphTrOperationbooking_Operation::model()->with(array('booking' => array('with' => 'session')))->find($criteria)) { echo '1'; } else { echo '0'; } return; case 'paediatric': foreach ($session->activeBookings as $booking) { if ($booking->operation->event->episode->patient->isChild($session->date)) { echo '1'; return; } } echo '0'; return; case 'anaesthetist': $criteria = new CDbCriteria(); $criteria->addCondition('session.id = :sessionId and booking.booking_cancellation_date is null and `t`.anaesthetist_required = :required'); $criteria->addInCondition('`t`.status_id', array(2, 4)); $criteria->params[':sessionId'] = $session->id; $criteria->params[':required'] = 1; if (Element_OphTrOperationbooking_Operation::model()->with(array('booking' => array('with' => 'session')))->find($criteria)) { echo '1'; } else { echo '0'; } return; case 'general_anaesthetic': $criteria = new CDbCriteria(); $criteria->addCondition('session.id = :sessionId and booking.booking_cancellation_date is null and `t`.anaesthetic_type_id = :anaestheticType'); $criteria->addInCondition('`t`.status_id', array(2, 4)); $criteria->params[':sessionId'] = $session->id; $criteria->params[':anaestheticType'] = 5; if (Element_OphTrOperationbooking_Operation::model()->with(array('booking' => array('with' => 'session')))->find($criteria)) { echo '1'; } else { echo '0'; } return; } throw new Exception('Unknown type: ' . @$_POST['type']); }
public function testActionScheduleOperation() { $this->markTestIncomplete(); $this->scheduleOperation(array('event_id' => 5, 'firm_id' => 2, 'session_id' => 6, 'date' => date('Ym'), 'day' => date('j'))); $eo = Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array(5)); $booking = OphTrOperationbooking_Operation_Booking::model()->find(array('condition' => 'element_id = :eoid', 'params' => array(':eoid' => $eo->id), 'order' => 'id desc')); $this->assertInstanceOf('OphTrOperationbooking_Operation_Booking', $booking); $this->assertEquals(6, $booking->session_id); $this->assertEquals('09:14:00', $booking->admission_time); $this->assertEquals('08:00:00', $booking->session_start_time); $this->assertEquals('13:00:00', $booking->session_end_time); $this->assertEquals('2014-01-27', $booking->session_date); $this->assertEquals(1, $booking->session_theatre_id); $this->assertEquals(1, $booking->ward_id); $this->assertEquals('Test 123', $eo->comments); $this->assertEquals('Test 456', $eo->comments_rtt); $this->assertEquals('Test 789', $booking->session->comments); $this->assertEquals(1, $eo->site_id); $this->assertEquals(2, $eo->status_id); $this->undoLastBooking(); }
public function findBookingByEventID($event_id) { if ($eo = Element_OphTrOperationbooking_Operation::model()->with('booking')->find('event_id=?', array($event_id))) { return $eo->booking; } return false; }
* @link http://www.openeyes.org.uk * * @author OpenEyes <*****@*****.**> * @copyright Copyright (c) 2008-2011, Moorfields Eye Hospital NHS Foundation Trust * @copyright Copyright (c) 2011-2013, OpenEyes Foundation * @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0 */ ?> <?php $this->beginContent('//patient/event_container'); ?> <?php $this->moduleNameCssClass .= ' highlight-fields'; $this->title .= ' (' . Element_OphTrOperationbooking_Operation::model()->find('event_id=?', array($this->event->id))->status->name . ')'; ?> <?php if (!$operation->has_gp) { ?> <div class="alert-box alert with-icon"> Patient has no GP practice address, please correct in PAS before printing GP letter. </div> <?php } ?> <?php if (!$operation->has_address) { ?> <div class="alert-box alert with-icon">
/** * Ajax method to mark the given operations with transport arranged. * * @throws Exception */ public function actionConfirm() { if (is_array(@$_POST['operations'])) { foreach ($_POST['operations'] as $operation_id) { if (!($operation = Element_OphTrOperationbooking_Operation::model()->with('latestBooking')->findByPk($operation_id))) { throw new Exception('Operation not found: ' . $operation_id); } $booking = $operation->latestBooking; if (!$booking->transport_arranged) { $booking->transport_arranged = 1; $booking->transport_arranged_date = date('Y-m-d'); if (!$booking->save(true, null, true)) { throw new Exception('Unable to save booking: ' . print_r($booking->getErrors(), true)); } } } } echo '1'; }
/** * Prints next pending letter type for requested operations * Operation IDs are passed as an array (operations[]) via GET or POST * Invalid operation IDs are ignored. * * @throws CHttpException */ public function actionPrintLetters() { Audit::add('waiting list', @$_REQUEST['all'] == 'true' ? 'print all' : 'print selected', serialize($_POST)); if (isset($_REQUEST['event_id'])) { $operations = Element_OphTrOperationbooking_Operation::model()->findAll('event_id=?', array($_REQUEST['event_id'])); $auto_confirm = true; } else { $operation_ids = isset($_REQUEST['operations']) ? $_REQUEST['operations'] : null; $auto_confirm = isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 1; if (!is_array($operation_ids)) { throw new CHttpException('400', 'Invalid operation list'); } $operations = Element_OphTrOperationbooking_Operation::model()->findAllByPk($operation_ids); } $this->layout = '//layouts/print'; $cmd = Yii::app()->db->createCommand('SELECT GET_LOCK(?, 1)'); while (!$cmd->queryScalar(array('waitingListPrint'))) { } $directory = Yii::app()->assetManager->basePath . '/waitingList'; Yii::app()->db->createCommand('SELECT RELEASE_LOCK(?)')->execute(array('waitingListPrint')); $html = ''; $docrefs = array(); $barcodes = array(); $patients = array(); $documents = 0; // FIXME: provide a means by which progress can be reported back to the user, possibly via session and parallel polling? foreach ($operations as $operation) { $letter_status = $operation->getDueLetter(); if ($letter_status === null && $operation->getLastLetter() == Element_OphTrOperationbooking_Operation::LETTER_GP) { $letter_status = Element_OphTrOperationbooking_Operation::LETTER_GP; } set_time_limit(3); $html .= $this->printLetter($operation, $auto_confirm); $docrefs[] = "E:{$operation->event->id}/" . strtoupper(base_convert(time() . sprintf('%04d', Yii::app()->user->getId()), 10, 32)) . '/{{PAGE}}'; $barcodes[] = $operation->event->barcodeHTML; $patients[] = $operation->event->episode->patient; ++$documents; if ($letter_status == Element_OphTrOperationbooking_Operation::LETTER_GP) { // Patient letter is another document $docrefs[] = "E:{$operation->event->id}/" . strtoupper(base_convert(time() . sprintf('%04d', Yii::app()->user->getId()), 10, 32)) . '/{{PAGE}}'; $barcodes[] = $operation->event->barcodeHTML; $patients[] = $operation->event->episode->patient; ++$documents; } } set_time_limit(10); $pdf_suffix = 'waitingList_' . Yii::app()->user->id . '_' . rand(); $wk = new WKHtmlToPDF(); $wk->setDocuments($documents); $wk->setDocrefs($docrefs); $wk->setBarcodes($barcodes); $wk->setPatients($patients); $wk->generatePDF($directory, $pdf_suffix, '', $html); $pdf = $directory . "/{$pdf_suffix}.pdf"; header('Content-Type: application/pdf'); header('Content-Length: ' . filesize($pdf)); readfile($pdf); @unlink($pdf); }
/** * Get the operation booking for the event. * * @return OphTrOperationbooking_Operation_Booking */ public function getCurrentBooking() { if ($this->event_id && ($op = Element_OphTrOperationbooking_Operation::model()->with('booking')->find('event_id = ?', array($this->event_id)))) { return $op->booking; } }