Example #1
0
 public function postSave($id = null)
 {
     $validator = Validator::make(Input::all(), Appointment::$rules);
     if ($validator->passes()) {
         $event = Appointment::find(Input::get('id'));
         if (!$event) {
             $event = new Appointment();
         }
         $calendar = Calendar::find(explode('/', Input::get('date'))[0]);
         if ($calendar) {
             $day = explode('/', Input::get('date'))[1];
             if ($day > 0 && $day <= $calendar->number_of_days) {
                 $event->name = Input::get('name');
                 $event->date = explode('/', Input::get('date'))[1];
                 $event->start_time = Input::get('start_time');
                 $event->end_time = Input::get('end_time');
                 $event->notes = Input::get('notes');
                 $event->calendar_id = $calendar->id;
                 $event->group_id = Input::get('group_id');
                 $event->user_id = Auth::user()->id;
                 $event->save();
                 return Response::json(array('status' => 'success', $event));
             } else {
                 $validator->messages()->add('date', 'The day is invalid.');
             }
         } else {
             $validator->messages()->add('date', 'The month is invalid.');
         }
     }
     return Response::json(array('status' => 'error', 'errors' => $validator->messages()));
 }
 /**
  * Display the specified resource.
  * GET /patientappointment/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function makeAppointment()
 {
     $patient = null;
     $rules = ['patient_id' => 'required', 'doctor_id' => 'required', 'date' => 'required', 'time' => 'required'];
     $data = Input::all();
     $validator = Validator::make(Input::all(), $rules);
     $patient = DB::table('patients')->where('id', $data['patient_id'])->first();
     if ($validator->fails()) {
         return View::make('PatientViews/appointment')->with('title', 'Appointment')->with('id', $data['patient_id'])->with('name', $patient->name)->withErrors($validator);
     } else {
         $doctor = DB::table('doctors')->where('id', $data['doctor_id'])->pluck('working_hourse');
         $doctor_name = DB::table('doctors')->where('id', $data['doctor_id'])->pluck('name');
         $appointmentCount = 0;
         $appointment = DB::table('appointments')->where('schedule', $data['date'])->get();
         $appointmentCount = count($appointment);
         $hourse = $doctor;
         $appointment = new Appointment();
         $appointment->patients_id = $data['patient_id'];
         $appointment->doctors_id = $data['doctor_id'];
         $appointment->schedule = $data['time'];
         if ($appointment->save()) {
             return View::make('PatientViews/appointmentComplete')->with('title', 'appointment_complete')->with('patient_name', $patient->name)->with('patient_id', $data['patient_id'])->with('doctor_name', $doctor_name)->with('appointment_date', $data['date'])->with('appointment_time', $data['time']);
         } else {
             return View::make('PatientViews/appointment')->with('title', 'Appointment')->with('id', $data['patient_id'])->with('name', $patient_name)->withErrors("Something Went Wrong, please try again");
         }
     }
 }
 /**
  * Store a newly created appointment in storage.
  *
  * Should have: category, advisor, studentId, startTime, endTime
  *
  * @return Response
  *
  */
 public function store()
 {
     $appointment = new Appointment();
     $input = Input::all();
     //Check Required
     if (!array_key_exists('category', $input)) {
         return Response::json(array('message' => 'Missing category'), 400);
     } elseif (!array_key_exists('advisor', $input)) {
         return Response::json(array('message' => 'Missing advisor'), 400);
     } elseif (!array_key_exists('start', $input)) {
         return Response::json(array('message' => 'Missing startTime'), 400);
     } elseif (!array_key_exists('end', $input)) {
         return Response::json(array('message' => 'Missing endTime'), 400);
     } elseif (!array_key_exists('studentId', $input)) {
         return Response::json(array('message' => 'Missing studentId'), 400);
     }
     $appointment->category_id = $input['category'];
     $appointment->start = $input['start'];
     $appointment->end = $input['end'];
     $appointment->save();
     $user = User::find($input['studentId']);
     $std_appt = $user->appointments()->save($appointment);
     // DOES NOT CURRENTLY SET 'is_advising' correctly ... need to fix
     $advisor = User::find($input['advisor']);
     $adv_appt = $advisor->appointments()->save($appointment);
     // Format the dates better
     $appointment->start = Carbon::parse($appointment->start)->toDayDateTimeString();
     $appointment->end = Carbon::parse($appointment->end)->toDayDateTimeString();
     // Return the advisorid and userid in the created appointment object
     $appointment->user = $user->fname . ' ' . $user->lname;
     $appointment->advisor = $advisor->fname . ' ' . $advisor->lname;
     $appointment->category = Category::find($appointment->category_id)->name;
     return Response::json($appointment);
 }
 public function executeQuery(sfWebRequest $request)
 {
     if ($request->isXmlHttpRequest()) {
         if ($request->isMethod(sfRequest::GET)) {
             $startDate = $request->getGetParameter('startDate');
             $endDate = $request->getGetParameter('endDate');
             $page = $request->getGetParameter('page');
             $start = $request->getGetParameter('start');
             $limit = $request->getGetParameter('limit');
             $this->convertParamToDateTime($startDate);
             $this->convertParamToDateTime($endDate);
             $result = Doctrine_Core::getTable('Appointment')->getBetween($startDate, $endDate);
             $response = $this->buildResponse($result, "Loading Record");
         } else {
             if ($request->isMethod(sfRequest::POST)) {
                 $form_data = json_decode(file_get_contents('php://input'));
                 $location = $form_data->loc;
                 $title = $form_data->title;
                 $notes = $form_data->notes;
                 $url = $form_data->url;
                 $reminder = $form_data->rem;
                 $cid = $form_data->cid;
                 $startDate = str_replace('T', ' ', $form_data->start);
                 $endDate = str_replace('T', ' ', $form_data->end);
                 $this->convertParamToDateTime($startDate, 'Y-m-d H:i:s');
                 $this->convertParamToDateTime($endDate, 'Y-m-d H:i:s');
                 $a = new Appointment();
                 $a->fromArray(array('coach_id' => 1, 'client_id' => 1, 'calendar_type_id' => $cid, 'scheduled' => $startDate, 'started_at' => $startDate, 'finished_at' => $endDate, 'title' => $title, 'location' => $location, 'notes' => $notes, 'web_link' => $url, 'reminder' => $reminder));
                 $a->save();
                 $response = $this->buildResponse($a, "Creating Record");
             } else {
                 if ($request->isMethod(sfRequest::PUT)) {
                     $form_data = json_decode(file_get_contents('php://input'));
                     $location = $form_data->loc;
                     $title = $form_data->title;
                     $notes = $form_data->notes;
                     $url = $form_data->url;
                     $reminder = $form_data->rem;
                     $cid = $form_data->cid;
                     $startDate = str_replace('T', ' ', $form_data->start);
                     $endDate = str_replace('T', ' ', $form_data->end);
                     $this->convertParamToDateTime($startDate, 'Y-m-d H:i:s');
                     $this->convertParamToDateTime($endDate, 'Y-m-d H:i:s');
                     $a = Doctrine_Core::getTable('Appointment')->find(array($request->getParameter('id')));
                     $a->fromArray(array('coach_id' => 1, 'client_id' => 1, 'calendar_type_id' => $cid, 'scheduled' => $startDate, 'started_at' => $startDate, 'finished_at' => $endDate, 'title' => $title, 'location' => $location, 'notes' => $notes, 'web_link' => $url, 'reminder' => $reminder));
                     $a->save();
                     $response = $this->buildResponse($a, "Updating Record");
                 } else {
                     if ($request->isMethod(sfRequest::DELETE)) {
                         $app = Doctrine_Core::getTable('Appointment')->find(array($request->getParameter('id')));
                         $app->delete();
                         $response = array('success' => true, 'message' => 'Destroyed Record', 'data' => array());
                     }
                 }
             }
         }
         sfConfig::set('sf_web_debug', false);
         return $this->renderPartial('global/ajax', array('ajax' => json_encode($response)));
     }
 }
 public function store()
 {
     if (Request::ajax()) {
         $data = array("agenda_id" => Input::get("agenda_id"), "patient" => Input::get("patient"), "reason" => Input::get("reason"), "fecha" => Input::get("fecha"), "start" => Input::get("start"), "end" => Input::get("end"));
         $rules = array("agenda_id" => 'required', "patient" => 'required|min:2|max:100', "reason" => 'required|min:2|max:200', "fecha" => 'required|min:1|max:100', "start" => 'required|min:1|max:100', "end" => 'required|min:1|max:100');
         $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png');
         $validation = Validator::make(Input::all(), $rules, $messages);
         //si la validación falla redirigimos al formulario de registro con los errores
         if ($validation->fails()) {
             return Response::json(array('success' => false, 'errors' => $validation->getMessageBag()->toArray()));
         } else {
             $agenda = Agenda::find(Input::get('agenda_id'));
             $user = User::where('email', Input::get('patient'))->orWhere('username', Input::get('patient'))->first();
             if ($user) {
                 $patient = Patient::where('user_id', $user->id)->first();
                 if (!$patient) {
                     $patient = new Patient();
                     $patient->user_id = $user->id;
                     $patient->save();
                 }
                 $docPatient = DoctorPatient::where('patient_id', $patient->id)->where('doctor_id', $agenda->doctor_id)->first();
                 if (!$docPatient) {
                     $docPatient = new DoctorPatient();
                     $docPatient->patient_id = $patient->id;
                     $docPatient->doctor_id = $agenda->doctor_id;
                     $docPatient->save();
                 }
                 $apo = new Appointment();
                 $apo->patient_id = $patient->id;
                 $apo->agenda_id = $agenda->id;
                 $apo->day = Input::get("fecha");
                 $apo->start_date = Input::get('start');
                 $apo->end_date = Input::get('end');
                 $apo->reason = Input::get('reason');
                 if ($agenda->appointment_state == 0) {
                     $apo->state = 'confirmed';
                 } else {
                     $apo->state = 'pending';
                 }
                 $apo->save();
                 if ($apo) {
                     if ($agenda->appointment_state == 0) {
                         $mgs = new MgsAppointment();
                         $mgs->appointment_id = $apo->id;
                         $mgs->text = "Su cita fue Confirmada";
                         $mgs->save();
                     }
                     return Response::json(array('success' => true));
                 }
             } else {
                 return Response::json(array('success' => false, 'errors' => 'El usuario no existe'));
             }
         }
     }
 }
 public function create()
 {
     $user = Confide::user();
     if (Request::isMethod('GET')) {
         $staffMembers = DB::table('doctor_patient')->where('doctor_patient.user_id', '=', $user->id)->join('user', 'doctor_patient.staff_id', '=', 'user.id')->join('staff', 'staff.user_id', '=', 'user.id')->select('user.id', 'first_name', 'last_name', 'position')->get();
         $staff = array();
         $staff[''] = "-- Select a Doctor --";
         foreach ($staffMembers as $staffMember) {
             $staff[$staffMember->id] = "Dr. " . $staffMember->first_name . " " . $staffMember->last_name . " " . "(" . $staffMember->position . ")";
         }
         return View::make('home/appointment/create', compact('staff', 'user'));
     } elseif (Request::isMethod('POST')) {
         $messages = array();
         $validator = Validator::make(Input::all(), array('date' => 'required|after:' . date('Y-m-d') . '', 'time' => 'required', 'staff_id' => 'required', 'reason' => 'required'), array('date.required' => 'You must specify a date for the appointment.', 'date.after' => 'You must specify a more future date.', 'time.required' => 'You must specify a time for the appointment.', 'staff_id.required' => 'You must select a doctor.', 'reason.required' => 'You must describe a reason for your appointment.'));
         // Get other errors
         if ($validator->fails()) {
             $messageBag = $validator->messages();
             foreach ($messageBag->all(':message<br>') as $message) {
                 $messages[] = $message;
             }
         }
         if (empty($messages)) {
             // Create a new Appointment with the given data
             $appointment = new Appointment();
             $appointment->fill(Input::all());
             $appointment->patient_id = $user->id;
             $appointment->timestamp = date('Y-m-d H:i:s', strtotime(Input::get('date') . " " . Input::get('time')));
             $appointment->status = 'unconfirmed';
             $appointment->save();
             return Redirect::route('appointment.show.all');
         } else {
             // Flash data to session vars to repopulate form later
             Input::flash();
             // Compile error messages
             $messages = implode($messages);
             return Redirect::route('appointment.create')->with(array('message' => 'Error:<br>' . $messages, 'message_type' => 'error'));
         }
     }
 }
 public function getdataAction()
 {
     $this->view->disable();
     if ($this->request->isPost()) {
         $infos = $this->request->getPost();
         $appointment = new Appointment();
         $appointment->custName = $infos['res_custName'];
         $appointment->mobile = $infos['res_mobile'];
         $appointment->telephone = $infos['res_telephone'];
         $appointment->email = $infos['res_email'];
         $appointment->postcode = $infos['res_postcode'];
         $appointment->custsex = $infos['res_custSex'];
         $appointment->address = $infos['res_address'];
         $appointment->type = 0;
         $appointment->time = time();
         if ($appointment->save()) {
             echo true;
         } else {
             echo false;
         }
     } else {
         $this->response->redirect("index/index");
     }
 }
Example #8
0
 function makeAppointment($user, $scheduleitem_id)
 {
     //get schedule item and verify it and update the darn status
     if (!($item =& $this->getScheduleItem($scheduleitem_id))) {
         return false;
     }
     if (!$item->isOpen()) {
         $this->addError('Requested appointment not open');
         return false;
     }
     $appointment = new Appointment($this->dbcon);
     $data = array('userdata_id' => $user, 'action_id' => $scheduleitem_id);
     $appointment->setData($data);
     return $appointment->save();
 }
Example #9
0
 /**
  * @before _secure
  */
 public function book()
 {
     $this->noview();
     $session = Registry::get("session");
     $configuration = Registry::get("configuration");
     $imojo = $configuration->parse("configuration/payment");
     $intoSeconds = function ($value) {
         $pieces = explode(":", $value);
         return 3600 * $pieces[0] + 60 * $pieces[1];
     };
     if (RequestMethods::get("action") == "pickupLocation") {
         $session->set('Appt\\Book:$location', RequestMethods::get("location_id"));
         echo "Success";
         return;
     }
     if (RequestMethods::post("action") != "checkout" || !$session->get('Appt\\Book:$location')) {
         $this->redirect("/404");
     }
     $charge = base64_decode(RequestMethods::post("tp"));
     $services = RequestMethods::post("service");
     $centre = RequestMethods::post("centre");
     $carts = RequestMethods::post("cart");
     $order = new Order(array("user_id" => $this->user->id, "type" => "appointment", "amount" => $charge, "mode" => "instamojo", "ref_id" => ""));
     $order->save();
     foreach ($services as $service) {
         $i = 0;
         $c = Centre::first(array("id = ?" => $centre[$i]), array("organization_id"));
         $appointment = new Appointment(array("patient_id" => RequestMethods::post("user_id", $this->user->id), "user_id" => $this->user->id, "order_id" => $order->id, "centre_id" => $centre[$i], "service_id" => $service, "location_id" => $session->get('Appt\\Book:$location'), "organization_id" => $c->organization_id, "start" => strftime("%Y-%m-%d %H:%M:%S", strtotime(RequestMethods::post("start")) + $intoSeconds(RequestMethods::post("startTime"))), "end" => strftime("%Y-%m-%d %H:%M:%S", strtotime(RequestMethods::post("start")) + $intoSeconds(RequestMethods::post("endTime"))), "allDay" => 0));
         $appointment->save();
         $i++;
     }
     $session->erase('Appt\\Book:$location');
     $curl = new Curl();
     $curl->setHeader('X-Api-Key', $imojo->payment->instamojo->key);
     $curl->setHeader('X-Auth-Token', $imojo->payment->instamojo->auth);
     $curl->post('https://www.instamojo.com/api/1.1/payment-requests/', array("purpose" => "Appointment", "amount" => $charge, "buyer_name" => $this->user->name, "email" => $this->user->email, "phone" => $this->user->phone, "redirect_url" => "http://healthlitmus.com/appointments/success", "allow_repeated_payments" => false));
     if (!isset($_COOKIE["fixedappointments"])) {
         setcookie("fixedappointments", 1, time() + 3600 * 24);
     } else {
         setcookie("fixedappointments", $_COOKIE["fixedappointments"] + 1, time() + 3600 * 24);
     }
     $payment = $curl->response;
     if ($payment->success == "true") {
         foreach ($carts as $cart) {
             $cart = Cart::first(array("id = ?" => $cart));
             $cart->delete();
         }
         $session->erase('User\\Cart:$cart')->erase('User\\Cart:$total');
         $instamojo = new Instamojo(array("user_id" => $this->user->id, "payment_request_id" => $payment->payment_request->id, "amount" => $payment->payment_request->amount, "purpose" => "order", "purpose_id" => $order->id, "status" => $payment->payment_request->status, "longurl" => $payment->payment_request->longurl, "live" => 1));
         $instamojo->save();
         $this->redirect($instamojo->longurl);
     }
 }
Example #10
0
 protected function afterSave()
 {
     /** @var $user User */
     $userId = $this->followUpUser ?: Yii::app()->user->id;
     $user = User::model()->findByPk($userId);
     if ($this->followUpDue) {
         if ($note = $this->followUpAppointment) {
             $note->app_start = date("Y-m-d", strtotime($this->followUpDue));
             $note->app_user = $user ? $user->use_id : $note->app_user;
             $note->calendarID = $user ? $user->use_branch : $note->calendarID;
         } else {
             if (!$user) {
                 throw new Exception('User for follow up is not selected');
             }
             $note = new Appointment();
             $note->app_type = Appointment::TYPE_VALUATION_FOLLOW_UP;
             $note->app_start = date("Y-m-d", strtotime($this->followUpDue));
             $note->app_user = $user->use_id;
             $note->calendarID = $user->use_branch;
             $note->app_subject = $this->property->address->toString(', ');
             $note->setInstructions([$this->dea_id]);
         }
         $existingFollowUps = Appointment::model()->findByAttributes(array("app_user" => $note->app_user, 'app_type' => Appointment::TYPE_VALUATION_FOLLOW_UP), array('order' => 'app_start DESC', 'condition' => 'DATE(app_start) = "' . date("Y-m-d", strtotime($note->app_start)) . '"'));
         if (!$existingFollowUps) {
             $note->app_start = date("Y-m-d", strtotime($note->app_start)) . " 09:00:00";
             // hardcoded time, not best solution ever
             $note->app_end = date("Y-m-d", strtotime($note->app_start)) . " 09:30:00";
         } else {
             $note->app_start = $existingFollowUps->app_end;
             $note->app_end = date("Y-m-d H:i:s", strtotime($note->app_start . " + 30 minutes"));
         }
         if ($note->save()) {
             $this->followUpAppointmentId = $note->app_id;
             $this->saveAttributes(['followUpAppointmentId']);
         } else {
             $this->addError("followUpUppointment", "Could not save follow up appointment");
         }
         $this->followUpAppointment = $note;
     }
     parent::afterSave();
 }
Example #11
0
 /**
  * Update the specified resource in storage.
  * PUT /patients/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function doctorSelection()
 {
     $rules = ['patient_id' => 'required', 'patient_name' => 'required', 'specialty' => 'required', 'doctor_id' => 'required', 'appointment_date' => 'required', 'appointment_time' => 'required'];
     $data = Input::all();
     $validator = Validator::make(Input::all(), $rules);
     $patient = DB::table('patients')->where('id', $data['patient_id'])->first();
     if ($validator->fails()) {
         return View::make('appointment')->with('title', 'Appointment')->with('id', $data['patient_id'])->with('name', $patient->name)->withErrors($validator);
     } else {
         $doctor = DB::table('doctors')->where('id', $data['doctor_id'])->pluck('working_hourse');
         $doctor_name = DB::table('doctors')->where('id', $data['doctor_id'])->pluck('name');
         $appointmentCount = 0;
         $appointment = DB::table('appointments')->where('schedule', $data['appointment_date'])->get();
         $appointmentCount = count($appointment);
         $hourse = $doctor;
         if ($appointmentCount >= $hourse * 60 / 15) {
             return View::make('appointment')->with('title', 'Appointment')->with('id', $data['patient_id'])->with('name', $patient_name)->withErrors($validator);
         } else {
             $appointment = new Appointment();
             $appointment->patients_id = $data['patient_id'];
             $appointment->doctors_id = $data['doctor_id'];
             $appointment->schedule = $data['appointment_date'] . ' ' . $data['appointment_time'];
             if ($appointment->save()) {
                 return View::make('appointmentComplete')->with('title', 'appointment_complete')->with('patient_name', $patient->name)->with('patient_serial', $data['patient_id'])->with('doctor_name', $doctor_name)->with('appointment_date', $data['appointment_date'])->with('appointment_time', $data['appointment_time']);
             }
         }
     }
     //return 'abc';
 }
 /**
  * edit method
  *
  * @param string $id
  * @return void
  */
 public function edit($id = null, $section = null)
 {
     $this->WorkOrder->id = $id;
     if (!$this->WorkOrder->exists()) {
         throw new NotFoundException(__('Invalid quote'));
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         $this->request->data['WorkOrder']['id'] = $id;
         if (trim($this->request->data['WorkOrderStatus']['status']) == "Approve") {
             $this->request->data['WorkOrder']['status'] = "Approve";
             $wo_data = $this->WorkOrder->find('first', array('conditions' => array('WorkOrder.id' => $id)));
             $s_date = date("Y-m-d H:i:s", strtotime($wo_data['Quote']['est_shipping']));
             $add_e_date = strtotime($wo_data['Quote']['est_shipping']);
             //				$add_e_date = strtotime($wo_data['Quote']['est_shipping']) + ( 60 * 60 );
             $e_date = date("Y-m-d H:i:s", $add_e_date);
             $schedule['Appointment']['work_order_id'] = $wo_data['WorkOrder']['id'];
             $schedule['Appointment']['address'] = $wo_data['Quote']['address'];
             $schedule['Appointment']['city'] = $wo_data['Quote']['city'];
             $schedule['Appointment']['province'] = $wo_data['Quote']['province'];
             $schedule['Appointment']['postal_code'] = $wo_data['Quote']['postal_code'];
             $schedule['Appointment']['country'] = $wo_data['Quote']['country'];
             $schedule['Appointment']['type'] = "Appointment";
             $schedule['Appointment']['created_by'] = $this->loginUser['id'];
             $schedule['Appointment']['start_date'] = $s_date;
             $schedule['Appointment']['end_date'] = $e_date;
         }
         if (trim($this->request->data['WorkOrderStatus']['status']) == "Review") {
             $this->request->data['WorkOrder']['status'] = "Review";
         }
         if (trim($this->request->data['WorkOrderStatus']['status']) == "New") {
             $this->request->data['WorkOrder']['status'] = "New";
         }
         if (trim($this->request->data['WorkOrderStatus']['status']) == "Cancel") {
             $this->request->data['WorkOrder']['status'] = "Cancel";
         }
         if (trim($this->request->data['WorkOrderStatus']['status']) == "Change") {
             $this->request->data['WorkOrder']['status'] = "Change";
         }
         //			pr($this->request->data);exit;
         if ($this->WorkOrder->save($this->request->data)) {
             App::import('Model', 'ScheduleManager.Appointment');
             $Appointment_Model = new Appointment();
             $Appointment_Model->save($schedule);
             $this->Session->setFlash(__('The Work Order status has been saved'), 'default', array('class' => 'text-success'));
             $this->redirect(array('action' => 'detail_section', $this->WorkOrder->id, $section));
         } else {
             $this->Session->setFlash(__('The Work Order status could not be saved. Please, try again.'), 'default', array('class' => 'text-error'));
             $this->redirect(array('action' => 'detail_section', $this->WorkOrder->id, $section));
         }
     }
 }