/** * Return a JSON list of visits * * @return \Illuminate\Http\Response */ public function visits(Request $request, $method) { $dates = $this->getCarbonDates($request); switch (strtolower($method)) { case "count": // $data = []; $visits = Visit::where('created_at', '>', $dates['from'])->where('created_at', '<', $dates['to'])->get(['patients', 'stage'])->groupBy('stage'); $stages = Stage::where('root', '!=', true)->orderBy('order', 'asc')->get(['id', 'name'])->groupBy('id'); $stages = $stages->keys()->push("__checkout__")->map(function ($stageID) use($stages, $visits) { $data = ["name" => $stageID == "__checkout__" ? "Checked out" : $stages[$stageID][0]['name']]; if ($visits->has($stageID)) { $data["visits"] = $visits->get($stageID)->count(); $data["patients"] = $visits->get($stageID)->map(function ($visit) { return count($visit->patients); })->sum(); } else { $data["visits"] = 0; $data["patients"] = 0; } return $data; }); return response()->json(["stages" => $stages]); break; } }
/** * Fetch visits for specified stage ID */ public function fetch(Stage $stage) { $response; $visits = Visit::where('stage', '=', $stage->id)->get()->keyBy('id')->toArray(); $rootStageFields = Stage::where('root', true)->first()->inputFields; foreach ($visits as $visitID => $visitData) { $models = array(); foreach ($visitData['patients'] as $patientID) { $patient = Patient::where('id', $patientID); if ($patient->count() > 0) { $models[$patientID] = $patient->first()->toArray(); } } $visits[$visitID]['patient_models'] = $models; } if (count($visits) > 0) { $response = ["status" => "success", "message" => "Visits found.", "visits" => $visits]; } else { $response = ["status" => "success", "message" => "No visits are currently at stage " . $stage->name . "."]; } return response()->json($response); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function timecard($id) { $member = Member::find($id); if (NULL == $member) { return response()->json("", 404); } else { $devices = Visit::where('memberID', $id)->select('deviceID')->groupBy('deviceID')->get(); $times = array(); foreach ($devices as $did) { $total_hrs = 0; $visits = Visit::where('memberID', $id)->where('deviceID', $did->deviceID)->select('checkIn', 'checkOut')->get(); foreach ($visits as $visit) { if ($visit->checkOut != NULL) { $date_time_in = strtotime($visit->checkIn); $date_time_out = strtotime($visit->checkOut); $total_hrs += round(abs($date_time_out - $date_time_in) / 3600, 2); } } array_push($times, ['checkInDevice' => $did->deviceID, 'totalTime' => $total_hrs, 'visits' => $visits]); } $member->times = $times; return response()->json($member, 200); } }
/** * return a small box that is green or red if the shop is open or clsoed * * @param int $id * @return \Illuminate\Http\Response */ public function isOpenWidget($did) { $device = CheckInDevice::find($did); if (NULL == $device) { return response()->json("", 404); } else { $open = false; $actives = Visit::where('deviceID', $did)->where('checkOut', NULL)->select('memberID')->get(); foreach ($actives as $visit) { $member = Member::find($visit->memberID); if (NULL != $member) { if (true == $member->hasKeys) { $open = true; break; } } } return response()->view('isOpenWidget', ['isopen' => $open]); } }