public function _editAppointment(array $params, $action = 'new')
 {
     $appointmentId = isset($params['appointmentId']) ? (int) $params['appointmentId'] : 0;
     $appointment = new Appointment();
     $appointment->appointmentId = $appointmentId;
     $date = isset($params['date']) ? $params['date'] : '';
     if ($appointmentId > 0 && $appointment->populate()) {
         $filter = $this->getCurrentDisplayFilter();
         $start = explode(' ', date('Y-m-d H:i', strtotime($appointment->start)));
         $date = $start[0];
         $appointment->start = $start[1];
         $appointment->end = date('H:i', strtotime($appointment->end));
         $recordNumber = $appointment->patient->record_number;
         $patientName = $appointment->patient->displayName;
         $this->view->patient = "{$patientName} #{$recordNumber} PID:{$appointment->patient->person_id}";
     } else {
         $start = isset($params['start']) ? $params['start'] : self::FILTER_TIME_START;
         $appointment->start = $start;
         $appointment->end = date('H:i', strtotime('+1 hour', strtotime($start)));
         $appointment->providerId = isset($params['providerId']) ? (int) $params['providerId'] : 0;
         $appointment->roomId = isset($params['roomId']) ? (int) $params['roomId'] : 0;
     }
     $this->view->date = $date;
     $form = new WebVista_Form(array('name' => $action . '-appointment'));
     $form->setAction(Zend_Registry::get('baseUrl') . 'calendar.raw/process-' . $action . '-appointment');
     $form->loadORM($appointment, 'Appointment');
     $form->setWindow('windowAppointmentId');
     $this->view->form = $form;
     $this->view->reasons = PatientNote::listReasons();
     $phones = array();
     $phone = new PhoneNumber();
     $phoneIterator = $phone->getIteratorByPersonId($appointment->patientId);
     foreach ($phoneIterator as $row) {
         $phones[] = $row->number;
     }
     $this->view->phones = $phones;
     $appointmentTemplate = new AppointmentTemplate();
     $this->view->appointmentReasons = $appointmentTemplate->getAppointmentReasons();
     $this->view->appointment = $appointment;
     $this->view->callbackId = $this->_getParam('callbackId', '');
     $this->render('appointment');
 }
 public static function generateCalendarPreferencesEnum($force = true)
 {
     $ret = false;
     do {
         $name = 'Calendar';
         $key = 'CALENDAR';
         $enumeration = new self();
         $enumeration->populateByEnumerationName($name);
         // check for key existence
         if (strlen($enumeration->key) > 0 && $enumeration->key == $key) {
             if (!$force) {
                 break;
             }
             $enumerationClosure = new EnumerationsClosure();
             $enumerationClosure->deleteEnumeration($enumeration->enumerationId);
         }
         $enums = array('appointment' => array('key' => 'APP_REASON', 'name' => AppointmentTemplate::ENUM_PARENT_NAME, 'active' => 1, 'data' => array('provider' => array('key' => 'PROVIDER', 'name' => 'Provider', 'active' => 1), 'specialist' => array('key' => 'SPECIALIST', 'name' => 'Specialist', 'active' => 1), 'medicalPhone' => array('key' => 'MEDPHONE', 'name' => 'Medical Phone', 'active' => 1), 'medicalPU' => array('key' => 'MEDPU', 'name' => 'Medication PU', 'active' => 1), 'education' => array('key' => 'EDUCATION', 'name' => 'Education', 'active' => 1), 'eligibility' => array('key' => 'ELIG', 'name' => 'Eligibility', 'active' => 1), 'blockedTime' => array('key' => 'BLOCKTIME', 'name' => 'Blocked Time', 'active' => 1))));
         $appointmentTemplate = new AppointmentTemplate();
         foreach ($enums['appointment']['data'] as $k => $item) {
             $appointmentTemplate->appointmentTemplateId = 0;
             $appointmentTemplate->name = $item['name'];
             $appointmentTemplate->persist();
             $enums['appointment']['data'][$k]['ormClass'] = 'AppointmentTemplate';
             $enums['appointment']['data'][$k]['ormEditMethod'] = 'ormEditMethod';
             $enums['appointment']['data'][$k]['ormId'] = $appointmentTemplate->appointmentTemplateId;
         }
         // top level
         $topLevel = array();
         $topLevel['key'] = $key;
         $topLevel['name'] = $name;
         $topLevel['category'] = 'System';
         $topLevel['active'] = 1;
         $topLevel['data'] = $enums;
         $data = array();
         $data[] = $topLevel;
         self::_saveEnumeration($data);
         $ret = true;
     } while (false);
     return $ret;
 }
 public static function generateCalendarPreferencesEnum($force = true)
 {
     $ret = false;
     do {
         $name = 'Calendar';
         $key = 'CALENDAR';
         $enumeration = new Enumeration();
         $enumeration->populateByEnumerationName($name);
         // check for key existence
         if (strlen($enumeration->key) > 0 && $enumeration->key == $key) {
             if (!$force) {
                 break;
             }
             $enumerationClosure = new EnumerationsClosure();
             $enumerationClosure->deleteEnumeration($enumeration->enumerationId);
         }
         $enums = array('appointment' => array('key' => 'APP_REASON', 'name' => AppointmentTemplate::ENUM_PARENT_NAME, 'active' => 1, 'guid' => 'cb4390f6-a334-4dbd-9edc-5637265b776b', 'data' => array('provider' => array('key' => 'PROVIDER', 'name' => 'Provider', 'active' => 1, 'guid' => '82084f77-65a1-466a-b5f8-63e3eb38af9a'), 'specialist' => array('key' => 'SPECIALIST', 'name' => 'Specialist', 'active' => 1, 'guid' => 'ca0e5f81-7105-4250-abed-8ee45c51b5e3'), 'medicalPhone' => array('key' => 'MEDPHONE', 'name' => 'Medical Phone', 'active' => 1, 'guid' => '8dd85952-3be8-4b7e-b153-01678f8b571f'), 'medicalPU' => array('key' => 'MEDPU', 'name' => 'Medication PU', 'active' => 1, 'guid' => '27cf00da-f8c0-4859-9205-63b9e056edf9'), 'education' => array('key' => 'EDUCATION', 'name' => 'Education', 'active' => 1, 'guid' => '23190974-896c-4dfa-b6db-3a8072aa6ca0'), 'eligibility' => array('key' => 'ELIG', 'name' => 'Eligibility', 'active' => 1, 'guid' => 'b9c4fb2f-5ddd-48e1-b733-44f7be127069'), 'blockedTime' => array('key' => 'BLOCKTIME', 'name' => 'Blocked Time', 'active' => 1, 'guid' => '7d6486a3-9655-44a3-b5ed-ad95da0cea7c'))));
         $appointmentTemplate = new AppointmentTemplate();
         foreach ($enums['appointment']['data'] as $k => $item) {
             $appointmentTemplate->appointmentTemplateId = 0;
             $appointmentTemplate->name = $item['name'];
             $appointmentTemplate->persist();
             $enums['appointment']['data'][$k]['ormClass'] = 'AppointmentTemplate';
             $enums['appointment']['data'][$k]['ormEditMethod'] = 'ormEditMethod';
             $enums['appointment']['data'][$k]['ormId'] = $appointmentTemplate->appointmentTemplateId;
         }
         // top level
         $level = array();
         $level['guid'] = 'e46d5343-18de-459a-9fa4-0dc46ab0c41c';
         $level['key'] = $key;
         $level['name'] = $name;
         $level['category'] = 'System';
         $level['active'] = 1;
         $level['data'] = $enums;
         $data = array($level);
         self::_saveEnumeration($data);
         $ret = true;
     } while (false);
     return $ret;
 }
 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));
 }
 public function addAppointmentAction()
 {
     $appointmentId = $this->_getParam('appointmentId');
     $appointment = new Appointment();
     if (strlen($appointmentId) > 0) {
         $filter = $this->getCurrentDisplayFilter();
         $appointment->appointmentId = (int) $appointmentId;
         $appointment->populate();
         $this->view->start = date('H:i', strtotime($appointment->start));
         $this->view->end = date('H:i', strtotime($appointment->end));
         foreach ($filter->columns as $index => $col) {
             if ($col['providerId'] > 0 && $col['roomId'] > 0 && $col['providerId'] == $appointment->providerId && $col['roomId'] == $appointment->roomId || $col['providerId'] > 0 && $col['providerId'] == $appointment->providerId || $col['roomId'] > 0 && $col['roomId'] == $appointment->roomId) {
                 $this->view->columnId = $index;
                 break;
             }
         }
         $recordNumber = $appointment->patient->record_number;
         $lastName = $appointment->patient->last_name;
         $firstName = $appointment->patient->first_name;
         $middleInitial = '';
         if (strlen($appointment->patient->middle_name) > 0) {
             $middleInitial = $appointment->patient->middle_name[0];
         }
         $this->view->patient = "{$lastName}, {$firstName} {$middleInitial} #{$recordNumber} PID:{$appointment->patient->person_id}";
     } else {
         $columnId = $this->_getParam('columnId');
         $rowId = $this->_getParam('rowId');
         $start = $this->_getParam('start');
         if (strlen($columnId) > 0) {
             $this->view->columnId = $columnId;
             $filter = $this->getCurrentDisplayFilter();
             if (!isset($filter->columns[$columnId])) {
                 throw new Exception(__("Cannot generate column with that index, there is no filter defined for that column Index: ") . $columnId);
             }
             $column = $filter->columns[$columnId];
             $appointment->providerId = isset($column['providerId']) ? $column['providerId'] : 0;
             $appointment->roomId = isset($column['roomId']) ? $column['roomId'] : 0;
         }
         if (strlen($start) > 0) {
             $this->view->start = $start;
             $this->view->end = date('H:i', strtotime('+1 hour', strtotime($start)));
         }
     }
     $form = new WebVista_Form(array('name' => 'add-appointment'));
     $form->setAction(Zend_Registry::get('baseUrl') . "calendar.raw/process-add-appointment");
     $form->loadORM($appointment, "Appointment");
     $form->setWindow('windowNewAppointment');
     $this->view->form = $form;
     $reasons = array();
     $enumeration = new Enumeration();
     $enumeration->populateByEnumerationName(PatientNote::ENUM_REASON_PARENT_NAME);
     $enumerationsClosure = new EnumerationsClosure();
     $enumerationIterator = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1);
     $ctr = 0;
     foreach ($enumerationIterator as $enum) {
         // since data type of patient_note.reason is tinyint we simply use the counter as id
         $reasons[$ctr++] = $enum->name;
     }
     /*
     $patientNotes = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = (int)$appointment->patientId;
     $filters['active'] = 1;
     $filters['posting'] = 0;
     $patientNoteIterator->setFilters($filters);
     foreach ($patientNoteIterator as $row) {
     	$patientNotes[$row->patientNoteId] = $reasons[$row->reason];
     }
     $this->view->patientNotes = $patientNotes;
     */
     $phones = array();
     $phone = new PhoneNumber();
     $phoneIterator = $phone->getIteratorByPatientId($appointment->patientId);
     foreach ($phoneIterator as $row) {
         $phones[] = $row->number;
     }
     $this->view->phones = $phones;
     $appointmentTemplate = new AppointmentTemplate();
     $appointmentReasons = $appointmentTemplate->getAppointmentReasons();
     $this->view->appointmentReasons = $appointmentReasons;
     $this->view->appointment = $appointment;
     $this->render('add-appointment');
 }