[Добавлено]: Вывод всех врачей при создании отчета #2
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Department;
|
||||
use App\Models\MisLpuDoctor;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
@@ -27,21 +28,29 @@ class DepartmentController extends Controller
|
||||
|
||||
if ($onlyUserDepartment) {
|
||||
$departmentIds = [$department->rf_mis_department_id];
|
||||
$doctorCacheKey = "doctors:nurse:$department->rf_mis_department_id";
|
||||
$doctorProfileIds = [];
|
||||
} else {
|
||||
$user = Auth::user();
|
||||
// TODO: Доработать сопоставление с должностями
|
||||
$userDepartmentProfile = $user->department->departmentType;
|
||||
$userDepartmentProfileId = $user->department->departmentType->department_type_id;
|
||||
|
||||
$departmentProfileToDoctorProfiles = [
|
||||
1 => [1336, 1351, 1379, 1393, 1402, 1423, 1424, 1505]
|
||||
];
|
||||
// Получаем ID профилей должностей для текущего типа отдела
|
||||
$doctorProfileIds = $departmentProfileToDoctorProfiles[$userDepartmentProfileId] ?? [];
|
||||
|
||||
$departmentIds = $user->misDepartments->pluck('rf_mis_department_id')->toArray();
|
||||
$doctorCacheKey = "doctors:duty:$userDepartmentProfileId";
|
||||
}
|
||||
|
||||
|
||||
$users = MisLpuDoctor::select(['LPUDoctorID', 'FAM_V', 'IM_V', 'OT_V'])
|
||||
->whereHas('prvds', function ($query) use ($departmentIds, $type) {
|
||||
$users = Cache::remember($doctorCacheKey, 21600, function () use ($doctorProfileIds, $departmentIds, $type) {
|
||||
return MisLpuDoctor::select(['LPUDoctorID', 'FAM_V', 'IM_V', 'OT_V'])
|
||||
->whereHas('prvds', function ($query) use ($doctorProfileIds, $departmentIds, $type) {
|
||||
$query->when($type === 'nurse', function ($query) {
|
||||
$query->whereIn('rf_PRVDID', [1567, 1629]);
|
||||
})->when($type !== 'nurse' && !empty($doctorProfileIds), function ($query) use ($doctorProfileIds) {
|
||||
$query->whereIn('rf_PRVDID', $doctorProfileIds);
|
||||
})
|
||||
->whereIn('rf_DepartmentID', $departmentIds)
|
||||
->whereDate('D_END', '2222-01-01 00:00:00.000000');
|
||||
@@ -50,6 +59,7 @@ class DepartmentController extends Controller
|
||||
->whereNotIn('LPUDoctorID', [0, 1])
|
||||
->orderBy('FAM_V')
|
||||
->get();
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
...$users,
|
||||
|
||||
Reference in New Issue
Block a user