query('orderNo'); $res = $this->SaveApply($orderNo); return \Yz::JsonReturn($res['status'],$res['msg'],$res['data']); } // 测试接口:查看即将推送给PACS的数据(不推送、不写日志、不操作数据) public function PacsSaveApplyInfoTest(Request $request) { $orderNo = $request->query('orderNo'); if (empty($orderNo)) { return \Yz::JsonReturn(false, 'orderNo 不能为空', []); } $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo, 'list_status' => 2, 'is_nullify' => 0])->first(); $reservation_time = ''; $reservation_end_time = ''; if (isset($entrust->roster_id) and !empty($entrust->roster_id)) { $plan = DB::table('s_source_roster_detail')->where(['id' => $entrust->roster_id])->first(); if (!!$plan) { $reservation_time = $plan->begin_time; $reservation_end_time = $plan->end_time; } } if ($entrust) { // 查询 HIS 获取检查申请单 $hisInfo = []; $res = HisController::GetApplyDetail($entrust->episodeid, $entrust->app_num, $entrust->patient_type, '本地'); if ($res['code'] == 200) { $res_data = $res['data']; foreach ($res_data as $data_k => $data_v) { $hisInfo = $data_v; } } $patientTypeMap = [ 0 => 'I', // I - 住院 1 => 'O', // O - 门诊 2 => 'E', // E - 急诊 3 => 'H', // H - 体检 ]; $jiuzhenliushuihao = [ 0 => $hisInfo['cardNo'] ?? '', // I - 住院 1 => $entrust->episodeid, // O - 门诊 2 => $hisInfo['cardNo'] ?? '', // E - 急诊 3 => $hisInfo['cardNo'] ?? '', // H - 体检 ]; $guid = Str::uuid()->toString(); $sex = 'U'; if ($entrust->user_sex == 1) $sex = 'M'; if ($entrust->user_sex == 2) $sex = 'F'; $hisiteminfo = collect($hisInfo['itemList'] ?? [])->firstWhere('termCode', $entrust->entrust_code); // 获取顶级科室名称 $deptName = ''; if (!empty($entrust->department_id)) { $execDept = DB::table('s_department')->where('id', $entrust->department_id)->where('is_del', 0)->first(); if ($execDept) { if ($execDept->pid == 0) { $deptName = $execDept->department_name; } else { $topDept = DB::table('s_department')->where('id', $execDept->pid)->where('is_del', 0)->first(); $deptName = $topDept->department_name ?? ''; } } } $send_data = [ 'Request' => [ 'Head' => [ 'TradeCode' => 'SaveApplyInfo', 'TradeTime' => date('Y-m-d H:i:s'), 'TradeNo' => $guid, 'BranchCode' => '01', 'HospitalCode' => '01' ], 'Body' => [ 'patientinfo' => [ 'patientid' => $entrust->reg_num, 'patientname' => $entrust->user_name, 'patientsex' => $sex, 'patientbirthday' => $entrust->user_brithday, 'age' => \Tools::calculateAge($entrust->user_brithday), 'height' => '', 'weight' => '', 'identifyid' => $entrust->idCardNumber, 'healthcard' => '', 'insurance_type' => '', 'mobilephone' => $entrust->user_phone, 'home_detail_address' => $hisInfo['address'] ?? '', 'visitinfo' => [ 'visitsqno' => $entrust->episodeid, 'inpatientno' => substr($entrust->episodeid, -10), 'outpatientno' => $jiuzhenliushuihao[$entrust->patient_type], 'caseno' => $hisInfo['markNo'] ?? '', 'source' => $patientTypeMap[$entrust->patient_type], 'hospitalization_count' => '', 'bed_no' => $hisInfo['bedNo'] ?? '', 'roomnumber' => '', 'inpatientareacode' => $hisInfo['areaCode'] ?? '', 'inpatientarea' => $hisInfo['areaName'] ?? '', ], 'applyinfo' => [ 'accessionnumber' => $entrust->app_num, 'hisapplytime' => $hisInfo['requestDate'] ?? '', 'hisapplydeptcode' => $hisInfo['orderDeptCode'] ?? '', 'hisapplydept' => $hisInfo['orderDeptName'] ?? '', 'hisapplydoctorcode' => $hisInfo['orderPersonCode'] ?? '', 'hisapplydoctor' => $hisInfo['orderPersonName'] ?? '', 'diagnosis' => $entrust->diagnosisName, 'isemergency' => $entrust->his_is_emergency, 'isarmyman' => $hisInfo['armyFlag'] ?? '', 'vip_indicator' => $hisInfo['vipFlag'] ?? '', 'applyorderinfo' => [ 'orderno' => $entrust->entrust_id, 'appoint_date' => $entrust->reservation_date . ' ' . substr($reservation_time, 0, 5), 'register_date' => $entrust->reservation_date . ' ' . substr($reservation_end_time, 0, 5), 'bodypartexamined' => $hisiteminfo['examPosiSmallName'] ?? '', 'medical_history' => $hisInfo['medicalHistory'], 'dept_name' => $deptName, 'studyclass1' => $hisInfo['requestTypeAlias'] ?? '', 'studyclass1his' => $hisiteminfo['execDeptName'] ?? '', 'studyclass1name' => $hisiteminfo['execDeptName'] ?? '', 'studyclass2hiscode' => $hisiteminfo['termCode'] ?? '', 'studyclass2his' => $hisiteminfo['termName'] ?? '', 'checkitemcode' => $entrust->entrust_code, 'checkitemname' => $entrust->entrust, 'factprice' => $hisInfo['itemList'][0]['itemCost'] ?? '', ], ] ] ] ] ]; return \Yz::JsonReturn(true, '测试数据(未推送)', ['send_data' => $send_data]); } else { return \Yz::JsonReturn(false, '医嘱不存在', []); } } //通知pacs 检查申请单推送 public function SaveApply($orderNo) { if(config('app.globals.是否推送Pacs')==0){ return ['status'=>false,'msg'=>'推送Pacs未开启','data'=>[]]; } Log::info('推送申请单'.$orderNo); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo, 'list_status' => 2, 'is_nullify' => 0])->first(); $reservation_time=''; $reservation_end_time=''; if(isset($entrust->roster_id) and !empty($entrust->roster_id)){ $plan= DB::table('s_source_roster_detail')->where(['id' => $entrust->roster_id])->first(); if(!!$plan){ $reservation_time=$plan->begin_time; $reservation_end_time=$plan->end_time; } } if ($entrust) { //查询his获取检查申请单 $hisInfo=[]; $res = HisController::GetApplyDetail($entrust->episodeid, $entrust->app_num, $entrust->patient_type, '本地'); if ($res['code'] == 200) { $res_data = $res['data']; foreach ($res_data as $data_k => $data_v) { $hisInfo=$data_v; } } $patientTypeMap = [ 0 => 'I', // I - 住院 1 => 'O', // O - 门诊 2 => 'E', // E - 急诊 3 => 'H', // H - 体检 ]; $jiuzhenliushuihao = [ 0 => $hisInfo['cardNo'] ?? '', // I - 住院 1 => $entrust->episodeid, // O - 门诊 2 => $hisInfo['cardNo'] ?? '', // E - 急诊 3 => $hisInfo['cardNo'] ?? '', // H - 体检 ]; $guid = Str::uuid()->toString(); $sex = 'U'; if ($entrust->user_sex == 1) $sex = 'M'; if ($entrust->user_sex == 2) $sex = 'F'; $hisiteminfo = collect($hisInfo['itemList']??[])->firstWhere('termCode', $entrust->entrust_code); // 获取顶级科室名称 $deptName = ''; if (!empty($entrust->department_id)) { $execDept = DB::table('s_department')->where('id', $entrust->department_id)->where('is_del', 0)->first(); if ($execDept) { if ($execDept->pid == 0) { $deptName = $execDept->department_name; } else { $topDept = DB::table('s_department')->where('id', $execDept->pid)->where('is_del', 0)->first(); $deptName = $topDept->department_name ?? ''; } } } $send_data = [ 'Request' => [ 'Head' => [ 'TradeCode' => 'SaveApplyInfo', 'TradeTime' => date('Y-m-d H:i:s'), 'TradeNo' => $guid, 'BranchCode' => '01', 'HospitalCode' => '01' ], 'Body' => [ 'patientinfo' => [ 'patientid' => $entrust->reg_num, 'patientname' => $entrust->user_name, 'patientsex' => $sex, 'patientbirthday' => $entrust->user_brithday, 'age' => \Tools::calculateAge($entrust->user_brithday), 'height' => '', 'weight' => '', 'identifyid' => $entrust->idCardNumber, 'healthcard' => '', 'insurance_type' => '', 'mobilephone' => $entrust->user_phone, 'home_detail_address'=>$hisInfo['address']??'', 'visitinfo' => [ 'visitsqno' => $entrust->episodeid, 'inpatientno'=>substr($entrust->episodeid, -10), // 取 visitsqno 后10位 'outpatientno' => $jiuzhenliushuihao[$entrust->patient_type], 'caseno'=>$hisInfo['markNo']??'', 'source' => $patientTypeMap[$entrust->patient_type], 'hospitalization_count' => '', 'bed_no' => $hisInfo['bedNo']??'', 'roomnumber' => '', 'inpatientareacode' => $hisInfo['areaCode']??'', 'inpatientarea' => $hisInfo['areaName']??'', ], 'applyinfo' => [ 'accessionnumber' => $entrust->app_num, 'hisapplytime' => $hisInfo['requestDate']??'', 'hisapplydeptcode'=> $hisInfo['orderDeptCode']??'', 'hisapplydept'=> $hisInfo['orderDeptName']??'', 'hisapplydoctorcode'=> $hisInfo['orderPersonCode']??'', 'hisapplydoctor'=> $hisInfo['orderPersonName']??'', 'diagnosis'=> $entrust->diagnosisName, 'isemergency'=> $entrust->his_is_emergency, 'isarmyman'=> $hisInfo['armyFlag']??'', 'vip_indicator'=> $hisInfo['vipFlag']??'', 'applyorderinfo' => [ 'orderno' => $entrust->entrust_id, 'appoint_date' => $entrust->reservation_date . ' ' . substr($reservation_time, 0, 5), 'register_date' => $entrust->reservation_date . ' ' . substr($reservation_end_time, 0, 5), 'bodypartexamined' => $hisiteminfo['examPosiSmallName']??'', 'medical_history' => $hisInfo['medicalHistory'], 'dept_name' => $deptName, 'studyclass1' => $hisInfo['requestTypeAlias']??'', 'studyclass1his' => $hisiteminfo['execDeptName']??'', 'studyclass1name' => $hisiteminfo['execDeptName']??'', 'studyclass2hiscode' => $hisiteminfo['termCode']??'', 'studyclass2his' => $hisiteminfo['termName']??'', 'checkitemcode' => $entrust->entrust_code, 'checkitemname' => $entrust->entrust, 'factprice' =>$hisInfo['itemList'][0]['itemCost']??'', ], ] // 'hisinfo'=>$hisInfo ] ] ] ]; self::RequestLog(self::$Url, $send_data, "推送检查申请单", 'PACS接口'); $response = Http::post(self::$Url, $send_data); if (!$response->successful()) { self::$request->response_data = "请求PACS接口失败"; self::$request->save(); return ['status'=>false,'msg'=>'请求PACS接口失败','data'=>[]]; } // 处理成功的响应 $res_string = json_encode($response->json(), JSON_UNESCAPED_UNICODE); // dd($res_string); $str_len = mb_strlen($res_string, 'utf-8'); $str_size = $str_len / 1024; $save_res = $res_string; if ($str_size > 10) $save_res = '{"data":"Row size too large"}'; self::$request->response_data = $save_res; self::$request->save(); $res = json_decode($res_string, true); if (isset($res['Response']['Head']['TradeStatus']) and $res['Response']['Head']['TradeStatus'] == 'AA') { return ['status'=>true,'msg'=>'PACS推送成功','data'=>['entrust_id' => $entrust->entrust_id,'res'=>$res]]; } else { return ['status'=>false,'msg'=>'PACS推送失败','data'=>[]]; } } else { return ['status'=>false,'msg'=>'医嘱不存在','data'=>[]]; } } public function PacsCancelApplyInfo(Request $request) { $orderNo = $request->query('orderNo');//医嘱号 $res=$this->CancelApply($orderNo); return \Yz::JsonReturn($res['status'],$res['msg'],$res['data']); } //检查申请单撤销 public function CancelApply ($orderNo) { if(config('app.globals.是否推送Pacs')==0){ return ['status'=>false,'msg'=>'推送Pacs未开启','data'=>[]]; } Log::info('撤销推送申请单'.$orderNo); $entrust = DB::table('s_list')->where(['entrust_id' => $orderNo])->first(); if ($entrust) { // 医嘱作废:清理预约字段并释放号源 if ($entrust->is_nullify == 1 && $entrust->list_status != 0 && $entrust->roster_id) { $rosterId = $entrust->roster_id; $nowdatetime = date('Y-m-d H:i:s'); $clearData = [ 'list_status' => 0, 'reservation_date' => null, 'reservation_time' => null, 'reservation_sources' => null, 'services_group' => null, 'roster_id' => null, 'xuhao' => null, 'department_id' => null, 'appointment_type_id' => null, 'appointment_use_plan_detail' => null, 'canel_time' => $nowdatetime, 'is_emergency' => 0, 'updated_at' => $nowdatetime, ]; try { DB::beginTransaction(); DB::table('s_list')->where('id', $entrust->id)->update($clearData); $planService = new PlanListService(); $planService->correctUsedCount($rosterId); DB::table('s_list_log')->insert([ 'list_id' => $entrust->id, 'reg_num' => $entrust->reg_num, 'old_status' => $entrust->list_status, 'new_status' => 0, 'create_user' => 'MQ', 'note' => '医嘱作废', 'data' => json_encode($clearData, JSON_UNESCAPED_UNICODE), ]); DB::commit(); } catch (\Exception $e) { DB::rollBack(); Log::error('医嘱作废清理失败: ' . $e->getMessage(), ['entrust_id' => $orderNo]); } } $guid = Str::uuid()->toString(); $send_data = [ 'Request' => [ 'Head' => [ 'TradeCode' => 'CancelApplyInfo', 'TradeTime' => date('Y-m-d H:i:s'), 'TradeNo' => $guid, 'BranchCode' => '01', 'HospitalCode' => '01' ], 'Body' => [ 'patientinfo' => [ 'patientid' => $entrust->reg_num, ], 'applyinfo' => [ 'accessionnumber' => $entrust->app_num, ] ] ] ]; self::RequestLog(self::$Url, $send_data, "撤销检查申请单", 'PACS接口'); $response = Http::post(self::$Url, $send_data); if (!$response->successful()) { self::$request->response_data = "请求PACS接口失败"; self::$request->save(); return ['status'=>false,'msg'=>'请求PACS接口失败','data'=>[]]; } // 处理成功的响应 $res_string = json_encode($response->json(), JSON_UNESCAPED_UNICODE); // dd($res_string); $str_len = mb_strlen($res_string, 'utf-8'); $str_size = $str_len / 1024; $save_res = $res_string; if ($str_size > 10) $save_res = '{"data":"Row size too large"}'; self::$request->response_data = $save_res; self::$request->save(); $res = json_decode($res_string, true); if (isset($res['Response']['Head']['TradeStatus']) and $res['Response']['Head']['TradeStatus'] == 'AA') { return ['status'=>true,'msg'=>'推送成功','data'=>['entrust_id' => $entrust->entrust_id]]; } else { return ['status'=>false,'msg'=>'撤销失败','data'=>[]]; } } else { return ['status'=>false,'msg'=>'医嘱不存在','data'=>[]]; } } public static function RequestLog($url, $post_data, $mark, $code = 0) { self::CheckTableName(); foreach ($post_data as $key => $post_datum) { $str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE), 'utf-8'); $str_size = $str_len / 1024; if ($str_size > 10) { $post_data["$key"] = 'Row size too large'; } } $post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE); self::$request->code = $code; self::$request->mark = $mark; self::$request->post_data = $post_data == '[]' ? '{}' : $post_data; self::$request->request_url = $url; self::$request->save(); } public static function CheckTableName() { $table_name = 'zz_peis_log_' . date('ym'); $table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0]; if ($table_count->c === 0) { Schema::create($table_name, function (Blueprint $table) { $table->id(); $table->string('code', 50)->index(); $table->string('mark', 50)->index(); $table->text('post_data'); $table->text('response_data')->nullable(); $table->string('request_url', 2000); $table->timestamps(); }); } self::$request = new \App\Models\PEISLog(); self::$request->setTable($table_name); } }