protected function _createVisit($appointmentId)
 {
     $ret = 0;
     if ($appointmentId > 0) {
         $appointment = new Appointment();
         $appointment->appointmentId = $appointmentId;
         $appointment->populate();
         $personId = (int) $appointment->patientId;
         $insuredRelationship = new InsuredRelationship();
         $insuredRelationship->personId = $personId;
         $visit = new Visit();
         $visit->patientId = $personId;
         $visit->activePayerId = $insuredRelationship->defaultActivePayer;
         $visit->roomId = $appointment->roomId;
         $visit->practiceId = $appointment->practiceId;
         $room = new Room();
         $room->roomId = $visit->roomId;
         $room->populate();
         $visit->buildingId = $room->buildingId;
         $visit->createdByUserId = $appointment->creatorId;
         $visit->lastChangeUserId = $appointment->lastChangeId;
         $visit->treatingPersonId = $appointment->providerId;
         $visit->encounterReason = $appointment->reason;
         $visit->dateOfTreatment = $appointment->start;
         $visit->timestamp = date('Y-m-d H:i:s');
         $visit->appointmentId = $appointment->appointmentId;
         $visit->persist();
         $visitId = (int) $visit->visitId;
         $payment = new Payment();
         foreach ($payment->getIteratorByAppointmentId($appointmentId) as $row) {
             $row->visitId = $visitId;
             $row->persist();
         }
         $miscCharge = new MiscCharge();
         foreach ($miscCharge->getIteratorByAppointmentId($appointmentId) as $row) {
             $row->visitId = $visitId;
             $row->persist();
         }
         $ret = $visitId;
     }
     return $ret;
 }
 protected function _processSetVisit($closed = null, $void = null)
 {
     $visitParams = $this->_getParam('visit');
     $visitParams['lastChangeUserId'] = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     //$visitParams['timestamp'] = date('Y-m-d h:i:s');
     if ($closed !== null) {
         $visitParams['closed'] = (int) $closed;
     }
     $visit = new Visit();
     $visit->visitId = (int) $visitParams['visitId'];
     $data = 'Visit ID ' . $visit->visitId . ' is invalid';
     if ($visit->populate()) {
         if ($void !== null) {
             $visit->void = (int) $void;
             if ($visit->void && $visit->hasPayments()) {
                 $error = 'Cannot void visit with payments';
             }
         } else {
             $visit->populateWithArray($visitParams);
         }
         if (isset($error)) {
             $data = $error;
         } else {
             $visit->persist();
             $data = $this->_generateVisitRowData($visit);
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
 function processAddVisitAction()
 {
     $visitParams = $this->_getParam('visit');
     $visitParams['created_by_user_id'] = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $visitParams['date_of_treatment'] = date('Y-m-d');
     $visitParams['timestamp'] = date('Y-m-d h:i:s');
     $visit = new Visit();
     $visit->populateWithArray($visitParams);
     $visit->persist();
     $msg = __("Visit added successfully.");
     $data = array();
     $data['msg'] = $msg;
     $data['visitId'] = $visit->encounter_id;
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
 public function processCloseVisitAction()
 {
     $visitId = (int) $this->_getParam('visitId');
     $data = array();
     $visit = new Visit();
     $visit->visitId = $visitId;
     if ($visitId > 0 && $visit->populate()) {
         $visit->closed = 1;
         $visit->persist();
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }