|
|
|
|
@ -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 格式)
|
|
|
|
|
|