Files
onboard/app/Http/Controllers/Api/DepartmentController.php
2026-07-13 14:02:19 +09:00

81 lines
4.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;
use Illuminate\Support\Facades\Cache;
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];
$doctorCacheKey = "doctors:nurse:$department->rf_mis_department_id";
$doctorProfileIds = [];
} else {
$user = Auth::user();
$userDepartmentProfileId = $user->department->departmentType->department_type_id;
// TODO: Возможно в будущем понадобится, пока вывожу все должности которые начинаются с Врач-
// $departmentProfileToDoctorProfiles = [
// 1 => [1336, 1351, 1379, 1393, 1402, 1423, 1424, 1505]
// ];
// Получаем ID профилей должностей для текущего типа отдела
// $doctorProfileIds = $departmentProfileToDoctorProfiles[$userDepartmentProfileId] ?? [];
$doctorProfileIds = [
1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341,
1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358,
1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, 1372, 1373, 1374, 1375,
1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392,
1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409,
1410, 1411, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1436, 1437,
1440, 1460, 1493, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508,
1509, 1510, 1511, 1512, 1513, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1558, 1593, 1594, 1595,
1596, 1597, 1598, 1607, 1608, 1609, 1615, 1618, 1619, 1620, 1621, 1622, 1624, 1625, 1626
];
$departmentIds = $user->misDepartments->pluck('rf_mis_department_id')->toArray();
$doctorCacheKey = "doctors:duty:$userDepartmentProfileId";
}
$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');
})
->active()
->whereNotIn('LPUDoctorID', [0, 1])
->orderBy('FAM_V')
->get();
});
return response()->json([
...$users,
])->setStatusCode(200);
}
}