From 5bdbb7b4d345403a1135eaa5cb04f80bbdbbf015 Mon Sep 17 00:00:00 2001 From: sa0ChunLuyu Date: Fri, 7 Aug 2026 22:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E9=A1=B9=E7=9B=AE=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Admin/YeWu/WorkMainController.php | 58 ++++++++++--------- .../Http/Controllers/API/PdfController.php | 18 ++++-- .../Services/Admin/YeWu/CheckItemService.php | 38 ++++++++++++ .../Services/Admin/YeWu/PlanListService.php | 15 ++--- .../src/components/Yewu/YuYue202506.vue | 2 + YiJi-admin/src/views/YeWu/MainList.vue | 2 + .../src/views/YeWu/MainListWithDept.vue | 2 + .../src/views/YeWu/MainList_ZhuYuan.vue | 4 ++ 8 files changed, 94 insertions(+), 45 deletions(-) diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php index 7c21933..e5003df 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php @@ -36,18 +36,23 @@ public function getMainDetail() $itemInfo=[]; $noDeptInfo=[]; $noScheduleInfo=[]; + $checkItemService = new \App\Services\Admin\YeWu\CheckItemService(); foreach ($info as $value){ - $ii = 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') - ->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(); + $theItem = $checkItemService->getCheckItemByEntrust($value->entrust_code, $value->entrust, $deptId); + $ii = collect(); + if ($theItem) { + $ii = 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') + ->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.id', $theItem->id)->where('a.status',1)->where('a.is_del',0)->get(); + } $source=null; if(!empty($value->reservation_sources)){ $source=DB::table('s_department_resources')->where(['id'=>$value->reservation_sources])->first(); @@ -453,37 +458,34 @@ public function CheckEntrstItemGroup() { $list=[]; $rowids=[]; - $itemNames=[]; + $itemIds=[]; $items= request('items'); if(!empty($items)){ $FirstItemDevices=[]; + $FirstItem=null; $userid = request()->get('userid'); $deptId = \App\Services\Admin\YeWu\DeptCheckItemService::getDeptIdByUserid($userid); + $checkItemService = new \App\Services\Admin\YeWu\CheckItemService(); 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){ //获取点击的检查项目关联的设备id - $FirstItemDevices= DB::table('s_check_item as a') - ->leftJoin('s_check_item_device as b','a.id','=','b.item_id') - ->select('b.device_id') - ->where(['a.item_name'=>$val['name'],'a.is_del'=>0,'a.status'=>1]) - ->whereNotNull('b.device_id') - ->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('此医嘱项目无效,请检查项目设置'); + $FirstItemDevices=DB::table('s_check_item_device') + ->where('item_id',$theItem->id) + ->whereNotNull('device_id') + ->pluck('device_id')->toArray(); + $FirstItem=$theItem; } - $itemNames[]=$val['name']; } + if(!$FirstItem) return \Yz::echoError1('此医嘱项目无效,请检查项目设置'); //获取所有传过来的检查项目关联的设备,并且只有设置相同的医嘱后等待时间才能同时勾选 $ItemsDevices= DB::table('s_check_item as a') ->leftJoin('s_check_item_device as b','a.id','=','b.item_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)){ diff --git a/Laravel/app/Http/Controllers/API/PdfController.php b/Laravel/app/Http/Controllers/API/PdfController.php index 8604781..b8b5244 100644 --- a/Laravel/app/Http/Controllers/API/PdfController.php +++ b/Laravel/app/Http/Controllers/API/PdfController.php @@ -80,12 +80,18 @@ public function GetCheckPdf() continue; } - //查s_check_item(判断是否需要预约) - $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.item_name' => $entrustInfo->entrust, 'a.status' => 1, 'a.is_del' => 0]) - ->first(); + //查s_check_item(判断是否需要预约):精确匹配检查项目,主用 item_code,查不到回退 item_name + $theItem = (new \App\Services\Admin\YeWu\CheckItemService()) + ->getCheckItemByEntrust($entrustInfo->entrust_code, $entrustInfo->entrust); + $checkItem = null; + if ($theItem) { + $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)) { $resultList[] = [ diff --git a/Laravel/app/Services/Admin/YeWu/CheckItemService.php b/Laravel/app/Services/Admin/YeWu/CheckItemService.php index fe3d0fe..9a12cac 100644 --- a/Laravel/app/Services/Admin/YeWu/CheckItemService.php +++ b/Laravel/app/Services/Admin/YeWu/CheckItemService.php @@ -399,4 +399,42 @@ public function GetItemRelatedResources($item_id, $userid) 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(); + } } \ No newline at end of file diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index 5883dd3..9bea0a7 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -25,6 +25,7 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ $shareSlotMaxSeats = 0;//共享号源项目的use_seats最大值 $allItemRules = [];//所有检查项目的TIME_RESTRICTION规则 $itemMainData = [];//存储项目主表数据,用于后续按排班科室重算覆盖值 + $checkItemService = new \App\Services\Admin\YeWu\CheckItemService(); 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(['entrust_id' => $entrustid, 'is_nullify' => 0])->first(); @@ -34,17 +35,9 @@ public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_typ $allEmergency = false; } - $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('没有找到可用的检查项目信息'); - $itemInfo = $itemInfo[0]; + // 精确匹配检查项目:主用 item_code,查不到回退 item_name(取最新),避免同名歧义 + $itemInfo = $checkItemService->getCheckItemByEntrust($info->entrust_code, $info->entrust, $userDeptId); + if (!$itemInfo) return \Yz::echoError1('没有找到可用的检查项目信息'); // 存储项目 ID 和主表值,后续按排班科室重新计算覆盖值 $itemMainData[] = [ 'id' => $itemInfo->id, diff --git a/YiJi-admin/src/components/Yewu/YuYue202506.vue b/YiJi-admin/src/components/Yewu/YuYue202506.vue index 510a2db..0bc7590 100644 --- a/YiJi-admin/src/components/Yewu/YuYue202506.vue +++ b/YiJi-admin/src/components/Yewu/YuYue202506.vue @@ -670,12 +670,14 @@ let TanChuangMsgDialogVisible=ref(false) if (v.id == selectedRows.value[length-1].id) { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 1 }) } else { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 0 }) diff --git a/YiJi-admin/src/views/YeWu/MainList.vue b/YiJi-admin/src/views/YeWu/MainList.vue index 693abff..ec20a1c 100644 --- a/YiJi-admin/src/views/YeWu/MainList.vue +++ b/YiJi-admin/src/views/YeWu/MainList.vue @@ -555,12 +555,14 @@ if (v.id == tableSelected.value[0].id) { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 1 }) } else { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 0 }) diff --git a/YiJi-admin/src/views/YeWu/MainListWithDept.vue b/YiJi-admin/src/views/YeWu/MainListWithDept.vue index 929c4a9..3531ee9 100644 --- a/YiJi-admin/src/views/YeWu/MainListWithDept.vue +++ b/YiJi-admin/src/views/YeWu/MainListWithDept.vue @@ -425,12 +425,14 @@ if (v.id == tableSelected.value[0].id) { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 1 }) } else { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 0 }) diff --git a/YiJi-admin/src/views/YeWu/MainList_ZhuYuan.vue b/YiJi-admin/src/views/YeWu/MainList_ZhuYuan.vue index 459cd51..e1eddc2 100644 --- a/YiJi-admin/src/views/YeWu/MainList_ZhuYuan.vue +++ b/YiJi-admin/src/views/YeWu/MainList_ZhuYuan.vue @@ -346,12 +346,14 @@ if (v.id == tableSelected.value[0].id) { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 1 }) } else { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 0 }) @@ -420,12 +422,14 @@ if (v.id == tableSelected.value[0].id) { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 1 }) } else { list.push({ name: v.entrust, + item_code: v.entrust_code, rowid: i, first: 0 })