|
|
|
|
@ -75,18 +75,22 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
}
|
|
|
|
|
// dd($commonDevice);
|
|
|
|
|
|
|
|
|
|
//获取主表检查项目绑定的科室id
|
|
|
|
|
$department_id = DB::table('s_department')->where(['department_number' => $info->RISRAcceptDeptCode])->first();
|
|
|
|
|
if (!$department_id) return \Yz::echoError1('获取医嘱检查项目科室信息失败');
|
|
|
|
|
|
|
|
|
|
//查询号源渠道是否有合并
|
|
|
|
|
$appointment_types=[$appointment_type];
|
|
|
|
|
$appointment_type_link = DB::table('s_appointment_type_ratio')->where(['department_id'=>$department_id->id,'appointment_type_id' => $appointment_type])->first();
|
|
|
|
|
if (!empty($appointment_type_link->link)) {
|
|
|
|
|
$appointment_types=json_decode($appointment_type_link->link, true);
|
|
|
|
|
$appointment_types=array_merge($appointment_types, [$appointment_type]);
|
|
|
|
|
}
|
|
|
|
|
$isDeviceMode = config('app.globals.号源查询模式') === 'device';
|
|
|
|
|
$department_id = null;
|
|
|
|
|
$appointment_types = [$appointment_type];
|
|
|
|
|
|
|
|
|
|
if (!$isDeviceMode) {
|
|
|
|
|
//科室模式:根据HIS科室代码查询号源
|
|
|
|
|
$department_id = DB::table('s_department')->where(['department_number' => $info->RISRAcceptDeptCode])->first();
|
|
|
|
|
if (!$department_id) return \Yz::echoError1('获取医嘱检查项目科室信息失败');
|
|
|
|
|
|
|
|
|
|
//查询号源渠道是否有合并
|
|
|
|
|
$appointment_type_link = DB::table('s_appointment_type_ratio')->where(['department_id'=>$department_id->id,'appointment_type_id' => $appointment_type])->first();
|
|
|
|
|
if (!empty($appointment_type_link->link)) {
|
|
|
|
|
$appointment_types=json_decode($appointment_type_link->link, true);
|
|
|
|
|
$appointment_types=array_merge($appointment_types, [$appointment_type]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(count($commonDevice)==0) return \Yz::echoError1("无可用号源");
|
|
|
|
|
$placeholders = implode(',', array_fill(0, count($commonDevice), '?'));
|
|
|
|
|
@ -102,9 +106,49 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
}
|
|
|
|
|
$appointment_dates_placeholders = implode(',', array_fill(0, count($appointment_date_arr), '?'));
|
|
|
|
|
|
|
|
|
|
if ($isDeviceMode) {
|
|
|
|
|
//设备模式:不限制科室,只按单渠道查号源,渠道合路后置处理
|
|
|
|
|
$canshu = array_merge($commonDevice, $appointment_date_arr, [$appointment_type]);
|
|
|
|
|
$plan = DB::select("SELECT
|
|
|
|
|
a.*,
|
|
|
|
|
dd.devices,
|
|
|
|
|
b.department_resources_name,
|
|
|
|
|
c.roster_detail_id,
|
|
|
|
|
c.count,
|
|
|
|
|
c.used_count,
|
|
|
|
|
c.locked_count
|
|
|
|
|
FROM
|
|
|
|
|
s_source_roster_detail AS a
|
|
|
|
|
LEFT JOIN s_department_resources AS b ON a.resources_id = b.id
|
|
|
|
|
LEFT JOIN s_source_roster_detail_count AS c ON a.id = c.roster_detail_id
|
|
|
|
|
JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
roster_detail_id,
|
|
|
|
|
GROUP_CONCAT( e.device_name SEPARATOR ', ' ) AS devices
|
|
|
|
|
FROM
|
|
|
|
|
s_source_roster_detail_device AS d
|
|
|
|
|
LEFT JOIN s_devices AS e ON d.device_id = e.id
|
|
|
|
|
WHERE
|
|
|
|
|
d.device_id IN ($placeholders)
|
|
|
|
|
GROUP BY
|
|
|
|
|
d.roster_detail_id
|
|
|
|
|
) AS dd ON a.id = dd.roster_detail_id
|
|
|
|
|
WHERE
|
|
|
|
|
a.date IN ($appointment_dates_placeholders)
|
|
|
|
|
AND a.STATUS = 1
|
|
|
|
|
AND a.is_del = 0
|
|
|
|
|
AND b.is_del = 0
|
|
|
|
|
AND c.appointment_type_id = ?", $canshu);
|
|
|
|
|
|
|
|
|
|
foreach ($plan as $p) {
|
|
|
|
|
$p->used_count = $p->used_count + ($p->locked_count ?? 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$canshu = array_merge($commonDevice, [$department_id->id], $appointment_date_arr, $appointment_types);
|
|
|
|
|
$plan = DB::select("SELECT
|
|
|
|
|
$plan = $this->mergeChannelsPerDepartment($plan, $appointment_type);
|
|
|
|
|
} else {
|
|
|
|
|
//科室模式:原有逻辑
|
|
|
|
|
$canshu = array_merge($commonDevice, [$department_id->id], $appointment_date_arr, $appointment_types);
|
|
|
|
|
$plan = DB::select("SELECT
|
|
|
|
|
a.*,
|
|
|
|
|
dd.devices,
|
|
|
|
|
b.department_resources_name,
|
|
|
|
|
@ -136,24 +180,19 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
|
|
|
|
|
AND b.is_del = 0
|
|
|
|
|
AND c.appointment_type_id IN ($appointment_types_placeholders)", $canshu);
|
|
|
|
|
|
|
|
|
|
$mergedPlan = [];
|
|
|
|
|
foreach ($plan as $key => $p) {
|
|
|
|
|
// 将占位数量加到已用数量中
|
|
|
|
|
$p->used_count = $p->used_count + ($p->locked_count ?? 0);
|
|
|
|
|
|
|
|
|
|
// 如果 roster_detail_id 已经存在,则合并 count 数量
|
|
|
|
|
if (isset($mergedPlan[$p->roster_detail_id])) {
|
|
|
|
|
// 累加 count 数量到已存在的记录中
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->count += $p->count;
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->used_count += $p->used_count;
|
|
|
|
|
} else {
|
|
|
|
|
// 初始化新的合并数据
|
|
|
|
|
$mergedPlan[$p->roster_detail_id] = $p;
|
|
|
|
|
$mergedPlan = [];
|
|
|
|
|
foreach ($plan as $key => $p) {
|
|
|
|
|
$p->used_count = $p->used_count + ($p->locked_count ?? 0);
|
|
|
|
|
if (isset($mergedPlan[$p->roster_detail_id])) {
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->count += $p->count;
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->used_count += $p->used_count;
|
|
|
|
|
} else {
|
|
|
|
|
$mergedPlan[$p->roster_detail_id] = $p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将合并后的数据重新组织为数组
|
|
|
|
|
$plan = array_values($mergedPlan);
|
|
|
|
|
$plan = array_values($mergedPlan);
|
|
|
|
|
}
|
|
|
|
|
//遍历列表 把超过当前时间的放在后面
|
|
|
|
|
$pl1 = [];
|
|
|
|
|
$pl2 = [];
|
|
|
|
|
@ -947,6 +986,99 @@ private function checkPlanAgainstRules($plan, $allItemRules)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设备模式-按号源所属科室做后置渠道合路
|
|
|
|
|
private function mergeChannelsPerDepartment($plan, $appointment_type)
|
|
|
|
|
{
|
|
|
|
|
if (empty($plan)) return $plan;
|
|
|
|
|
|
|
|
|
|
$departmentIds = [];
|
|
|
|
|
foreach ($plan as $p) {
|
|
|
|
|
if ($p->department_id) {
|
|
|
|
|
$departmentIds[$p->department_id] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($departmentIds)) return $plan;
|
|
|
|
|
$departmentIds = array_keys($departmentIds);
|
|
|
|
|
|
|
|
|
|
$mergeConfigs = [];
|
|
|
|
|
$ratios = DB::table('s_appointment_type_ratio')
|
|
|
|
|
->whereIn('department_id', $departmentIds)
|
|
|
|
|
->where('appointment_type_id', $appointment_type)
|
|
|
|
|
->get();
|
|
|
|
|
foreach ($ratios as $r) {
|
|
|
|
|
if (!empty($r->link)) {
|
|
|
|
|
$mergeChannels = json_decode($r->link, true);
|
|
|
|
|
if (is_array($mergeChannels)) {
|
|
|
|
|
$mergeConfigs[$r->department_id] = $mergeChannels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($mergeConfigs)) return $plan;
|
|
|
|
|
|
|
|
|
|
$rosterDetailIds = [];
|
|
|
|
|
foreach ($plan as $p) {
|
|
|
|
|
if (isset($mergeConfigs[$p->department_id])) {
|
|
|
|
|
$rosterDetailIds[] = $p->roster_detail_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($rosterDetailIds)) return $plan;
|
|
|
|
|
$rosterDetailIds = array_unique($rosterDetailIds);
|
|
|
|
|
|
|
|
|
|
$allMergedChannels = [];
|
|
|
|
|
foreach ($mergeConfigs as $channels) {
|
|
|
|
|
$allMergedChannels = array_merge($allMergedChannels, $channels);
|
|
|
|
|
}
|
|
|
|
|
$allMergedChannels = array_unique($allMergedChannels);
|
|
|
|
|
$extraChannels = array_diff($allMergedChannels, [$appointment_type]);
|
|
|
|
|
if (empty($extraChannels)) return $plan;
|
|
|
|
|
|
|
|
|
|
$extraCounts = DB::table('s_source_roster_detail_count')
|
|
|
|
|
->whereIn('roster_detail_id', $rosterDetailIds)
|
|
|
|
|
->whereIn('appointment_type_id', $extraChannels)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
if ($extraCounts->isEmpty()) return $plan;
|
|
|
|
|
|
|
|
|
|
$extraMap = [];
|
|
|
|
|
foreach ($extraCounts as $ec) {
|
|
|
|
|
if (!isset($extraMap[$ec->roster_detail_id])) {
|
|
|
|
|
$extraMap[$ec->roster_detail_id] = [];
|
|
|
|
|
}
|
|
|
|
|
$extraMap[$ec->roster_detail_id][$ec->appointment_type_id] = $ec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mergedPlan = [];
|
|
|
|
|
foreach ($plan as $p) {
|
|
|
|
|
$rid = $p->roster_detail_id;
|
|
|
|
|
$deptChannels = $mergeConfigs[$p->department_id] ?? [];
|
|
|
|
|
|
|
|
|
|
$extraCount = 0;
|
|
|
|
|
$extraUsed = 0;
|
|
|
|
|
foreach ($deptChannels as $ch) {
|
|
|
|
|
if (isset($extraMap[$rid][$ch])) {
|
|
|
|
|
$ec = $extraMap[$rid][$ch];
|
|
|
|
|
$extraCount += $ec->count;
|
|
|
|
|
$extraUsed += $ec->used_count + ($ec->locked_count ?? 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($extraCount > 0) {
|
|
|
|
|
$p->count += $extraCount;
|
|
|
|
|
$p->used_count += $extraUsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($mergedPlan[$rid])) {
|
|
|
|
|
$mergedPlan[$rid]->count += $p->count;
|
|
|
|
|
$mergedPlan[$rid]->used_count += $p->used_count;
|
|
|
|
|
} else {
|
|
|
|
|
$mergedPlan[$rid] = $p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array_values($mergedPlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断是否在互斥组内
|
|
|
|
|
function isMutuallyExclusive($ids, $huchi) {
|
|
|
|
|
foreach ($huchi as $pair) {
|
|
|
|
|
|