diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php index 06cdccd..b472170 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php @@ -82,8 +82,10 @@ public function getMainDetail() // } // } + $isDeviceMode = config('app.globals.号源查询模式') === 'device'; $enable_zhixingkeshi_name=[]; $enable_zhixingkeshi_code=[]; + if (!$isDeviceMode) { foreach ($ii as $ii_value){ if (!empty($ii_value->department_number) and !in_array($ii_value->department_name, $enable_zhixingkeshi_name)) { $enable_zhixingkeshi_name[]=$ii_value->department_name; @@ -93,6 +95,7 @@ public function getMainDetail() if(count($enable_zhixingkeshi_code)>0 and !in_array($value->RISRAcceptDeptCode, $enable_zhixingkeshi_code)){ $msg=$msg.' 开医嘱时执行科室选择错误,请选择:'.json_encode($enable_zhixingkeshi_name,JSON_UNESCAPED_UNICODE); } + } } $generator = new \Picqer\Barcode\BarcodeGeneratorHTML(); $tiaoma= $generator->getBarcode($value->app_num, $generator::TYPE_CODE_128, 2, 40); diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index c598003..4763045 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -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) { diff --git a/Laravel/app/Services/LogService.php b/Laravel/app/Services/LogService.php index 1cb6574..15a2671 100644 --- a/Laravel/app/Services/LogService.php +++ b/Laravel/app/Services/LogService.php @@ -45,9 +45,10 @@ public function RequestLog($arr,$id){ //记录请求日志 } public static function CheckTableName(){ // 查看日志表是否存在,每月一个表,如果没有就创建 $table_name='zz_request_log_' . date('ym'); - if(Schema::hasTable($table_name)){ - - }else{ + if (Schema::hasTable($table_name)) { + return; + } + try { Schema::create($table_name, function (Blueprint $table) { $table->id(); $table->string('mark', 100)->nullable(); @@ -61,6 +62,8 @@ public static function CheckTableName(){ // 查看日志表是否存在,每 $table->string('update_time', 30); $table->timestamps(); }); + } catch (\Exception $e) { + // 并发时另一个请求已先创建,忽略此异常 } } public static function JsonEncode($data){ //格式化数据,转json diff --git a/Laravel/config/app.php b/Laravel/config/app.php index 8e5e1ab..d239345 100644 --- a/Laravel/config/app.php +++ b/Laravel/config/app.php @@ -9,6 +9,7 @@ '预约完成短信通知'=>0,//预约完成后短信通知1开启0关闭 '自动预约'=>1,//开启自动预约,收到推送的医嘱后,自动预约最近可用号源 '可用号源查询范围'=>7,//根据此字段循环查询当前日期 N天后的数据 + '号源查询模式'=>'device',//department:按HIS科室(RISRAcceptDeptCode)匹配号源, device:按设备交集匹配号源(不限制科室) '是否推送Pacs'=>0,//是否推送pacs '患者类型'=>[ '0'=>'住院',