protected function __setData(stdClass $data)
 {
     try {
         $finalVisitTime = DateTime::create($data->final_visit_time);
         $visitEndTime = DateTime::create($data->visit_end_time);
     } catch (Exception $e) {
         throw new Exception('Время имеет неверный формат');
     }
     if ($finalVisitTime->getTimestamp() > $visitEndTime->getTimestamp()) {
         throw new Exception('Время приема не может быть позже времени окончания приема');
     }
     $timeChanged = false || $this->_entity->getFinalVisitTime() != $finalVisitTime->getTimestamp();
     $timeChanged = $timeChanged || $this->_entity->getVisitEndTime() != $visitEndTime->getTimestamp();
     if ($timeChanged) {
         $schedule = $this->_entity->getDoctor()->getSchedule($finalVisitTime);
         if (!$schedule->isAvailable($finalVisitTime, $visitEndTime, [(int) $this->_entity->getId()])) {
             throw new Exception('В это время доктор не принимает или занят');
         }
     }
     $this->_entity->setFinalVisitTime($finalVisitTime->getTimestamp());
     $this->_entity->setVisitEndTime($visitEndTime->getTimestamp());
     $serviceCollection = $this->_entity->getServiceCollection();
     $serviceCollection->resetItems();
     foreach ($data->id_services as $idService) {
         $service = Application_Model_Medical_Service::getById($idService);
         if ($service instanceof Application_Model_Medical_Service) {
             $serviceCollection->add($service);
         }
     }
     $this->_entity->setStatus($data->status);
 }
示例#2
0
 public function showList()
 {
     $date = isset($this->_data->date) ? $this->_data->date : null;
     $services = isset($this->_data->services) ? $this->_data->services : '';
     if (is_string($date)) {
         $date = MedOptima_DateTime::create($date);
         $services = empty($services) ? [] : explode(',', $services);
         $doctors = (new Repo())->getWorkingDoctorsWithServices($date, $services);
         return DTO::jsonSerializeList($doctors, $date);
     } else {
         return [];
     }
 }
示例#3
0
 private function _sync()
 {
     $event = $this->_calendar->getEventById($this->_reservation->getIdGoogleEvent());
     if ($event->getStatus() == self::EVENT_STATUS_CANCELLED) {
         $this->_deleteLocal();
     } else {
         $localUpdateTime = $this->_reservation->getLastSaveTime();
         $remoteUpdateTime = DateTime::create($event->getUpdated())->getTimestamp();
         if ($localUpdateTime < $remoteUpdateTime) {
             $this->_updateLocal($event);
         } else {
             $this->_updateRemote($event);
         }
     }
 }
示例#4
0
 public function jsonSerialize()
 {
     $result = array();
     $duration = $this->_schedule->getDoctor()->getReceptionDuration()->getTimestamp();
     $from = clone $this->_schedule->getDate();
     $to = clone $from;
     $currentTimestamp = MedOptima_DateTime::create()->getTimestamp();
     foreach ($this->_schedule->getWorkTimeList() as $workTime) {
         $from->setTime(0, 0);
         $to->setTime(0, 0);
         $to->addSeconds($duration);
         $period = $workTime->getPeriod();
         $time = $period->getTimestampBegin();
         $from->addSeconds($time);
         $to->addSeconds($time);
         for (; $time <= $period->getTimestampEnd() - $duration; $time += $duration) {
             $result[$from->getTimestamp()] = array('time' => $from->getGostTime(), 'available' => $from->getTimestamp() > $currentTimestamp && !$this->_getReservationService()->hasReservationsBetween($from, $to));
             $from->addSeconds($duration);
             $to->addSeconds($duration);
         }
     }
     ksort($result);
     return array_values($result);
 }
示例#5
0
 public function isExpired()
 {
     return MedOptima_DateTime::create()->getTimestamp() > $this->getTimeExpires();
 }
示例#6
0
 private function _prepareVisitTime(array $excludedReservations = array())
 {
     $this->_fromTime = MedOptima_DateTime::create($this->_data->visitDate . ' ' . $this->_data->visitTime);
     if ($this->_fromTime->isToday()) {
         throw new Exception('Can not make reservation for today');
     }
     $this->_toTime = clone $this->_fromTime;
     $this->_toTime->addSeconds($this->_doctor->getMinReceptionDuration()->getTimestamp());
     if (!$this->_doctor->getSchedule($this->_fromTime)->isAvailable($this->_fromTime, $this->_toTime, $excludedReservations)) {
         throw new Exception('Doctor is not available at this time (' . $this->_fromTime->getGostDatetime() . ')');
     }
 }
示例#7
0
 public function onlyActive()
 {
     $this->_getWhere()->add('finalVisitTime', '>', MedOptima_DateTime::create()->getTimestamp());
 }
示例#8
0
 public function updateReservationFromEvent(Google_Event $event)
 {
     $this->_reservation->setFinalVisitTime(DateTime::create($event->getStart()->getDateTime())->getTimestamp());
     $this->_reservation->setVisitEndTime(DateTime::create($event->getEnd()->getDateTime())->getTimestamp());
 }