function processNextStationByAppointmentAction()
 {
     $appointmentId = (int) $this->_getParam('appointmentId');
     $stationId = $this->_getParam('stationId');
     $appointment = new Appointment();
     $appointment->appointmentId = $appointmentId;
     $appointment->populate();
     $provider = new Provider();
     $provider->personId = $appointment->providerId;
     $provider->populate();
     $routing = new Routing();
     $routing->personId = $appointment->patientId;
     $routing->appointmentId = $appointment->appointmentId;
     $routing->providerId = $appointment->providerId;
     $routing->roomId = $appointment->roomId;
     $routing->populateByAppointments();
     $routing->fromStationId = $routing->stationId;
     $routing->stationId = $stationId;
     $routing->timestamp = date('Y-m-d H:i:s');
     $routing->persist();
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array(true));
 }
 protected function _populateAppointmentRow(Appointment $app, array &$columnData, $colIndex, $index, $rowsLen)
 {
     $startToTime = strtotime($app->start);
     $endToTime = strtotime($app->end);
     $tmpStart = date('H:i', $startToTime);
     $tmpEnd = date('H:i', $endToTime);
     $timeLen = ceil(($endToTime - $startToTime) / 60 / self::FILTER_MINUTES_INTERVAL);
     $appointmentId = (int) $app->appointmentId;
     $patientId = (int) $app->patientId;
     $providerId = (int) $app->providerId;
     $roomId = (int) $app->roomId;
     $patient = new Patient();
     $patient->personId = $patientId;
     $patient->populate();
     $id = isset($columnData[$colIndex]['id']) ? $columnData[$colIndex]['id'] : '';
     $columnData[$colIndex]['id'] = $appointmentId;
     if (strlen($id) > 0) {
         $columnData[$colIndex]['id'] .= 'i' . $id;
     }
     $visit = new Visit();
     $visit->appointmentId = $appointmentId;
     $visit->populateByAppointmentId();
     $visitIcon = $visit->visitId > 0 ? '<img src="' . $this->view->baseUrl . '/img/appointment_visit.png" alt="' . __('Visit') . '" title="' . __('Visit') . '" style="border:0px;height:18px;width:18px;margin-left:5px;" />' : '';
     $routingStatuses = array();
     if (strlen($app->appointmentCode) > 0) {
         $routingStatuses[] = __('Mark') . ': ' . $app->appointmentCode;
     }
     $routing = new Routing();
     $routing->personId = $patientId;
     $routing->appointmentId = $appointmentId;
     $routing->providerId = $providerId;
     $routing->roomId = $roomId;
     $routing->populateByAppointments();
     if (strlen($routing->stationId) > 0) {
         $routingStatuses[] = __('Station') . ': ' . $routing->stationId;
     }
     $routingStatus = implode(' ', $routingStatuses);
     $nameLink = $patientId > 0 ? "<a href=\"javascript:showPatientDetails({$patientId});\">{$patient->person->displayName} (#{$patient->recordNumber})</a>" : '';
     $cellRow = 20;
     $height = $cellRow * $timeLen * 1.1;
     $marginTop = 2;
     // compute and adjust margin top and height
     $heightPerMinute = $cellRow / self::FILTER_MINUTES_INTERVAL;
     $map = $columnData[$colIndex]['map'];
     $diff = ($startToTime - $map['start']) / 60;
     if ($diff > 0) {
         $marginTop += $diff * $heightPerMinute;
         $height -= $marginTop;
     }
     $marginLeft = $rowsLen > 1 && $index > 0 ? $index * 250 : 8;
     $zIndex = $colIndex . $index;
     $columnData[$colIndex]['data'][0] .= "<div onmousedown=\"calendarSetAppointmentId('{$appointmentId}')\" ondblclick=\"timeSearchDoubleClicked(this,event)\" appointmentId=\"{$appointmentId}\" visitId=\"{$visit->visitId}\" style=\"float:left;position:absolute;margin-top:{$marginTop}px;height:{$height}px;width:230px;overflow:hidden;border:thin solid black;margin-left:{$marginLeft}px;padding-left:2px;background-color:lightgrey;z-index:{$zIndex};\" class=\"dataForeground\" id=\"event{$appointmentId}\" onmouseover=\"calendarExpandAppointment({$appointmentId},this,{$height});\" onmouseout=\"calendarShrinkAppointment({$appointmentId},this,{$height},{$zIndex});\">{$tmpStart}-{$tmpEnd} {$nameLink} {$visitIcon} <br />{$routingStatus}<div class=\"bottomInner\" id=\"bottomInnerId{$appointmentId}\" style=\"white-space:normal;\">{$app->title}</div></div>";
     $columnData[$colIndex]['userdata']['visitId'] = $visit->visitId;
     $columnData[$colIndex]['userdata']['appointmentId'] = $appointmentId;
     $columnData[$colIndex]['userdata']['length'] = $timeLen;
 }
 public function listHistoryAction()
 {
     $personId = (int) $this->_getParam('personId');
     $future = (int) $this->_getParam('future');
     $rows = array();
     $appointmentTemplate = new AppointmentTemplate();
     $reasons = $appointmentTemplate->getAppointmentReasons();
     $iterator = new AppointmentIterator(null, false);
     $filters = array('patientId' => $personId);
     if ($future) {
         $filters['start'] = date('Y-m-d');
     }
     $iterator->setFilters($filters);
     foreach ($iterator as $app) {
         $personId = (int) $app->patientId;
         $appointmentId = (int) $app->appointmentId;
         $providerId = (int) $app->providerId;
         $roomId = (int) $app->roomId;
         list($dateStart, $timeStart) = explode(' ', $app->start);
         list($dateEnd, $timeEnd) = explode(' ', $app->end);
         $providerName = '';
         if ($providerId > 0) {
             $provider = new Provider();
             $provider->setPersonId($providerId);
             $provider->populate();
             $providerName = $provider->displayName;
         }
         $roomName = '';
         if ($roomId > 0) {
             $room = new Room();
             $room->setRoomId($roomId);
             $room->populate();
             $roomName = $room->displayName;
         }
         $routing = new Routing();
         $routing->personId = $personId;
         $routing->appointmentId = $appointmentId;
         $routing->providerId = $providerId;
         $routing->roomId = $roomId;
         $routing->populateByAppointments();
         $station = $routing->stationId;
         $reason = $app->reason;
         $appointmentReason = isset($reasons[$reason]) ? $reasons[$reason]['name'] : '';
         $row = array();
         $row['id'] = $appointmentId;
         $row['data'] = array();
         $row['data'][] = $dateStart;
         $row['data'][] = $timeStart . ' - ' . $timeEnd;
         $row['data'][] = $providerName;
         $row['data'][] = $app->title;
         $row['data'][] = $roomName;
         $row['data'][] = $appointmentReason;
         $row['data'][] = $app->appointmentCode;
         $row['data'][] = $routing->stationId;
         $rows[] = $row;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }