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');
 }