|
|
|
|
@ -425,7 +425,7 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//最优时间/单天全检 分配
|
|
|
|
|
public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope = 'all', $userDeptId = 0)
|
|
|
|
|
public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope = 'all', $userDeptId = 0, $occupied_plan_ids = [])
|
|
|
|
|
{
|
|
|
|
|
date_default_timezone_set('PRC');
|
|
|
|
|
$dateRange = config('app.globals.可用号源查询范围');
|
|
|
|
|
@ -435,14 +435,14 @@ public function GetOptimalPlan($type, $regnum, $entrustids, $episodeid, $appoint
|
|
|
|
|
$endDate->modify('+' . $dateRange . ' day');
|
|
|
|
|
|
|
|
|
|
if ($type === 'full_day') {
|
|
|
|
|
return $this->doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId);
|
|
|
|
|
return $this->doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId);
|
|
|
|
|
return $this->doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 最优时间分配:按科室分组,逐个 item 找最早可用号源,可跨天
|
|
|
|
|
private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId)
|
|
|
|
|
private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids = [])
|
|
|
|
|
{
|
|
|
|
|
// 按科室分组
|
|
|
|
|
$deptGroups = $this->groupItemsByDept($items);
|
|
|
|
|
@ -471,6 +471,14 @@ private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
|
|
|
|
|
|
$availablePlans = $this->getAvailablePlansForDate($regnum, $groupEntrustids, $episodeid, $appointment_type, $nowdate, $scope, $userDeptId);
|
|
|
|
|
|
|
|
|
|
// 过滤已占用的号源
|
|
|
|
|
if (!empty($occupied_plan_ids)) {
|
|
|
|
|
$availablePlans = array_filter($availablePlans, function($plan) use ($occupied_plan_ids) {
|
|
|
|
|
return !in_array($plan->id, $occupied_plan_ids);
|
|
|
|
|
});
|
|
|
|
|
$availablePlans = array_values($availablePlans);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($availablePlans)) {
|
|
|
|
|
// 当天该科室无号源,整组留到下一轮
|
|
|
|
|
$newRemainingGroups[$deptCode] = $group;
|
|
|
|
|
@ -531,7 +539,7 @@ private function doOptimalTimeAssign($startDate, $endDate, $regnum, $entrustids,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 单天全检分配:所有 item 必须在同一天完成
|
|
|
|
|
private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId)
|
|
|
|
|
private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $episodeid, $appointment_type, $items, $scope, $userDeptId, $occupied_plan_ids = [])
|
|
|
|
|
{
|
|
|
|
|
// 按科室分组
|
|
|
|
|
$deptGroups = $this->groupItemsByDept($items);
|
|
|
|
|
@ -549,6 +557,14 @@ private function doFullDayAssign($startDate, $endDate, $regnum, $entrustids, $ep
|
|
|
|
|
foreach ($deptGroups as $deptCode => $group) {
|
|
|
|
|
$availablePlans = $this->getAvailablePlansForDate($regnum, $group['entrustids'], $episodeid, $appointment_type, $nowdate, $scope, $userDeptId);
|
|
|
|
|
|
|
|
|
|
// 过滤已占用的号源
|
|
|
|
|
if (!empty($occupied_plan_ids)) {
|
|
|
|
|
$availablePlans = array_filter($availablePlans, function($plan) use ($occupied_plan_ids) {
|
|
|
|
|
return !in_array($plan->id, $occupied_plan_ids);
|
|
|
|
|
});
|
|
|
|
|
$availablePlans = array_values($availablePlans);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($availablePlans)) {
|
|
|
|
|
$allAssigned = false;
|
|
|
|
|
break;
|
|
|
|
|
|