[Добавлено]: Вывод всех врачей при создании отчета #2

This commit is contained in:
brusnitsyn
2026-06-05 09:40:39 +09:00
parent 0a6af0a315
commit cb046516af

View File

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