|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\API\Third;
|
|
|
|
|
|
use App\Http\Controllers\API\His\HisController;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class PacsController extends Controller
|
|
|
{
|
|
|
//报到机调用此接口查询预约的记录
|
|
|
public function GetEntrustInfo(){
|
|
|
$orderNo = request('orderNo');//医嘱号
|
|
|
$idCardNumber = request('idCardNumber');//身份证
|
|
|
$visitSqNo = request('visitSqNo');//门诊挂号流水号/住院流水号
|
|
|
$dateRange = request('dateRange');//医嘱开单日期
|
|
|
$requestNo = request('requestNo');//申请单号
|
|
|
$visitNo = request('visitNo');//通用查询编号:门诊查reg_num,住院查episodeid
|
|
|
$dev = request('dev');//开发调试模式
|
|
|
$testdate = request('testdate');//测试日期
|
|
|
// 判断所有字段是否都为空
|
|
|
if (empty($orderNo) && empty($idCardNumber) && empty($visitSqNo) && empty($dateRange) && empty($requestNo) && empty($visitNo)) {
|
|
|
return \Yz::JsonError("缺失查询条件");
|
|
|
}
|
|
|
|
|
|
$queryDate = date('Y-m-d');
|
|
|
if ($dev == 1 && !empty($testdate)) {
|
|
|
$queryDate = $testdate;
|
|
|
}
|
|
|
$entrust_list=DB::table('s_list')
|
|
|
->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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$His = new HisController();
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
$patientHisTypeMap = [
|
|
|
0 => '03', // I - 住院
|
|
|
1 => '01', // O - 门诊
|
|
|
2 => '02', // E - 急诊
|
|
|
3 => '04', // H - 体检
|
|
|
];
|
|
|
$sendHisData = [
|
|
|
'visitSqNo' => $entrust->episodeid,
|
|
|
'requestNo' => $entrust->app_num,
|
|
|
'visitTypeCode' => $patientHisTypeMap[$entrust->patient_type],
|
|
|
'feeFlag' => $entrust->is_pay == 0 ? 0 : 1, // 住院=0,其他=1
|
|
|
];
|
|
|
$entrust->requestTypeCode='';
|
|
|
$entrust->requestTypeName='';
|
|
|
$entrust->orderDeptCode='';
|
|
|
$res = $His::Get("查询检查申请单", $sendHisData);
|
|
|
if ($res['code'] == 200) {
|
|
|
$res_data = $res['data'];
|
|
|
foreach ($res_data as $data_k => $data_v) {
|
|
|
$hisInfo=$data_v;
|
|
|
$entrust->requestTypeCode=$hisInfo['requestTypeCode'];
|
|
|
$entrust->requestTypeName=$hisInfo['requestTypeName'];
|
|
|
$entrust->orderDeptCode=$hisInfo['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');//报道号(检查号)
|
|
|
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' => 'Pacs通知',
|
|
|
'note' => '报到成功',
|
|
|
'data' => json_encode(['checkNo'=>$checkNo],JSON_UNESCAPED_UNICODE)
|
|
|
]);
|
|
|
|
|
|
return \Yz::JsonReturn(true,'报道成功',['orderNo'=>$orderNo]);
|
|
|
}else{
|
|
|
return \Yz::JsonError('报道失败');
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//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($entrust->list_status <> 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::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('取消报道失败');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//条形码测试接口
|
|
|
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');
|
|
|
}
|
|
|
}
|