leftJoin('s_period', 's_list.reservation_time', '=', 's_period.id') ->select( "list_status", "is_nullify", "reg_num", "user_name", "user_sex", "user_brithday", "user_phone", "entrust_code", "entrust", "is_pay", "reservation_department", "entrust_date", "entrust_time", "docotr as doctor", "patient_type", "implement_department", "entrust_id", "episodeid", "RISRAcceptDeptCode", "reservation_date", 's_period.period_begin_time as reservation_time', "canel_time as cancel_time", "warddesc", "wardcode", "bedname", "bedno", "app_num", "medicalHistory", "diagnosisName", "idCardNumber", "reservation_sources as reservation_sources_id", "reservation_department_code", "doctor_code", )->where('s_list.reservation_date', $queryDate) ->where('s_list.is_del', 0) ->where('s_list.is_nullify', 0) ->where(function($q) { $q->where('patient_type', 0) // 住院类型不限制支付状态 ->orWhere('is_pay', 1); // 其他类型必须已支付 }); if(isset($dateRange)){ if(!is_array($dateRange)) return \Yz::JsonError("日期范围必须是数组"); $entrust_list=$entrust_list->whereBetween('entrust_date',[$dateRange[0],$dateRange[1]]); } if(isset($orderNo)){ $entrust_list=$entrust_list->where('entrust_id',$orderNo); } if(isset($visitSqNo)){ $entrust_list=$entrust_list->where('episodeid',$visitSqNo); } if(isset($requestNo)){ $entrust_list=$entrust_list->where('app_num',$requestNo); } if(isset($idCardNumber)){ $entrust_list=$entrust_list->where('idCardNumber',$idCardNumber); } if(isset($visitNo)){ $entrust_list=$entrust_list->where(function($q) use ($visitNo) { $q->where('reg_num', $visitNo) ->where('patient_type', 1) ->orWhere(function($q2) use ($visitNo) { $q2->where('episodeid', 'ZY001' . $visitNo) ->where('patient_type', 0); }); }); } $entrust_list=$entrust_list->get(); foreach ($entrust_list as $entrust) { $entrust->reservation_sources_name=null; $source = null; if(!empty($entrust->reservation_sources_id)){ $source=DB::table('s_department_resources') ->where('id',$entrust->reservation_sources_id) ->first(); if(!!$source){ $parts = explode('-', $source->department_resources_name); $entrust->reservation_sources_name = $parts[0]; } } // 组装 info 字段 $entrust->info = [ 'deptId' => '', 'deptName' => '', 'roomId' => '', 'roomName' => '', 'scheduleName' => '', 'reservationDepartmentCode' => (string)($entrust->reservation_department_code ?? ''), 'reservationDepartment' => (string)($entrust->reservation_department ?? ''), 'entrustCode' => (string)($entrust->entrust_code ?? ''), 'entrust' => (string)($entrust->entrust ?? ''), 'doctorCode' => (string)($entrust->doctor_code ?? ''), 'doctor' => (string)($entrust->doctor ?? ''), 'implementDepartment' => (string)($entrust->implement_department ?? ''), 'wardcode' => (string)($entrust->wardcode ?? ''), 'warddesc' => (string)($entrust->warddesc ?? ''), 'RISRAcceptDeptCode' => (string)($entrust->RISRAcceptDeptCode ?? ''), ]; if (!empty($entrust->RISRAcceptDeptCode)) { $deptRoom = DB::table('s_department') ->where('department_number', $entrust->RISRAcceptDeptCode) ->where('is_del', 0) ->first(); if ($deptRoom) { $entrust->info['roomId'] = (string)$deptRoom->id; $entrust->info['roomName'] = (string)$deptRoom->department_name; if ($deptRoom->pid == 0) { $entrust->info['deptId'] = (string)$deptRoom->id; $entrust->info['deptName'] = (string)$deptRoom->department_name; } else { $deptParent = DB::table('s_department') ->where('id', $deptRoom->pid) ->where('is_del', 0) ->first(); $entrust->info['deptId'] = (string)($deptParent->id ?? $deptRoom->id); $entrust->info['deptName'] = (string)($deptParent->department_name ?? $deptRoom->department_name); } } } if ($source) { $entrust->info['scheduleName'] = (string)$source->department_resources_name; } $entrust->requestTypeCode=''; $entrust->requestTypeName=''; $entrust->orderDeptCode=''; $res = HisController::GetApplyDetail($entrust->episodeid, $entrust->app_num, $entrust->patient_type, '本地'); if ($res['code'] == 200) { foreach ($res['data'] as $data_v) { $entrust->requestTypeCode=$data_v['requestTypeCode']; $entrust->requestTypeName=$data_v['requestTypeName']; $entrust->orderDeptCode=$data_v['orderDeptCode']; } } } return \Yz::JsonReturn(true,'查询完成',$entrust_list); } //报到机调用此接口通知已经报道 public function SignIn(){ $orderNo = request('orderNo');//医嘱号 $checkNo = request('checkNo');//报道号(检查号) if(!isset($orderNo)) return \Yz::JsonError('医嘱号不能为空'); if(!isset($checkNo)) return \Yz::JsonError('报道号不能为空'); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo,'is_nullify'=>0,'is_del'=>0])->first(); if(!$entrust) return \Yz::JsonError('未找到对应医嘱'); if($entrust->list_status <> 1) return \Yz::JsonError('医嘱当前状态无法报道'); $data = [ 'list_status' => 2, 'check_num' => $checkNo, ]; $u = DB::table('s_list')->where(['entrust_id' => $orderNo])->update($data); if($u){ $i_log = DB::table('s_list_log')->insert([ 'list_id' =>$entrust->id, 'reg_num' => $entrust->reg_num, 'old_status' => $entrust->list_status, 'new_status' => 2, 'create_user' => '报到机接口', 'note' => '报到成功', 'data' => json_encode(['checkNo'=>$checkNo],JSON_UNESCAPED_UNICODE) ]); //通知pacs $pacs=new CSharpController(); $pacs_res=$pacs->SaveApply($entrust->entrust_id); $i_log = DB::table('s_list_log')->insert([ 'list_id' =>$entrust->id, 'reg_num' => $entrust->reg_num, 'old_status' => $entrust->list_status, 'new_status' => 2, 'create_user' => 'Pacs接口', 'note' => '通知PacS', 'data' => json_encode($pacs_res,JSON_UNESCAPED_UNICODE) ]); if (!!$pacs_res['status']) { return \Yz::JsonReturn(true, '报道成功', ['orderNo' => $orderNo, 'pacs_info' => $pacs_res]); } else { $data = [ 'list_status' => 1, 'check_num' => '', ]; $u = DB::table('s_list')->where(['entrust_id' => $orderNo])->update($data); $i_log = DB::table('s_list_log')->insert([ 'list_id' => $entrust->id, 'reg_num' => $entrust->reg_num, 'old_status' => 2, 'new_status' => 1, 'create_user' => 'Pacs接口', 'note' => '通知Pacs失败', 'data' => json_encode(['checkNo' => $checkNo], JSON_UNESCAPED_UNICODE) ]); return \Yz::JsonReturn(false, '报道失败', ['orderNo' => $orderNo, 'pacs_info' => $pacs_res]); } }else{ return \Yz::JsonError('报道失败'); } } //报到机调用此接口通知取消报道 public function CancelSignIn(){ $orderNo = request('orderNo'); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo,'is_nullify'=>0,'is_del'=>0])->first(); if(!$entrust) return \Yz::JsonError('未找到对应医嘱'); if($entrust->list_status <> 2) return \Yz::JsonError('医嘱当前状态无法取消报道'); $data = [ 'list_status' => 1, 'check_num' => '', ]; $u = DB::table('s_list')->where(['entrust_id' => $orderNo])->update($data); if($u){ return \Yz::JsonReturn(true,'取消报道成功',['orderNo'=>$orderNo]); }else{ return \Yz::JsonError('取消报道失败'); } } //Pacs调用此接口通知已经报道 给Pacs用,通知本系统到检(场景,不经过报到机直接人工窗口) public function SignInOnPacs(){ $orderNo = request('orderNo');//医嘱号 $checkNo = request('checkNo');//报道号(检查号) $type = request('type');//签到 或 完成 if(!isset($orderNo)) return \Yz::JsonReturn(true, '成功', ['warn' => '医嘱号不能为空']); if(!isset($checkNo)) return \Yz::JsonReturn(true, '成功', ['warn' => '报道号不能为空']); $targetStatus = ($type === '完成') ? 3 : 2; $allowedStatus = ($type === '完成') ? [0, 1, 2] : [0, 1]; $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo,'is_nullify'=>0,'is_del'=>0])->first(); if(!$entrust) return \Yz::JsonReturn(true, '成功', ['warn' => '未找到对应医嘱']); if(!in_array($entrust->list_status, $allowedStatus)) return \Yz::JsonReturn(true, '成功', ['warn' => '医嘱当前状态无法操作']); $data = [ 'list_status' => $targetStatus, 'check_num' => $checkNo, ]; $u = DB::table('s_list')->where(['entrust_id' => $orderNo])->update($data); if($u){ $note = ($type === '完成') ? '完成' : '报到成功'; $createUser = ($type === '完成') ? 'Pacs完成' : 'Pacs通知'; $i_log = DB::table('s_list_log')->insert([ 'list_id' =>$entrust->id, 'reg_num' => $entrust->reg_num, 'old_status' => $entrust->list_status, 'new_status' => $targetStatus, 'create_user' => $createUser, 'note' => $note, 'data' => json_encode(['checkNo'=>$checkNo, 'type'=>$type],JSON_UNESCAPED_UNICODE) ]); return \Yz::JsonReturn(true, $note, ['orderNo'=>$orderNo]); }else{ return \Yz::JsonReturn(true, '成功', ['warn' => '操作失败']); } } //Pacs调用此接口通知已经报道(测试接口,不修改数据) public function SignInOnPacsTest(){ $orderNo = request('orderNo');//医嘱号 $checkNo = request('checkNo');//报道号(检查号) if(!isset($orderNo)) return \Yz::JsonError('医嘱号不能为空'); if(!isset($checkNo)) return \Yz::JsonError('报道号不能为空'); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo,'is_nullify'=>0,'is_del'=>0])->first(); if(!$entrust) return \Yz::JsonError('未找到对应医嘱'); if(!in_array($entrust->list_status, [0, 1])) return \Yz::JsonError('医嘱当前状态无法报道'); return \Yz::JsonReturn(true,'报道成功(测试)',['orderNo'=>$orderNo,'checkNo'=>$checkNo,'entrust'=>$entrust]); } //Pacs调用此接口通知取消报道 给Pacs用,通知本系统取消报道(场景,不经过报到机直接人工窗口) public function CancelSignInOnPacs(){ $orderNo = request('orderNo'); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo,'is_nullify'=>0,'is_del'=>0])->first(); if(!$entrust) return \Yz::JsonReturn(true, '成功', ['warn' => '未找到对应医嘱']); if(!in_array($entrust->list_status, [2, 3])) return \Yz::JsonReturn(true, '成功', ['warn' => '医嘱当前状态无法取消报道']); $newStatus = $entrust->reservation_date ? 1 : 0; $data = [ 'list_status' => $newStatus, 'check_num' => '', ]; $u = DB::table('s_list')->where(['entrust_id' => $orderNo])->update($data); if($u){ return \Yz::JsonReturn(true,'取消报道成功',['orderNo'=>$orderNo]); }else{ return \Yz::JsonReturn(true, '成功', ['warn' => '取消报道失败']); } } //条形码测试接口 public function BarcodeTest() { $code = request('code'); if (empty($code)) { return \Yz::JsonError('code 不能为空'); } $generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); $barcode = $generator->getBarcode($code, $generator::TYPE_CODE_128, 2, 40); return response($barcode)->header('Content-Type', 'image/png'); } }