* добавлены операции и услуги операций
* добавлена выборка и подсчет по датам для роли зав. * переключатель ролей * выбор отделений для роли зав.
This commit is contained in:
@@ -7,13 +7,16 @@ use App\Http\Resources\Mis\FormattedPatientResource;
|
||||
use App\Models\MetrikaGroup;
|
||||
use App\Models\MetrikaResult;
|
||||
use App\Models\MisMedicalHistory;
|
||||
use App\Models\MisMigrationPatient;
|
||||
use App\Models\MisStationarBranch;
|
||||
use App\Models\ObservationPatient;
|
||||
use App\Models\Report;
|
||||
use App\Models\UnwantedEvent;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -21,9 +24,26 @@ class ReportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$user = Auth::user();
|
||||
$department = $user->department;
|
||||
|
||||
$startDateCarbon = Carbon::now()->firstOfMonth();
|
||||
$startDate = $request->query('startAt', $startDateCarbon->format('Y-m-d'));
|
||||
$endDateCarbon = Carbon::now();
|
||||
$endDate = $request->query('endAt', $endDateCarbon->format('Y-m-d'));
|
||||
|
||||
$doctorStartDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$doctorEndDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
if (is_numeric($startDate)) {
|
||||
$startDateCarbon = Carbon::createFromTimestampMs($startDate);
|
||||
$startDate = Carbon::createFromTimestampMs($startDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
if (is_numeric($endDate)) {
|
||||
$endDateCarbon = Carbon::createFromTimestampMs($endDate);
|
||||
$endDate = Carbon::createFromTimestampMs($endDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
|
||||
$beds = (int)$department->metrikaDefault()->where('rf_metrika_item_id', 1)->first()->value;
|
||||
$occupiedBeds = optional(Report::where('rf_department_id', $user->rf_department_id)
|
||||
->join('metrika_results', 'reports.report_id', '=', 'metrika_results.rf_report_id')
|
||||
@@ -35,10 +55,103 @@ class ReportController extends Controller
|
||||
$metrikaGroup = MetrikaGroup::whereMetrikaGroupId(2)->first();
|
||||
$metrikaItems = $metrikaGroup->metrikaItems;
|
||||
|
||||
$misDepartmentId = $request->user()->department->rf_mis_department_id;
|
||||
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
if ($user->isHeadOfDepartment())
|
||||
{
|
||||
$medicalHistoryIds = MisMigrationPatient::whereInDepartment($branchId)
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
$extractedMedicalHistoryIds = MisMigrationPatient::extractedToday($branchId, $startDate, $endDate)
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
$recipientCount = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->when($user->isHeadOfDepartment(), function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateRecipient', [$startDate, $endDate]);
|
||||
})
|
||||
->when(!$user->isHeadOfDepartment(), function($query) use ($doctorStartDate, $doctorEndDate) {
|
||||
return $query->whereBetween('DateRecipient', [$doctorStartDate, $doctorEndDate]);
|
||||
})
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
|
||||
$extractedCount = MisMedicalHistory::whereIn('MedicalHistoryID', $extractedMedicalHistoryIds)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
|
||||
$recipientIds = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->when($doctorStartDate, function($query) use ($doctorStartDate, $doctorEndDate) {
|
||||
return $query->whereBetween('DateRecipient', [$doctorStartDate, $doctorEndDate]);
|
||||
})
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->pluck('MedicalHistoryID')
|
||||
->values();
|
||||
|
||||
$currentCount = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else {
|
||||
$medicalHistoryIds = MisMigrationPatient::currentlyInTreatment($branchId)
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
$extractedMedicalHistoryIds = MisMigrationPatient::extractedToday($branchId)
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
$recipientCount = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->when($user->isHeadOfDepartment(), function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateRecipient', [$startDate, $endDate]);
|
||||
})
|
||||
->when(!$user->isHeadOfDepartment(), function($query) use ($doctorStartDate, $doctorEndDate) {
|
||||
return $query->whereBetween('DateRecipient', [$doctorStartDate, $doctorEndDate]);
|
||||
})
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
|
||||
$extractedCount = MisMedicalHistory::whereIn('MedicalHistoryID', $extractedMedicalHistoryIds)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
|
||||
$recipientIds = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->when($user->isHeadOfDepartment(), function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateRecipient', [$startDate, $endDate]);
|
||||
})
|
||||
->when(!$user->isHeadOfDepartment(), function($query) use ($doctorStartDate, $doctorEndDate) {
|
||||
return $query->whereBetween('DateRecipient', [$doctorStartDate, $doctorEndDate]);
|
||||
})
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->pluck('MedicalHistoryID')
|
||||
->values();
|
||||
|
||||
$currentCount = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'department' => [
|
||||
'beds' => $beds,
|
||||
'percentLoadedBeds' => $percentLoadedBeds,
|
||||
'recipientCount' => $recipientCount,
|
||||
'extractCount' => $extractedCount,
|
||||
'currentCount' => $currentCount,
|
||||
'recipientIds' => $recipientIds
|
||||
],
|
||||
'dates' => [
|
||||
'startAt' => $startDateCarbon->getTimestampMs(),
|
||||
'endAt' => $endDateCarbon->getTimestampMs()
|
||||
],
|
||||
'metrikaItems' => $metrikaItems
|
||||
]);
|
||||
@@ -50,6 +163,7 @@ class ReportController extends Controller
|
||||
'metrics' => 'required',
|
||||
'observationPatients' => 'nullable',
|
||||
'departmentId' => 'required|integer',
|
||||
'unwantedEvent' => 'nullable'
|
||||
]);
|
||||
|
||||
$metrics = $data['metrics'];
|
||||
@@ -74,6 +188,13 @@ class ReportController extends Controller
|
||||
'sent_at' => now()
|
||||
]);
|
||||
|
||||
if (in_array('unwantedEvent', $data)) {
|
||||
$unwantedEvent = UnwantedEvent::create([
|
||||
'rf_report_id' => $report->id,
|
||||
'comment' => $data['unwantedEvent']['comment'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($metriks as $metrika) {
|
||||
$metrika->rf_report_id = $report->report_id;
|
||||
$metrika->save();
|
||||
@@ -97,59 +218,215 @@ class ReportController extends Controller
|
||||
|
||||
public function getPatients(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$data = $request->validate([
|
||||
'status' => 'required|string', // plan emergency
|
||||
'startAt' => 'nullable',
|
||||
'endAt' => 'nullable',
|
||||
]);
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
$startDateCarbon = Carbon::now()->firstOfMonth();
|
||||
$startDate = $data['startAt'] ?? $startDateCarbon->format('Y-m-d');
|
||||
$endDateCarbon = Carbon::now();
|
||||
$endDate = $data['endAt'] ?? $startDateCarbon->format('Y-m-d');
|
||||
|
||||
$doctorStartDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$doctorEndDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
if (is_numeric($startDate)) {
|
||||
$startDateCarbon = Carbon::createFromTimestampMs($startDate);
|
||||
$startDate = Carbon::createFromTimestampMs($startDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
if (is_numeric($endDate)) {
|
||||
$endDateCarbon = Carbon::createFromTimestampMs($endDate);
|
||||
$endDate = Carbon::createFromTimestampMs($endDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
$misDepartmentId = $request->user()->department->rf_mis_department_id;
|
||||
$userDepartmentId = $request->user()->department->department_id;
|
||||
$misStationarBranchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)->first()->StationarBranchID;
|
||||
if ($status === 'plan') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->plan()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});;
|
||||
} else if ($status === 'emergency') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->emergency()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});
|
||||
} else if ($status === 'observation') {
|
||||
$patients = ObservationPatient::with(['history'])
|
||||
->where('rf_department_id', $misDepartmentId)
|
||||
->history;
|
||||
} else if ($status === 'deceased') {
|
||||
$patients = MisMedicalHistory::select(...$model->getFillable())
|
||||
->deceased()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});
|
||||
|
||||
if ($user->isHeadOfDepartment()) {
|
||||
if ($status === 'plan') {
|
||||
// Сначала получаем ID локально
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
|
||||
if (!$branchId) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$medicalHistoryIds = MisMigrationPatient::whereInDepartment($branchId)
|
||||
->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
||||
})
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
// Получаем истории
|
||||
$patients = MisMedicalHistory::select($model->getFillable())
|
||||
->plan()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
} else if ($status === 'emergency') {
|
||||
// Сначала получаем ID локально
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
|
||||
if (!$branchId) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$medicalHistoryIds = MisMigrationPatient::whereInDepartment($branchId)
|
||||
->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
||||
})
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
// Получаем истории
|
||||
$patients = MisMedicalHistory::select($model->getFillable())
|
||||
->emergency()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->with(['surgicalOperations'])
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
} else if ($status === 'observation') {
|
||||
$medicalHistoryIds = ObservationPatient::where('rf_department_id', $userDepartmentId)
|
||||
->pluck('rf_medicalhistory_id')
|
||||
->toArray();
|
||||
|
||||
$patients = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->get()->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
|
||||
} else if ($status === 'deceased') {
|
||||
$patients = MisMedicalHistory::select(...$model->getFillable())
|
||||
->deceased()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if ($status === 'plan') {
|
||||
// Сначала получаем ID локально
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
|
||||
if (!$branchId) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$medicalHistoryIds = MisMigrationPatient::currentlyInTreatment($branchId)
|
||||
// ->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
// return $query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
||||
// })
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
// Получаем истории
|
||||
$patients = MisMedicalHistory::select($model->getFillable())
|
||||
->plan()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
} else if ($status === 'emergency') {
|
||||
// Сначала получаем ID локально
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
|
||||
if (!$branchId) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$medicalHistoryIds = MisMigrationPatient::currentlyInTreatment($branchId)
|
||||
// ->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
// return $query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
||||
// })
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
// Получаем истории
|
||||
$patients = MisMedicalHistory::select($model->getFillable())
|
||||
->emergency()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->with(['surgicalOperations'])
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get()
|
||||
->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
} else if ($status === 'observation') {
|
||||
$medicalHistoryIds = ObservationPatient::where('rf_department_id', $userDepartmentId)
|
||||
->pluck('rf_medicalhistory_id')
|
||||
->toArray();
|
||||
|
||||
$patients = MisMedicalHistory::whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->get()->map(function ($item, $index) use ($misStationarBranchId) {
|
||||
$item->num = $index + 1;
|
||||
$item->misStationarBranchId = $misStationarBranchId;
|
||||
return $item;
|
||||
});
|
||||
|
||||
} else if ($status === 'deceased') {
|
||||
$patients = MisMedicalHistory::select(...$model->getFillable())
|
||||
->deceased()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->get()
|
||||
->map(function ($item, $index) {
|
||||
$item->num = $index + 1;
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$patients->load(['migrations' => function ($query) use ($startDate, $endDate, $misStationarBranchId) {
|
||||
@@ -164,29 +441,97 @@ class ReportController extends Controller
|
||||
|
||||
public function getPatientsCount(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$data = $request->validate([
|
||||
'status' => 'required|string', // plan emergency
|
||||
'startAt' => 'nullable',
|
||||
'endAt' => 'nullable',
|
||||
]);
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$endDate = Carbon::now()->format('Y-m-d');
|
||||
$startDateCarbon = Carbon::now()->firstOfMonth();
|
||||
$startDate = $data['startAt'] ?? $startDateCarbon->format('Y-m-d');
|
||||
$endDateCarbon = Carbon::now();
|
||||
$endDate = $data['endAt'] ?? $endDateCarbon->format('Y-m-d');
|
||||
|
||||
$doctorStartDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
$doctorEndDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
if (is_numeric($startDate)) {
|
||||
$startDateCarbon = Carbon::createFromTimestampMs($startDate);
|
||||
$startDate = Carbon::createFromTimestampMs($startDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
if (is_numeric($endDate)) {
|
||||
$endDateCarbon = Carbon::createFromTimestampMs($endDate);
|
||||
$endDate = Carbon::createFromTimestampMs($endDate)->setTimezone('Asia/Yakutsk')->format('Y-m-d');
|
||||
}
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
$misDepartmentId = $request->user()->department->rf_mis_department_id;
|
||||
if ($status === 'plan') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->plan()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else if ($status === 'emergency') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->emergency()
|
||||
->inDepartment($misDepartmentId, $startDate, $endDate)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
|
||||
// Получаем ID отделения
|
||||
$branchId = MisStationarBranch::where('rf_DepartmentID', $misDepartmentId)
|
||||
->value('StationarBranchID');
|
||||
|
||||
if (!$branchId) {
|
||||
return response()->json(0);
|
||||
}
|
||||
|
||||
if ($user->isHeadOfDepartment()) {
|
||||
// Получаем ID медицинских историй по миграциям
|
||||
$medicalHistoryIds = MisMigrationPatient::whereInDepartment($branchId)
|
||||
->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateIngoing', [$startDate, $endDate]);
|
||||
})
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return response()->json(0);
|
||||
}
|
||||
|
||||
// Подсчет в зависимости от статуса
|
||||
if ($status === 'plan') {
|
||||
$count = MisMedicalHistory::plan()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else if ($status === 'emergency') {
|
||||
$count = MisMedicalHistory::emergency()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
} else {
|
||||
// Получаем ID медицинских историй по миграциям
|
||||
$medicalHistoryIds = MisMigrationPatient::currentlyInTreatment($branchId)
|
||||
->pluck('rf_MedicalHistoryID')
|
||||
->unique()
|
||||
->toArray();
|
||||
|
||||
if (empty($medicalHistoryIds)) {
|
||||
return response()->json(0);
|
||||
}
|
||||
|
||||
// Подсчет в зависимости от статуса
|
||||
if ($status === 'plan') {
|
||||
$count = MisMedicalHistory::plan()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else if ($status === 'emergency') {
|
||||
$count = MisMedicalHistory::emergency()
|
||||
->whereIn('MedicalHistoryID', $medicalHistoryIds)
|
||||
->currentlyHospitalized()
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($count);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Inertia\Inertia;
|
||||
|
||||
@@ -53,4 +54,22 @@ class AuthController extends Controller
|
||||
|
||||
return Inertia::location(route('start'));
|
||||
}
|
||||
|
||||
public function changeRole(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if (!$user) return null;
|
||||
|
||||
$data = $request->validate([
|
||||
'role_id' => 'required|integer|exists:roles,role_id'
|
||||
]);
|
||||
|
||||
$sessionKey = 'user_' . $user->id . '_current_role';
|
||||
|
||||
$user->current_role_id = $data['role_id'];
|
||||
$user->save();
|
||||
|
||||
return redirect()->route('start')->setStatusCode(302);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class HandleInertiaRequests extends Middleware
|
||||
'token' => Session::get('token'),
|
||||
'permissions' => $user->permissions(),
|
||||
'role' => $user->currentRole(),
|
||||
'available_roles' => $user->roles,
|
||||
'available_departments' => $user->availableDepartments(),
|
||||
'current_department' => $user->department
|
||||
] : null,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Resources\Mis;
|
||||
|
||||
use App\Models\MisSurgicalOperation;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -25,6 +26,15 @@ class FormattedPatientResource extends JsonResource
|
||||
'name' => $this->migrations()->first()->diagnosis()->first()?->mkb()->first()->NAME ?? null,
|
||||
];
|
||||
}),
|
||||
'operations' => $this->whenLoaded('surgicalOperations', function () {
|
||||
return $this->surgicalOperations()->where('rf_StationarBranchID', $this->misStationarBranchId)
|
||||
->get()
|
||||
->map(function (MisSurgicalOperation $operation) {
|
||||
return [
|
||||
'code' => $operation->serviceMedical->ServiceMedicalCode ?? null,
|
||||
];
|
||||
});
|
||||
}),
|
||||
'fullname' => Str::ucwords(Str::lower("$this->FAMILY $this->Name $this->OT")),
|
||||
'age' => Carbon::parse($this->BD)->diff(Carbon::now())->format('%y'),
|
||||
'birth_date' => Carbon::parse($this->BD)->format('d.m.Y'),
|
||||
|
||||
@@ -24,6 +24,22 @@ class MisMedicalHistory extends Model
|
||||
'DateRecipient' => 'datetime'
|
||||
];
|
||||
|
||||
public function observationPatient()
|
||||
{
|
||||
return $this->belongsTo(ObservationPatient::class, 'MedicalHistoryID', 'rf_medicalhistory_id');
|
||||
}
|
||||
|
||||
public function surgicalOperations()
|
||||
{
|
||||
return $this->hasMany(MisSurgicalOperation::class, 'rf_MedicalHistoryID', 'MedicalHistoryID');
|
||||
}
|
||||
|
||||
public function scopeCurrentlyHospitalized($query)
|
||||
{
|
||||
return $query->whereDate('DateExtract', '1900-01-01')
|
||||
->where('MedicalHistoryID', '<>', 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Истории со срочностью - Плановая
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class MisMigrationPatient extends Model
|
||||
{
|
||||
@@ -23,4 +24,45 @@ class MisMigrationPatient extends Model
|
||||
{
|
||||
return $this->hasOne(MisMKB::class, 'MKBID', 'rf_MKBID');
|
||||
}
|
||||
|
||||
public function scopeCurrentlyInTreatment($query, $branchId = null)
|
||||
{
|
||||
$query->where('rf_kl_VisitResultID', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('rf_StationarBranchID', $branchId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function scopeWhereInDepartment($query, $branchId = null)
|
||||
{
|
||||
$query->where('rf_MedicalHistoryID', '<>', 0);
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('rf_StationarBranchID', $branchId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function scopeExtractedToday($query, $branchId = null, $startDate = null, $endDate = null)
|
||||
{
|
||||
if (is_null($startDate)) $startDate = Carbon::now()->addDays(-1)->format('Y-m-d');
|
||||
if (is_null($endDate)) $endDate = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$query->where('rf_kl_VisitResultID', '<>', 0)
|
||||
->where('rf_MedicalHistoryID', '<>', 0)
|
||||
->when($startDate && $endDate, function($query) use ($startDate, $endDate) {
|
||||
return $query->whereBetween('DateOut', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
if ($branchId) {
|
||||
$query->where('rf_StationarBranchID', $branchId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
16
app/Models/MisServiceMedical.php
Normal file
16
app/Models/MisServiceMedical.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisServiceMedical extends Model
|
||||
{
|
||||
protected $table = 'oms_servicemedical';
|
||||
protected $primaryKey = 'ServiceMedicalID';
|
||||
|
||||
public function surgicalOperations()
|
||||
{
|
||||
return $this->hsaMany(MisServiceMedical::class, 'ServiceMedicalID', 'rf_ServiceMedicalID');
|
||||
}
|
||||
}
|
||||
16
app/Models/MisSurgicalOperation.php
Normal file
16
app/Models/MisSurgicalOperation.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisSurgicalOperation extends Model
|
||||
{
|
||||
protected $table = 'stt_surgicaloperation';
|
||||
protected $primaryKey = 'SurgicalOperationID';
|
||||
|
||||
public function serviceMedical()
|
||||
{
|
||||
return $this->belongsTo(MisServiceMedical::class, 'rf_kl_ServiceMedicalID', 'ServiceMedicalID');
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class ObservationPatient extends Model
|
||||
'rf_mkab_id',
|
||||
'rf_department_id',
|
||||
'rf_report_id',
|
||||
'comment'
|
||||
];
|
||||
|
||||
public function history()
|
||||
|
||||
15
app/Models/UnwantedEvent.php
Normal file
15
app/Models/UnwantedEvent.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UnwantedEvent extends Model
|
||||
{
|
||||
protected $primaryKey = 'unwanted_event_id';
|
||||
|
||||
protected $fillable = [
|
||||
'rf_report_id',
|
||||
'comment'
|
||||
];
|
||||
}
|
||||
@@ -28,6 +28,7 @@ class User extends Authenticatable
|
||||
'password',
|
||||
'rf_lpudoctor_id',
|
||||
'rf_department_id',
|
||||
'current_role_id'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -78,7 +79,8 @@ class User extends Authenticatable
|
||||
public function currentRole()
|
||||
{
|
||||
$defaultRoleId = $this->roles()->where('is_default', true)->first()->role_id;
|
||||
$roleId = session('currentRoleId', $defaultRoleId);
|
||||
$sessionKey = 'user_' . $this->id . '_current_role';
|
||||
$roleId = $this->current_role_id ?? $defaultRoleId;
|
||||
|
||||
$role = Role::where('role_id', $roleId)->first();
|
||||
|
||||
@@ -101,11 +103,6 @@ class User extends Authenticatable
|
||||
return $this->currentRole()->slug === 'head_of_department';
|
||||
}
|
||||
|
||||
public function isStatistician()
|
||||
{
|
||||
return $this->currentRole()->slug === 'statistician';
|
||||
}
|
||||
|
||||
// Получение доступных отделений
|
||||
public function availableDepartments()
|
||||
{
|
||||
@@ -134,11 +131,6 @@ class User extends Authenticatable
|
||||
$permissions['manage_users'] = $this->isAdmin();
|
||||
}
|
||||
|
||||
if ($this->isStatistician()) {
|
||||
$permissions['view_statistics'] = true;
|
||||
$permissions['export_data'] = true;
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user