2243 lines
147 KiB
PHP
2243 lines
147 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Models\AfterQuestionnaire;
|
||
use App\Models\AppealsDoctor;
|
||
use App\Models\AppealsPatient;
|
||
use App\Models\BeforeQuestionnaire;
|
||
use App\Models\CalendarDays;
|
||
use App\Models\CoursesSportEdit;
|
||
use App\Models\Doctor;
|
||
use App\Models\Image;
|
||
use App\Models\Patient;
|
||
use App\Models\SetOfSportsExercises;
|
||
use App\Models\SetsOfSportsActivities;
|
||
use App\Models\SportCourses;
|
||
use App\Models\Category;
|
||
use App\Models\Product;
|
||
use App\Models\SportForDay;
|
||
use App\Models\SportPatient;
|
||
use App\Models\SportTasks;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Auth;
|
||
use Illuminate\Support\Facades\Crypt;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Validator;
|
||
use Illuminate\Support\Str;
|
||
use Ramsey\Uuid\Type\Integer;
|
||
|
||
|
||
class PatientController extends Controller
|
||
{
|
||
public function LoginPatient(Request $request)
|
||
{
|
||
$validation = Validator::make($request->all(), [
|
||
'login' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:20',
|
||
'password' => 'required|regex:/^[a-zA-Z0-9\-]+$/|string|max:100',
|
||
]);
|
||
if ($validation->fails()) {
|
||
// $result = [
|
||
// 'error' => [
|
||
// 'code' => 400,
|
||
// 'message' => 'Validation error',
|
||
// 'error' => $validation->errors()
|
||
// ]];
|
||
|
||
return response(['message' => 'Ошибка валидации'], 422);
|
||
}
|
||
|
||
if (Auth::guard('patient')->attempt(['login' => $request->login, 'password' => $request->password])) {
|
||
$user = Auth::guard('patient')->user();
|
||
$pat = $user;
|
||
$pat->api_token = Str::random(80);
|
||
$pat->update();
|
||
|
||
return response([
|
||
'id' => $user->id,
|
||
'token' => $user->api_token,
|
||
], 200);
|
||
}
|
||
return response(['message' => 'Неверные данные'], 401);
|
||
}
|
||
|
||
public function LogoutPatient()
|
||
{
|
||
$user = Auth::user()->makeHidden(['id', 'role']);
|
||
$pat = $user;
|
||
$pat->api_token = null;
|
||
$pat->update();
|
||
|
||
return response(['message' => 'Вы вышли из аккаунта'], 200);
|
||
}
|
||
|
||
//Вывод курса для пациента в зависимоти от того сколько дней у него пройдено
|
||
public function GetCoursSportPatient(Request $request)
|
||
{
|
||
$error = Validator::make($request->all(), [
|
||
'name' => 'required',
|
||
'day' => 'required',
|
||
]);
|
||
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')
|
||
->d('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 AddBeforeQuestionnaire(Request $request)
|
||
{
|
||
$error = Validator::make($request->all(), [
|
||
'one' => 'required',
|
||
'two' => 'required',
|
||
'three' => 'required',
|
||
'four' => 'required',
|
||
'five' => 'required',
|
||
'six' => 'required',
|
||
'seven' => 'required',
|
||
'eight' => 'required',
|
||
'nine' => 'required',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$date = date("Y-m-d");
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
//Проверка на то, закончин ли данный курс
|
||
if ($SportPatient->finished == false) {
|
||
|
||
$date = date("Y-m-d");
|
||
$BeforeQuestionnaire = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
//Если была хоть одна анкета под данный курс
|
||
if ($BeforeQuestionnaireDate != null) {
|
||
//Проверка на то есть заполнял ли пользватель анкету ДО на эту дату
|
||
if ($BeforeQuestionnaire == null) {
|
||
$BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$AfterQuestionnaire = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
//Проверка на то заполнил ли пользователь анкету ПОСЛЕ за предыдущий день
|
||
if ($AfterQuestionnaire != null) {//Если заполнил
|
||
|
||
//Заполнение анкеты
|
||
$BQ = BeforeQuestionnaire::create([
|
||
'id_sport_patient' => $SportPatient->id,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
]);
|
||
return response(['Анкета ДО добавлена', date('Y-m-d', strtotime("0 day"))], 200);
|
||
|
||
//Подтверждаем в календарном дне, что анкета ДО заполнена
|
||
$pat = $Patient;
|
||
$pat->before_questionnaire = $BQ->id;
|
||
$pat->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->one >= 6) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->ban = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
} //Проверка на паузу
|
||
else if ($request->four == "1" || $request->five == "1" || $request->six == "1" || $request->seven == "1" || $request->nine == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
}
|
||
} else if ($AfterQuestionnaire == null &&
|
||
(($Patient->pause == $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) == $BeforeQuestionnaireSearch->date) ||
|
||
($Patient->block == $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) == $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) == $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) == $BeforeQuestionnaireSearch->date))) {//Заполнение анкеты за предыдущий день занятий
|
||
//Заполнение анкеты
|
||
$BQ = BeforeQuestionnaire::create([
|
||
'id_sport_patient' => $SportPatient->id,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
]);
|
||
|
||
|
||
//Подтверждаем в календарном дне, что анкета ДО заполнена
|
||
$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('date', date('Y-m-d'))->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
if ($CalendarDays != null) {
|
||
$CD = $CalendarDays;
|
||
$CD->id_before_questionnaire = $BQ->id;
|
||
$CD->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->one >= 6) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
} //Проверка на паузу
|
||
else if ($request->four == "1" || $request->five == "1" || $request->six == "1" || $request->seven == "1" || $request->nine == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
}
|
||
return response(['Анкета ДО добавлена'], 200);
|
||
} else {
|
||
return response(['Ошибка системы'], 401);
|
||
}
|
||
|
||
|
||
} else {
|
||
return response(['У вас не заполнена анкета за придушивший день занятий'], 401);
|
||
}
|
||
} else {
|
||
return response(['У пользователя уже заполнена анкета ДО на сегодня'], 401);
|
||
}
|
||
} else {//Если небыло ни одной анкеты за курс(первая)
|
||
|
||
//Создание списка на 30 дней в таблице calendar_days
|
||
for ($i = 0; $i < $Patient->total_days_sports; $i++) {//Циул на количество дней
|
||
$date = date('Y-m-d', strtotime("$i day"));
|
||
CalendarDays::create([
|
||
'id_patient' => $Patient->id,
|
||
'day' => $i + 1,
|
||
'date' => date('d-m-Y', strtotime($date)),
|
||
'id_sport_patient' => $SportPatient->id,
|
||
]);
|
||
}
|
||
|
||
//Заполнение анкеты
|
||
$BQ = BeforeQuestionnaire::create([
|
||
'id_sport_patient' => $SportPatient->id,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
]);
|
||
|
||
$BQ = BeforeQuestionnaire::where('date', date('Y-m-d'))->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
//Подтверждаем в календарном дне, что анкета ДО заполнена
|
||
$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('date', date('Y-m-d'))->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CD = $CalendarDays;
|
||
$CD->id_before_questionnaire = $BQ->id;
|
||
$CD->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->one >= 6) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
} //Проверка на паузу
|
||
else if ($request->four == "1" || $request->five == "1" || $request->six == "1" || $request->seven == "1" || $request->nine == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
}
|
||
return response(['Анкета ДО добавлена'], 200);
|
||
|
||
}
|
||
|
||
|
||
} else {
|
||
return response(['Данный курс уже окончен, обратитесь к врачу'], 401);
|
||
}
|
||
} else {
|
||
return response(['У вас нету курса, попросите врача добавить вать вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//Подтверждение анкеты ПОСЛЕ, после увеличится количество выполненных дней и подтверждения анкет на определенный день
|
||
public function AddAfterQuestionnaire(Request $request)
|
||
{
|
||
//Сегодняшняя дата
|
||
$date = date("Y-m-d");
|
||
|
||
$error = Validator::make($request->all(), [
|
||
'one' => 'required',
|
||
'two' => 'required',
|
||
'three' => 'required',
|
||
'four' => 'required',
|
||
'five' => 'required',
|
||
'six' => 'required',
|
||
'seven' => 'required',
|
||
'eight' => 'required',
|
||
'nine' => 'required',
|
||
'ten' => 'required',
|
||
'eleven' => 'required',
|
||
'twelve' => 'required',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaireNew = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
//Проверка на то отправлялась ли хоть одна анкета ДО
|
||
if ($BeforeQuestionnaireNew != null) {
|
||
|
||
//Проверка на то, активен ли данный курс
|
||
if ($SportPatient->finished == false) {
|
||
$BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
//Проверка на то отправлена ли анкета ДО за сегодня
|
||
if ($BeforeQuestionnaireDate == null && $AfterQuestionnaireSearch == null) {
|
||
$dateBefSearch = $BeforeQuestionnaireSearch->date;
|
||
$pause = $Patient->pause;
|
||
$pauseNo1DAy = date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause)));
|
||
$block = $Patient->block;
|
||
$blockNo1DAy = date('Y-m-d', strtotime('-1 day', strtotime($Patient->block)));
|
||
$blockNo2DAy = date('Y-m-d', strtotime('-2 day', strtotime($Patient->block)));
|
||
$blockNo3DAy = date('Y-m-d', strtotime('-3 day', strtotime($Patient->block)));
|
||
|
||
//Проверка на то заполнялась ли анкета ПОСЛЕ за предыдущий день и не было ли блокировок или пауза
|
||
if ($AfterQuestionnaireSearch == null) {
|
||
if (($pause == null && $block == null) ||
|
||
((($pause != null && $block != null)) && $pause != $dateBefSearch && $pauseNo1DAy != $dateBefSearch && $block != $dateBefSearch && $blockNo1DAy != $dateBefSearch && $blockNo2DAy != $dateBefSearch && $blockNo3DAy != $dateBefSearch) ||
|
||
((($pause != null && $block == null)) && $pause != $dateBefSearch && $pauseNo1DAy != $dateBefSearch) ||
|
||
((($pause == null && $block != null)) && $block != $dateBefSearch && $blockNo1DAy != $dateBefSearch && $blockNo2DAy != $dateBefSearch && $blockNo3DAy != $dateBefSearch)) {
|
||
|
||
$SportForDay = SportForDay::where('day', $BeforeQuestionnaireSearch->date)->where('date', $date)->where('id_patient', $Patient->id_patient)->where('id_sport_patient', $Patient->id_sport_patient)->where('finish', 0)->first();
|
||
//Проверка на то все ли задания были выполнены, если нет, то нельзя отправить отчет
|
||
if ($SportForDay == null) {
|
||
//Заполнение анкеты за предыдущий день
|
||
$AQ = AfterQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => $BeforeQuestionnaireSearch->date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
'ten' => $request->ten,
|
||
'eleven' => $request->eleven,
|
||
'twelve' => $request->twelve,
|
||
]);
|
||
|
||
$AfterQuestionnaireUpdate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
//Подтверждаем в календарном дне, что анкета ПОСЛЕ заполнена
|
||
$CalendarDays = CalendarDays::where('date', $BeforeQuestionnaireSearch->date)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$pat = $CalendarDays;
|
||
$pat->id_after_questionnaire = $AfterQuestionnaireUpdate->id;
|
||
$pat->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->ten == 1) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
} //Проверка на паузу
|
||
else if ($request->one >= "6" || $request->three == "0" || $request->six == "1" || $request->eight == "1" || $request->eleven == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
}
|
||
$pat2 = $Patient;
|
||
$pat2->now_days_sports = $Patient->now_days_sports + 1;
|
||
$pat2->update();
|
||
|
||
return response(['Анкета ПОСЛЕ добавлена за предыдущий день' . "dateBefSearch=" . $dateBefSearch . ". pause=" . $pause . ". pauseNo1DAy=" . $pauseNo1DAy . ". block=" . $block . ". blockNo1DAy=" . $blockNo1DAy . ". blockNo2DAy=" . $blockNo2DAy . ". blockNo3DAy=" . $blockNo3DAy], 200);
|
||
|
||
} else {
|
||
return response(['Не все задания выполнены'], 200);
|
||
}
|
||
} else if ($AfterQuestionnaireSearch != null) {//Заполнение анкеты за предыдущий день занятий
|
||
return response(['У вас уже заполнена анкета ПОСЛЕ предыдущий день'], 401);
|
||
} else {
|
||
return response(['У пользователя не заполнена анкета ДО на сегодня, поэтому анкету после он не может заполнить'], 401);
|
||
}
|
||
} else {
|
||
return response(['У пользователя не заполнена анкета ДО на сегодня, поэтому анкету после он не может заполнить'], 401);
|
||
}
|
||
} else if ($BeforeQuestionnaireDate != null && $AfterQuestionnaireDate == null) {
|
||
|
||
$SportForDay = SportForDay::where('finish', 0)->first();
|
||
//Проверка на то все ли задания были выполнены, если нет, то нельзя отправить отчет
|
||
if ($SportForDay == null) {
|
||
$AQ = AfterQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
'ten' => $request->ten,
|
||
'eleven' => $request->eleven,
|
||
'twelve' => $request->twelve,
|
||
]);
|
||
|
||
|
||
$AfterQuestionnaireUpdate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
//Подтверждаем в календарном дне, что анкета ПОСЛЕ заполнена
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$pat = $CalendarDays;
|
||
$pat->id_after_questionnaire = $AfterQuestionnaireUpdate->id;
|
||
$pat->update();
|
||
|
||
|
||
//ПРоверка на блок
|
||
if ($request->ten == 1) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
} //Проверка на паузу
|
||
else if ($request->one >= "6" || $request->three == "0" || $request->six == "1" || $request->eight == "1" || $request->eleven == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
}
|
||
return response(['Анкета ПОСЛЕ добавлена', $SportForDay], 200);
|
||
} else {
|
||
return response(['Не все задания выполнены'], 200);
|
||
}
|
||
} else {
|
||
return response(['У пользователя уже заполнена анкета ПОСЛЕ на сегодня'], 401);
|
||
}
|
||
|
||
|
||
} else {
|
||
return response(['Данный курс уже окончен, обратитесь к врачу'], 401);
|
||
}
|
||
} else {
|
||
return response(['У вас не заполнена анкета ДО'], 401);
|
||
}
|
||
|
||
} else {
|
||
return response(['У вас нету курса, попросите врача добавить вать вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// //Функция для вывода нужной карточки на экран
|
||
// public function VisibleView()
|
||
// {
|
||
// $Patient = Auth::user()->makeHidden(['id']);
|
||
// $date = date("Y-m-d");
|
||
//
|
||
// if ($Patient != null) {
|
||
// //Проверка на то, есть ли курс у пациента
|
||
// if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
// $SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
// $Calendare = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
// //Проверка на то, закончин ли данный курс
|
||
// if ($SportPatient->finished == false) {
|
||
// //ППоверка есть ли нужное количество дней в календаре на данный курс, если нет то отправлять пациента на экран с подтверждением начинания сегодняшнего дня, в акнкету до тренировки, чтобы он создавал
|
||
//
|
||
// $BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
// $AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
//
|
||
// $AfterQuestionnaire = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
// $BeforeQuestionnaire = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
// if ($Patient->block >= $date) {//Если блок
|
||
// return response(['view' => 3, 'text' => 'Курс заблокирован до' . $Patient->block], 200);
|
||
// } else if ($Patient->pause >= $date) {//Если пауза
|
||
// return response(['view' => 4, 'text' => 'Курс на паузе до' . $Patient->block], 200);
|
||
// } else if ($BeforeQuestionnaire == null && $AfterQuestionnaire == null && $AfterQuestionnaireSearch != null) {//Ели не заполнена анкеты ДО
|
||
// return response(['view' => 5, 'text' => 'Анкета ДО тренировки'], 200);
|
||
// } else if ($BeforeQuestionnaire != null && $AfterQuestionnaire == null && ($Calendare->count_workout_max != null && $Calendare->count_workout_make != null) && ($Calendare->count_workout_max == $Calendare->count_workout_make)) {//Еcли не заполнена анкеты ПОСЛЕ
|
||
// return response(['view' => 6, 'text' => 'Анкета ПОСЛЕ тренировки'], 200);
|
||
// } //Вывод анкеты ПОСЛЕ если не заполнил за предыдущий день
|
||
// else if ($AfterQuestionnaireSearch == null &&
|
||
// (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
// ($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {//Заполнение анкеты за предыдущий день занятий
|
||
// return response(['view' => 7, 'text' => 'Анкета ПОСЛЕ за предыдущий день'], 200);
|
||
// } else if ($AfterQuestionnaire != null && $BeforeQuestionnaire != null) {//Ели не заполнены анкеты
|
||
// return response(['view' => 8, 'text' => 'Тренировки на сегодня окончены, ждем вас завтра'], 200);
|
||
// } else if ($AfterQuestionnaire != null && $BeforeQuestionnaire == null && $Patient->pause == null && $Patient->block == null && ($Calendare->count_workout_max != $Calendare->count_workout_make)) {//Ели не заполнены анкеты
|
||
// return response(['view' => 9, 'text' => 'Тренировки на сегодня'], 200);
|
||
// } //Условие, если курса на этот день нету, то выводим экран с сообщение, "чтобы начать вам нужно подтвердить данное действие"
|
||
// else if ($AfterQuestionnaire != null && $BeforeQuestionnaire == null && $Patient->pause == null && $Patient->block == null && $Calendare->id_sport_patient == null) {//Ели не заполнены анкеты
|
||
// return response(['view' => 10, 'text' => 'Чтобы начать вам нужно подтвердить данное действие'], 200);
|
||
// }
|
||
//
|
||
//
|
||
// } else {
|
||
// return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
// }
|
||
// } else {
|
||
// return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
// }
|
||
// } else {
|
||
// return response(['Такого пациента нету'],);
|
||
// }
|
||
// }
|
||
|
||
|
||
// //Функция для вывода нужной карточки на экран
|
||
// public function VisibleView2()
|
||
// {
|
||
// $Patient = Auth::user()->makeHidden(['id']);
|
||
// $date = date("Y-m-d");
|
||
//
|
||
// if ($Patient != null) {
|
||
// //Проверка на то, есть ли курс у пациента
|
||
// if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
//
|
||
// $SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
// //Проверка на то, закончен ли данный курс
|
||
// if ($SportPatient->finished == 0) {
|
||
// //Проверка если ли блокировка
|
||
// if (($Patient->block !== null && $Patient->block !== "" && $Patient->block >= $date) || ($Patient->pause !== null && $Patient->pause !== "" && $Patient->pause >= $date)) {
|
||
// if ($Patient->block !== null && $Patient->block !== "" && $Patient->block >= $date) {
|
||
// return response(['view' => 3, 'text' => 'У вас блокировка до ' . $Patient->block], 200);
|
||
// } else if ($Patient->pause !== null && $Patient->pause !== "" && $Patient->pause >= $date) {
|
||
// return response(['view' => 4, 'text' => 'У вас пауза до ' . $Patient->pause], 200);
|
||
// }
|
||
// } else {
|
||
// //Проверка на то есть ли хоть одна анкета ДО
|
||
// $BeforeQ = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
// $AfterQ = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
// if ($BeforeQ != null) {
|
||
// $BeforeQuestionnaire = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->where('date', $date)->first();
|
||
// $AfterQuestionnaire = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->where('date', $date)->first();
|
||
//
|
||
// $SportForDay = SportForDay::where('day', $date)->where('finish', 1)->get();
|
||
//
|
||
// $CalendareDays = CalendarDays::where('date', $date)->first();
|
||
//
|
||
// if($AfterQ == null && ($Patient->pause != null || $Patient->block != null) &&
|
||
// (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
// ($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))){
|
||
//
|
||
// }
|
||
//
|
||
// if ($BeforeQuestionnaire!= null && $AfterQ == null &&$CalendareDays->count_workout_max > Count($SportForDay)) {
|
||
// return response(['view' => 9, 'text' => 'Список тренировок'], 200);
|
||
// }
|
||
// else if($BeforeQuestionnaire!= null && $AfterQ == null &&$CalendareDays->count_workout_max == Count($SportForDay)){
|
||
// return response(['view' => 10, 'text' => 'Анкета ПОСЛЕ тренировки'], 200);
|
||
// }
|
||
// else{
|
||
//
|
||
// $BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->orderBy('date', 'DESC')->first();
|
||
//
|
||
// $AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->where('date', $BeforeQuestionnaireDate->date)->first();
|
||
// $SportForDateOld = SportForDay::where('day', $BeforeQuestionnaireDate->date)->where('finish', 0)->get();
|
||
// $CalendareDaysOld = CalendarDays::where('date', $BeforeQuestionnaireDate->date)->first();
|
||
//
|
||
//
|
||
//
|
||
//
|
||
//
|
||
// $BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
// $AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
//
|
||
// //Если небыло выполнено ни одног дня
|
||
// if ($BeforeQuestionnaire == null && $AfterQuestionnaire == null && $Patient->now_days_sport == 0) {
|
||
// return response(['view' => 5, 'text' => 'Нажмите кнопку подтверждения чтобы начать курс'], 200);
|
||
// } else if ($BeforeQuestionnaire == null && $AfterQuestionnaire == null && $Patient->now_days_sport > 0) {
|
||
// if ($SportForDateOld < $CalendareDaysOld->count_workout_max && $AfterQuestionnaireSearch == null &&
|
||
// (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
// ($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {//Заполнение анкеты за предыдущий день занятий
|
||
// return response(['view' => 6, 'text' => 'Список тренировок которые не закончил пациент за предыдущий день'], 200);
|
||
// } else if ($SportForDateOld == $CalendareDaysOld->count_workout_max && $AfterQuestionnaireSearch == null &&
|
||
// (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
// ($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {//Заполнение анкеты за предыдущий день занятий
|
||
// return response(['view' => 7, 'text' => 'Анкета ПОСЛЕ за предыдущий день'], 200);
|
||
// } else {
|
||
// return response(['view' => 8, 'text' => 'Анкета ДО тренировки'], 200);
|
||
// }
|
||
// } else if ($BeforeQuestionnaire != null && $AfterQuestionnaire == null && $Patient->now_days_sport > 0 && $SportForDay < $CalendareDays->count_workout_max) {
|
||
// return response(['view' => 9, 'text' => 'Список тренировок'], 200);
|
||
// } else if ($BeforeQuestionnaire != null && $AfterQuestionnaire == null && $Patient->now_days_sport > 0 && $SportForDay == $CalendareDays->count_workout_max) {
|
||
// return response(['view' => 10, 'text' => 'Анкета ПОСЛЕ тренировки'], 200);
|
||
// } else if ($BeforeQuestionnaire != null && $AfterQuestionnaire != null && $Patient->now_days_sport > 0 && $SportForDay == $CalendareDays->count_workout_max) {
|
||
// return response(['view' => 11, 'text' => 'Комплекс на сегодня вы выполнили, ждем вас завтра'], 200);
|
||
// } else {
|
||
// return response(['view' => 616.1, 'text' => 'Ошибка системы'], 400);
|
||
// }
|
||
// }
|
||
// } else {
|
||
// return response(['view' => 12, 'text' => 'Начало курса. Нажмите кнопку подтверждения чтобы начать курс'], 200);
|
||
// }
|
||
//
|
||
// }
|
||
// } else {
|
||
// return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
// }
|
||
// } else {
|
||
// return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
// }
|
||
// } else {
|
||
// return response(['Такого пациента нету'],);
|
||
// }
|
||
// }
|
||
|
||
|
||
//Функция для вывода нужной карточки на экран
|
||
public function VisibleView3()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$date = date("Y-m-d");
|
||
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
//$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('article_sport_for_day','!=',null)->orderBy('id','DESC')->first();
|
||
$SportForDay = SportForDay::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('day', $date)->where('finish', 0)->first();
|
||
$BeforeQuestionnaireToday = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireToday = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
if(($Patient->total_days_sports == $Patient->now_days_sports)&&($SportForDay==null)&&($BeforeQuestionnaireToday!=null)&&($AfterQuestionnaireToday==null)){
|
||
return response(['view' => 4, 'text' => 'Анкета ПОСЛЕ тренировки'], 200);
|
||
|
||
}
|
||
else{
|
||
if(($Patient->total_days_sports == $Patient->now_days_sports)&&($SportForDay==null)&&($BeforeQuestionnaireToday!=null)&&($AfterQuestionnaireToday!=null)){
|
||
return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
}
|
||
else{
|
||
//Проверка на то, закончен ли данный курс
|
||
if (($SportPatient->finished == 0) ) {
|
||
|
||
//Есть ли блок или пауза на данный момент
|
||
if (($Patient->block !== null && $Patient->block !== "" && $Patient->block >= $date) || ($Patient->pause !== null && $Patient->pause !== "" && $Patient->pause >= $date)) {
|
||
if ($Patient->block !== null && $Patient->block !== "" && $Patient->block >= $date) {
|
||
$blockDate = $Patient->block[8].$Patient->block[9].'.'.$Patient->block[5].$Patient->block[6].'.'.$Patient->block[0].$Patient->block[1].$Patient->block[2].$Patient->block[3];
|
||
|
||
return response(['view' => 9, 'text' => 'Ваш курс заблокирован до ' . $blockDate], 200);
|
||
} else if ($Patient->pause !== null && $Patient->pause !== "" && $Patient->pause >= $date) {
|
||
$pauseDate = $Patient->pause[8].$Patient->pause[9].'.'.$Patient->pause[5].$Patient->pause[6].'.'.$Patient->pause[0].$Patient->pause[1].$Patient->pause[2].$Patient->pause[3];
|
||
|
||
return response(['view' => 10, 'text' => 'Ваш курс на пауза до ' . $pauseDate], 200);
|
||
}
|
||
//Если нету паузы на данный момент
|
||
} else {
|
||
$BeforeQuestionnaire = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$AfterQuestionnaire = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
//Не было заполнено ни одной анкеты
|
||
if ($BeforeQuestionnaire == null && $AfterQuestionnaire == null) {
|
||
return response(['view' => 3, 'text' => 'Начало курса. Нажмите кнопку подтверждения чтобы начать курс'], 200);
|
||
} //Если была заполнена хотя бы анкета ДО
|
||
else if ($BeforeQuestionnaire != null) {
|
||
$BeforeQuestionnaireToday = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireToday = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
$SportForDay = SportForDay::where('day', $date)->where('finish', 1)->get();
|
||
$CalendareDays = CalendarDays::where('date', $date)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
//Заполнена ли анкета ДО на сегодня
|
||
if ($BeforeQuestionnaireToday == null && $AfterQuestionnaireToday == null) {
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->orderBy('date', 'DESC')->first();
|
||
$AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', '<', $date)->where('date', $BeforeQuestionnaireDate->date)->first();
|
||
|
||
// //Заполнялась ли анкета ПОСЛЕ за предыдущий день
|
||
// if ($AfterQuestionnaireDate == null) {
|
||
//
|
||
// $BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
// $AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
// //Были ли паузы или блокировки в эти даты
|
||
// if ($AfterQuestionnaireSearch == null &&
|
||
// (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
// ($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {
|
||
// return response(['view' => 7, 'text' => 'Анкета ПОСЛЕ за предыдущий день'], 200);
|
||
// } //Если была пауза или блокировка в эти даты
|
||
// else {
|
||
// return response(['view' => 8, 'text' => 'Анкета ДО тренировки'], 200);
|
||
// }
|
||
//
|
||
// } //Если анкета ПОЛСЕ за предыдущий день присутствует
|
||
// else {
|
||
return response(['view' => 8, 'text' => 'Анкета ДО тренировки'], 200);
|
||
// }
|
||
|
||
} //Если заполнена анкета ДО на сегодня, но не заполнена после
|
||
else if ($BeforeQuestionnaireToday != null && $AfterQuestionnaireToday == null) {
|
||
$SportForDay = SportForDay::where('id_sport_patient', $Patient->id_sport_patient)->where('id_patient', $Patient->id)->where('day', $date)->where('finish', 0)->get();
|
||
// if ($CalendareDays->count_workout_max == $CalendareDays->count_workout_make) {
|
||
if (Count($SportForDay) == 0) {
|
||
return response(['view' => 4, 'text' => 'Анкета ПОСЛЕ тренировки'], 200);
|
||
} else {
|
||
return response(['view' => 5, 'text' => 'Список упражнений на сегодня'], 200);
|
||
}
|
||
} else if ($BeforeQuestionnaireToday != null && $AfterQuestionnaireToday != null) {
|
||
return response(['view' => 6, 'text' => 'Тренировки на сегодня выполнены'], 200);
|
||
} else {
|
||
return response(['view' => 616, 'text' => 'Ошибка системы'], 400);
|
||
}
|
||
} else {
|
||
return response(['view' => 617, 'text' => 'Ошибка системы3'], 400);
|
||
}
|
||
}
|
||
} else {
|
||
return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
} else {
|
||
return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
}
|
||
} else {
|
||
return response(['Такого пациента нету'],);
|
||
}
|
||
}
|
||
|
||
//Функция добавления занятий надень при различных условия, то ест сколько пройдено дней, сколько осталось, есть ли блокировка или пауза и т.д.
|
||
public function AddCourses()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$date = date("Y-m-d");
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
//Проверка на то, закончин ли данный курс
|
||
if ($SportPatient->finished == false) {
|
||
|
||
if ($Patient->block >= $date) {//Если блок
|
||
return response(['view' => 3, 'text' => 'Курс заблокирован до' . $Patient->block], 200);
|
||
} else if ($Patient->pause >= $date) {//Если пауза
|
||
return response(['view' => 4, 'text' => 'Курс на паузе до' . $Patient->block], 200);
|
||
} else {
|
||
$totalDaySport = $Patient->total_days_sports;//Всего дней спорта
|
||
$nowDaySport = $Patient->now_days_sports;//Пройдено дней
|
||
$remainedDaySport = $totalDaySport - $nowDaySport;//Пройдено дней
|
||
|
||
$CalendarDays = CalendarDays::where('date', '>=', $date)->where('id_patient', $Patient->id)->get();
|
||
$countCalendar = count($CalendarDays);//Сколько дней пройдено
|
||
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
//Проверка на то отправлена ли анкета ДО за сегодня
|
||
if ($BeforeQuestionnaireDate != null && $AfterQuestionnaireDate == null) {
|
||
//Если равно это первый день
|
||
if ($nowDaySport == 0) {
|
||
$SportPatient = SportPatient::where('id_patient', $Patient->id)->where('finished', 0)->first();
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', 1)->first();
|
||
$SetOfSportsExercises = SetOfSportsExercises::where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$CD = $CalendarDays;
|
||
$CD->article_sport_for_day = $SportForDay->article;
|
||
$CD->update();
|
||
return response(['$SetOfSportsExercises' => $SetOfSportsExercises, $CalendarDays], 200);
|
||
|
||
} else if ($nowDaySport > 0) {
|
||
if ($remainedDaySport <= $countCalendar) {
|
||
return response(['view' => 1, '$totalDaySport' => "$totalDaySport", '$nowDaySport' => "$nowDaySport", '$remainedDaySport' => "$remainedDaySport", '$countCalendar' => "$countCalendar", '$CalendarDays' => "$CalendarDays"], 200);
|
||
} else {
|
||
return response(['view' => 2, '$totalDaySport' => "$totalDaySport", '$nowDaySport' => "$nowDaySport", '$remainedDaySport' => "$remainedDaySport", '$countCalendar' => "$countCalendar", '$CalendarDays' => "$CalendarDays"], 200);
|
||
|
||
}
|
||
}
|
||
} else {
|
||
return response(['Отсутствует анкета ДО'], 200);
|
||
}
|
||
}
|
||
} else {
|
||
return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
}
|
||
} else {
|
||
return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
}
|
||
} else {
|
||
return response(['Такого пациента нету'],);
|
||
}
|
||
}
|
||
|
||
//Функция добавления занятий на текуший день
|
||
public function AddCourses2(string $id)
|
||
{
|
||
$Patient = Patient::where('id', $id)->first();
|
||
$date = date("Y-m-d");
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
//Проверка на то, добавлялся ли сегодня данный курс
|
||
$SportForDay = SportForDay::where('day', $date)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
if ($SportForDay == null) {
|
||
$totalDaySport = $Patient->total_days_sports;//Всего дней спорта
|
||
$allDaySport = $Patient->all_days_sports;//Пройдено дней
|
||
$nowDaySport = $Patient->now_days_sports;//Пройдено курсов
|
||
$remainedDaySport = $totalDaySport - $allDaySport;//Осталось пройти
|
||
//Проверка на то, закончен ли данный курс
|
||
if ($SportPatient->finished == false && ($totalDaySport != $allDaySport)) {
|
||
|
||
$CalendarDays = CalendarDays::where('date', '>=', $date)->where('id_patient', $Patient->id)->get();
|
||
$countCalendar = count($CalendarDays);//Сколько дней пройдено
|
||
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
//Проверка на то отправлена ли анкета ДО за сегодня
|
||
if ($BeforeQuestionnaireDate != null && $AfterQuestionnaireDate == null) {
|
||
|
||
|
||
$SetsOfSportsActivitiesSearchDay = SetsOfSportsActivities::orderBy('id', 'ASC')
|
||
->join('sports_courses', 'sports_courses.id', 'sets_of_sports_activities.id_sports_courses')
|
||
->join('sport_patient', 'sport_patient.id_sports_courses', 'sports_courses.id')
|
||
->select('sets_of_sports_activities.id', 'sets_of_sports_activities.day')
|
||
->distinct()
|
||
->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->get();
|
||
//Проверка на то сколько есть дней курса, то есть если всего один день в курсе, то его и выдаем, а иначе идем по дням
|
||
if (Count($SetsOfSportsActivitiesSearchDay) == 1) {
|
||
$SportPatient = SportPatient::where('id_patient', $Patient->id)->where('finished', 0)->first();
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', 1)->first();
|
||
//$SetOfSportsExercises = SetOfSportsExercises::where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)->get();
|
||
|
||
$CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
|
||
|
||
$result = [];
|
||
|
||
$number = 0;
|
||
|
||
if (Count($CoursesSportEdit) == 0) {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
//->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
} else {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
}
|
||
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$CD = $CalendarDays;
|
||
$CD->article_sport_for_day = $SportForDay->article;
|
||
$CD->count_workout_max = count($SetOfSportsExercises);
|
||
$CD->update();
|
||
return response(['message', 'Тренировка на сегодня добавлена'], 200);
|
||
} else {
|
||
|
||
|
||
//Если равно это первый день
|
||
if ($nowDaySport == 1) {
|
||
$SportPatient = SportPatient::where('id_patient', $Patient->id)->where('finished', 0)->first();
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', 1)->first();
|
||
//$SetOfSportsExercises = SetOfSportsExercises::where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)->get();
|
||
|
||
$CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
|
||
if (Count($CoursesSportEdit) == 0) {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
//->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
} else {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
}
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$CD = $CalendarDays;
|
||
$CD->article_sport_for_day = $SportForDay->article;
|
||
$CD->count_workout_max = Count($SetOfSportsExercises);
|
||
$CD->update();
|
||
return response(['message', 'Тренировка на сегодня добавлена'], 200);
|
||
|
||
} else if ($nowDaySport > 1) {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->where('id_patient', $Patient->id)->first();
|
||
$SetsOfSportsActivitiesCours = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->first();
|
||
//Есть ли такой курс
|
||
if ($SetsOfSportsActivitiesCours != null) {
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', $nowDaySport)->first();
|
||
//Есть ли такой день
|
||
if ($SetsOfSportsActivities != null) {
|
||
|
||
$CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
|
||
if (Count($CoursesSportEdit) == 0) {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
//->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
} else {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
}
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$CD = $CalendarDays;
|
||
$CD->article_sport_for_day = $SportForDay->article;
|
||
$CD->count_workout_max = count($SetOfSportsExercises);
|
||
$CD->update();
|
||
// return response(['$SetOfSportsExercises' => $SetOfSportsExercises, $CalendarDays], 200);
|
||
return response(['message', 'Тренировка на сегодня добавлена'], 200);
|
||
} else {
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->orderBy('day', 'DESC')->first();
|
||
$CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
|
||
if (Count($CoursesSportEdit) == 0) {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
//->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
} else {
|
||
$SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
}
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$CD = $CalendarDays;
|
||
$CD->article_sport_for_day = $SportForDay->article;
|
||
$CD->count_workout_max = count($SetOfSportsExercises);
|
||
$CD->update();
|
||
return response(['message', 'Тренировка на сегодня добавлена'], 200);
|
||
}
|
||
|
||
} else {
|
||
return response(['text' => 'Такого курса нету'], 200);
|
||
}
|
||
|
||
} else {
|
||
return response(['Отсутствует анкета ДО 1'], 200);
|
||
}
|
||
}
|
||
} else {
|
||
return response(['Отсутствует анкета ДО 2'], 200);
|
||
}
|
||
} else {
|
||
return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
}
|
||
} else {
|
||
return response(['view' => 123, 'text' => 'На сегодня вы уже добавили задания на данный курс'], 200);
|
||
|
||
}
|
||
} else {
|
||
return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
}
|
||
} else {
|
||
return response(['Такого пациента нету'],);
|
||
}
|
||
}
|
||
|
||
function CoutSportCourses()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$date = date("Y-m-d");
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null || $Patient->id_sport_patient != "") {
|
||
$SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->first();
|
||
//Проверка на то, закончен ли данный курс
|
||
if ($SportPatient->finished == false) {
|
||
$SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
return response(['SportForDay' => $SportForDay], 200);
|
||
} else {
|
||
return response(['view' => 2, 'text' => 'Ваш курс окончен. Для дальнейших действий обратитесь к врачу'], 200);
|
||
}
|
||
} else {
|
||
return response(['view' => 1, 'text' => 'Попросите врача добавить вам курс'], 200);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'],);
|
||
}
|
||
}
|
||
|
||
function AddBeforeQuestionnaire2(Request $request)
|
||
{
|
||
$error = Validator::make($request->all(), [
|
||
'one' => 'required|numeric|max:10|min:0',
|
||
'two' => 'required|numeric|max:1|min:0',
|
||
'three' => 'required|numeric|max:1|min:0',
|
||
'four' => 'required|numeric|max:1|min:0',
|
||
'five' => 'required|numeric|max:1|min:0',
|
||
'six' => 'required|numeric|max:1|min:0',
|
||
'seven' => 'required|numeric|max:1|min:0',
|
||
'eight' => 'required|numeric|max:1|min:0',
|
||
'nine' => 'required|numeric|max:1|min:0',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
// return response(['message' => 'Анкета ПОСЛПЕ за сегодня уже заполненаassdasd1243'], 200);
|
||
|
||
//Проверка количества дней в календаре и их изменение
|
||
$this->AddandClearDayPatient($Patient->id);
|
||
|
||
//Добовлени дня в календарь
|
||
if( $this->AddDayCalendare($Patient->id)){
|
||
// return $this->AddandClearDayPatient();
|
||
|
||
$date = date("Y-m-d");
|
||
$BeforeQuestionnaireNEW = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
$pause = $Patient->pause;
|
||
$block = $Patient->block;
|
||
//Был ли блок или пауза
|
||
if (($Patient->block == null && $Patient->pause == null) || ($pause < $date && $block < $date) || ($pause < $date && $block == null) || ($pause == null && $block < $date)) {//Если да
|
||
|
||
//Если первое заполнение анкеты
|
||
if ($BeforeQuestionnaireNEW == null) {
|
||
// //Создание списка на n дней в таблице calendar_days
|
||
// for ($i = 0; $i < $Patient->total_days_sports; $i++) {//Циул на количество дней
|
||
// $date = date('Y-m-d', strtotime("$i day"));
|
||
// CalendarDays::create([
|
||
// 'id_patient' => $Patient->id,
|
||
// 'day' => $i + 1,
|
||
// //'date'=>date('d-m-Y',strtotime($date)),
|
||
// 'id_sport_patient' => $Patient->id_sport_patient,
|
||
// 'date' => $date,
|
||
// ]);
|
||
// }
|
||
|
||
//Заполнение анкеты
|
||
$BQ = BeforeQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => date("Y-m-d"),
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
]);
|
||
//Увеличения дня на 1 и задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->now_days_sports = $Patient->now_days_sports + 1;
|
||
$pat2->all_days_sports = $Patient->all_days_sports + 1;
|
||
$pat2->update();
|
||
|
||
|
||
//Подтверждаем в календарном дне, что анкета ДО заполнена
|
||
$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('date', date("Y-m-d"))->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaire = BeforeQuestionnaire::where('date', date("Y-m-d"))->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
if ($CalendarDays != null) {
|
||
$CD = $CalendarDays;
|
||
$CD->id_before_questionnaire = $BeforeQuestionnaire->id;
|
||
$CD->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->one >= 6) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
$CD->block = date('Y-m-d', strtotime("3 day"));
|
||
$CD->update();
|
||
PatientController::AddCourses2($Patient->id);
|
||
} //Проверка на паузу
|
||
else if ($request->four == "1" || $request->five == "1" || $request->six == "1" || $request->seven == "1" || $request->nine == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
$CD->pause = date('Y-m-d', strtotime("1 day"));
|
||
$CD->update();
|
||
|
||
PatientController::AddCourses2($Patient->id);
|
||
} else {
|
||
PatientController::AddCourses2($Patient->id);
|
||
}
|
||
|
||
return response(['message' => 'Анкета ДО добавлена', $CalendarDays], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка системы', $CalendarDays], 401);
|
||
}
|
||
} else {
|
||
//Заполнена ли анкета ДО на сегодня
|
||
if ($BeforeQuestionnaireDate == null) {
|
||
$BeforeQuestionnaire = BeforeQuestionnaire::where('date', $date)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaireDateLast = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
|
||
$dateBefSearch = $BeforeQuestionnaireDateLast[count($BeforeQuestionnaireDateLast) - 1]->date;
|
||
|
||
//$AfterQuestionnaire = AfterQuestionnaire::where('date', $dateBefSearch)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
//$AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
//////////////////////////////////////////////////////////////
|
||
/// /////////////////////////////////////////////////////////
|
||
/// ////////////////////////////////////////////////////////
|
||
/// //////////////////////////////////////////////////////////
|
||
/// //////////////////////////////////////////////////////
|
||
//Заполнена ли анкета ПОСЛЕ за вчераи небыло ли блока в это время
|
||
if ((($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {
|
||
//Заполнение анкеты
|
||
$BQ = BeforeQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
]);
|
||
//Увеличения дня на 1 и задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->now_days_sports = $Patient->now_days_sports + 1;
|
||
$pat2->all_days_sports = $Patient->all_days_sports + 1;
|
||
$pat2->update();
|
||
|
||
|
||
//Подтверждаем в календарном дне, что анкета ДО заполнена
|
||
$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('date', $date)->where('id_sport_patient', $Patient->id_sport_patient)->orderBy('day', 'DESC')->first();
|
||
$BeforeQuestionnaire = BeforeQuestionnaire::where('date', $date)->first();
|
||
if ($CalendarDays != null) {
|
||
$CD = $CalendarDays;
|
||
$CD->id_before_questionnaire = $BeforeQuestionnaire->id;
|
||
$CD->update();
|
||
|
||
//ПРоверка на блок
|
||
if ($request->one >= 6) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
$CD->block = date('Y-m-d', strtotime("3 day"));
|
||
$CD->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Уменьшние задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
PatientController::AddCourses2($Patient->id);
|
||
} //Проверка на паузу
|
||
else if ($request->four == "1" || $request->five == "1" || $request->six == "1" || $request->seven == "1" || $request->nine == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
$CD->pause = date('Y-m-d', strtotime("1 day"));
|
||
$CD->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Увеличения задания для следующего дня
|
||
$pat2 = $Patient;
|
||
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
PatientController::AddCourses2($Patient->id);
|
||
} else {
|
||
PatientController::AddCourses2($Patient->id);
|
||
}
|
||
return response(['message' => 'Анкета ДО добавлена'], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка системы'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Вам сначала нужно заполнить анкету ПОСЛЕ за вчерашний день'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Анкета ДО уже заполнена на сегодня'], 401);
|
||
}
|
||
}
|
||
} else {
|
||
return response(['message' => 'У вас есть или блок или пауза, поэтому вам ограничен временно доступ'], 401);
|
||
}
|
||
}
|
||
else {
|
||
return response(['message' => 'Ошибка системы2'], 401);
|
||
}
|
||
|
||
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу, чтобы он добавил вам курс'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//Подтверждение анкеты ПОСЛЕ, после увеличится количество выполненных дней и подтверждения анкет на определенный день
|
||
public function AddAfterQuestionnaire2(Request $request)
|
||
{
|
||
//Сегодняшняя дата
|
||
$date = date("Y-m-d");
|
||
|
||
$error = Validator::make($request->all(), [
|
||
'one' => 'required|numeric|max:10|min:0',
|
||
'two' => 'required|numeric|max:1|min:0',
|
||
'three' => 'required|numeric|max:1|min:0',
|
||
'four' => 'required|numeric|max:1|min:0',
|
||
'five' => 'required|numeric|max:1|min:0',
|
||
'six' => 'required|numeric|max:1|min:0',
|
||
'seven' => 'required|numeric|max:1|min:0',
|
||
'eight' => 'required|numeric|max:1|min:0',
|
||
'nine' => 'required|numeric|max:1|min:0',
|
||
'ten' => 'required|numeric|max:1|min:0',
|
||
'eleven' => 'required|numeric|max:1|min:0',
|
||
'twelve' => 'required|numeric|max:1|min:0',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
if ($Patient != null) {
|
||
//Проверка на то, есть ли курс у пациента
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
//Был ли блок или пауза
|
||
$pause = $Patient->pause;
|
||
$block = $Patient->block;
|
||
if (($Patient->block == null && $Patient->pause == null) || ($pause < $date && $block < $date) || ($pause < $date && $block == null) || ($pause == null && $block < $date)) {//Если да
|
||
$date = date("Y-m-d");
|
||
$BeforeQuestionnaireNEW = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$BeforeQuestionnaireDate = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
$AfterQuestionnaireDate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $date)->first();
|
||
|
||
//Проверка на то отправлялась ли хоть одна анкета ДО
|
||
if ($BeforeQuestionnaireNEW != null) {
|
||
//Проверка на то заполнялась ли анкета ДО за сегодня
|
||
if ($AfterQuestionnaireDate == null) {
|
||
|
||
//Проверка количества дней в календаре и их изменение
|
||
//$this->AddandClearDayPatient($Patient->id);
|
||
|
||
//Проверка на то заполнялась ли анкета ДО за сегодня
|
||
if ($BeforeQuestionnaireDate == null) {
|
||
|
||
$BeforeQuestionnaireSearch = BeforeQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
$AfterQuestionnaireSearch = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->where('date', $BeforeQuestionnaireSearch->date)->first();
|
||
//Проверка на то отправлялась ли анкета за вчера
|
||
if ($AfterQuestionnaireSearch != null && (($Patient->pause == null || $Patient->pause != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->pause))) != $BeforeQuestionnaireSearch->date) ||
|
||
($Patient->block == null || $Patient->block != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-1 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-2 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date || date('Y-m-d', strtotime('-3 day', strtotime($Patient->block))) != $BeforeQuestionnaireSearch->date))) {
|
||
return response(['message' => 'У вас не заполнена анкета ДО за сегодня'], 401);
|
||
} else {
|
||
|
||
$AQ = AfterQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => $BeforeQuestionnaireSearch->date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
'ten' => $request->ten,
|
||
'eleven' => $request->eleven,
|
||
'twelve' => $request->twelve,
|
||
]);
|
||
|
||
|
||
$AfterQuestionnaireUpdate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
|
||
//Подтверждаем в календарном дне, что анкета ПОСЛЕ заполнена
|
||
$CalendarDays = CalendarDays::where('date', $AfterQuestionnaireUpdate->date)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$pat = $CalendarDays;
|
||
$pat->id_after_questionnaire = $AfterQuestionnaireUpdate->id;
|
||
$pat->update();
|
||
|
||
|
||
//ПРоверка на блок
|
||
if ($request->nine == "1") {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Увеличения задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
} //Проверка на паузу
|
||
else if ($request->one >= "6" || $request->three == "0" || $request->six == "1" || $request->eight == "1" || $request->eleven == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Увеличения задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
} else {
|
||
|
||
//Увеличения задания для следующего дня
|
||
// $pat2 = $Patient;
|
||
// $pat2->all_days_sports = $Patient->all_days_sports + 1;
|
||
// $pat2->update();
|
||
}
|
||
|
||
|
||
|
||
return response(['message' => 'Анкета ПОСЛЕ за предыдуший день заполнена'], 200);
|
||
}
|
||
} else {
|
||
//$SportForDay = SportForDay::where('finish', 0)->where('day', $date)->first();
|
||
//Проверка на то все ли задания были выполнены, если нет, то нельзя отправить отчет
|
||
// if ($SportForDay == null) {
|
||
$AQ = AfterQuestionnaire::create([
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
'date' => $date,
|
||
'one' => $request->one,
|
||
'two' => $request->two,
|
||
'three' => $request->three,
|
||
'four' => $request->four,
|
||
'five' => $request->five,
|
||
'six' => $request->six,
|
||
'seven' => $request->seven,
|
||
'eight' => $request->eight,
|
||
'nine' => $request->nine,
|
||
'ten' => $request->ten,
|
||
'eleven' => $request->eleven,
|
||
'twelve' => $request->twelve,
|
||
]);
|
||
|
||
|
||
$AfterQuestionnaireUpdate = AfterQuestionnaire::where('id_sport_patient', $Patient->id_sport_patient)->orderBy('date', 'DESC')->first();
|
||
|
||
//Подтверждаем в календарном дне, что анкета ПОСЛЕ заполнена
|
||
$CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
$pat = $CalendarDays;
|
||
$pat->id_after_questionnaire = $AfterQuestionnaireUpdate->id;
|
||
$pat->update();
|
||
|
||
//Проверка на блок
|
||
if ($request->ten == 1) {
|
||
//Блокировка
|
||
$pat = $Patient;
|
||
$pat->block = date('Y-m-d', strtotime("3 day"));
|
||
$pat->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Увеличения задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
} //Проверка на паузу
|
||
else if ($request->one >= "6" || $request->three == "0" || $request->six == "1" || $request->eight == "1" || $request->eleven == "1") {
|
||
//Пауза
|
||
$pat = $Patient;
|
||
$pat->pause = date('Y-m-d', strtotime("1 day"));
|
||
$pat->update();
|
||
if ($Patient->all_days_sports > 1) {
|
||
//Увеличения задания для следующего дня
|
||
$pat2 = $Patient;
|
||
$pat2->all_days_sports = $Patient->all_days_sports - 1;
|
||
$pat2->update();
|
||
}
|
||
} else {
|
||
//Увеличения задания для следующего дня
|
||
// $pat2 = $Patient;
|
||
// $pat2->all_days_sports = $Patient->all_days_sports + 1;
|
||
// $pat2->update();
|
||
}
|
||
|
||
|
||
|
||
return response(['message' => 'Анкета ПОСЛПЕ заполнена'], 200);
|
||
//} else {
|
||
// return response(['message' => 'Не все задания были заполнена'], 200);
|
||
//}
|
||
}
|
||
} else {
|
||
return response(['message' => 'Анкета ПОСЛПЕ за сегодня уже заполнена'], 200);
|
||
}
|
||
} else {
|
||
return response(['message' => 'У вас не заполнена первая анкета ДО'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'У вас есть или блок или пауза, поэтому вам ограничен временно доступ'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//Добовления дня в календарь
|
||
function AddDayCalendare(string $id)
|
||
{
|
||
$Patient = Patient::where('id', $id)->first();
|
||
// $Patient = Auth::user()->makeHidden(['id']);
|
||
$CalendarDays = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->where('date', date('Y-m-d'))->first();//Проверяем есть ли такая дата в календаре
|
||
$CalendarDaysAdd = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->orderBy('id','DESC')->first();//Проверяем есть ли такая дата в календаре
|
||
|
||
if($CalendarDays==null){
|
||
CalendarDays::create([
|
||
'id_patient' => $Patient->id,
|
||
'day' => $CalendarDaysAdd->day + 1,
|
||
'date' => date('Y-m-d', strtotime("+1 day", strtotime($CalendarDaysAdd->date))),
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
return response(['message' => 'День в календарь добавлен'], 200);
|
||
}
|
||
else{
|
||
return response(['message' => 'День в календарь уже добавлен'], 200);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//Функция добавляющая дни в календарь
|
||
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;
|
||
$CalendarDays = 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' => $CalendarDays->day + $i,
|
||
'date' => date('Y-m-d', strtotime("+$i day", strtotime($CalendarDays->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", 200);
|
||
|
||
}
|
||
else{
|
||
return response("CoutCD - $CoutCD | dateMax - $dateMax | Patient->total_days_sports - $Patient->total_days_sports | Patient->now_days_sports - $Patient->now_days_sports", 200);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
// function asdasdas(){
|
||
// $Patient = Patient::where('id', 17)->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 = 12;
|
||
// $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();
|
||
//// }
|
||
// return response($max, 200);
|
||
//
|
||
// }
|
||
|
||
//Вывода данных для списка в календарь
|
||
function PatientCalendareDay()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
if ($Patient != null) {
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
$Calendare = CalendarDays::where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->distinct()->orderBy('id', 'ASC')->get();
|
||
if ($Calendare != null) {
|
||
return response(["сalendare" => $Calendare], 200);
|
||
} else {
|
||
return response(['message' => 'Данные отсутсвуют'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
|
||
|
||
//Вывода данных для одного определенного упражнения
|
||
function patientDaySport(Request $request)
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$error = Validator::make($request->all(), [
|
||
'id' => 'required',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
function CheckTokenPatient()
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
return response(['status' => "300"], 200);
|
||
} else {
|
||
return response(['status' => "600"], 200);
|
||
}
|
||
}
|
||
|
||
|
||
//Список упражнений на сегодня
|
||
function GetSportDay()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
|
||
if ($Patient != null) {
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
$date = date("Y-m-d");
|
||
$SportForDay = SportForDay::where('day', $date)->where('id_sport_patient', $Patient->id_sport_patient)->orderBy('finish', 'ASC')->get();
|
||
$number = 0;
|
||
$result = [];
|
||
for ($i = 0; $i != Count($SportForDay); $i++) {
|
||
$number++;
|
||
$SportTasks = SportTasks::where('id', $SportForDay[$i]->id_sports_tasks)->first();
|
||
$search_sport = [
|
||
'number' => $number,
|
||
'id' => $SportForDay[$i]->id,
|
||
'article' => $SportForDay[$i]->article,
|
||
'day' => $SportForDay[$i]->day,
|
||
'category' => $SportTasks->article_image,
|
||
'id_patient' => $SportForDay[$i]->id_patient,
|
||
'id_sports_tasks' => $SportForDay[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $SportForDay[$i]->id_sport_patient,
|
||
'finish' => $SportForDay[$i]->finish,
|
||
'created_at' => $SportForDay[$i]->created_at,
|
||
'updated_at' => $SportForDay[$i]->updated_at,
|
||
];
|
||
array_push($result, $search_sport);
|
||
}
|
||
return response(['sport_for_day' => $result], 200);
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
|
||
function GetSportDayOne(Request $request)
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$error = Validator::make($request->all(), [
|
||
'id' => 'required|numeric|max:10000|min:1',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
if ($Patient != null) {
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
$date = date("Y-m-d");
|
||
//$CalendarDays = CalendarDays::where('date', $date)->where('id_sport_patient', $Patient->id_sport_patient)->get();
|
||
$SportForDay = SportForDay::where('id', $request->id)->first();
|
||
$SportTasks = SportTasks::where('id', $SportForDay->id_sports_tasks)->first();
|
||
$Image = Image::where('article', $SportTasks->article_image)->get();
|
||
$search_sport = [
|
||
'id' => $SportTasks->id,
|
||
'name' => $SportTasks->name,
|
||
'description' => $SportTasks->description,
|
||
'count' => $SportTasks->count,
|
||
'image_url' => $Image,
|
||
'category' => $Image[0]->article[0],
|
||
'finish' => $SportForDay->finish,
|
||
'created_at' => $SportTasks->created_at,
|
||
'updated_at' => $SportTasks->updated_at,
|
||
];
|
||
|
||
return response($search_sport, 200);
|
||
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
// function asddsasdasad(){
|
||
// $Patient = Auth::user()->makeHidden(['id']);
|
||
// $SportPatient = SportPatient::where('id', $Patient->id_sport_patient)->where('id_patient', $Patient->id)->first();
|
||
// $nowDaySport = $Patient->now_days_sports;//Пройдено курсов
|
||
//
|
||
// $CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->get();
|
||
// $SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', $nowDaySport)->first();
|
||
// $SetOfSportsExercises = DB::table('set_of_sports_exercises')->orderBy('id', 'ASC')
|
||
// ->join('courses_sport_edit', 'set_of_sports_exercises.id_sports_tasks', '!=', 'courses_sport_edit.id_sports_tasks')
|
||
// ->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
// ->distinct()
|
||
// //->where('sport_patient.id', $Patient->id_sport_patient)
|
||
// ->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
// ->get();
|
||
// $result = [];
|
||
//
|
||
// $number = 0;
|
||
// for ($i = 0; $i != Count($SetOfSportsExercises); $i++) {
|
||
// $res = 0;
|
||
// for ($j = 0; $j != Count($CoursesSportEdit); $j++) {
|
||
// if ($SetOfSportsExercises[$i]->id_sports_tasks != $CoursesSportEdit[$j]->id_sports_tasks) {
|
||
// $res++;
|
||
// }
|
||
// }
|
||
// if ($res == Count($CoursesSportEdit)) {
|
||
// $number++;
|
||
// $search_sport = [
|
||
// 'number' => $number,
|
||
// 'id' => $SetOfSportsExercises[$i]->id,
|
||
// 'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
// 'id_sets_of_sports_activities' => $SetOfSportsExercises[$i]->id_sets_of_sports_activities,
|
||
// 'created_at' => $SetOfSportsExercises[$i]->created_at,
|
||
// 'updated_at' => $SetOfSportsExercises[$i]->updated_at,
|
||
// ];
|
||
// array_push($result, $search_sport);
|
||
// }
|
||
// }
|
||
//
|
||
// return response($result, 200);
|
||
// }
|
||
|
||
|
||
function AddSportCheck(Request $request)
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
$error = Validator::make($request->all(), [
|
||
'id' => 'required|numeric|max:10000|min:1',
|
||
'check' => 'required|numeric|max:2|min:1',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
if ($Patient != null) {
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
|
||
$SportForDay = SportForDay::where('id', $request->id)->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
$SFD = $SportForDay;
|
||
if ($SportForDay->finish == 0) {
|
||
if ($request->check == 1) {
|
||
$SFD->finish = $request->check;
|
||
$SFD->update();
|
||
return response(['message' => 'Упражнение выполнено'], 200);
|
||
} else if ($request->check == 2) {
|
||
$SFD->finish = $request->check;
|
||
$SFD->update();
|
||
return response(['message' => 'Упражнение пропущено'], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка 124'], 200);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Упражнение уже было пройдено'], 200);
|
||
}
|
||
|
||
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
}
|
||
|
||
function ProgressPatientCourses()
|
||
{
|
||
$Patient = Auth::user()->makeHidden(['id']);
|
||
|
||
if ($Patient != null) {
|
||
if ($Patient->id_sport_patient != null && $Patient->finished == 0) {
|
||
|
||
$SportForDay = SportForDay::select('day')
|
||
->Count('day')
|
||
->where('id_patient', $Patient->id)
|
||
->where('id_sport_patient', $Patient->id_sport_patient)
|
||
->orderBy('day', 'ASC')
|
||
->groupBy('day')
|
||
->get();
|
||
|
||
$result = [];
|
||
$result1 = [];
|
||
$number = 0;
|
||
for ($i = 0; $i != Count($SportForDay); $i++) {
|
||
$SportForDayCheck = SportForDay::where('day', $SportForDay[$i]->day)->get();
|
||
$check_1 = 0;
|
||
$check_0 = 0;
|
||
$count_workout_max = 0;
|
||
$number++;
|
||
for ($j = 0; $j != Count($SportForDayCheck); $j++) {
|
||
$count_workout_max++;
|
||
|
||
if ($SportForDayCheck[$j]->finish == 1) {
|
||
$check_1++;
|
||
}
|
||
if ($SportForDayCheck[$j]->finish == 0) {
|
||
$check_0++;
|
||
}
|
||
|
||
}
|
||
$search_check = [
|
||
'number' => $number,
|
||
'id' => $SportForDayCheck[$i]->id,
|
||
'count_workout_max' => $count_workout_max,
|
||
'day' => $SportForDayCheck[$i]->day,
|
||
'count' => $check_1,
|
||
'finish' => $check_0
|
||
];
|
||
array_push($result, $search_check);
|
||
}
|
||
|
||
return response(['search_check_sport' => $result], 200);
|
||
|
||
} else {
|
||
return response(['message' => 'У вас нету курса, обратитесь к врачу чтобы он добавил вам курс'], 401);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Такого пациента нету'], 401);
|
||
}
|
||
}
|
||
|
||
|
||
//Вывод новых необработанных заявлений
|
||
public function GetAppealsPatientNew()
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
$Appeals = AppealsPatient::where('check', 0)->where('id_patient', $User->id)->first();
|
||
$result = [];
|
||
$number = 0;
|
||
if ($Appeals != null) {
|
||
$AppealsList = AppealsPatient::where('check', 0)->where('id_patient', $User->id)->get();
|
||
for ($i = 0; $i != Count($AppealsList); $i++) {
|
||
$Doctor = Doctor::where('id', $AppealsList[$i]->id_doctor)->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' => $Doctor->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 GetAppealsPatientOld()
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
$Appeals = AppealsPatient::where('check', 1)->where('id_patient', $User->id)->first();
|
||
$result = [];
|
||
$number = 0;
|
||
if ($Appeals != null) {
|
||
$AppealsList = AppealsPatient::where('check', 1)->where('id_patient', $User->id)->get();
|
||
for ($i = 0; $i != Count($AppealsList); $i++) {
|
||
$Doctor = Doctor::where('id', $AppealsList[$i]->id_doctor)->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' => $Doctor->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 AddMessagePatient(Request $request)
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
$error = Validator::make($request->all(), [
|
||
'text' => 'required|string|max:1000|min:1',
|
||
]);
|
||
if ($error->fails()) {
|
||
return response(['error' => ['code' => 400, 'message' => 'Validation error', 'errors' => $error->errors()]], 400);
|
||
} else {
|
||
$Doctor = Doctor::where('id', $User->id_doctor)->first();
|
||
if ($Doctor != null) {
|
||
AppealsDoctor::create([
|
||
'text' => $request->text,
|
||
'id_patient' => $User->id,
|
||
'id_doctor' => $Doctor->id,
|
||
]);
|
||
return response(['message' => 'Сообщение отправлено'], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка, такого врача нету'], 400);
|
||
}
|
||
}
|
||
} else {
|
||
return response(['message' => 'Ошибка 404'], 404);
|
||
}
|
||
}
|
||
|
||
//Создание сообщения для пациента
|
||
public function UpdateMessagePatient(Request $request)
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
$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', $User->id)->first();
|
||
$Doctor = Doctor::where('id', $Patient->id_doctor)->first();
|
||
|
||
if ($Doctor != null) {
|
||
$AppealsDoctor = AppealsPatient::where('id', $request->id)->where('check', 0)->first();
|
||
if ($AppealsDoctor != null) {
|
||
if ($AppealsDoctor->check == 0) {
|
||
$AP = $AppealsDoctor;
|
||
$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 getDatePause()
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
if ($Patient != null) {
|
||
|
||
return response(['date_pause' => $Patient->pause], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка, такого пациента нету'], 400);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Ошибка 404'], 404);
|
||
}
|
||
}
|
||
|
||
//Вывод дня окончания блока
|
||
function getDateBlock()
|
||
{
|
||
$User = Auth::user();
|
||
if ($User != null) {
|
||
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
if ($Patient != null) {
|
||
|
||
return response(['date_pause' => $Patient->block], 200);
|
||
} else {
|
||
return response(['message' => 'Ошибка, такого пациента нету'], 400);
|
||
}
|
||
} else {
|
||
return response(['message' => 'Ошибка 404'], 404);
|
||
}
|
||
}
|
||
|
||
|
||
function dkkofskfkk()
|
||
{
|
||
$User = Auth::user();
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
$date = date("Y-m-d");
|
||
|
||
|
||
$SportPatient = SportPatient::where('id_patient', $Patient->id)->where('finished', 0)->first();
|
||
$SetsOfSportsActivities = SetsOfSportsActivities::where('id_sports_courses', $SportPatient->id_sports_courses)->where('day', 1)->first();
|
||
//$SetOfSportsExercises = SetOfSportsExercises::where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)->get();
|
||
|
||
$CoursesSportEdit = CoursesSportEdit::orderBy('id', 'ASC')->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
|
||
if ($CoursesSportEdit != null) {
|
||
$SetOfSportsExercises = SetOfSportsExercises::orderBy('id', 'ASC')
|
||
->join('courses_sport_edit', 'courses_sport_edit.id_sports_tasks', '!=', 'set_of_sports_exercises.id_sports_tasks')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
|
||
$result = [];
|
||
|
||
$number = 0;
|
||
for ($i = 0; $i != Count($SetOfSportsExercises); $i++) {
|
||
|
||
$number++;
|
||
$search_sport = [
|
||
'number' => $number,
|
||
'id' => $SetOfSportsExercises[$i]->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sets_of_sports_activities' => $SetOfSportsExercises[$i]->id_sets_of_sports_activities,
|
||
'created_at' => $SetOfSportsExercises[$i]->created_at,
|
||
'updated_at' => $SetOfSportsExercises[$i]->updated_at,
|
||
];
|
||
array_push($result, $search_sport);
|
||
}
|
||
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
|
||
return response(['message' => $result], 200);
|
||
} else {
|
||
$SetOfSportsExercises = SetOfSportsExercises::orderBy('id', 'ASC')
|
||
->select('set_of_sports_exercises.id', 'set_of_sports_exercises.number', 'set_of_sports_exercises.id_sports_tasks', 'set_of_sports_exercises.id_sets_of_sports_activities', 'set_of_sports_exercises.created_at', 'set_of_sports_exercises.updated_at')
|
||
->distinct()
|
||
//->where('sport_patient.id', $Patient->id_sport_patient)
|
||
->where('id_sets_of_sports_activities', $SetsOfSportsActivities->id)
|
||
->get();
|
||
|
||
$result = [];
|
||
|
||
$number = 0;
|
||
|
||
for ($i = 0; $i != Count($SetOfSportsExercises); $i++) {
|
||
|
||
$number++;
|
||
$search_sport = [
|
||
'number' => $number,
|
||
'id' => $SetOfSportsExercises[$i]->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sets_of_sports_activities' => $SetOfSportsExercises[$i]->id_sets_of_sports_activities,
|
||
'created_at' => $SetOfSportsExercises[$i]->created_at,
|
||
'updated_at' => $SetOfSportsExercises[$i]->updated_at,
|
||
];
|
||
array_push($result, $search_sport);
|
||
}
|
||
|
||
$article = uniqid();
|
||
//Заполняем цикл
|
||
for ($i = 0; $i < Count($SetOfSportsExercises); $i++) {
|
||
SportForDay::create([
|
||
'article' => $article,
|
||
'day' => $date,
|
||
'id_patient' => $Patient->id,
|
||
'id_sports_tasks' => $SetOfSportsExercises[$i]->id_sports_tasks,
|
||
'id_sport_patient' => $Patient->id_sport_patient,
|
||
]);
|
||
}
|
||
|
||
return response(['message' => $result], 200);
|
||
}
|
||
|
||
|
||
// $SportForDay = SportForDay::where('day', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
//
|
||
// $CalendarDays = CalendarDays::where('date', date("Y-m-d"))->where('id_patient', $Patient->id)->where('id_sport_patient', $Patient->id_sport_patient)->first();
|
||
// $CD = $CalendarDays;
|
||
// $CD->article_sport_for_day = $SportForDay->article;
|
||
// $CD->count_workout_max = count($SetOfSportsExercises);
|
||
// $CD->update();
|
||
|
||
|
||
return response(['message' => $SetOfSportsExercises], 200);
|
||
|
||
}
|
||
|
||
//Провверка на то есть ли анкета ДО
|
||
function LookBefore()
|
||
{
|
||
$User = Auth::user();
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
$date = date("Y-m-d");
|
||
$BeforeQuestion = BeforeQuestionnaire::where('id_sport_patient',$Patient->id_sport_patient)->where('date',$date)->first();
|
||
if($BeforeQuestion!=null){
|
||
return response(['before_look' => 1], 200);
|
||
}
|
||
else{
|
||
return response(['before_look' => 2], 200);
|
||
}
|
||
}
|
||
|
||
//Провверка на то есть ли анкета ПОСЛЕ
|
||
function LookAfter()
|
||
{
|
||
$User = Auth::user();
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
$date = date("Y-m-d");
|
||
$AfterQuestion = AfterQuestionnaire::where('id_sport_patient',$Patient->id_sport_patient)->where('date',$date)->first();
|
||
if($AfterQuestion!=null){
|
||
return response(['after_look' => 1], 200);
|
||
}
|
||
else{
|
||
return response(['after_look' => 2], 200);
|
||
}
|
||
}
|
||
|
||
//Вывод календаря для пациента
|
||
function GetCalendare(){
|
||
$User = Auth::user();
|
||
$Patient = Patient::where('id', $User->id)->first();
|
||
$date = date("Y-m-d");
|
||
if($Patient!=null){
|
||
if($Patient->id_sport_patient!=null){
|
||
$Calendare = CalendarDays::where('id_sport_patient',$Patient->id_sport_patient)->where('id_patient',$Patient->id)->distinct()->first();
|
||
if($Calendare!=null){
|
||
$Calendare_list = CalendarDays::where('id_sport_patient',$Patient->id_sport_patient)->where('id_patient',$Patient->id)->orderBy('day','ASC')->distinct()->get();
|
||
|
||
return response(['calendare_day' => $Calendare_list], 200);
|
||
}
|
||
else{
|
||
return response(['message' => 'Таких данных нету'], 400);
|
||
}
|
||
}
|
||
else{
|
||
return response(['message' => 'Курса у пациента нету'], 400);
|
||
}
|
||
}
|
||
else{
|
||
return response(['message' => 'Такого пациента нету'], 400);
|
||
}
|
||
|
||
}
|
||
|
||
}
|