makeHidden(['id']); $error = Validator::make($request->all(), [ 'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20|min:4|unique:patient', 'password' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100|min:10', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { Patient::create([ 'login' => $request->login, 'password' => Hash::make($request->password), 'token' => Str::random(80), 'id_doctor' => $Doctor->id, ]); return response(['message' => 'Новый пациент был создан'], 200); } } //Обновление данных пациента public function UpdateAccountPatient(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', 'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20|min:4|unique:patient', 'password' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100|min:10', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $pat = $Patient; $pat->login = $request->login; $pat->password = Crypt::encryptString($request->password); $pat->update(); } return response(['Данные обновлены' => $request->password], 200); } } // //Обновление данных пациента // public function AddCoursesAccountPatient(Request $request) // { // $error = Validator::make($request->all(), [ // 'id' => 'required', // 'login' => 'required', // 'password' => 'required', // ]);//1024 // if ($error->fails()) { // return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); // } // else{ // $Patient = Patient::where('id', $request->id)->first(); // if ($Patient != null) { // $pat = $Patient; // $pat->login = $request->login; // $pat->password = Crypt::encryptString($request->password); // $pat->update(); // } // // return response(['Данные обновлены' => $request->password], 200); // } // } //Редактирвоание курса public function GetCoursesSport(Request $request) { $Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', 'id_sports_courses_patient' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") { $SetOfSportsExercises = SetOfSportsExercises::orderBy('id', 'ASC') ->leftJoin('sets_of_sports_activities', 'sets_of_sports_activities.id', '=', 'set_of_sports_exercises.id_sets_of_sports_activities') ->leftJoin('sports_tasks', 'sports_tasks.id', '=', 'set_of_sports_exercises.id_sports_tasks') ->leftJoin('sports_courses', 'sports_courses.id', '=', 'sets_of_sports_activities.id_sports_courses') ->leftJoin('sport_patient', 'sport_patient.id_sports_courses', '=', 'sports_courses.id') ->leftJoin('image', 'image.id', '=', 'sports_tasks.id_image') ->select('sports_tasks.id', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image')->where("sport_patient.id", $Patient->id_sport_patient) ->distinct() ->where("sports_courses.id", $request->id_sports_courses_patient)->get();//, 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'sport_patient.id_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at' return response(["set_of_sports_exercises" => $SetOfSportsExercises], 200); } else { return response(['message' => 'Ошибка, курса у пациента нету'], 400); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } //Редактирвоание курса //в БУДУШЕМ НУЖНО ИЗМЕНИТЬ И УБИРАТЬ ЗАБЛОКИРОВАННЫЕ НЕ ЧЕРЕЗ ПЕРЕБОРКУ ЦИКЛА А ПРОСТО ЧЕРЕЗ ЗАПРОС В БАЗУ, ПРОСТО НУЖНО ПОСИДЕТЬ И ПОНЯТЬ ЧТО Я НЕПРАВИЛЬНО ЗАБИВАЛ В БАЗУ public function GetCoursesSportYes(Request $request) { $Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") { $SetOfSportsExercises2 = CoursesSportEdit::get(); $CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get(); $result = []; $number = 0; if (Count($CoursesSportEdit) != 0) { $CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get(); $SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC') ->join('sets_of_sports_activities', 'set_of_sports_exercises.id_sets_of_sports_activities', '=', 'sets_of_sports_activities.id') ->join('sports_tasks', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') ->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks') ->join('sports_courses', 'sets_of_sports_activities.id_sports_courses', '=', 'sports_courses.id') ->join('sport_patient', 'sport_patient.id_sports_courses', '=', 'sports_courses.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image') ->distinct('id') ->where('sport_patient.id', $Patient->id_sport_patient) ->get(); for ($i = 0; $i != Count($SetOfSportsExercises); $i++) { $res = 0; for ($j = 0; $j != Count($CoursesSportEdit); $j++) { if ($SetOfSportsExercises[$i]->id != $CoursesSportEdit[$j]->id_sports_tasks) { $res++; } } if ($res == Count($CoursesSportEdit)) { $number++; $search_sport = [ 'number' => $number, 'id' => $SetOfSportsExercises[$i]->id, 'name' => $SetOfSportsExercises[$i]->name, 'description' => $SetOfSportsExercises[$i]->description, 'url_image' => $SetOfSportsExercises[$i]->url_image, ]; array_push($result, $search_sport); } } } else { $SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC') ->join('sets_of_sports_activities', 'set_of_sports_exercises.id_sets_of_sports_activities', '=', 'sets_of_sports_activities.id') ->join('sports_tasks', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') ->join('sports_courses', 'sets_of_sports_activities.id_sports_courses', '=', 'sports_courses.id') ->join('sport_patient', 'sport_patient.id_sports_courses', '=', 'sports_courses.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image') ->distinct('id') ->where('sport_patient.id', $Patient->id_sport_patient) ->get(); for ($i = 0; $i != Count($SetOfSportsExercises); $i++) { $number++; $search_sport = [ 'number' => $number, 'id' => $SetOfSportsExercises[$i]->id, 'name' => $SetOfSportsExercises[$i]->name, 'description' => $SetOfSportsExercises[$i]->description, 'url_image' => $SetOfSportsExercises[$i]->url_image, ]; array_push($result, $search_sport); } } return response(["set_of_sports_exercises_yes" => $result], 200); } else { return response(['message' => 'Ошибка, курса у пациента нету'], 400); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } public function GetCoursesSportNo(Request $request) { $Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") { $CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->distinct() ->join('sports_tasks', 'courses_sport_edit.id_sports_tasks', '=', 'sports_tasks.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id as sports_tasks_id', 'courses_sport_edit.id', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image') ->distinct('id') ->where('courses_sport_edit.id_sport_patient', $Patient->id_sport_patient) ->get(); $result = []; $number = 0; for ($i = 0; $i != Count($CoursesSportEdit); $i++) { $number++; $search_sport = [ 'number' => $number, 'id' => $CoursesSportEdit[$i]->id, 'name' => $CoursesSportEdit[$i]->name, 'description' => $CoursesSportEdit[$i]->description, 'url_image' => $CoursesSportEdit[$i]->url_image, ]; array_push($result, $search_sport); } return response(["set_of_sports_exercises_no" => $result], 200); } else { return response(['message' => 'Ошибка, курса у пациента нету'], 400); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } public function UpdateBlockSportTasksYes(Request $request) { $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', 'id_sports_tasks' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { $SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first(); $SportTasks = SportTasks::where('id', $request->id_sports_tasks)->first(); if ($SportTasks != null && $SportPatient != null) { CoursesSportEdit::create([ 'id_sport_patient' => $SportPatient->id, 'id_sports_tasks' => $SportTasks->id, ]); return response(['message' => 'Тренировка добавлена в блок'], 200); } else { return response(['message' => 'Таких данных нету'], 400); } } else { return response(['message' => 'Такого пациента нету'], 400); } } } public function UpdateBlockSportTasksNo(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $CoursesSportEdit = CoursesSportEdit::where('id', $request->id)->first(); if ($CoursesSportEdit != null) { $CoursesSportEdit->delete(); return response(['message' => 'Тренировка убрана из блока'], 200); } else { return response(['message' => 'Таких данных нету'], 400); } } } //Блокировка public function UpdateBlockAccountPatient(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->orderBy('day', 'DESC')->first(); if ($Patient->block == null || $Patient->block == "") { //Если есть календарный список if ($CalendarDays != null) { for ($i = 0; $i < 4; $i++) { CalendarDays::create([ 'id_patient' => $Patient->id, 'day' => $CalendarDays->day + $i, 'date' => date('Y-m-d', strtotime("+$i day", strtotime($CalendarDays->date))), 'id_sport_patient' => $Patient->id_sport_patient, ]); } $pat = $Patient; $date = date('Y-m-d', strtotime('+3 day')); $pat->block = $date; $pat->update(); //Установка блока в календаре for ($i = 0; $i < 4; $i++) { $dateCD = date('Y-m-d', strtotime("+$i day")); $CD = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD->block = $dateCD; $CD->update(); } } //Если нету календарного списка else if ($CalendarDays == null) { $pat = $Patient; $date = date('Y-m-d', strtotime('+3 day')); $pat->block = $date; $pat->update(); //Установка блока в календаре for ($i = 0; $i < 4; $i++) { $dateCD = date('Y-m-d', strtotime("+$i day")); $CD = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD->block = $dateCD; $CD->update(); } } else { return response(['message' => 'Ошибка, обратитесь в поддержку. Код - 1.1'], 400); } return response(['message' => 'Блокировка включена'], 200); } else if ($Patient->block != null && $Patient->block != "") { if ($CalendarDays != null) { $pat = $Patient; $pat->block = null; $pat->update(); //Проверка количества дней в календаре и их изменение $this->AddandClearDayPatient($Patient->id); } //Если нету календарного списка else if ($CalendarDays == null) { $pat = $Patient; $pat->block = null; $pat->update(); } else { return response(['message' => 'Ошибка, обратитесь в поддержку. Код - 1.2'], 400); } //Сброс блока в календаре $dateCD = date('Y-m-d'); $CD1 = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD2 = CalendarDays::where('day', '>=', $CD1->day)->where('id_sport_patient', $Patient->id_sport_patient)->get(); for ($i = 0; $i < count($CD2); $i++) { $CDUpdate = CalendarDays::where('id', $CD2[$i]->id)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CDUpdate->block = null; $CDUpdate->update(); } return response(['message' => 'Блокировка отключена'], 200); } else { return response(['message' => 'Ошибка, неизвестные данные в поле'], 400); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } //Пауза public function UpdatePauseAccountPatient(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->orderBy('day', 'DESC')->first(); if ($Patient->pause == null || $Patient->pause == "") { if ($CalendarDays != null) { for ($i = 0; $i < 2; $i++) { CalendarDays::create([ 'id_patient' => $Patient->id, 'day' => $CalendarDays->day + $i, 'date' => date('Y-m-d', strtotime("+$i day", strtotime($CalendarDays->date))), 'id_sport_patient' => $Patient->id_sport_patient, ]); } $pat = $Patient; $date = date('Y-m-d', strtotime('+1 day')); $pat->pause = $date; $pat->update(); //Установка пауз в календаре for ($i = 0; $i < 2; $i++) { $dateCD = date('Y-m-d', strtotime("+$i day")); $CD = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD->pause = $dateCD; $CD->update(); } } else if ($CalendarDays == null) { $pat = $Patient; $date = date('Y-m-d', strtotime('+1 day')); $pat->pause = $date; $pat->update(); //Установка пауз в календаре for ($i = 0; $i < 2; $i++) { $dateCD = date('Y-m-d', strtotime("+$i day")); $CD = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD->pause = $dateCD; $CD->update(); } } else { return response(['message' => 'Ошибка, обратитесь в поддержку. Код - 2.1'], 400); } return response(['message' => 'Пауза включена'], 200); } else if ($Patient->pause != null && $Patient->pause != "") { if ($CalendarDays != null) { $pat = $Patient; $pat->pause = null; $pat->update(); //Проверка количества дней в календаре и их изменение $this->AddandClearDayPatient($Patient->id); } else if ($CalendarDays == null) { $pat = $Patient; $pat->pause = null; $pat->update(); } else { return response(['message' => 'Ошибка, обратитесь в поддержку. Код - 2.2'], 400); } //Сброс паузы в календаре $dateCD = date('Y-m-d'); $CD1 = CalendarDays::where('date', $dateCD)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CD2 = CalendarDays::where('day', '>=', $CD1->day)->where('id_sport_patient', $Patient->id_sport_patient)->get(); for ($i = 0; $i < count($CD2); $i++) { $CDUpdate = CalendarDays::where('id', $CD2[$i]->id)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first(); $CDUpdate->pause = null; $CDUpdate->update(); } return response(['message' => 'Пауза отключена'], 200); } else { return response(['message' => 'Ошибка, неизвестные данные в поле'], 400); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } // //Подтверждение на 7 день // public function Addreport7dayAccountPatient(Request $request) // { // $error = Validator::make($request->all(), [ // 'id' => 'required', // ]);//1024 // if ($error->fails()) { // return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); // } // else{ // $Patient = Patient::where('id', $request->id)->first(); // if ($Patient != null) { // if($Patient->report7day == null || $Patient->report7day == ""){ // $pat = $Patient; // $pat->report7day = date ('Y-m-d'); // $pat->update(); // return response(['Отчет за 7 дней отправлен'], 200); // } // else{ // return response(['Отчет за 7 дней уже отправлен'], 400); // } // } // else{ // return response(['Ошибка, такого пациента нету'], 400); // } // // } // } // // //Подтверждение на 15 день // public function Addreport15dayAccountPatient(Request $request) // { // $error = Validator::make($request->all(), [ // 'id' => 'required', // ]);//1024 // if ($error->fails()) { // return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); // } // else{ // $Patient = Patient::where('id', $request->id)->first(); // if ($Patient != null) { // if($Patient->report15day == null || $Patient->report15day == ""){ // $pat = $Patient; // $pat->report15day = date ('Y-m-d'); // $pat->update(); // return response(['Отчет за 15 дней отправлен'], 200); // } // else{ // return response(['Отчет за 15 дней уже отправлен'], 400); // } // } // else{ // return response(['Ошибка, такого пациента нету'], 400); // } // } // } public function GetPatientSearch(Request $request) { $error = Validator::make($request->all(), [ 'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20|min:4', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('login', 'like', '%' . $request->login . '%')->orderBy('id', 'ASC')->get(); return response()->json($Patient); } } //Вывод всех пациентов public function GetPatientAll() { $Patient = Patient::orderBy('id', 'ASC') ->leftJoin('doctor', 'doctor.id', '=', 'patient.id_doctor') ->leftJoin('sport_patient', 'sport_patient.id', '=', 'patient.id_sport_patient') ->select('patient.id', 'patient.login', 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'patient.id_sport_patient as id_sport_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at') ->get();//, 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'sport_patient.id_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at' $result = []; $number = 0; for ($i = 0; $i != Count($Patient); $i++) { $number++; $search_patient = [ 'number' => $number, 'id' => $Patient[$i]->id, 'login' => $Patient[$i]->login, 'loginDoctor' => $Patient[$i]->login, 'emailDoctor' => $Patient[$i]->emailDoctor, 'pause' => $Patient[$i]->pause, 'block' => $Patient[$i]->block, 'report7day' => $Patient[$i]->report7day, 'report15day' => $Patient[$i]->report15day, 'id_sport_patient' => $Patient[$i]->id_sport_patient, 'total_days_sports' => $Patient[$i]->total_days_sports, 'now_days_sports' => $Patient[$i]->now_days_sports, 'created_at' => $Patient[$i]->created_at, 'updated_at' => $Patient[$i]->updated_at, ]; array_push($result, $search_patient); } return response(["patient" => $result], 200); } //Вывод все пациентов конкретного врача с курсом public function GetPatientAllActive() { $Doctor = Auth::user()->makeHidden(['id']); $Patient = Patient::orderBy('id', 'ASC') ->leftJoin('doctor', 'doctor.id', '=', 'patient.id_doctor') ->leftJoin('sport_patient', 'sport_patient.id', '=', 'patient.id_sport_patient') ->select('patient.id', 'patient.login', 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'patient.id_sport_patient as id_sport_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at') ->where("patient.id_doctor", $Doctor->id) ->where("patient.id_sport_patient","!=", null) ->get();//, 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'sport_patient.id_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at' $result = []; $number = 0; for ($i = 0; $i != Count($Patient); $i++) { $number++; $search_patient = [ 'number' => $number, 'id' => $Patient[$i]->id, 'login' => $Patient[$i]->login, 'loginDoctor' => $Patient[$i]->login, 'emailDoctor' => $Patient[$i]->emailDoctor, 'pause' => $Patient[$i]->pause, 'block' => $Patient[$i]->block, 'report7day' => $Patient[$i]->report7day, 'report15day' => $Patient[$i]->report15day, 'id_sport_patient' => $Patient[$i]->id_sport_patient, 'total_days_sports' => $Patient[$i]->total_days_sports, 'now_days_sports' => $Patient[$i]->now_days_sports, 'created_at' => $Patient[$i]->created_at, 'updated_at' => $Patient[$i]->updated_at, ]; array_push($result, $search_patient); } return response(["patient" => $result], 200); } //Вывод все пациентов конкретного врача без курса public function GetPatientAllNotActive() { $Doctor = Auth::user()->makeHidden(['id']); $Patient = Patient::orderBy('id', 'ASC') ->leftJoin('doctor', 'doctor.id', '=', 'patient.id_doctor') ->leftJoin('sport_patient', 'sport_patient.id', '=', 'patient.id_sport_patient') ->select('patient.id', 'patient.login', 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'patient.id_sport_patient as id_sport_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at') ->where("patient.id_doctor", $Doctor->id) ->where("patient.id_sport_patient", null) ->get();//, 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'sport_patient.id_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at' $result = []; $number = 0; for ($i = 0; $i != Count($Patient); $i++) { $number++; $search_patient = [ 'number' => $number, 'id' => $Patient[$i]->id, 'login' => $Patient[$i]->login, 'loginDoctor' => $Patient[$i]->login, 'emailDoctor' => $Patient[$i]->emailDoctor, 'pause' => $Patient[$i]->pause, 'block' => $Patient[$i]->block, 'report7day' => $Patient[$i]->report7day, 'report15day' => $Patient[$i]->report15day, 'id_sport_patient' => $Patient[$i]->id_sport_patient, 'total_days_sports' => $Patient[$i]->total_days_sports, 'now_days_sports' => $Patient[$i]->now_days_sports, 'created_at' => $Patient[$i]->created_at, 'updated_at' => $Patient[$i]->updated_at, ]; array_push($result, $search_patient); } return response(["patient" => $result], 200); } public function GetPatientID(Request $request) { $Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::orderBy('id', 'ASC') ->leftJoin('doctor', 'doctor.id', '=', 'patient.id_doctor') ->select('patient.id', 'patient.login', 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'patient.id_sport_patient as id_sport_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at')->where("patient.id", $request->id)->first();//, 'patient.email', 'doctor.login as loginDoctor', 'doctor.email as emailDoctor', 'patient.pause', 'patient.block', 'patient.report7day', 'patient.report15day', 'sport_patient.id_patient', 'patient.total_days_sports', 'patient.now_days_sports', 'patient.created_at', 'patient.updated_at' return response( $Patient, 200); } } //Авторизация врача public function LoginDoctor(Request $request) { $validation = Validator::make($request->all(), [ 'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20|min:4', 'password' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100|min:8', ]); if ($validation->fails()) { $result = [ 'error' => [ 'code' => 400, 'message' => 'Validation error', 'error' => $validation->errors() ]]; return response($result, 422); } if (Auth::guard('doctor')->attempt(['login' => $request->login, 'password' => $request->password])) { $user = Auth::guard('doctor')->user(); $pat = $user; $pat->api_token = Str::random(80); $pat->update(); return response([ 'id' => $user->id, 'token' => $user->api_token, ], 200); } return response([ 'error' => [ 'code' => 401, 'message' => 'Unauthorized', 'error' => [ 'ОУ у тебя произошла ошибка']] ], 401); } public function LogoutDoctor() { $user = Auth::user()->makeHidden(['id', 'role']); $pat = $user; $pat->api_token = null; $pat->update(); return response(['message' => 'Вы вышли из аккаунта'], 200); } //Вывод курса для врача, чтобы он смог посмотеть что входит в курс public function GetCours(Request $request) { $error = Validator::make($request->all(), [ 'name' => 'required|regex:/^[a-z0-9а-яё;]+$/iu|string|max:100|min:4', 'day' => 'required|numeric|max:365|min:1', ]); if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Cours = SportTasks::orderBy('id', 'ASC') ->leftJoin('image', 'image.id', '=', 'sports_tasks.id_image') ->leftJoin('set_of_sports_exercises', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') ->leftJoin('sets_of_sports_activities', 'sets_of_sports_activities.id', '=', 'set_of_sports_exercises.id_sets_of_sports_activities') ->leftJoin('sports_courses', 'sports_courses.id', '=', 'sets_of_sports_activities.id_sports_courses') ->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'sets_of_sports_activities.name as sets_of_sports_activities_Name', 'sets_of_sports_activities.description as sets_of_sports_activities_Description', 'sports_tasks.name as sports_tasks_Name', 'sports_tasks.description as sports_tasks_Description', 'sports_tasks.count as sports_tasks_Count', 'image.url_image as image_Url',) ->where('sports_courses.name', '=', $request->name)->where('sets_of_sports_activities.day', '=', $request->day) ->get(); return response()->json($Cours); } } //Вывод всех курсов public function GetCoursAll() { $Cours = SportCourses::get(); return response(['courses' => $Cours], 200); } //Вывод курса пациента public function GetCoursAllPatient(Request $request) { $user = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $Cours = SportCourses::where('user_id',0)->get(); $SportCourses = SportCourses::join('sport_patient', 'sports_courses.id', '=', 'sport_patient.id_sports_courses') ->distinct() ->select('sports_courses.id', 'sports_courses.name', 'sports_courses.description', 'sports_courses.visibility', 'sports_courses.created_at', 'sports_courses.updated_at') ->where('id_patient', $Patient->id) ->where('sport_patient.id', $Patient->id_sport_patient) ->where('user_id',0) ->first(); $result = []; $number = 0; //Если у пациента есть курс $SportPatient_ = SportPatient::where('id',$request->id)->first(); $Cours_ = SportCourses::where('user_id',0)->where('id',$SportPatient_->id_sports_courses)->first(); if ($Patient->id_sport_patient != null && $Cours_!=null && $SportCourses !=null) { for ($i = 0; $i != Count($Cours); $i++) { $number++; if ($Cours[$i]->id == $SportCourses->id) { $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 100000, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } else { $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 0, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } } } //Если его нету else { for ($i = 0; $i != Count($Cours); $i++) { $number++; $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 0, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } } return response(['courses' => $result], 200); //return response(['courses' => $Cours], 200); } else { return response(['Такого пациента нету'], 401); } } } //Вывод курсов созданных врачем function GetCoursesDoctorPatient(Request $request){ $user = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $Cours = SportCourses::where('user_id',$user->id)->get(); $SportCourses = SportCourses::join('sport_patient', 'sports_courses.id', '=', 'sport_patient.id_sports_courses') ->distinct() ->select('sports_courses.id', 'sports_courses.name', 'sports_courses.description', 'sports_courses.visibility', 'sports_courses.created_at', 'sports_courses.updated_at') ->where('id_patient', $Patient->id) ->where('sport_patient.id', $Patient->id_sport_patient) ->where('user_id',$user->id) ->first(); $result = []; $number = 0; //Если у пациента есть курс $SportPatient_ = SportPatient::where('id',$request->id)->first(); $Cours_ = SportCourses::where('user_id',$user->id)->where('id',$SportPatient_->id_sports_courses)->first(); if ($Patient->id_sport_patient != null && $Cours_==null && $SportCourses !=null) { for ($i = 0; $i != Count($Cours); $i++) { $number++; if ($Cours[$i]->id == $SportCourses->id) { $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 100000, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } else { $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 0, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } } } //Если его нету else { for ($i = 0; $i != Count($Cours); $i++) { $number++; $search_cours = [ 'number' => $number, 'id' => $Cours[$i]->id, 'name' => $Cours[$i]->name, 'description' => $Cours[$i]->description, 'visibility' => 0, 'created_at' => $Cours[$i]->created_at, 'updated_at' => $Cours[$i]->updated_at, ]; array_push($result, $search_cours); } } return response(['courses_doctor' => $result], 200); //return response(['courses' => $Cours], 200); } else { return response(['Такого пациента нету'], 401); } } } //Добавление курса пациенту public function AddSportPatient(Request $request) { $user = Auth::user()->makeHidden(['id']); $Patient = Patient::where('id', $request->id_patient)->first(); $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', 'id_course' => 'required|numeric|max:10000|min:1', 'all_day' => 'required|numeric|max:365|min:1', ]); if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { if ($Patient->id_sport_patient == null) { //Добовляем данные для списка с курсами $SportPatient = SportPatient::create([ 'id_patient' => $request->id_patient, 'id_sports_courses' => $request->id_course, ]); //Добавление в таблицу пациентов в запись пациента к какая запись из sport_patient относится к нему(в которой хранится ID курса который к неу относится) $pat = $Patient; $pat->id_sport_patient = $SportPatient->id; $pat->total_days_sports = $request->all_day; $pat->now_days_sports = 0; $pat->all_days_sports = 0; $pat->id_doctor = $user->id; $pat->update(); //Создание списка на 30 дней в таблице calendar_days for ($i = 0; $i < $request->all_day; $i++) {//Цикл на количество дней $date = date('Y-m-d', strtotime("$i day")); CalendarDays::create([ 'id_patient' => $request->id_patient, 'day' => $i + 1, 'date' => $date, 'id_sport_patient' => $Patient->id_sport_patient, ]); } return response(['message' => 'Курс был добавлен в таблицу для хранения всех куров у пациента'], 200); } else { return response(['message' => 'У пациента уже есть курс, чтобы добавить новый удалите предыдуший'], 200); } } else { return response(['message' => 'Такого пациента нету'], 401); } } } //Очистка курса пациента public function ClearPatientSport(Request $request) { $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', ]); if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { if ($Patient->id_sport_patient == null) { return response(['message' => 'У пациента нету курса'], 200); } else { //Обновляем что курс окончен $SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first(); $SP = $SportPatient; $SP->finished = 1; $SP->update(); $pat = $Patient; $pat->pause = null; $pat->block = null; $pat->report7day = null; $pat->report15day = null; $pat->id_sport_patient = null; $pat->total_days_sports = null; $pat->now_days_sports = null; $pat->all_days_sports = null; $pat->update(); return response(['message' => 'Курс пациента был очишен'], 200); } } else { return response(['message' => 'Такого пациента нету'], 401); } } } function AddandClearDayPatient(string $id) { $Patient = Patient::where('id', $id)->first(); $CalendarDaysAdd = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('date', '>=', date('Y-m-d'))->get(); $dateMax = $Patient->total_days_sports - $Patient->now_days_sports; $CoutCD = Count($CalendarDaysAdd); if ($dateMax != $CoutCD) { if ($dateMax < $CoutCD) { $max = $CoutCD - $dateMax; for ($i = 1; $i < $max; $i++) { CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('date', '>=', date('Y-m-d'))->orderBy('date', 'DESC')->first()->delete(); } } else { $max = ($dateMax - $CoutCD) + 1; $CalendarDaysDelete = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('date', '>=', date('Y-m-d'))->orderBy('date', 'DESC')->first(); for ($i = 1; $i < $max; $i++) { CalendarDays::create([ 'id_patient' => $Patient->id, 'day' => $CalendarDaysDelete->day + $i, 'date' => date('Y-m-d', strtotime("+$i day", strtotime($CalendarDaysDelete->date))), 'id_sport_patient' => $Patient->id_sport_patient, ]); } } } return response("CoutCD - $CoutCD | dateMax - $dateMax | Patient->total_days_sports - $Patient->total_days_sports | Patient->now_days_sports - $Patient->now_days_sports", 400); } //Вывод курса для врача, чтобы он смог посмотеть что входит в курс public function GetPatientBAQiestionar(Request $request) { $error = Validator::make($request->all(), [ 'id' => '', ]); if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient->id_sport_patient == null || $Patient->id_sport_patient == "") { return response(['message' => "У пациента отсутсвует курс"], 200); } else { $BeforeQuestionnaire = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'ASC')->get(); $result = []; for ($i = 0; $i < Count($BeforeQuestionnaire); $i++) { $AfterQuestionnaireSearch = AfterQuestionnaire::where('date', $BeforeQuestionnaire[$i]->date)->where('id_sport_patient', $Patient->id_sport_patient)->first(); if ($AfterQuestionnaireSearch != null) { $search_sport = [ 'date' => $BeforeQuestionnaire[$i]->date, 'idb' => $BeforeQuestionnaire[$i]->id, 'oneb' => $BeforeQuestionnaire[$i]->one, 'twob' => $BeforeQuestionnaire[$i]->two, 'threeb' => $BeforeQuestionnaire[$i]->three, 'fourb' => $BeforeQuestionnaire[$i]->four, 'fiveb' => $BeforeQuestionnaire[$i]->five, 'sixb' => $BeforeQuestionnaire[$i]->six, 'sevenb' => $BeforeQuestionnaire[$i]->seven, 'eightb' => $BeforeQuestionnaire[$i]->eight, 'nineb' => $BeforeQuestionnaire[$i]->nine, 'statusa' => "1", 'ida' => $AfterQuestionnaireSearch->id, 'onea' => $AfterQuestionnaireSearch->one, 'twoa' => $AfterQuestionnaireSearch->two, 'threea' => $AfterQuestionnaireSearch->three, 'foura' => $AfterQuestionnaireSearch->four, 'fivea' => $AfterQuestionnaireSearch->five, 'sixa' => $AfterQuestionnaireSearch->six, 'sevena' => $AfterQuestionnaireSearch->seven, 'eighta' => $AfterQuestionnaireSearch->eight, 'ninea' => $AfterQuestionnaireSearch->nine, 'tena' => $AfterQuestionnaireSearch->ten, 'elevena' => $AfterQuestionnaireSearch->eleven, 'twelvea' => $AfterQuestionnaireSearch->twelve, ]; } else { $search_sport = [ 'date' => $BeforeQuestionnaire[$i]->date, 'idb' => $BeforeQuestionnaire[$i]->id, 'oneb' => $BeforeQuestionnaire[$i]->one, 'twob' => $BeforeQuestionnaire[$i]->two, 'threeb' => $BeforeQuestionnaire[$i]->three, 'fourb' => $BeforeQuestionnaire[$i]->four, 'fiveb' => $BeforeQuestionnaire[$i]->five, 'sixb' => $BeforeQuestionnaire[$i]->six, 'sevenb' => $BeforeQuestionnaire[$i]->seven, 'eightb' => $BeforeQuestionnaire[$i]->eight, 'nineb' => $BeforeQuestionnaire[$i]->nine, 'statusa' => "0", 'onea' => 0, 'twoa' => 0, 'threea' => 0, 'foura' => 0, 'fivea' => 0, 'sixa' => 0, 'sevena' => 0, 'eighta' => 0, 'ninea' => 0, 'tena' => 0, 'elevena' => 0, 'twelvea' => 0, ]; } array_push($result, $search_sport); } return response(['questionnaire' => $result], 200); } } } function CheckTokenDoctor() { $User = Auth::user(); if ($User != null) { return response(['status' => "300"], 200); } else { return response(['status' => "600"], 200); } } public function UpdatePatientLogin(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', 'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20|min:4', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $PatientLogin = Patient::where('login', $request->login)->first(); if ($PatientLogin == null) { $P = $Patient; $P->login = $request->login; $P->update(); return response(['message' => 'Логин обновлен'], 200); } else { return response(['message' => 'Данный логин уже занят'], 200); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } public function UpdatePatientPassword(Request $request) { $error = Validator::make($request->all(), [ 'id' => 'required|numeric|max:10000|min:1', 'password' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100|min:10', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id)->first(); if ($Patient != null) { $P = $Patient; $P->password = Hash::make($request->password); $P->update(); return response(['message' => 'Пароль обновлен'], 200); } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } //Вывод новых необработанных заявлений public function GetAppealsDoctorNew() { $User = Auth::user(); if ($User != null) { $Appeals = AppealsDoctor::where('check', 0)->where('id_doctor', $User->id)->first(); $result = []; $number=0; if($Appeals!=null){ $AppealsList = AppealsDoctor::where('check', 0)->where('id_doctor', $User->id)->get(); for ($i = 0; $i != Count($AppealsList); $i++) { $Patient = Patient::where('id',$AppealsList[$i]->id_patient)->first(); $number = $number+1; $search_check = [ 'number' => $number, 'id' => $AppealsList[$i]->id, 'text' => $AppealsList[$i]->text, 'id_patient' => $AppealsList[$i]->id_patient, 'id_doctor'=>$AppealsList[$i]->id_doctor, 'check'=>$AppealsList[$i]->check, 'login'=>$Patient->login, 'created_at'=>$AppealsList[$i]->created_at, 'updated_at'=>$AppealsList[$i]->updated_at, ]; array_push($result, $search_check); } return response(['appeals_new' => $result], 200); } else{ return response(['appeals_new' => null], 200); } } else { return response(['message' => 'Ошибка 404'], 404); } } //Вывод новых обработанных заявлений public function GetAppealsDoctorOld() { $User = Auth::user(); if ($User != null) { $Appeals = AppealsDoctor::where('check', 1)->where('id_doctor', $User->id)->first(); $result = []; $number=0; if($Appeals!=null){ $AppealsList = AppealsDoctor::where('check', 1)->where('id_doctor', $User->id)->get(); for ($i = 0; $i != Count($AppealsList); $i++) { $Patient = Patient::where('id',$AppealsList[$i]->id_patient)->first(); $number = $number+1; $search_check = [ 'number' => $number, 'id' => $AppealsList[$i]->id, 'text' => $AppealsList[$i]->text, 'id_patient' => $AppealsList[$i]->id_patient, 'id_doctor'=>$AppealsList[$i]->id_doctor, 'check'=>$AppealsList[$i]->check, 'login'=>$Patient->login, 'created_at'=>$AppealsList[$i]->created_at, 'updated_at'=>$AppealsList[$i]->updated_at, ]; array_push($result, $search_check); } return response(['appeals_old' => $result], 200); } else{ return response(['appeals_old' => null], 200); } } else { return response(['message' => 'Ошибка 404'], 404); } } //Создание сообщения для пациента public function AddMessageDoctor(Request $request) { $User = Auth::user(); if ($User != null) { $error = Validator::make($request->all(), [ //'id' => 'required|numeric|max:10000|min:1', 'login' => 'required|string|max:1000|min:4', // 'text' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100|min:4', 'text' => 'required|string|max:1000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('login', $request->login)->first(); if ($Patient != null) { AppealsPatient::create([ 'text' => $request->text, 'id_patient' => $Patient->id, 'id_doctor' => $User->id, ]); return response(['message' => 'Сообщение отправлено'], 200); } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } else { return response(['message' => 'Ошибка 404'], 404); } } //Создание сообщения для пациента public function UpdateMessageDoctor(Request $request) { $User = Auth::user(); if ($User != null) { $error = Validator::make($request->all(), [ 'id_patient' => 'required|numeric|max:10000|min:1', 'id' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $Patient = Patient::where('id', $request->id_patient)->first(); if ($Patient != null) { $AppealsPatient = AppealsDoctor::where('id',$request->id)->where('check',0)->where('id_patient',$Patient->id)->where('id_doctor',$User->id)->first(); if($AppealsPatient!=null){ if($AppealsPatient->check == 0){ $AP = $AppealsPatient; $AP->check = 1; $AP->update(); return response(['message' => 'Подтверждено'], 200); } else{ return response(['message' => 'Данное сообщение уже отмечено'], 200); } } else{ return response(['message' => 'Такого сообщения нету'], 200); } } else { return response(['message' => 'Ошибка, такого пациента нету'], 400); } } } else { return response(['message' => 'Ошибка 404'], 404); } } //Создание основы для собственного курса от врача function AddCoursesName(Request $request){ $User = Auth::user(); if ($User != null) { $error = Validator::make($request->all(), [ 'name' => 'required|string|max:150|min:4', 'description' => 'required|string|max:1000|min:4', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $SportCourses = SportCourses::create([ 'name'=>$request->name, 'description'=>$request->description, 'visibility'=>1, 'user_id'=>$User->id, ]); SetsOfSportsActivities::create([ 'name'=>uniqid(), 'day'=>1, 'description'=>"Общий курс", 'id_sports_courses'=>$SportCourses->id, ]); return response(['message' => 'Шаблон для курса создан'], 200); } } else { return response(['message' => 'Ошибка 404'], 404); } } //Добавление упражнения в курс function AddCoursesCreatingDoctor(Request $request){ $User = Auth::user(); if ($User != null) { $error = Validator::make($request->all(), [ 'id_sports_tasks' => 'required|numeric|max:10000|min:1', 'id_sets_of_sports_activities' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $SportTasks = SportTasks::where('id',$request->id_sports_tasks)->first(); if($SportTasks!=null){ $SetOfSportsExercises = SetOfSportsExercises::where('id_sets_of_sports_activities',$request->id_sets_of_sports_activities)->where('id_sports_tasks',$request->id_sports_tasks)->orderBy('id','DESC')->first(); if($SetOfSportsExercises ==null){ $SetOfSportsExercisesSport = SetOfSportsExercises::where('id_sets_of_sports_activities',$request->id_sets_of_sports_activities)->where('id_sports_tasks','!=',$request->id_sports_tasks)->orderBy('id','DESC')->first(); if($SetOfSportsExercisesSport==null){ SetOfSportsExercises::create([ 'number'=>1, 'day'=>1, 'id_sports_tasks'=>$request->id_sports_tasks, 'id_sets_of_sports_activities'=>$request->id_sets_of_sports_activities, ]); return response(['message' => 'Первое упражнение добавлено'], 200); } else{ SetOfSportsExercises::create([ 'number'=>$SetOfSportsExercisesSport->number+1, 'day'=>1, 'id_sports_tasks'=>$request->id_sports_tasks, 'id_sets_of_sports_activities'=>$request->id_sets_of_sports_activities, ]); return response(['message' => 'Упражнение добавлено'], 200); } } else{ return response(['message' => 'Такое упражнение уже есть'], 200); } } else{ return response(['message' => 'Такого упражнения нету'], 200); } } } else { return response(['message' => 'Ошибка 404'], 404); } } //Удаление упражнения из курса function ClearCoursesCreatingDoctor(Request $request){ $User = Auth::user(); if ($User != null) { $error = Validator::make($request->all(), [ 'id_sets_of_sports_exercises' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $SetOfSportsExercises = SetOfSportsExercises::where('id',$request->id_sets_of_sports_exercises)->first(); if($SetOfSportsExercises!=null){ SetOfSportsExercises::where('id',$request->id_sets_of_sports_exercises)->delete(); return response(['message' => 'Упражнение удалено'], 200); } else{ return response(['message' => 'Такого упражнения нету'], 200); } } } else { return response(['message' => 'Ошибка 404'], 404); } } //Вывод курсов созданных врачем function GetCoursesDoctor(){ $User = Auth::user(); $SportCoursesDoctor = SportCourses::where('user_id',$User->id)->get(); $SetsOfSportsActivities = SetsOfSportsActivities::orderBy('id', 'ASC') ->leftJoin('sports_courses', 'sports_courses.id', '=', 'sets_of_sports_activities.id_sports_courses') ->select('sports_courses.id', 'sports_courses.name', 'sports_courses.description', 'sports_courses.visibility', 'sports_courses.visibility','sports_courses.user_id','sets_of_sports_activities.id as id_activity','sports_courses.created_at','sports_courses.updated_at') ->distinct() ->where("sports_courses.user_id", $User->id) ->get(); $result = []; $number=0; for ($i = 0; $i != Count($SetsOfSportsActivities); $i++) { $number = $number+1; $search_check = [ 'number' => $number, 'id' => $SetsOfSportsActivities[$i]->id, 'name' => $SetsOfSportsActivities[$i]->name, 'description' => $SetsOfSportsActivities[$i]->description, 'visibility' => $SetsOfSportsActivities[$i]->visibility, 'user_id'=>$SetsOfSportsActivities[$i]->user_id, 'id_activity'=>$SetsOfSportsActivities[$i]->id_activity, 'created_at'=>$SetsOfSportsActivities[$i]->created_at, 'updated_at'=>$SetsOfSportsActivities[$i]->updated_at, ]; array_push($result, $search_check); } return response(['sport_courses_doctor' => $result], 200); } //Вывод всех упражнений function GetEditCourseDoctorAll(Request $request){ //$Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id_doctor_courses' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $SportCourses = SportCourses::orderBy('id', 'ASC')->where('id', $request->id_doctor_courses)->first(); if ($SportCourses != null) { //$SportCoursesAdd = SportCourses::orderBy('id', 'ASC')->where('id_doctor_courses', $request->id_doctor_courses)->get(); // $SportTasks = $Set::get(); $SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC') ->join('sets_of_sports_activities', 'set_of_sports_exercises.id_sets_of_sports_activities', '=', 'sets_of_sports_activities.id') ->join('sports_tasks', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') // ->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks') ->join('sports_courses', 'sets_of_sports_activities.id_sports_courses', '=', 'sports_courses.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id','set_of_sports_exercises.id as id_exercises', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image') ->distinct('id') ->where('sports_courses.id', '!=',$request->id_doctor_courses) ->get(); $CoursesSportEdit = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC') ->join('sets_of_sports_activities', 'set_of_sports_exercises.id_sets_of_sports_activities', '=', 'sets_of_sports_activities.id') ->join('sports_tasks', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') // ->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks') ->join('sports_courses', 'sets_of_sports_activities.id_sports_courses', '=', 'sports_courses.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id','set_of_sports_exercises.id as id_exercises', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image') ->distinct('id') ->where('sports_courses.id',$request->id_doctor_courses) ->get(); $result = []; $number = 0; if ($CoursesSportEdit != null) { for ($i = 0; $i != Count($SetOfSportsExercises); $i++) { $res = 0; for ($j = 0; $j != Count($CoursesSportEdit); $j++) { if ($SetOfSportsExercises[$i]->id != $CoursesSportEdit[$j]->id) { $res++; } } if ($res == Count($CoursesSportEdit)) { $number++; $search_sport = [ 'number' => $number, 'id' => $SetOfSportsExercises[$i]->id, 'id_exercises' => $SetOfSportsExercises[$i]->id_exercises, 'name' => $SetOfSportsExercises[$i]->name, 'description' => $SetOfSportsExercises[$i]->description, 'url_image' => $SetOfSportsExercises[$i]->url_image, ]; array_push($result, $search_sport); } } } else { for ($i = 0; $i != Count($SetOfSportsExercises); $i++) { $search_sport = [ 'number' => $number, 'id' => $SetOfSportsExercises[$i]->id, 'id_exercises' => $SetOfSportsExercises[$i]->id_exercises, 'name' => $SetOfSportsExercises[$i]->name, 'description' => $SetOfSportsExercises[$i]->description, 'url_image' => $SetOfSportsExercises[$i]->url_image, ]; array_push($result, $search_sport); } } return response(['set_of_sports_exercises_all' => $result], 200); } else { return response(['message' => 'Ошибка, такого курса нету'], 400); } } } //Вывод добавленных упражнений в курс function GetEditCourseDoctorYour(Request $request){ //$Doctor = Auth::user()->makeHidden(['id']); $error = Validator::make($request->all(), [ 'id_doctor_courses' => 'required|numeric|max:10000|min:1', ]);//1024 if ($error->fails()) { return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400); } else { $SportCourses = SportCourses::orderBy('id', 'ASC')->where('id', $request->id_doctor_courses)->first(); if ($SportCourses != null) { $CoursesSportEdit = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC') ->join('sets_of_sports_activities', 'set_of_sports_exercises.id_sets_of_sports_activities', '=', 'sets_of_sports_activities.id') ->join('sports_tasks', 'set_of_sports_exercises.id_sports_tasks', '=', 'sports_tasks.id') // ->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks') ->join('sports_courses', 'sets_of_sports_activities.id_sports_courses', '=', 'sports_courses.id') ->join('image', 'sports_tasks.article_image', '=', 'image.article') ->select('sports_tasks.id', 'sports_tasks.name', 'sports_tasks.description', 'image.url_image','set_of_sports_exercises.id as id_exercises') ->distinct('id') ->where('sports_courses.id',$request->id_doctor_courses, ) ->get(); $result = []; $number = 0; for ($i = 0; $i != Count($CoursesSportEdit); $i++) { $number++; $search_sport = [ 'number' => $number, 'id' => $CoursesSportEdit[$i]->id, 'id_exercises' => $CoursesSportEdit[$i]->id_exercises, 'name' => $CoursesSportEdit[$i]->name, 'description' => $CoursesSportEdit[$i]->description, 'url_image' => $CoursesSportEdit[$i]->url_image, ]; array_push($result, $search_sport); } return response(['set_of_sports_exercises_your' => $result], 200); } else { return response(['message' => 'Ошибка, такого курса нету'], 400); } } } //Получение данных для первой страницы врача function CountPatientAndAppeals() { $User = Auth::user(); $Patient = Patient::where('id_doctor',$User->id)->get(); $AppealsCheck = AppealsDoctor::where('check',0)->where('id_doctor',$User->id)->get(); $AppealsAll = AppealsDoctor::where('id_doctor',$User->id)->get(); return response(['patient' => Count($Patient),'appeals_check' => Count($AppealsCheck),'appeals_all' => Count($AppealsAll)], 200); } }