检查项目逻辑调整

dev
鹿和sa0ChunLuyu 9 hours ago
parent 52fa8641c6
commit 5bdbb7b4d3

@ -36,18 +36,23 @@ public function getMainDetail()
$itemInfo=[]; $itemInfo=[];
$noDeptInfo=[]; $noDeptInfo=[];
$noScheduleInfo=[]; $noScheduleInfo=[];
$checkItemService = new \App\Services\Admin\YeWu\CheckItemService();
foreach ($info as $value){ foreach ($info as $value){
$ii = DB::table('s_check_item as a') $theItem = $checkItemService->getCheckItemByEntrust($value->entrust_code, $value->entrust, $deptId);
->leftJoin('s_check_item_device as b','a.id','=','b.item_id') $ii = collect();
->leftJoin('s_department_resources_device as c','b.device_id','=','c.device_id') if ($theItem) {
->leftJoin('s_department as d','c.department_id','=','d.id') $ii = DB::table('s_check_item as a')
->leftJoin('s_dept_check_item', function($j) use ($deptId) { ->leftJoin('s_check_item_device as b','a.id','=','b.item_id')
$j->on('s_dept_check_item.check_item_id', '=', 'a.id') ->leftJoin('s_department_resources_device as c','b.device_id','=','c.device_id')
->where('s_dept_check_item.department_id', '=', $deptId); ->leftJoin('s_department as d','c.department_id','=','d.id')
}) ->leftJoin('s_dept_check_item', function($j) use ($deptId) {
->select('a.*', 'b.device_id', 'c.department_id as dept_device_dept_id', 'd.department_name', $j->on('s_dept_check_item.check_item_id', '=', 'a.id')
DB::raw('COALESCE(s_dept_check_item.reservation_method, a.reservation_method) as reservation_method')) ->where('s_dept_check_item.department_id', '=', $deptId);
->where(['a.item_name' => $value->entrust,'a.status'=>1,"a.is_del"=>0])->get(); })
->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.id', $theItem->id)->where('a.status',1)->where('a.is_del',0)->get();
}
$source=null; $source=null;
if(!empty($value->reservation_sources)){ if(!empty($value->reservation_sources)){
$source=DB::table('s_department_resources')->where(['id'=>$value->reservation_sources])->first(); $source=DB::table('s_department_resources')->where(['id'=>$value->reservation_sources])->first();
@ -453,37 +458,34 @@ public function CheckEntrstItemGroup()
{ {
$list=[]; $list=[];
$rowids=[]; $rowids=[];
$itemNames=[]; $itemIds=[];
$items= request('items'); $items= request('items');
if(!empty($items)){ if(!empty($items)){
$FirstItemDevices=[]; $FirstItemDevices=[];
$FirstItem=null;
$userid = request()->get('userid'); $userid = request()->get('userid');
$deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid); $deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid);
$checkItemService = new \App\Services\Admin\YeWu\CheckItemService();
foreach ($items as $key=>$val){ foreach ($items as $key=>$val){
//精确匹配检查项目:主用 item_code查不到回退 item_name取最新避免同名歧义
$theItem = $checkItemService->getCheckItemByEntrust($val['item_code'] ?? null, $val['name'], $deptId);
if(!$theItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置');
$itemIds[]=$theItem->id;
if($val['first']==1){ if($val['first']==1){
//获取点击的检查项目关联的设备id //获取点击的检查项目关联的设备id
$FirstItemDevices= DB::table('s_check_item as a') $FirstItemDevices=DB::table('s_check_item_device')
->leftJoin('s_check_item_device as b','a.id','=','b.item_id') ->where('item_id',$theItem->id)
->select('b.device_id') ->whereNotNull('device_id')
->where(['a.item_name'=>$val['name'],'a.is_del'=>0,'a.status'=>1]) ->pluck('device_id')->toArray();
->whereNotNull('b.device_id') $FirstItem=$theItem;
->pluck('b.device_id')->toArray();
$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();
if(!$FirstItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置');
} }
$itemNames[]=$val['name'];
} }
if(!$FirstItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置');
//获取所有传过来的检查项目关联的设备,并且只有设置相同的医嘱后等待时间才能同时勾选 //获取所有传过来的检查项目关联的设备,并且只有设置相同的医嘱后等待时间才能同时勾选
$ItemsDevices= DB::table('s_check_item as a') $ItemsDevices= 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_devices as c','b.device_id','=','c.id') ->leftJoin('s_devices as c','b.device_id','=','c.id')
->whereIn('a.item_name',$itemNames)->where(['a.is_del'=>0,'a.status'=>1,'check_begin_time'=>$FirstItem->check_begin_time])->get(); ->whereIn('a.id',$itemIds)->where(['a.is_del'=>0,'a.status'=>1,'check_begin_time'=>$FirstItem->check_begin_time])->get();
//按照第一个勾选的检查项目关联的设备进行分组,能在一个设备上进行检查的分在一组 //按照第一个勾选的检查项目关联的设备进行分组,能在一个设备上进行检查的分在一组
if(!empty($FirstItemDevices)){ if(!empty($FirstItemDevices)){

@ -80,12 +80,18 @@ public function GetCheckPdf()
continue; continue;
} }
//查s_check_item判断是否需要预约 //查s_check_item判断是否需要预约精确匹配检查项目主用 item_code查不到回退 item_name
$checkItem = DB::table('s_check_item as a') $theItem = (new \App\Services\Admin\YeWu\CheckItemService())
->leftJoin('s_check_item_device as b', 'a.id', '=', 'b.item_id') ->getCheckItemByEntrust($entrustInfo->entrust_code, $entrustInfo->entrust);
->leftJoin('s_department_resources_device as c', 'b.device_id', '=', 'c.device_id') $checkItem = null;
->where(['a.item_name' => $entrustInfo->entrust, 'a.status' => 1, 'a.is_del' => 0]) if ($theItem) {
->first(); $checkItem = DB::table('s_check_item as a')
->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')
->where('a.id', $theItem->id)
->where('a.status', 1)->where('a.is_del', 0)
->first();
}
if (!$checkItem || empty($checkItem->device_id)) { if (!$checkItem || empty($checkItem->device_id)) {
$resultList[] = [ $resultList[] = [

@ -399,4 +399,42 @@ public function GetItemRelatedResources($item_id, $userid)
return \Yz::Return(true, '查询成功', $resources); return \Yz::Return(true, '查询成功', $resources);
} }
//按医嘱精确获取唯一检查项目:主用 item_code 匹配,查不到时回退 item_name取 id 最大的一条),避免同名项目歧义
public function getCheckItemByEntrust($entrustCode, $entrustName, $userDeptId = 0)
{
// 主查询item_code 精确匹配(全局唯一)
$item = $this->queryCheckItemByField('item_code', $entrustCode, $userDeptId);
if ($item) {
return $item;
}
// 兜底item_name 匹配,取 id 最大的一条(最新配置)
return $this->queryCheckItemByField('item_name', $entrustName, $userDeptId);
}
//按指定字段查询唯一有效检查项目,带科室映射覆盖
private function queryCheckItemByField($field, $value, $userDeptId)
{
if (empty($value)) {
return null;
}
$query = 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);
})
->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.check_begin_time, s_check_item.check_begin_time, 0) as check_begin_time')
)
->where('s_check_item.status', 1)
->where('s_check_item.is_del', 0);
if ($field === 'item_name') {
return $query->where('s_check_item.item_name', $value)
->orderByDesc('s_check_item.id')
->first();
}
return $query->where('s_check_item.' . $field, $value)->first();
}
} }

@ -25,6 +25,7 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
$shareSlotMaxSeats = 0;//共享号源项目的use_seats最大值 $shareSlotMaxSeats = 0;//共享号源项目的use_seats最大值
$allItemRules = [];//所有检查项目的TIME_RESTRICTION规则 $allItemRules = [];//所有检查项目的TIME_RESTRICTION规则
$itemMainData = [];//存储项目主表数据,用于后续按排班科室重算覆盖值 $itemMainData = [];//存储项目主表数据,用于后续按排班科室重算覆盖值
$checkItemService = new \App\Services\Admin\YeWu\CheckItemService();
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();
@ -34,17 +35,9 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ
$allEmergency = false; $allEmergency = false;
} }
$itemInfo = DB::table('s_check_item') // 精确匹配检查项目:主用 item_code查不到回退 item_name取最新避免同名歧义
->leftJoin('s_dept_check_item', function($j) use ($userDeptId) { $itemInfo = $checkItemService->getCheckItemByEntrust($info->entrust_code, $info->entrust, $userDeptId);
$j->on('s_dept_check_item.check_item_id', '=', 's_check_item.id') if (!$itemInfo) return \Yz::echoError1('没有找到可用的检查项目信息');
->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('没有找到可用的检查项目信息');
$itemInfo = $itemInfo[0];
// 存储项目 ID 和主表值,后续按排班科室重新计算覆盖值 // 存储项目 ID 和主表值,后续按排班科室重新计算覆盖值
$itemMainData[] = [ $itemMainData[] = [
'id' => $itemInfo->id, 'id' => $itemInfo->id,

@ -670,12 +670,14 @@ let TanChuangMsgDialogVisible=ref(false)
if (v.id == selectedRows.value[length-1].id) { if (v.id == selectedRows.value[length-1].id) {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 1 first: 1
}) })
} else { } else {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 0 first: 0
}) })

@ -555,12 +555,14 @@
if (v.id == tableSelected.value[0].id) { if (v.id == tableSelected.value[0].id) {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 1 first: 1
}) })
} else { } else {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 0 first: 0
}) })

@ -425,12 +425,14 @@
if (v.id == tableSelected.value[0].id) { if (v.id == tableSelected.value[0].id) {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 1 first: 1
}) })
} else { } else {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 0 first: 0
}) })

@ -346,12 +346,14 @@
if (v.id == tableSelected.value[0].id) { if (v.id == tableSelected.value[0].id) {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 1 first: 1
}) })
} else { } else {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 0 first: 0
}) })
@ -420,12 +422,14 @@
if (v.id == tableSelected.value[0].id) { if (v.id == tableSelected.value[0].id) {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 1 first: 1
}) })
} else { } else {
list.push({ list.push({
name: v.entrust, name: v.entrust,
item_code: v.entrust_code,
rowid: i, rowid: i,
first: 0 first: 0
}) })

Loading…
Cancel
Save