public function testConvertBlockToTime() { $block = 0; $time = new DateTime(); $time->setTime(8, 0); $tmp = DoctorTime::blockToTime($block); $this->assertEquals(0, $tmp->diff($time)->i); $this->assertEquals(0, $tmp->diff($time)->h); $this->assertEquals(0, $tmp->diff($time)->y); $this->assertEquals(0, $tmp->diff($time)->m); $this->assertEquals(0, $tmp->diff($time)->d); $block = 2; $time = new DateTime(); $time->setTime(8, 30); $tmp = DoctorTime::blockToTime($block); $this->assertEquals(0, $tmp->diff($time)->i); $this->assertEquals(0, $tmp->diff($time)->h); $this->assertEquals(0, $tmp->diff($time)->y); $this->assertEquals(0, $tmp->diff($time)->m); $this->assertEquals(0, $tmp->diff($time)->d); $block = 16; $time = new DateTime(); $time->setTime(12, 0); $tmp = DoctorTime::blockToTime($block); $this->assertEquals(0, $tmp->diff($time)->i); $this->assertEquals(0, $tmp->diff($time)->h); $this->assertEquals(0, $tmp->diff($time)->y); $this->assertEquals(0, $tmp->diff($time)->m); $this->assertEquals(0, $tmp->diff($time)->d); $block = 16; $time = new DateTime(); $time->setTime(12, 0); $basedate = new DateTime(); $basedate->setDate(2010, 10, 10); $tmp = DoctorTime::blockToTime($block, $basedate); $this->assertEquals(0, $tmp->diff($time)->i); $this->assertEquals(0, $tmp->diff($time)->h); $this->assertEquals(0, $tmp->diff($basedate)->y); $this->assertEquals(0, $tmp->diff($basedate)->m); $this->assertEquals(0, $tmp->diff($basedate)->d); }
public static function refreshDoctorTime($doctor_id) { $appointments = Appointment::where('emp_id', $doctor_id)->get(); $doctorTimes = DoctorTime::where('doctor_id', $doctor_id)->get(); foreach ($appointments as $appointment) { $aptime = new DateTime($appointment->time); $del = true; foreach ($doctorTimes as $doctorTime) { $begin = new DateTime($doctorTime->doctorTime_begin); $end = new DateTime($doctorTime->doctorTime_end); if ($aptime >= $begin && $aptime < $end) { $del = false; } } if ($del) { // find a new appointment Appointment::createNextAppointment($doctor_id, $appointment); // delete the old one Appointment::deleteAppointment($appointment->appointment_id); } } $docTime = DoctorTime::orderBy('doctorTime_begin', 'asc')->where('doctor_id', $doctor_id)->get(); return ["success" => true, "new doctorTime" => $docTime]; }
public function getFreeSlotBySpecialty($specialty) { if (!Patient::isPatient() && !HospitalEmployee::isDoctor() && !HospitalEmployee::isStaff()) { return response()->json(["success" => false, "error" => 'notlogin or notvalid']); } return response()->json(["success" => true, "data" => DoctorTime::getFreeSlotBySpecialty($specialty)]); }
public static function createNextAppointment($doctor_id, $appointment) { $freeSlots = DoctorTime::getFreeSlotByDoctor($doctor_id); foreach ($freeSlots as $freeSlot) { $datetime = $freeSlot['datetime']; if ($datetime < new \DateTime($appointment->time)) { continue; } return Appointment::makeAppointment($doctor_id, $appointment->patient_id, $datetime); } }
public function deleteDoctorTime($doctor_time_id) { if (!HospitalEmployee::isDoctor()) { return response()->json(["success" => false, "messages" => ['notlogin or notvalid']]); } // if(!HospitalEmployee::isDoctor()) // return response()->json(["success" = false]; $doctorTime = DoctorTime::where('doctorTime_id', $doctor_time_id)->first(); if ($doctorTime) { $doctorTime->delete(); } return response()->json(["success" => true]); }