Files
onboard/app/Http/Controllers/Api/DepartmentController.php

59 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Department;
use App\Models\MisLpuDoctor;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class DepartmentController extends Controller
{
public function index(Request $request)
{
$user = $request->user();
$departmentIds = $user->departments()->pluck('rf_department_id');
$departments = Department::whereIn('department_id', $departmentIds)->orderBy('name_short')->get();
return response()->json($departments);
}
public function getDepartmentUsers(Department $department, Request $request)
{
$onlyUserDepartment = filter_var($request->query('onlyUserDepartment', false), FILTER_VALIDATE_BOOLEAN);
$type = $request->query('type', 'duty');
if ($onlyUserDepartment) {
$departmentIds = [$department->rf_mis_department_id];
} else {
$user = Auth::user();
// TODO: Доработать сопоставление с должностями
$userDepartmentProfile = $user->department->departmentType;
$departmentProfileToDoctorProfiles = [
1 => [1336, 1351, 1379, 1393, 1402, 1423, 1424, 1505]
];
$departmentIds = $user->misDepartments->pluck('rf_mis_department_id')->toArray();
}
$users = MisLpuDoctor::select(['LPUDoctorID', 'FAM_V', 'IM_V', 'OT_V'])
->whereHas('prvds', function ($query) use ($departmentIds, $type) {
$query->when($type === 'nurse', function ($query) {
$query->whereIn('rf_PRVDID', [1567, 1629]);
})
->whereIn('rf_DepartmentID', $departmentIds)
->whereDate('D_END', '2222-01-01 00:00:00.000000');
})
->active()
->whereNotIn('LPUDoctorID', [0, 1])
->orderBy('FAM_V')
->get();
return response()->json([
...$users,
])->setStatusCode(200);
}
}