where(['pid'=>0,'is_del'=>0])->get(); $smallClass=[]; if(!empty($searchInfo['bigClass'])) { $smallClass = DB::table('s_check_item_class')->where(['pid'=>$searchInfo['bigClass'],'is_del'=>0])->get(); } return \Yz::Return(true, '查询成功', ['bigClass'=>$bigClass,'smallClass'=>$smallClass]); } //获取检查项目列表 public function GetItemList($searchInfo,$page,$pageSize){ $small_id=[]; $list=DB::table('s_check_item')->where('s_check_item.is_del', 0)->whereNotNull('sheetType')->where('sheetType', '!=', ''); if(empty($searchInfo['bigClass'])!==true and empty($searchInfo['smallClass'])===true){ $small_id= DB::table('s_check_item_class')->where(['pid'=>$searchInfo['bigClass'],'is_del'=>0])->pluck('id')->toArray(); $list= $list->whereIn('item_class_id',$small_id); } if(!empty($searchInfo['smallClass'])){ $small_id[0]=$searchInfo['smallClass']; $list= $list->whereIn('item_class_id',$small_id); } if(!empty($searchInfo['name'])){ $list->where(function($query) use ($searchInfo) { $query->where('item_name', 'like', '%'.$searchInfo['name'].'%') ->orWhere('item_code', 'like', '%'.$searchInfo['name'].'%'); }); } if (isset($searchInfo['deviceBind']) && $searchInfo['deviceBind'] !== '') { if ($searchInfo['deviceBind'] == 1) { $list->whereIn('s_check_item.id', function($q) { $q->select('item_id')->from('s_check_item_device'); }); } elseif ($searchInfo['deviceBind'] == 0) { $list->whereNotIn('s_check_item.id', function($q) { $q->select('item_id')->from('s_check_item_device'); }); } } //执行科室筛选 if (isset($searchInfo['hisExecDepts']) && $searchInfo['hisExecDepts'] !== '') { if ($searchInfo['hisExecDepts'] == 1) { $list->whereNotNull('hisExecDepts')->where('hisExecDepts', '!=', ''); } elseif ($searchInfo['hisExecDepts'] == 0) { $list->where(function($q) { $q->whereNull('hisExecDepts')->orWhere('hisExecDepts', ''); }); } } //只显示参与预约科室的项目 if (!empty($searchInfo['appointmentDeptOnly'])) { $deptNumbers = DB::table('s_department') ->where('appointment_enabled', 1) ->where('is_del', 0) ->where('department_status', 1) ->pluck('department_number') ->toArray(); if (!empty($deptNumbers)) { $list->where(function($q) use ($deptNumbers) { foreach ($deptNumbers as $num) { $q->orWhere('hisExecDepts', 'like', '%"' . $num . '"%'); } }); } } $count = $list->count(); $list= $list ->leftJoin('s_appointment_type', 's_check_item.reservation_method', '=', 's_appointment_type.id') ->select('s_check_item.*','s_appointment_type.name as reservation_method_name'); if (!empty($searchInfo['orderField']) && !empty($searchInfo['orderDirection'])) { $direction = $searchInfo['orderDirection'] == 'ascending' ? 'asc' : 'desc'; $list->orderBy($searchInfo['orderField'], $direction); } $list = $list->skip(($page-1)*$pageSize)->take($pageSize)->get(); //查询出所有的预约渠道 $qudaoList=DB::table('s_appointment_type')->get(); foreach ($list as $k=>$v){ $qudao_names=[]; $qudao_ids = explode(",", $v->reservation_method); foreach ($qudaoList as $k1=>$v1){ foreach ($qudao_ids as $k2=>$v2){ if($v1->id==$v2){ $qudao_names[]=$v1->name; } } } $list[$k]->reservation_method= array_map('intval', $qudao_ids); $list[$k]->reservation_method_name=$qudao_names; $list[$k]->devicesInfo=DB::table('s_check_item_device') ->join('s_devices', 's_check_item_device.device_id', '=', 's_devices.id') ->select('s_devices.*') ->where('item_id',$v->id)->get(); // 解析原始科室 $deptNames = []; if (!empty($v->hisExecDepts)) { $deptCodes = json_decode($v->hisExecDepts, true); if (!empty($deptCodes) && is_array($deptCodes)) { $deptNames = DB::table('s_department') ->whereIn('department_number', $deptCodes) ->pluck('department_name') ->toArray(); } } $list[$k]->his_exec_dept_names = $deptNames; } return \Yz::Return(true, '查询成功', ['list'=>$list,'count'=>$count]); } //导出检查项目列表 public function ExportItemList($searchInfo) { $small_id=[]; $list=DB::table('s_check_item')->where('s_check_item.is_del', 0)->whereNotNull('sheetType')->where('sheetType', '!=', ''); if(empty($searchInfo['bigClass'])!==true and empty($searchInfo['smallClass'])===true){ $small_id= DB::table('s_check_item_class')->where(['pid'=>$searchInfo['bigClass'],'is_del'=>0])->pluck('id')->toArray(); $list= $list->whereIn('item_class_id',$small_id); } if(!empty($searchInfo['smallClass'])){ $small_id[0]=$searchInfo['smallClass']; $list= $list->whereIn('item_class_id',$small_id); } if(!empty($searchInfo['name'])){ $list->where(function($query) use ($searchInfo) { $query->where('item_name', 'like', '%'.$searchInfo['name'].'%') ->orWhere('item_code', 'like', '%'.$searchInfo['name'].'%'); }); } if (isset($searchInfo['deviceBind']) && $searchInfo['deviceBind'] !== '') { if ($searchInfo['deviceBind'] == 1) { $list->whereIn('s_check_item.id', function($q) { $q->select('item_id')->from('s_check_item_device'); }); } elseif ($searchInfo['deviceBind'] == 0) { $list->whereNotIn('s_check_item.id', function($q) { $q->select('item_id')->from('s_check_item_device'); }); } } if (isset($searchInfo['hisExecDepts']) && $searchInfo['hisExecDepts'] !== '') { if ($searchInfo['hisExecDepts'] == 1) { $list->whereNotNull('hisExecDepts')->where('hisExecDepts', '!=', ''); } elseif ($searchInfo['hisExecDepts'] == 0) { $list->where(function($q) { $q->whereNull('hisExecDepts')->orWhere('hisExecDepts', ''); }); } } $list = $list->orderBy('s_check_item.id')->get(); // 构建 HTML 表格 $html = '
| 检查项目代码 | 检查项目名称 | HIS执行科室 | 关联排班 |
|---|---|---|---|
| '.$v->item_code.' | '; $html .= ''.$v->item_name.' | '; $html .= ''.($deptNames[0] ?? '').' | '; $html .= ''.($deviceNames[0] ?? '').' | '; $html .= '
| '.($deptNames[$i] ?? '').' | '; $html .= ''.($deviceNames[$i] ?? '').' | '; $html .= '