科室映射检查项目

dev
鹿和sa0ChunLuyu 2 days ago
parent 820866b30e
commit 197a85a59a

@ -38,21 +38,23 @@ public function BindDevice(Request $request)
} }
//批量更新检查须知/温馨提示 //批量更新检查须知/温馨提示
public function BatchUpdateNotice() public function BatchUpdateNotice(Request $request)
{ {
$item_ids = request('item_ids'); $item_ids = request('item_ids');
$field = request('field'); $field = request('field');
$value = request('value'); $value = request('value');
$userid = $request->get('userid');
$service = new DeptCheckItemService(); $service = new DeptCheckItemService();
return $service->BatchUpdateNotice($item_ids, $field, $value); return $service->BatchUpdateNotice($item_ids, $field, $value, $userid);
} }
//保存检查项目信息 //保存检查项目信息
public function Save() public function Save(Request $request)
{ {
$Info = request('Info'); $Info = request('Info');
$userid = $request->get('userid');
$service = new DeptCheckItemService(); $service = new DeptCheckItemService();
return $service->Save($Info); return $service->Save($Info, $userid);
} }
//同步检查项目分类 //同步检查项目分类

@ -79,6 +79,8 @@ public function getMainDetail_duoren()
$entrustids = request('entrustid'); $entrustids = request('entrustid');
$episodeid = request('episodeid'); $episodeid = request('episodeid');
$appointment_type=request('appointment_type'); $appointment_type=request('appointment_type');
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
if(empty($entrustInfos)) return \Yz::echoError1("entrustInfo不能为空"); if(empty($entrustInfos)) return \Yz::echoError1("entrustInfo不能为空");
$allInfo=[]; $allInfo=[];
foreach ($entrustInfos as $key => $entrustInfo) { foreach ($entrustInfos as $key => $entrustInfo) {
@ -96,6 +98,12 @@ public function getMainDetail_duoren()
foreach ($info as $value){ foreach ($info as $value){
$ii = DB::table('s_check_item as a') $ii = DB::table('s_check_item as a')
->leftJoin('s_check_item_device as b','a.id','=','b.item_id') ->leftJoin('s_check_item_device as b','a.id','=','b.item_id')
->leftJoin('s_dept_check_item', function($j) use ($deptId) {
$j->on('s_dept_check_item.check_item_id', '=', 'a.id')
->where('s_dept_check_item.department_id', '=', $deptId);
})
->select('a.*', 'b.device_id',
DB::raw('COALESCE(s_dept_check_item.reservation_method, a.reservation_method) as reservation_method'))
->where(['a.item_code' => $value->entrust_code,'a.status'=>1,"a.is_del"=>0])->first(); ->where(['a.item_code' => $value->entrust_code,'a.status'=>1,"a.is_del"=>0])->first();

@ -214,9 +214,11 @@ public function GetEnablePlan()
$episodeid = request('episodeid'); $episodeid = request('episodeid');
$appointment_type = request('appointment_type'); //预约类型 $appointment_type = request('appointment_type'); //预约类型
$appointment_date = request('date'); //预约日期 $appointment_date = request('date'); //预约日期
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$service = new PlanListService(); $service = new PlanListService();
return $service->GetEnablePlan($regnum, $entrustid, $episodeid, $appointment_type, $appointment_date); return $service->GetEnablePlan($regnum, $entrustid, $episodeid, $appointment_type, $appointment_date, 'all', $deptId);
} }
//最优时间/单天全检 分配 //最优时间/单天全检 分配
@ -229,9 +231,11 @@ public function GetOptimalPlan()
$appointment_type = request('appointment_type'); $appointment_type = request('appointment_type');
$items = request('items'); $items = request('items');
$occupied_plan_ids = request('occupied_plan_ids', []); $occupied_plan_ids = request('occupied_plan_ids', []);
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$service = new PlanListService(); $service = new PlanListService();
return $service->GetOptimalPlan($type, $regnum, $entrustid, $episodeid, $appointment_type, $items, 'all', 0, $occupied_plan_ids); return $service->GetOptimalPlan($type, $regnum, $entrustid, $episodeid, $appointment_type, $items, 'all', $deptId, $occupied_plan_ids);
} }
//获取最近可用的,计划 日期 //获取最近可用的,计划 日期
@ -243,6 +247,8 @@ public function NearestEnablePlanDate()
$episodeid = request('episodeid'); $episodeid = request('episodeid');
$appointment_type = request('appointment_type'); //预约类型 $appointment_type = request('appointment_type'); //预约类型
$appointment_date = request('date'); //预约日期 $appointment_date = request('date'); //预约日期
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$service = new PlanListService(); $service = new PlanListService();
$date_arr = []; $date_arr = [];
@ -256,7 +262,7 @@ public function NearestEnablePlanDate()
$currentDate = $startDate; $currentDate = $startDate;
while ($currentDate <= $endDate) { while ($currentDate <= $endDate) {
$nowdate = $currentDate->format('Y-m-d'); $nowdate = $currentDate->format('Y-m-d');
$s = $service->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate); $s = $service->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate, 'all', $deptId);
if ($s['status']) { if ($s['status']) {
$list = $s['data']['plan_list']; $list = $s['data']['plan_list'];
if (count($list) > 0) { if (count($list) > 0) {
@ -298,6 +304,8 @@ public function AutoYuYue()
$entrustids = request('entrustid'); $entrustids = request('entrustid');
$episodeid = request('episodeid'); $episodeid = request('episodeid');
$appointment_type = request('appointment_type'); //预约类型 $appointment_type = request('appointment_type'); //预约类型
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$TodayDateTime = date("Y-m-d H:i:s"); $TodayDateTime = date("Y-m-d H:i:s");
$service = new PlanListService(); $service = new PlanListService();
@ -310,7 +318,7 @@ public function AutoYuYue()
$enable_plan=false; $enable_plan=false;
while ($currentDate <= $endDate) { while ($currentDate <= $endDate) {
$nowdate = $currentDate->format('Y-m-d'); $nowdate = $currentDate->format('Y-m-d');
$s = $service->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate); $s = $service->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate, 'all', $deptId);
if ($s['status']) { if ($s['status']) {
$list = $s['data']['plan_list']; $list = $s['data']['plan_list'];
if (count($list) > 0) { if (count($list) > 0) {
@ -386,7 +394,13 @@ public function GetUsedList()
->where('s_check_item.is_del', 0) ->where('s_check_item.is_del', 0)
->where('s_check_item.status', 1); ->where('s_check_item.status', 1);
}) })
->select('s_list.*', 's_department_resources.department_resources_name', 's_check_item.use_seats', 's_check_item.is_share_slot') ->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');
})
->select('s_list.*', 's_department_resources.department_resources_name',
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'))
->where(['s_list.roster_id' => $planid, 's_list.is_del' => 0, 's_list.is_nullify' => 0])->whereIn('s_list.list_status', [1, 2, 3]); ->where(['s_list.roster_id' => $planid, 's_list.is_del' => 0, 's_list.is_nullify' => 0])->whereIn('s_list.list_status', [1, 2, 3]);
if (!empty($qudaoid)) { if (!empty($qudaoid)) {
$list = $list->where(['s_list.appointment_type_id' => $qudaoid]); $list = $list->where(['s_list.appointment_type_id' => $qudaoid]);

@ -23,6 +23,8 @@ public function getMainDetail()
$entrustids = request('entrustid'); $entrustids = request('entrustid');
$episodeid = request('episodeid'); $episodeid = request('episodeid');
$appointment_type=request('appointment_type'); $appointment_type=request('appointment_type');
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$arrayEntrustids = explode(",", $entrustids); $arrayEntrustids = explode(",", $entrustids);
$info = DB::table('s_list as a')->where(['a.reg_num' => $regnum, 'a.episodeid'=>$episodeid,'a.is_nullify'=>0]) $info = DB::table('s_list as a')->where(['a.reg_num' => $regnum, 'a.episodeid'=>$episodeid,'a.is_nullify'=>0])
@ -39,6 +41,12 @@ public function getMainDetail()
->leftJoin('s_check_item_device as b','a.id','=','b.item_id') ->leftJoin('s_check_item_device as b','a.id','=','b.item_id')
->leftJoin('s_department_resources_device as c','b.device_id','=','c.device_id') ->leftJoin('s_department_resources_device as c','b.device_id','=','c.device_id')
->leftJoin('s_department as d','c.department_id','=','d.id') ->leftJoin('s_department as d','c.department_id','=','d.id')
->leftJoin('s_dept_check_item', function($j) use ($deptId) {
$j->on('s_dept_check_item.check_item_id', '=', 'a.id')
->where('s_dept_check_item.department_id', '=', $deptId);
})
->select('a.*', 'b.device_id', 'c.department_id as dept_device_dept_id', 'd.department_name',
DB::raw('COALESCE(s_dept_check_item.reservation_method, a.reservation_method) as reservation_method'))
->where(['a.item_name' => $value->entrust,'a.status'=>1,"a.is_del"=>0])->get(); ->where(['a.item_name' => $value->entrust,'a.status'=>1,"a.is_del"=>0])->get();
$source=null; $source=null;
if(!empty($value->reservation_sources)){ if(!empty($value->reservation_sources)){
@ -442,6 +450,8 @@ public function CheckEntrstItemGroup()
$items= request('items'); $items= request('items');
if(!empty($items)){ if(!empty($items)){
$FirstItemDevices=[]; $FirstItemDevices=[];
$userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
foreach ($items as $key=>$val){ foreach ($items as $key=>$val){
if($val['first']==1){ if($val['first']==1){
//获取点击的检查项目关联的设备id //获取点击的检查项目关联的设备id
@ -452,6 +462,11 @@ public function CheckEntrstItemGroup()
->whereNotNull('b.device_id') ->whereNotNull('b.device_id')
->pluck('b.device_id')->toArray(); ->pluck('b.device_id')->toArray();
$FirstItem= DB::table('s_check_item as a') $FirstItem= DB::table('s_check_item as a')
->leftJoin('s_dept_check_item', function($j) use ($deptId) {
$j->on('s_dept_check_item.check_item_id', '=', 'a.id')
->where('s_dept_check_item.department_id', '=', $deptId);
})
->select('a.*', DB::raw('COALESCE(s_dept_check_item.check_begin_time, a.check_begin_time, 0) as check_begin_time'))
->where(['a.item_name'=>$val['name'],'a.is_del'=>0,'a.status'=>1])->first(); ->where(['a.item_name'=>$val['name'],'a.is_del'=>0,'a.status'=>1])->first();
if(!$FirstItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置'); if(!$FirstItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置');
} }

@ -1,6 +1,6 @@
<?php <?php
namespace App\Http\Controllers\API; namespace App\Http\Controllers\API\Admin\YeWu;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Barryvdh\Snappy\Facades\SnappyPdf; use Barryvdh\Snappy\Facades\SnappyPdf;
@ -8,6 +8,10 @@
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use function App\Http\Controllers\API\config;
use function App\Http\Controllers\API\env;
use function App\Http\Controllers\API\request;
use function App\Http\Controllers\API\storage_path;
class PdfController extends Controller class PdfController extends Controller
{ {
@ -181,6 +185,7 @@ public function GetCheckPdf()
'reservation_date' => $item->reservation_date, 'reservation_date' => $item->reservation_date,
'period_begin_time' => $item->period_begin_time, 'period_begin_time' => $item->period_begin_time,
'period_end_time' => $item->period_end_time, 'period_end_time' => $item->period_end_time,
'reservation_sources' => $item->reservation_sources,
]; ];
} }
@ -224,10 +229,20 @@ public function GetCheckPdf()
//检查须知:从该诊室所有检查项目读取 check_notice去重过滤 //检查须知:从该诊室所有检查项目读取 check_notice去重过滤
$itemNames = array_column($room['items'], 'entrust'); $itemNames = array_column($room['items'], 'entrust');
$firstItem = $room['items'][0] ?? null;
$deptId = 0;
if ($firstItem && !empty($firstItem['reservation_sources'])) {
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByResourceId($firstItem['reservation_sources']);
}
$notices = DB::table('s_check_item') $notices = 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);
})
->whereIn('item_name', $itemNames) ->whereIn('item_name', $itemNames)
->where('status', 1) ->where('s_check_item.status', 1)
->where('is_del', 0) ->where('s_check_item.is_del', 0)
->select(DB::raw('COALESCE(s_dept_check_item.check_notice, s_check_item.check_notice) as check_notice'))
->pluck('check_notice') ->pluck('check_notice')
->filter() ->filter()
->unique() ->unique()
@ -237,9 +252,14 @@ public function GetCheckPdf()
//温馨提示:从该诊室所有检查项目读取 warm_tips去重过滤 //温馨提示:从该诊室所有检查项目读取 warm_tips去重过滤
$tips = DB::table('s_check_item') $tips = 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);
})
->whereIn('item_name', $itemNames) ->whereIn('item_name', $itemNames)
->where('status', 1) ->where('s_check_item.status', 1)
->where('is_del', 0) ->where('s_check_item.is_del', 0)
->select(DB::raw('COALESCE(s_dept_check_item.warm_tips, s_check_item.warm_tips) as warm_tips'))
->pluck('warm_tips') ->pluck('warm_tips')
->filter() ->filter()
->unique() ->unique()
@ -512,6 +532,7 @@ public function GenerateGroupedCheckPdf()
'reservation_date' => $item->reservation_date, 'reservation_date' => $item->reservation_date,
'period_begin_time' => $item->period_begin_time, 'period_begin_time' => $item->period_begin_time,
'period_end_time' => $item->period_end_time, 'period_end_time' => $item->period_end_time,
'reservation_sources' => $item->reservation_sources,
]; ];
} }
@ -560,10 +581,20 @@ public function GenerateGroupedCheckPdf()
//检查须知:从该诊室所有检查项目读取 check_notice去重过滤 //检查须知:从该诊室所有检查项目读取 check_notice去重过滤
$itemNames = array_column($room['items'], 'entrust'); $itemNames = array_column($room['items'], 'entrust');
$firstItem = $room['items'][0] ?? null;
$deptId = 0;
if ($firstItem && !empty($firstItem['reservation_sources'])) {
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByResourceId($firstItem['reservation_sources']);
}
$notices = DB::table('s_check_item') $notices = 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);
})
->whereIn('item_name', $itemNames) ->whereIn('item_name', $itemNames)
->where('status', 1) ->where('s_check_item.status', 1)
->where('is_del', 0) ->where('s_check_item.is_del', 0)
->select(DB::raw('COALESCE(s_dept_check_item.check_notice, s_check_item.check_notice) as check_notice'))
->pluck('check_notice') ->pluck('check_notice')
->filter() ->filter()
->unique() ->unique()
@ -573,9 +604,14 @@ public function GenerateGroupedCheckPdf()
//温馨提示:从该诊室所有检查项目读取 warm_tips去重过滤 //温馨提示:从该诊室所有检查项目读取 warm_tips去重过滤
$tips = DB::table('s_check_item') $tips = 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);
})
->whereIn('item_name', $itemNames) ->whereIn('item_name', $itemNames)
->where('status', 1) ->where('s_check_item.status', 1)
->where('is_del', 0) ->where('s_check_item.is_del', 0)
->select(DB::raw('COALESCE(s_dept_check_item.warm_tips, s_check_item.warm_tips) as warm_tips'))
->pluck('warm_tips') ->pluck('warm_tips')
->filter() ->filter()
->unique() ->unique()

@ -89,8 +89,21 @@ public function GetItemList($searchInfo,$page,$pageSize,$userid){
} }
$count = $list->count(); $count = $list->count();
$list= $list $list= $list
->leftJoin('s_appointment_type', 's_check_item.reservation_method', '=', 's_appointment_type.id') ->leftJoin('s_dept_check_item', function($join) use ($user) {
->select('s_check_item.*','s_appointment_type.name as reservation_method_name'); $join->on('s_dept_check_item.check_item_id', '=', 's_check_item.id')
->where('s_dept_check_item.department_id', '=', $user->department_id);
})
->select(
's_check_item.*',
DB::raw('COALESCE(s_dept_check_item.reservation_method, s_check_item.reservation_method) as reservation_method'),
DB::raw('COALESCE(s_dept_check_item.limosis, s_check_item.limosis) as limosis'),
DB::raw('COALESCE(s_dept_check_item.check_time, s_check_item.check_time) as check_time'),
DB::raw('COALESCE(s_dept_check_item.check_begin_time, s_check_item.check_begin_time) as check_begin_time'),
DB::raw('COALESCE(s_dept_check_item.check_notice, s_check_item.check_notice) as check_notice'),
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.warm_tips, s_check_item.warm_tips) as warm_tips'),
DB::raw('COALESCE(s_dept_check_item.is_share_slot, s_check_item.is_share_slot, 0) as is_share_slot')
);
if (!empty($searchInfo['orderField']) && !empty($searchInfo['orderDirection'])) { if (!empty($searchInfo['orderField']) && !empty($searchInfo['orderDirection'])) {
$direction = $searchInfo['orderDirection'] == 'ascending' ? 'asc' : 'desc'; $direction = $searchInfo['orderDirection'] == 'ascending' ? 'asc' : 'desc';
$list->orderBy($searchInfo['orderField'], $direction); $list->orderBy($searchInfo['orderField'], $direction);
@ -168,30 +181,95 @@ public function BindDevice($item_id,$device_ids,$userid){
return \Yz::Return(false, '绑定失败'); return \Yz::Return(false, '绑定失败');
} }
} }
public function BatchUpdateNotice($item_ids, $field, $value) public function BatchUpdateNotice($item_ids, $field, $value, $userid)
{ {
if (empty($item_ids) || !in_array($field, ['check_notice', 'warm_tips'])) { if (empty($item_ids) || !in_array($field, ['check_notice', 'warm_tips'])) {
return \Yz::Return(false, '参数错误'); return \Yz::Return(false, '参数错误');
} }
$updated = DB::table('s_check_item')
->whereIn('id', $item_ids) $user = DB::table('users')->where('id', $userid)->first();
->where('is_del', 0) if (!$user || !$user->department_id) {
return \Yz::Return(false, '用户科室信息不存在');
}
$deptId = $user->department_id;
foreach ($item_ids as $item_id) {
// 查覆盖表是否已有记录
$existing = DB::table('s_dept_check_item')
->where('check_item_id', $item_id)
->where('department_id', $deptId)
->first();
if ($existing) {
// 已有记录,直接更新目标字段
DB::table('s_dept_check_item')
->where('id', $existing->id)
->update([$field => $value]); ->update([$field => $value]);
return \Yz::Return(true, '批量更新成功,共更新' . $updated . '条'); } else {
// 不存在,从主表读取基线数据回填
$base = DB::table('s_check_item')
->where('id', $item_id)
->first();
$data = [
'check_item_id' => $item_id,
'department_id' => $deptId,
'reservation_method' => $base->reservation_method ?? null,
'limosis' => $base->limosis ?? null,
'check_time' => $base->check_time ?? null,
'check_begin_time' => $base->check_begin_time ?? null,
'check_notice' => $base->check_notice ?? null,
'warm_tips' => null,
'use_seats' => $base->use_seats ?? 1,
'is_share_slot' => 0,
];
// 覆盖目标字段
$data[$field] = $value;
DB::table('s_dept_check_item')->insert($data);
}
}
return \Yz::Return(true, '批量更新成功,共更新' . count($item_ids) . '条');
}
public function Save($Info, $userid){
if(empty($Info['id'])){
return \Yz::Return(false, 'id不能为空');
}
$user = DB::table('users')->where('id', $userid)->first();
if(!$user || !$user->department_id){
return \Yz::Return(false, '用户科室信息不存在');
}
// 预约方式数组转逗号分隔串
$reservationMethod = $Info['reservation_method'];
if(is_array($reservationMethod)){
$reservationMethod = implode(',', $reservationMethod);
} }
public function Save($Info){ $data = [
if(!empty($Info['id'])){ 'reservation_method' => $reservationMethod,
$Info['reservation_method']=implode(',', $Info['reservation_method']); 'limosis' => $Info['limosis'] ?? null,
$res=DB::table('s_check_item')->where('id',$Info['id'])->update($Info); 'check_time' => $Info['check_time'] ?? null,
'check_begin_time' => $Info['check_begin_time'] ?? null,
'check_notice' => $Info['check_notice'] ?? null,
'warm_tips' => $Info['warm_tips'] ?? null,
'use_seats' => $Info['use_seats'] ?? 1,
'is_share_slot' => $Info['is_share_slot'] ?? 0,
];
$res = DB::table('s_dept_check_item')->updateOrInsert(
['check_item_id' => $Info['id'], 'department_id' => $user->department_id],
$data
);
if($res){ if($res){
return \Yz::Return(true, '修改成功'); return \Yz::Return(true, '修改成功');
}else{ }else{
return \Yz::Return(false, '修改失败'); return \Yz::Return(false, '修改失败');
} }
}else{
return \Yz::Return(false, 'id不能为空');
}
} }
//同步检查项目分类(全量,复用 HIS 逻辑) //同步检查项目分类(全量,复用 HIS 逻辑)
@ -240,6 +318,38 @@ public function SyncCheckItem($userid)
]); ]);
} }
// ========== 公共方法department_id 获取 ==========
/**
* 根据 userid 查 users.department_id
*/
public static function getDeptIdByUserid($userid)
{
if (empty($userid)) return 0;
$user = DB::table('users')->where('id', $userid)->first(['department_id']);
return $user->department_id ?? 0;
}
/**
* 根据排班明细 ID 查 s_source_roster_detail.department_id
*/
public static function getDeptIdByRosterId($rosterId)
{
if (empty($rosterId)) return 0;
$roster = DB::table('s_source_roster_detail')->where('id', $rosterId)->first(['department_id']);
return $roster->department_id ?? 0;
}
/**
* 根据预约资源 ID 查 s_department_resources.department_id
*/
public static function getDeptIdByResourceId($resourceId)
{
if (empty($resourceId)) return 0;
$resource = DB::table('s_department_resources')->where('id', $resourceId)->first(['department_id']);
return $resource->department_id ?? 0;
}
//获取当前科室所有符合条件的项目快照code => 字段摘要) //获取当前科室所有符合条件的项目快照code => 字段摘要)
private function getDeptItemSnapshot($userid) private function getDeptItemSnapshot($userid)
{ {

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

Loading…
Cancel
Save