public function referPatient($id, ReferPatientRequest $request)
 {
     if ($report = Reports::find($id)) {
         $report->assigned_doctor_id = $request->doctors;
         $report->save();
         $newDocAss = new PatientAssignment();
         $newDocAss->doctor_id = $request->doctors;
         $newDocAss->patient_id = $report->user_id;
         $newDocAss->report_id = $report->id;
         $newDocAss->save();
         return redirect('doctor/dashboard')->withFlashSuccess("The patient <strong>({$report->patient_name})</strong> has been referred appropriately ");
     } else {
         abort(404);
     }
 }
 public function postReport(ReportRequest $request)
 {
     $user = auth()->user();
     $lastAssignedDoc = PatientAssignment::join('users', 'users.id', '=', 'patient_assignments.doctor_id')->where('users.specialization_id', 1)->orderBy('patient_assignments.id', 'DESC')->pluck('doctor_id');
     //This gets the id of the last doctor in the database that has a general (1) specialization.
     $lastDoc = User::where('specialization_id', 1)->orderBy('id', 'DESC')->pluck('id');
     //Reset last doc when we get to our last doctor
     if ($lastAssignedDoc == $lastDoc) {
         $lastAssignedDoc = 0;
     }
     $nextDocId = User::where('specialization_id', 1)->where('id', '>', $lastAssignedDoc)->first();
     $report = new Reports();
     $report->report = $request->txtReport;
     $report->user_id = $user->id;
     $report->patient_name = $user->name;
     $report->assigned_doctor_id = $nextDocId->id;
     //Save Report... Incase you dont know
     $report->save();
     $patientAss = new PatientAssignment();
     //Create a record of this assignment
     $patientAss->patient_id = $user->id;
     $patientAss->doctor_id = $nextDocId->id;
     $patientAss->report_id = $report->id;
     $patientAss->save();
     #Ideally, You should send a notification email to the doctor assigned and the user
     return redirect()->back()->withFlashSuccess('Your report has been submitted, one of our doctor will respond to it shortly.');
 }