增加按科室/设备匹配号源切换功能

main
岩仔88 1 day ago
parent 583b766ae5
commit 1b79829470

@ -82,8 +82,10 @@ public function getMainDetail()
// } // }
// } // }
$isDeviceMode = config('app.globals.号源查询模式') === 'device';
$enable_zhixingkeshi_name=[]; $enable_zhixingkeshi_name=[];
$enable_zhixingkeshi_code=[]; $enable_zhixingkeshi_code=[];
if (!$isDeviceMode) {
foreach ($ii as $ii_value){ foreach ($ii as $ii_value){
if (!empty($ii_value->department_number) and !in_array($ii_value->department_name, $enable_zhixingkeshi_name)) { if (!empty($ii_value->department_number) and !in_array($ii_value->department_name, $enable_zhixingkeshi_name)) {
$enable_zhixingkeshi_name[]=$ii_value->department_name; $enable_zhixingkeshi_name[]=$ii_value->department_name;
@ -94,6 +96,7 @@ public function getMainDetail()
$msg=$msg.' 开医嘱时执行科室选择错误,请选择:'.json_encode($enable_zhixingkeshi_name,JSON_UNESCAPED_UNICODE); $msg=$msg.' 开医嘱时执行科室选择错误,请选择:'.json_encode($enable_zhixingkeshi_name,JSON_UNESCAPED_UNICODE);
} }
} }
}
$generator = new \Picqer\Barcode\BarcodeGeneratorHTML(); $generator = new \Picqer\Barcode\BarcodeGeneratorHTML();
$tiaoma= $generator->getBarcode($value->app_num, $generator::TYPE_CODE_128, 2, 40); $tiaoma= $generator->getBarcode($value->app_num, $generator::TYPE_CODE_128, 2, 40);
$updatedHtml = preg_replace('/background-color:\s*black\s*;/i', 'background-color: black !important;', $tiaoma); $updatedHtml = preg_replace('/background-color:\s*black\s*;/i', 'background-color: black !important;', $tiaoma);

@ -75,18 +75,22 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
} }
// dd($commonDevice); // dd($commonDevice);
//获取主表检查项目绑定的科室id $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(); $department_id = DB::table('s_department')->where(['department_number' => $info->RISRAcceptDeptCode])->first();
if (!$department_id) return \Yz::echoError1('获取医嘱检查项目科室信息失败'); 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(); $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)) { if (!empty($appointment_type_link->link)) {
$appointment_types=json_decode($appointment_type_link->link, true); $appointment_types=json_decode($appointment_type_link->link, true);
$appointment_types=array_merge($appointment_types, [$appointment_type]); $appointment_types=array_merge($appointment_types, [$appointment_type]);
} }
}
if(count($commonDevice)==0) return \Yz::echoError1("无可用号源"); if(count($commonDevice)==0) return \Yz::echoError1("无可用号源");
$placeholders = implode(',', array_fill(0, count($commonDevice), '?')); $placeholders = implode(',', array_fill(0, count($commonDevice), '?'));
@ -102,7 +106,47 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
} }
$appointment_dates_placeholders = implode(',', array_fill(0, count($appointment_date_arr), '?')); $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);
}
$plan = $this->mergeChannelsPerDepartment($plan, $appointment_type);
} else {
//科室模式:原有逻辑
$canshu = array_merge($commonDevice, [$department_id->id], $appointment_date_arr, $appointment_types); $canshu = array_merge($commonDevice, [$department_id->id], $appointment_date_arr, $appointment_types);
$plan = DB::select("SELECT $plan = DB::select("SELECT
a.*, a.*,
@ -138,22 +182,17 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
$mergedPlan = []; $mergedPlan = [];
foreach ($plan as $key => $p) { foreach ($plan as $key => $p) {
// 将占位数量加到已用数量中
$p->used_count = $p->used_count + ($p->locked_count ?? 0); $p->used_count = $p->used_count + ($p->locked_count ?? 0);
// 如果 roster_detail_id 已经存在,则合并 count 数量
if (isset($mergedPlan[$p->roster_detail_id])) { if (isset($mergedPlan[$p->roster_detail_id])) {
// 累加 count 数量到已存在的记录中
$mergedPlan[$p->roster_detail_id]->count += $p->count; $mergedPlan[$p->roster_detail_id]->count += $p->count;
$mergedPlan[$p->roster_detail_id]->used_count += $p->used_count; $mergedPlan[$p->roster_detail_id]->used_count += $p->used_count;
} else { } else {
// 初始化新的合并数据
$mergedPlan[$p->roster_detail_id] = $p; $mergedPlan[$p->roster_detail_id] = $p;
} }
} }
// 将合并后的数据重新组织为数组
$plan = array_values($mergedPlan); $plan = array_values($mergedPlan);
}
//遍历列表 把超过当前时间的放在后面 //遍历列表 把超过当前时间的放在后面
$pl1 = []; $pl1 = [];
$pl2 = []; $pl2 = [];
@ -947,6 +986,99 @@ private function checkPlanAgainstRules($plan, $allItemRules)
return true; 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) { function isMutuallyExclusive($ids, $huchi) {
foreach ($huchi as $pair) { foreach ($huchi as $pair) {

@ -46,8 +46,9 @@ public function RequestLog($arr,$id){ //记录请求日志
public static function CheckTableName(){ // 查看日志表是否存在,每月一个表,如果没有就创建 public static function CheckTableName(){ // 查看日志表是否存在,每月一个表,如果没有就创建
$table_name='zz_request_log_' . date('ym'); $table_name='zz_request_log_' . date('ym');
if (Schema::hasTable($table_name)) { if (Schema::hasTable($table_name)) {
return;
}else{ }
try {
Schema::create($table_name, function (Blueprint $table) { Schema::create($table_name, function (Blueprint $table) {
$table->id(); $table->id();
$table->string('mark', 100)->nullable(); $table->string('mark', 100)->nullable();
@ -61,6 +62,8 @@ public static function CheckTableName(){ // 查看日志表是否存在,每
$table->string('update_time', 30); $table->string('update_time', 30);
$table->timestamps(); $table->timestamps();
}); });
} catch (\Exception $e) {
// 并发时另一个请求已先创建,忽略此异常
} }
} }
public static function JsonEncode($data){ //格式化数据转json public static function JsonEncode($data){ //格式化数据转json

@ -9,6 +9,7 @@
'预约完成短信通知'=>0,//预约完成后短信通知1开启0关闭 '预约完成短信通知'=>0,//预约完成后短信通知1开启0关闭
'自动预约'=>1,//开启自动预约,收到推送的医嘱后,自动预约最近可用号源 '自动预约'=>1,//开启自动预约,收到推送的医嘱后,自动预约最近可用号源
'可用号源查询范围'=>7,//根据此字段循环查询当前日期 N天后的数据 '可用号源查询范围'=>7,//根据此字段循环查询当前日期 N天后的数据
'号源查询模式'=>'device',//department:按HIS科室(RISRAcceptDeptCode)匹配号源, device:按设备交集匹配号源(不限制科室)
'是否推送Pacs'=>0,//是否推送pacs '是否推送Pacs'=>0,//是否推送pacs
'患者类型'=>[ '患者类型'=>[
'0'=>'住院', '0'=>'住院',

Loading…
Cancel
Save