diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php
index 0d9389a..423cc68 100644
--- a/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php
+++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/WorkMainController.php
@@ -32,6 +32,8 @@ public function getMainDetail()
->get();
if (!$info) return \Yz::echoError1('没有找到对应医嘱信息');
$itemInfo=[];
+ $noDeptInfo=[];
+ $noScheduleInfo=[];
foreach ($info as $value){
$ii = DB::table('s_check_item as a')
->leftJoin('s_check_item_device as b','a.id','=','b.item_id')
@@ -101,14 +103,101 @@ public function getMainDetail()
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
$barcodePng = $generator->getBarcode($barcodeContent, $generator::TYPE_CODE_128, 2, 40);
$value->barcode = base64_encode($barcodePng);
- $itemInfo[]=[
- 'maininfo'=>$value,
- 'iteminfo'=>$ii,
- 'msg'=>$msg
+
+ // ====== 分类判断:检查室状态 / 诊室资源状态 / 排班配置 ======
+
+ // ====== 分类判断:检查室状态 / 诊室资源状态 / 排班配置 ======
+
+ // 链路A:通过 hisExecDepts 查科室状态,同时收集科室名称
+ $checkItemRaw = DB::table('s_check_item')
+ ->where('item_code', $value->entrust_code)
+ ->where('status', 1)
+ ->where('is_del', 0)
+ ->first(['id', 'item_code', 'item_name', 'hisExecDepts']);
+
+ $deptAvailable = false;
+ $resourceItemPairs = [];
+
+ if ($checkItemRaw && !empty($checkItemRaw->hisExecDepts)) {
+ $deptCodes = json_decode($checkItemRaw->hisExecDepts, true);
+ if (!empty($deptCodes) && is_array($deptCodes)) {
+ $departments = DB::table('s_department')
+ ->whereIn('department_number', $deptCodes)
+ ->select('department_number', 'department_name', 'appointment_enabled', 'department_status', 'is_del')
+ ->get();
+
+ foreach ($departments as $dept) {
+ // 收集科室名称(用于前端提示消息)
+ if (!empty($dept->department_name)) {
+ $resourceItemPairs[] = [
+ 'resource_name' => $dept->department_name,
+ 'item_name' => $checkItemRaw->item_name,
+ ];
+ }
+ // 判断科室是否参与预约
+ if ($dept->appointment_enabled == 1 && $dept->department_status == 1 && $dept->is_del == 0) {
+ $deptAvailable = true;
+ }
+ }
+ }
+ }
+
+ // 是否有设备
+ $hasDevice = count($ii) > 0 && !empty($ii[0]->device_id);
+
+ // 链路B:通过设备反查诊室资源是否有效
+ $resourceAvailable = false;
+ if ($hasDevice) {
+ $deviceIds = $ii->pluck('device_id')->filter()->unique()->values()->toArray();
+ $deptIds = DB::table('s_department_resources_device')
+ ->whereIn('device_id', $deviceIds)
+ ->pluck('department_id')
+ ->unique()
+ ->values()
+ ->toArray();
+
+ if (!empty($deptIds)) {
+ $resourceCount = DB::table('s_department_resources')
+ ->where(function($q) use ($deptIds) {
+ $q->whereIn('department_id', $deptIds)
+ ->orWhereIn('execute_department_id', $deptIds);
+ })
+ ->where('appointment_enabled', 1)
+ ->where('department_resources_status', 1)
+ ->where('is_del', 0)
+ ->count();
+ $resourceAvailable = $resourceCount > 0;
+ }
+ }
+
+ // 分类归入对应数组
+ $entry = [
+ 'maininfo' => $value,
+ 'iteminfo' => $ii,
+ 'msg' => $msg,
];
+
+ if (!empty($resourceItemPairs)) {
+ if (!$deptAvailable) {
+ $noDeptInfo = array_merge($noDeptInfo, $resourceItemPairs);
+ } elseif ($hasDevice && !$resourceAvailable) {
+ $noDeptInfo = array_merge($noDeptInfo, $resourceItemPairs);
+ } elseif (!$hasDevice) {
+ $noScheduleInfo = array_merge($noScheduleInfo, $resourceItemPairs);
+ } else {
+ $itemInfo[] = $entry;
+ }
+ } else {
+ $itemInfo[] = $entry;
+ }
}
- return \Yz::Return(true,'查询完成',['today_date'=>date("Y-m-d"),'info'=>$itemInfo]);
+ return \Yz::Return(true,'查询完成',[
+ 'today_date' => date("Y-m-d"),
+ 'info' => $itemInfo,
+ 'no_appointment_dept' => $noDeptInfo,
+ 'no_schedule' => $noScheduleInfo,
+ ]);
}
public function GetList(Request $request)
{
diff --git a/Laravel/app/Http/Controllers/API/Third/YiJiController.php b/Laravel/app/Http/Controllers/API/Third/YiJiController.php
index 0050219..91e0e0b 100644
--- a/Laravel/app/Http/Controllers/API/Third/YiJiController.php
+++ b/Laravel/app/Http/Controllers/API/Third/YiJiController.php
@@ -149,6 +149,16 @@ public function CheckAppointment()
+ // ====== HIS 执行科室可预约性检查 ======
+ $deptCheckResult = $this->classifyCheckItemsByDept($termCodes);
+ if (empty($deptCheckResult['normal'])) {
+ return \Yz::JsonReturn(true, '查询成功', [
+ 'is_redirect' => false,
+ 'url' => '',
+ 'room_names' => [],
+ ]);
+ }
+
// 检查是否有诊室参与预约
$termCodes = array_unique($termCodes);
$execDeptCodes = array_unique($execDeptCodes);
@@ -536,6 +546,149 @@ function build_yiji_url($regnum, $entrustid, $episodeid)
return "http://192.168.80.76/yiji?$query";
}
+ /**
+ * 根据项目编号数组,检查各项目对应的 HIS 执行科室是否可预约
+ * 存在至少一个满足条件的科室(appointment_enabled=1, department_status=1, is_del=0)
+ * 则该项目归入 normal 数组,否则归入 disabled 数组
+ * @param array $entrustCodes 项目编号数组
+ * @return array ['normal' => [...], 'disabled' => [...]]
+ */
+ private function classifyCheckItemsByDept(array $entrustCodes)
+ {
+ $normal = [];
+ $disabled = [];
+
+ if (empty($entrustCodes)) {
+ return ['normal' => $normal, 'disabled' => $disabled];
+ }
+
+ // 去重
+ $entrustCodes = array_unique($entrustCodes);
+
+ // 批量查询检查项目
+ $items = DB::table('s_check_item')
+ ->whereIn('item_code', $entrustCodes)
+ ->select('item_code', 'item_name', 'hisExecDepts')
+ ->get()
+ ->keyBy('item_code');
+
+ // 收集所有需要查询的科室编号
+ $allDeptCodes = [];
+ $itemDeptMap = []; // item_code => ['item_name' => ..., 'dept_codes' => [...]]
+
+ foreach ($entrustCodes as $code) {
+ if (!isset($items[$code])) {
+ // 查不到记录 → 非预约
+ $disabled[] = [
+ 'entrust_code' => $code,
+ 'item_name' => '',
+ 'depts' => [],
+ 'has_normal_dept' => false,
+ ];
+ continue;
+ }
+
+ $item = $items[$code];
+ $hisExecDepts = $item->hisExecDepts;
+
+ if (empty($hisExecDepts)) {
+ // hisExecDepts 为空或 null → 非预约
+ $disabled[] = [
+ 'entrust_code' => $code,
+ 'item_name' => $item->item_name,
+ 'depts' => [],
+ 'has_normal_dept' => false,
+ ];
+ continue;
+ }
+
+ $deptCodes = json_decode($hisExecDepts, true);
+ if (empty($deptCodes) || !is_array($deptCodes)) {
+ // 解析失败或为空 → 非预约
+ $disabled[] = [
+ 'entrust_code' => $code,
+ 'item_name' => $item->item_name,
+ 'depts' => [],
+ 'has_normal_dept' => false,
+ ];
+ continue;
+ }
+
+ $itemDeptMap[$code] = [
+ 'item_name' => $item->item_name,
+ 'dept_codes' => $deptCodes,
+ ];
+ $allDeptCodes = array_merge($allDeptCodes, $deptCodes);
+ }
+
+ if (empty($allDeptCodes)) {
+ return ['normal' => $normal, 'disabled' => $disabled];
+ }
+
+ // 批量查询科室信息
+ $allDeptCodes = array_unique($allDeptCodes);
+ $departments = DB::table('s_department')
+ ->whereIn('department_number', $allDeptCodes)
+ ->select('department_number', 'department_name', 'appointment_enabled', 'department_status', 'is_del')
+ ->get()
+ ->keyBy('department_number');
+
+ // 遍历每个项目,判断科室状态
+ foreach ($itemDeptMap as $code => $info) {
+ $deptList = [];
+ $hasNormal = false;
+
+ foreach ($info['dept_codes'] as $deptCode) {
+ if (!isset($departments[$deptCode])) {
+ // 科室不存在 → 算非预约
+ $deptList[] = [
+ 'dept_code' => $deptCode,
+ 'dept_name' => '',
+ 'status' => 'disabled',
+ 'reason' => '科室不存在',
+ ];
+ continue;
+ }
+
+ $dept = $departments[$deptCode];
+ $isNormal = $dept->appointment_enabled == 1
+ && $dept->department_status == 1
+ && $dept->is_del == 0;
+
+ $reasons = [];
+ if ($dept->appointment_enabled != 1) $reasons[] = 'appointment_enabled=' . $dept->appointment_enabled;
+ if ($dept->department_status != 1) $reasons[] = 'department_status=' . $dept->department_status;
+ if ($dept->is_del != 0) $reasons[] = 'is_del=' . $dept->is_del;
+
+ $deptList[] = [
+ 'dept_code' => $deptCode,
+ 'dept_name' => $dept->department_name,
+ 'status' => $isNormal ? 'normal' : 'disabled',
+ 'reason' => $isNormal ? '' : implode(', ', $reasons),
+ ];
+
+ if ($isNormal) {
+ $hasNormal = true;
+ }
+ }
+
+ $entry = [
+ 'entrust_code' => $code,
+ 'item_name' => $info['item_name'],
+ 'depts' => $deptList,
+ 'has_normal_dept' => $hasNormal,
+ ];
+
+ if ($hasNormal) {
+ $normal[] = $entry;
+ } else {
+ $disabled[] = $entry;
+ }
+ }
+
+ return ['normal' => $normal, 'disabled' => $disabled];
+ }
+
/**
* 测试获取申请单详情
* 入参: visitSqNo, requestNo, visitTypeCode(HIS 格式)
diff --git a/YiJi-admin/src/components/Yewu/YuYue202506.vue b/YiJi-admin/src/components/Yewu/YuYue202506.vue
index dbd41c5..d1b7f1f 100644
--- a/YiJi-admin/src/components/Yewu/YuYue202506.vue
+++ b/YiJi-admin/src/components/Yewu/YuYue202506.vue
@@ -17,6 +17,16 @@
患者所有检查项目未预约至同一天,请注意是否需手动调整预约
+