コード例 #1
0
 public function approveStaff($empId)
 {
     if (!HospitalEmployee::isStaff()) {
         return response()->json(["success" => false, "error" => 'notlogin or notvalid']);
     }
     // DB::table('HospitalEmployee')->where('emp_id',$empId)->update(['valid' => true]);
     $emp = HospitalEmployee::find($empId);
     $emp->valid = true;
     $emp->save();
     return response()->json(["success" => true]);
 }
コード例 #2
0
ファイル: DoctorTime.php プロジェクト: phizaz/se2015-backend
 public static function getFreeSlotByDoctor($doctor_id)
 {
     $doctorTimes = DoctorTime::where('doctor_id', $doctor_id)->where('doctorTime_end', '>=', new DateTime())->get();
     // echo "doctortimes: \n";
     // var_dump($doctorTimes->toArray());
     $appointments = Appointment::where('time', '>=', new DateTime())->get();
     // echo "appointmnets: \n";
     // var_dump($appointments->toArray());
     $freeSlots = [];
     // cerate doctortimes slots
     foreach ($doctorTimes as $doctorTime) {
         $beginTime = $doctorTime->doctorTime_begin;
         $endTime = $doctorTime->doctorTime_end;
         $datetime = $beginTime;
         $date = (new DateTime($datetime))->format('Y-m-d');
         $freeSlots[$date] = array_fill(0, (20 - 8) * 4, false);
         $beginBlock = DoctorTime::timeToBlock(new DateTime($beginTime));
         $endBlock = DoctorTime::timeToBlock(new DateTime($endTime));
         // echo 'beginblock:', $beginBlock, 'endblock:', $endBlock, "\n";
         // set as free
         for ($i = $beginBlock; $i < $endBlock; ++$i) {
             $freeSlots[$date][$i] = true;
         }
     }
     // echo "freeslots: \n";
     // var_dump($freeSlots);
     // mark out the unfit
     foreach ($appointments as $appointment) {
         $datetime = $appointment->time;
         $date = (new DateTime($datetime))->format('Y-m-d');
         $block = DoctorTime::timeToBlock(new DateTime($datetime));
         if (isset($freeSlots[$date]) && isset($freeSlots[$date][$block])) {
             $freeSlots[$date][$block] = false;
         }
     }
     // echo "after freeslots: \n";
     // var_dump($freeSlots);
     // make the result
     $doctor = HospitalEmployee::find($doctor_id);
     $result = [];
     foreach ($freeSlots as $date => $free) {
         foreach ($free as $i => $isFree) {
             if ($isFree) {
                 $datetime = DoctorTime::blockToTime($i, new DateTime($date));
                 $result[] = ['datetime' => $datetime, 'doctor' => $doctor];
             }
         }
     }
     return $result;
 }