/** * Get bookings for the given selection criteria. * * @param $data * * @return OphTrOperationbooking_Operation_Booking[] $bookings * * @throws Exception */ public function getBookingList($data) { foreach (array('date-start', 'date-end', 'subspecialty-id', 'site-id') as $required) { if (!isset($data[$required])) { throw new Exception('invalid request for booking list'); } } $criteria = new CDbCriteria(); $criteria->addCondition('session.date >= :dateFrom and session.date <= :dateTo'); $criteria->addInCondition('operation.status_id', array(2, 4)); $criteria->params[':dateFrom'] = Helper::convertNHS2MySQL($data['date-start']); $criteria->params[':dateTo'] = Helper::convertNHS2MySQL($data['date-end']); if (@$data['emergency_list']) { $criteria->addCondition('firm.id IS NULL'); } else { $criteria->addCondition('theatre.site_id = :siteId and subspecialty_id = :subspecialtyId'); $criteria->params[':siteId'] = $data['site-id']; $criteria->params[':subspecialtyId'] = $data['subspecialty-id']; } if (@$data['ward-id']) { $criteria->addCondition('ward.id = :wardId'); $criteria->params[':wardId'] = $data['ward-id']; } if (@$data['firm-id']) { $criteria->addCondition('firm.id = :firmId'); $criteria->params[':firmId'] = $data['firm-id']; } $criteria->addCondition('`t`.booking_cancellation_date is null'); $criteria->order = 'ward.code, patient.hos_num'; Yii::app()->event->dispatch('start_batch_mode'); return OphTrOperationbooking_Operation_Booking::model()->with(array('session' => array('with' => array('theatre', 'firm' => array('with' => array('serviceSubspecialtyAssignment' => array('with' => 'subspecialty'))))), 'operation' => array('with' => array('event' => array('with' => array('episode' => array('with' => array('patient' => array('with' => 'contact'))))))), 'ward'))->findAll($criteria); }
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(); }
protected function appendBookingValues(&$record, $event_id, $booking_diagnosis, $theatre, $bookingcomments, $surgerydate) { if ($api = Yii::app()->moduleAPI->get('OphTrOperationbooking')) { $procedure = Element_OphTrOperationnote_ProcedureList::model()->find('event_id=:event_id', array(':event_id' => $event_id)); $bookingEventID = $procedure['booking_event_id']; foreach (array('booking_diagnosis', 'theatre', 'bookingcomments', 'surgerydate') as $k) { if (${$k}) { $record[$k] = ''; } } if ($bookingEventID) { $operationElement = $api->getOperationForEvent($bookingEventID); $latestBookingID = $operationElement['latest_booking_id']; $operationBooking = OphTrOperationbooking_Operation_Booking::model()->find('id=:id', array('id' => $latestBookingID)); if ($booking_diagnosis) { $diag_el = $operationElement->getDiagnosis(); $disorder = $diag_el->disorder(); if ($disorder) { $record['booking_diagnosis'] = $diag_el->eye->adjective . ' ' . $disorder->term; } else { $record['booking_diagnosis'] = 'Unknown'; } } if ($this->theatre && $operationElement && $operationBooking) { $theatreName = $operationElement->site['name'] . ' ' . $operationBooking->theatre['name']; $record['theatre'] = $theatreName; } if ($this->bookingcomments) { $record['bookingcomments'] = $operationElement['comments']; } if ($this->surgerydate) { $record['surgerydate'] = $operationBooking['session_date']; } } } }
/** * 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(); }
/** * Get the most recent booking for the patient in the given episode. * * @param Episode $episode * * @return OphTrOperationbooking_Operation_Booking */ public function getMostRecentBookingForEpisode($episode) { $criteria = new CDbCriteria(); $criteria->compare('episode_id', $episode->id); $criteria->order = 'event.created_date desc'; return OphTrOperationbooking_Operation_Booking::model()->with(array('operation' => array('with' => 'event')))->find($criteria); }
/** * Print transport letters for bookings. */ public function actionPrint($id) { $operation_ids = isset($_GET['operations']) ? $_GET['operations'] : null; if (!is_array($booking_ids)) { throw new CHttpException('400', 'Invalid operation list'); } $bookings = OphTrOperationbooking_Operation_Booking::model()->findAllByPk($booking_ids); // Print a letter for booking, separated by a page break $break = false; foreach ($bookings as $booking) { if ($break) { $this->renderPartial('letters/break'); } else { $break = true; } $patient = $booking->operation->event->episode->patient; $transport = array('request_to' => 'FIXME: REQUEST TO', 'request_from' => 'FIXME: REQUEST FROM', 'escort' => '', 'mobility' => '', 'oxygen' => '', 'contact_name' => 'FIXME: CONTACT NAME', 'contact_number' => 'FIXME: CONTACT NUMBER', 'comments' => ''); $this->renderPartial('transport/transport_form', array('booking' => $booking, 'patient' => $patient, 'transport' => $transport)); } }
public function actionVerifyDeleteTheatres() { $criteria = new CDbCriteria(); $criteria->addInCondition('session.theatre_id', $_POST['theatre']); $criteria->addCondition('booking_cancellation_date is null'); $criteria->addCondition('session_date >= :today'); $criteria->params[':today'] = date('Y-m-d'); if (OphTrOperationbooking_Operation_Booking::model()->with(array('session', 'operation' => array('with' => array('event' => array('with' => 'episode')))))->find($criteria)) { echo '0'; } else { echo '1'; } }
public function delete() { // Delete related records OphTrOperationbooking_Operation_Date_Letter_Sent::model()->deleteAll('element_id = ?', array($this->id)); OphTrOperationbooking_Operation_Procedures::model()->deleteAll('element_id = ?', array($this->id)); OphTrOperationbooking_Operation_Booking::model()->deleteAll('element_id = ?', array($this->id)); OphTrOperationbooking_Operation_EROD::model()->deleteAll('element_id = ?', array($this->id)); parent::delete(); }