Ejemplo n.º 1
0
 public static function makeAppointment($emp_id, $patient_id, $datetime)
 {
     $error = [];
     if ($datetime == null) {
         $error[] = 'datetime_not_found';
     }
     if ($patient_id == null) {
         $error[] = 'patient_id_not_found';
     }
     if ($emp_id == null) {
         $error[] = 'emp_id_not_found';
     }
     if (Appointment::where('time', $datetime)->where('emp_id', $emp_id)->first()) {
         $error[] = 'this_time_not_available';
     }
     if (sizeof($error) == 0) {
         $appointment = new Appointment();
         $appointment->time = $datetime;
         $appointment->emp_id = $emp_id;
         $appointment->patient_id = $patient_id;
         $appointment->save();
         return ["success" => true, "data" => $appointment->toArray()];
     } else {
         return ["success" => false, "message" => $error];
     }
 }
Ejemplo n.º 2
0
 public function addTime(Request $request)
 {
     $user = \App\User::getCurrentUser();
     $busy_time = new \App\Appointment();
     $busy_time->user()->associate($user);
     $busy_time->day = $request->input('day');
     $busy_time->reason = $request->input('reason');
     $busy_time->save();
     return 'Added';
 }
 public function makeAppointmentCreate()
 {
     $validator = Validator::make(Input::all(), array('doctor' => 'required_without:department', 'department' => 'required_without:doctor', 'apptDate' => 'already_have_appointment_patient'), array('doctor.required_without' => 'กรุณาเลือกแพทย์หรือแผนกที่ต้องการนัด', 'department.required_without' => 'กรุณาเลือกแพทย์หรือแผนกที่ต้องการนัด', 'apptDate.already_have_appointment_patient' => 'ท่านมีนัดแล้วในช่วงเวลาที่ท่านเลือก'));
     if ($validator->passes()) {
         if (Input::get('doctor') >= 0) {
             $depentOnDr = 1;
             $n = Input::get('doctor');
             $doctors = DB::table('users')->where('type', 'doctor')->get();
             $i = 0;
             foreach ($doctors as $doctor) {
                 if ($i++ == $n) {
                     $doctorEmpID = $doctor->username;
                     break;
                 }
             }
         } else {
             if (Input::get('department') >= 0) {
                 $depentOnDr = 0;
                 $d = Input::get('department');
                 $departmentsList = ['อายุรกรรม', 'ศัลยกรรม', 'ออร์โธปีดิกส์', 'กุมารเวชกรรม', 'สูตินรีเวช', 'ทันตกรรม', 'เวชปฏิบัติ', 'แพทย์เฉพาะทางอื่นๆ'];
                 $department = $departmentsList[$d];
                 $doctorEmpID = DB::table('users')->where('department', $department)->first()->username;
             }
         }
         $addAppointment = new Appointment();
         $addAppointment->HN = Session::get('username');
         $addAppointment->dependOnDr = $depentOnDr;
         $addAppointment->doctorEmpID = $doctorEmpID;
         $str = Input::get('apptDate');
         $cut = strpos($str, " ");
         $len = strlen($str);
         $date = substr($str, 0, $cut);
         $addAppointment->appointmentDate = $date;
         if (strcmp(substr($str, $cut + 1, $len - $cut - 1), "เช้า") == 0) {
             $morning = 0;
         } else {
             $morning = 1;
         }
         $addAppointment->morning = $morning;
         $addAppointment->symptomOrReason = Input::get('cause');
         $addAppointment->save();
         DB::table('ondutySchedule')->where('doctorEmpID', $doctorEmpID)->where('date', $date)->where('morning', $morning)->update(array('appointed' => 1));
         return Redirect::to('patient/makeAppointment')->with('flash_notice', 'ดำเนินการทำนัดสำเร็จ');
     } else {
         return Redirect::to('patient/makeAppointment')->withErrors($validator)->withInput();
     }
 }
Ejemplo n.º 4
0
 public static function addNew($type, $name, $patient, $dentist, $date, $start_hour, $start_minute, $end_hour, $end_minute, $notes = '', $treatment_plan_id = 0, $booked = 1, $treatment_plan_order = 0)
 {
     $clash = 0;
     if ($date != '') {
         $start_date = Carbon::createFromFormat("d/m/Y", $date);
         $start_date->hour = $start_hour;
         $start_date->minute = $start_minute;
         $end_date = Carbon::createFromFormat("d/m/Y", $date);
         $end_date->hour = $end_hour;
         $end_date->minute = $end_minute;
         if (Appointment::checkClashingAppointment($dentist, $start_date, $end_date)) {
             $clash = 1;
         }
     } else {
         $start_date = '';
         $end_date = '';
     }
     if ($clash === 0) {
         $appointment = new Appointment();
         $appointment->type_id = $type;
         $appointment->name = $name;
         $appointment->booked = $booked;
         $appointment->treatment_plan_id = $treatment_plan_id;
         $appointment->treatment_plan_order = $treatment_plan_order;
         $dentist_obj = User::findOrFail($dentist);
         $appointment->branch_id = $dentist_obj->dentistAt()->first()->id;
         if ($type != 4) {
             $appointment->patient_id = $patient;
             $patient = Patient::findOrFail($patient);
             if ($date) {
                 $patient->addHistoryItem("Appointment Added", "An appointment has been added for this patient on " . $start_date->format('d/m/Y') . " at " . $start_date->format('H:i') . " with <a href='" . url('user/' . $dentist_obj->id) . "'>" . $dentist_obj->first_name . " " . $dentist_obj->last_name . "</a>", Auth::user()->id, 7);
             }
         }
         $appointment->dentist_id = $dentist;
         if ($date != '') {
             $appointment->start_date = $start_date->format('Y-m-d H:i:s');
             $appointment->end_date = $end_date->format('Y-m-d H:i:s');
         }
         $appointment->status_id = 1;
         $appointment->notes = $notes;
         $appointment->save();
         if ($booked == 1) {
             Appointment::incrementBookingStats();
         }
         return $appointment;
     } else {
         return false;
     }
 }