|
|
|
|
@ -24,6 +24,7 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
$zhanweiCount=0;//勾选的检查项目共计占多少名额
|
|
|
|
|
$shareSlotMaxSeats = 0;//共享号源项目的use_seats最大值
|
|
|
|
|
$allItemRules = [];//所有检查项目的TIME_RESTRICTION规则
|
|
|
|
|
$itemMainData = [];//存储项目主表数据,用于后续按排班科室重算覆盖值
|
|
|
|
|
foreach ($entrustids as $key => $entrustid) {
|
|
|
|
|
// $info = DB::table('s_list')->where(['reg_num' => $regnum, 'entrust_id' => $entrustid, 'episodeid' => $episodeid, 'is_nullify' => 0])->first();
|
|
|
|
|
$info = DB::table('s_list')->where(['entrust_id' => $entrustid, 'is_nullify' => 0])->first();
|
|
|
|
|
@ -33,9 +34,24 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
$allEmergency = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$itemInfo = DB::table('s_check_item')->where(['item_name' => $info->entrust, 'status' => 1, "is_del" => 0])->get();
|
|
|
|
|
$itemInfo = DB::table('s_check_item')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) use ($userDeptId) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->where('s_dept_check_item.department_id', '=', $userDeptId);
|
|
|
|
|
})
|
|
|
|
|
->where(['s_check_item.item_name' => $info->entrust, 's_check_item.status' => 1, 's_check_item.is_del' => 0])
|
|
|
|
|
->select('s_check_item.*',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.reservation_method, s_check_item.reservation_method) as reservation_method'))
|
|
|
|
|
->get();
|
|
|
|
|
if (count($itemInfo) == 0) return \Yz::echoError1('没有找到可用的检查项目信息');
|
|
|
|
|
$itemInfo = $itemInfo[0];
|
|
|
|
|
// 存储项目 ID 和主表值,后续按排班科室重新计算覆盖值
|
|
|
|
|
$itemMainData[] = [
|
|
|
|
|
'id' => $itemInfo->id,
|
|
|
|
|
'use_seats' => $itemInfo->use_seats ?? 1,
|
|
|
|
|
'is_share_slot' => $itemInfo->is_share_slot ?? 0,
|
|
|
|
|
'item_name' => $itemInfo->item_name,
|
|
|
|
|
];
|
|
|
|
|
if (!empty($itemInfo->is_share_slot)) {
|
|
|
|
|
$shareSlotMaxSeats = max($shareSlotMaxSeats, isset($itemInfo->use_seats) ? $itemInfo->use_seats : 0);
|
|
|
|
|
} else {
|
|
|
|
|
@ -292,6 +308,47 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
|
|
|
|
|
$plan = array_values($mergedPlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按排班资源关联科室,重算号源占位
|
|
|
|
|
$deptZhanweiMap = []; // [department_id => ['zhanweiCount' => int, 'newSharedMax' => int]]
|
|
|
|
|
$deptIdsInPlan = [];
|
|
|
|
|
foreach ($plan as $p) {
|
|
|
|
|
if (!empty($p->id) && !empty($p->resource_department_id)) {
|
|
|
|
|
$deptIdsInPlan[$p->resource_department_id] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!empty($deptIdsInPlan) && !empty($itemMainData)) {
|
|
|
|
|
$itemIds = array_column($itemMainData, 'id');
|
|
|
|
|
foreach (array_keys($deptIdsInPlan) as $deptId) {
|
|
|
|
|
// 批量查该科室的覆盖值
|
|
|
|
|
$deptOverrides = DB::table('s_dept_check_item')
|
|
|
|
|
->whereIn('check_item_id', $itemIds)
|
|
|
|
|
->where('department_id', $deptId)
|
|
|
|
|
->get()
|
|
|
|
|
->keyBy('check_item_id');
|
|
|
|
|
|
|
|
|
|
$calcZhanwei = 0;
|
|
|
|
|
$calcSharedMax = 0;
|
|
|
|
|
foreach ($itemMainData as $imd) {
|
|
|
|
|
$override = $deptOverrides->get($imd['id']);
|
|
|
|
|
$useSeats = $override->use_seats ?? $imd['use_seats'];
|
|
|
|
|
$isShareSlot = $override->is_share_slot ?? $imd['is_share_slot'];
|
|
|
|
|
if (!empty($isShareSlot)) {
|
|
|
|
|
$calcSharedMax = max($calcSharedMax, $useSeats);
|
|
|
|
|
} else {
|
|
|
|
|
$calcZhanwei += $useSeats;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($calcSharedMax > 0) {
|
|
|
|
|
$calcZhanwei += $calcSharedMax;
|
|
|
|
|
}
|
|
|
|
|
$deptZhanweiMap[$deptId] = [
|
|
|
|
|
'zhanweiCount' => $calcZhanwei,
|
|
|
|
|
'newSharedMax' => $calcSharedMax,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//遍历列表 把超过当前时间的放在后面
|
|
|
|
|
// debug: 查看plan中的resources_id
|
|
|
|
|
$debugAllRids = [];
|
|
|
|
|
@ -314,11 +371,15 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
if (!empty($regnum)) {
|
|
|
|
|
$existingSharedItems = DB::table('s_list')
|
|
|
|
|
->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.reg_num', $regnum)
|
|
|
|
|
->where('s_list.list_status', 1)
|
|
|
|
|
->where('s_list.roster_id', '>', 0)
|
|
|
|
|
->where('s_check_item.is_share_slot', 1)
|
|
|
|
|
->select('s_list.roster_id', 's_check_item.use_seats')
|
|
|
|
|
->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1)
|
|
|
|
|
->select('s_list.roster_id', DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'))
|
|
|
|
|
->get();
|
|
|
|
|
foreach ($existingSharedItems as $esi) {
|
|
|
|
|
$pid = $esi->roster_id;
|
|
|
|
|
@ -367,7 +428,10 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
$time = $p->date . ' ' . $p->end_reservation_time;
|
|
|
|
|
$remaining = ($p->count ?? 0) - ($p->used_count ?? 0);
|
|
|
|
|
$existingMax = $existingSharedAtPlan[$p->id] ?? 0;
|
|
|
|
|
$needed = $zhanweiCount - min($newSharedMax, $existingMax);
|
|
|
|
|
$deptData = $deptZhanweiMap[$p->resource_department_id ?? 0] ?? ['zhanweiCount' => $zhanweiCount, 'newSharedMax' => $newSharedMax];
|
|
|
|
|
$planZhanwei = $deptData['zhanweiCount'];
|
|
|
|
|
$planSharedMax = $deptData['newSharedMax'];
|
|
|
|
|
$needed = $planZhanwei - min($planSharedMax, $existingMax);
|
|
|
|
|
if ($time > $nowtime && $remaining >= $needed) {
|
|
|
|
|
$p->plan_enable=true;
|
|
|
|
|
$pl1[] = $p;
|
|
|
|
|
@ -558,8 +622,14 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint
|
|
|
|
|
if (!empty($entrustIds)) {
|
|
|
|
|
$itemData = DB::table('s_list')
|
|
|
|
|
->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->whereIn('s_list.entrust_id', $entrustIds)
|
|
|
|
|
->select('s_list.entrust_id', 's_check_item.use_seats', 's_check_item.is_share_slot')
|
|
|
|
|
->select('s_list.entrust_id',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot'))
|
|
|
|
|
->get();
|
|
|
|
|
foreach ($itemData as $row) {
|
|
|
|
|
$useSeatsMap[$row->entrust_id] = $row->use_seats;
|
|
|
|
|
@ -603,12 +673,16 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint
|
|
|
|
|
$existingSharedAtPlan = [];
|
|
|
|
|
$existingSharedItems = DB::table('s_list')
|
|
|
|
|
->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.reg_num', $regnum)
|
|
|
|
|
->where('s_list.list_status', 1)
|
|
|
|
|
->where('s_list.is_nullify', 0)
|
|
|
|
|
->where('s_list.roster_id', '>', 0)
|
|
|
|
|
->where('s_check_item.is_share_slot', 1)
|
|
|
|
|
->select('s_list.roster_id', 's_check_item.use_seats')
|
|
|
|
|
->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1)
|
|
|
|
|
->select('s_list.roster_id', DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'))
|
|
|
|
|
->get();
|
|
|
|
|
foreach ($existingSharedItems as $esi) {
|
|
|
|
|
$pid = $esi->roster_id;
|
|
|
|
|
@ -1069,7 +1143,19 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme
|
|
|
|
|
|
|
|
|
|
//判断互斥(暂时根据reg_num判断身份)
|
|
|
|
|
//查询想要预约的项目 其自身code
|
|
|
|
|
$item = DB::table('s_check_item')->where(['item_code' => $mainInfo->entrust_code, 'status' => 1, 'is_del' => 0])->first();
|
|
|
|
|
$deptId = $planInfo->department_id ?? 0;
|
|
|
|
|
$item = DB::table('s_check_item')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) use ($deptId) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->where('s_dept_check_item.department_id', '=', $deptId);
|
|
|
|
|
})
|
|
|
|
|
->where(['s_check_item.item_code' => $mainInfo->entrust_code, 's_check_item.status' => 1, 's_check_item.is_del' => 0])
|
|
|
|
|
->select('s_check_item.*',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.check_begin_time, s_check_item.check_begin_time, 0) as check_begin_time'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.limosis, s_check_item.limosis) as limosis'))
|
|
|
|
|
->first();
|
|
|
|
|
if (!$item) return \Yz::echoError1('此检查项目不可用');
|
|
|
|
|
// 校验检查项目与排班资源的匹配性(通过设备/服务组交集判断)
|
|
|
|
|
$itemDeviceIds = DB::table('s_check_item_device')
|
|
|
|
|
@ -1260,11 +1346,15 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme
|
|
|
|
|
if (!empty($shareSlotIds) && $regNum) {
|
|
|
|
|
$existingSharedItems = DB::table('s_list')
|
|
|
|
|
->join('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.reg_num', $regNum)
|
|
|
|
|
->where('s_list.roster_id', $planid)
|
|
|
|
|
->where('s_list.list_status', 1)
|
|
|
|
|
->where('s_check_item.is_share_slot', 1)
|
|
|
|
|
->select('s_check_item.use_seats')
|
|
|
|
|
->where(DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0)'), 1)
|
|
|
|
|
->select(DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'))
|
|
|
|
|
->get();
|
|
|
|
|
if ($existingSharedItems->isNotEmpty()) {
|
|
|
|
|
$existingSharedMax = $existingSharedItems->max('use_seats');
|
|
|
|
|
@ -1488,6 +1578,10 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme
|
|
|
|
|
// 复用correctUsedCount的分组算法:按患者分组,共享取max,非共享累加
|
|
|
|
|
$activeItems = DB::table('s_list')
|
|
|
|
|
->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.roster_id', $planid)
|
|
|
|
|
->whereIn('s_list.list_status', [1, 2, 3])
|
|
|
|
|
->where('s_list.is_nullify', 0)
|
|
|
|
|
@ -1496,7 +1590,9 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme
|
|
|
|
|
->when($do_type == 2, function($q) use ($mainlistids) {
|
|
|
|
|
$q->whereNotIn('s_list.id', $mainlistids);
|
|
|
|
|
})
|
|
|
|
|
->select('s_list.*', 's_check_item.use_seats', 's_check_item.is_share_slot')
|
|
|
|
|
->select('s_list.*',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot'))
|
|
|
|
|
->get();
|
|
|
|
|
$grouped = [];
|
|
|
|
|
foreach ($activeItems as $item) {
|
|
|
|
|
@ -1696,7 +1792,7 @@ public function YuYue($planid, $appointment_type, $mainlistids, $do_type,$is_eme
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public function AutoYuYue($regnum,$entrustids,$episodeid,$appointment_type)
|
|
|
|
|
public function AutoYuYue($regnum,$entrustids,$episodeid,$appointment_type,$department_id = 0)
|
|
|
|
|
{
|
|
|
|
|
$dateRange=config('app.globals.可用号源查询范围');
|
|
|
|
|
// $regnum = request('regnum');
|
|
|
|
|
@ -1715,7 +1811,7 @@ public function AutoYuYue($regnum,$entrustids,$episodeid,$appointment_type)
|
|
|
|
|
$enable_plan=false;
|
|
|
|
|
while ($currentDate <= $endDate) {
|
|
|
|
|
$nowdate = $currentDate->format('Y-m-d');
|
|
|
|
|
$s = $this->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate);
|
|
|
|
|
$s = $this->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate, 'all', $department_id);
|
|
|
|
|
|
|
|
|
|
if ($s['status']) {
|
|
|
|
|
$list = $s['data']['plan_list'];
|
|
|
|
|
@ -1946,10 +2042,16 @@ public function correctUsedCount($rosterId)
|
|
|
|
|
// 获取该排班上所有活跃项目及其配置
|
|
|
|
|
$activeItems = DB::table('s_list')
|
|
|
|
|
->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.roster_id', $rosterId)
|
|
|
|
|
->whereIn('s_list.list_status', [1, 2, 3])
|
|
|
|
|
->where('s_list.is_nullify', 0)
|
|
|
|
|
->select('s_list.*', 's_check_item.use_seats', 's_check_item.is_share_slot')
|
|
|
|
|
->select('s_list.*',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot'))
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
// 计算总占位:按人隔离,共享取 max,非共享累加
|
|
|
|
|
@ -2057,10 +2159,16 @@ public function calculateUsedCount($rosterId, $correct = 0)
|
|
|
|
|
// 获取该排班上所有活跃项目及其配置
|
|
|
|
|
$activeItems = DB::table('s_list')
|
|
|
|
|
->leftJoin('s_check_item', 's_list.entrust_code', '=', 's_check_item.item_code')
|
|
|
|
|
->leftJoin('s_dept_check_item', function($j) {
|
|
|
|
|
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
|
|
|
|
|
->on('s_dept_check_item.department_id', '=', 's_list.department_id');
|
|
|
|
|
})
|
|
|
|
|
->where('s_list.roster_id', $rosterId)
|
|
|
|
|
->whereIn('s_list.list_status', [1, 2, 3])
|
|
|
|
|
->where('s_list.is_nullify', 0)
|
|
|
|
|
->select('s_list.*', 's_check_item.use_seats', 's_check_item.is_share_slot')
|
|
|
|
|
->select('s_list.*',
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.use_seats, s_check_item.use_seats, 1) as use_seats'),
|
|
|
|
|
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot'))
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
// 按患者分组计算占位
|
|
|
|
|
|