where('id',$doctor['institution_id'])->field('name,report_subtitle')->find(); $param = $_REQUEST['param']; $id = $param['id']; $info = DB::table('exams')->where('id',$id)->field(['id','study_id','exam_class','exam_datetime','exam_sub_class','body_part','accession_num','patient_id'])->find(); $exam_class = DB::table('constant')->where('id',$info['exam_class'])->field('constant_value')->find(); $info['exam_class'] = $exam_class['constant_value']; $exam_subclass = DB::table('exam_subclass')->where('id',$info['exam_sub_class'])->field('name')->find(); $info['exam_sub_class'] = $exam_subclass['name']; $patient_info = DB::table('patient_infos')->where('id',$info['patient_id'])->field(['id','temp_patient_id','name','sex','age'])->find(); $info['pid'] = $patient_info['temp_patient_id']; $info['name'] = $patient_info['name']; $info['sex'] = $patient_info['sex']; $info['age'] = $patient_info['age']; $info['hospital_name'] = $institution['name']; $info['hospital_title'] = $institution['report_subtitle']; $info['images'] = isset($param['images']) ? $param['images'] : ''; $report = DB::table('report')->where('exam_id',$id)->field('report_datetime,report_doctor_id,review_datetime,review_doctor_id,impression,description')->find(); $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find(); $info['report_doctor'] = $report_doctor['realname']; $info['report_datetime'] = $report['report_datetime']; $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find(); $info['review_doctor'] = $review_doctor['realname']; $info['review_datetime'] = $report['review_datetime']; $info['description'] = $report['description']; $info['impression'] = $report['impression']; return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function upload($files){ // 获取表单上传文件 foreach($files as $file){ // 移动到框架应用根目录/public/uploads/ 目录下 $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'); if($info){ return $info->getSaveName(); // 成功上传后 获取上传信息 // 输出 jpg // echo $info-> getExtension(); // 输出 42a79759f284b767dfcb2a0197904287.jpg // echo $info->getFilename(); }else{ // 上传失败获取错误信息 // echo $file->getError(); } } } public function write(){ try{ $sessionid = $_REQUEST['sessionid']; if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){ // 是远程写报告 7 $return = Verify::check_role($sessionid,7); }else{ // 本地写报告权限 2 $return = Verify::check_role($sessionid,2); } if($return != 1){ return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']); } $param = $_REQUEST['param']; // Verify::wreportCheck($param); $doctor = Cache::get($sessionid); $remote_app = DB::table('remote_application')->where('exam_id',$param['id'])->field('remote_doctor_id')->find(); if(!empty($remote_app['remote_doctor_id'])){ if($remote_app['remote_doctor_id'] != $doctor['id']){ // return json_encode(['status'=>'fail','code'=>'1029','msg'=>'已被指定报告医生,您没有操作权限']); } } $this->uuids = new UUIDs(); $id = $this->uuids->uuid16(); //初步报告生成 $film_type = isset($param['film_type']) ? $param['film_type'] : ''; DB::table('exams')->where('id',$param['id'])->update(['exam_status'=>7,'film_type'=>$film_type]); $patient_info = array(); $patient_info['id'] = isset($param['pid']) ? $param['pid'] : ''; $patient_info['name'] = isset($param['name']) ? $param['name'] : ''; $patient_info['age'] = isset($param['age']) ? $param['age'] : ''; $patient_info['sex'] = isset($param['sex']) ? $param['sex'] : ''; $patient = DB::table('patient_infos')->where('id',$param['pid'])->update($patient_info); $info = array(); $info['exam_id'] = $param['id']; $info['impression'] = isset($param['impression']) ? $param['impression'] : ''; $info['description'] = isset($param['description']) ? $param['description'] : ''; if(isset($param['r_result']) && $param['r_result'] == 'true'){ $info['report_result'] = 2; }else{ $info['report_result'] = 1; } $info['report_datetime'] = date('Y-m-d H:i:s',time()); $info['report_doctor_id'] = $doctor['id']; $report_info = DB::table('report')->where('exam_id',$param['id'])->find(); if($report_info){ $report = DB::table('report')->where('exam_id',$param['id'])->update($info); }else{ $info['id'] = $id; $report = DB::table('report')->insert($info); } //写入log日志 $log = array(); $log['id'] = UUIDs::uuid16(); $log['impression'] = isset($param['impression']) ? $param['impression'] : ''; $log['description'] = isset($param['description']) ? $param['description'] : ''; $log['report_id'] = $id; $log['ctime'] = date('Y-m-d H:i:s',time()); $log['doctor_id'] = $doctor['id']; $log['type'] = 1; //写报告 $report_log = DB::table('report_record')->insert($log); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'保存成功','sessionid'=>$sessionid]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function public_template(){ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $exam = $_REQUEST['exam_class']; //第一级 公共模板 $info = $this->get_template(1,$doctor['id'],$exam); echo json_encode($info); } public function private_template(){ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $exam = $_REQUEST['exam_class']; //第一级 公共模板 $info = $this->get_template(2,$doctor['id'],$exam); echo json_encode($info); } public function get_template($public,$id,$exam){ // 查询exam_class表 $examCla = DB::table('constant')->where('id',$exam)->field('constant_value as name')->find(); if($public == 1){ $t = DB::table('templates')->where('is_public',$public)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select(); }else{ // 私有模板 添加创建人条件 $t = DB::table('templates')->where('is_public',$public)->where('create_user',$id)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select(); } if(!$t){ return ''; } $data = array(); foreach ($t as $k => $v) { if($v['parent_id'] == 0){ $data[] = $v; } } foreach ($data as $k => $v) { unset($data[$k]['impression']); unset($data[$k]['description']); unset($data[$k]['parent_id']); } foreach ($t as $k => $v) { foreach ($data as $key => $value) { if($v['parent_id'] == $value['id']){ unset($t[$k]['parent_id']); $data[$key]['children'][] = $t[$k]; } } } if($data){ return $data; } } //确认 5 public function confirm(){ try{ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $id = $_REQUEST['id']; $status = DB::table('exams')->where('id',$id)->field('exam_status')->find(); if($status['exam_status'] < 8 ){ return json_encode(['status'=>'fail','code'=>'1033','msg'=>'只能确认通过审核的报告']); }elseif($status['exam_status'] == 9){ return json_encode(['status'=>'fail','code'=>'1034','msg'=>'已经确认过该报告,不可再次确认']); } DB::table('exams')->where('id',$id)->update(['exam_status'=>9]); DB::table('report')->where('exam_id',$id)->update(['confirm_doctor_id'=>$doctor['id'],'confirm_datetime'=>date('Y-m-d H:i:s')]); // 添加 确认log日志 $info = array(); $info['id'] = UUIDs::uuid16(); $info['ctime'] = date('Y-m-d H:i:s',time()); $info['doctor_id'] = $doctor['id']; $info['type'] = 3; $info['report_id'] = ''; DB::table('report_record')->insert($info); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } // 审核 public function examine(){ try{ $id = $_REQUEST['id']; $status = DB::table('exams')->where('id',$id)->field('exam_status')->find(); if($status['exam_status'] < 7){ return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']); }elseif($status['exam_status']>7){ return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']); } $report = DB::table('report')->where('exam_id',$id)->field('id')->find(); $param = $_REQUEST['param']; $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){ // 是远程审核报告 8 $return = Verify::check_role($sessionid,8); }else{ // 本地审核权限 3 $return = Verify::check_role($sessionid,3); } $report_info = array(); $report_info['impression'] = isset($param['impression']) ? $param['impression'] : ''; $report_info['description'] = isset($param['description']) ? $param['description'] : ''; $report_info['report_result'] = isset($param['r_result']) ? $param['r_result'] : ''; $report_info['review_datetime'] = date('Y-m-d H:i:s',time()); $report_info['review_doctor_id'] = $doctor['id']; DB::table('report')->where('id',$report['id'])->update($report_info); $info = array(); $info['id'] = UUIDs::uuid16(); $info['type'] = 2; //审核 $info['ctime'] = date('Y-m-d H:i:s',time()); $info['doctor_id'] = $doctor['id']; $info['impression'] = isset($param['impression']) ? $param['impression'] : ''; $info['description'] = isset($param['description']) ? $param['description'] : ''; $info['report_id'] = $report['id']; DB::table('report_record')->insert($info); DB::table('exams')->where('id',$id)->update(['exam_status'=>8]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function getrole(){ try{ if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){ $is_remote = $_REQUEST['is_remote']; } $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->field('doctor_class')->find(); $doctor_class = explode(',',$dclass['doctor_class']); $info = array(); foreach ($doctor_class as $k=>$v) { switch($v){ case 2: //报告医生 if(isset($is_remote)){ //远程报告 break; } $info['bg'] = 1; break; case 7: //远程报告医生 if(!isset($is_remote)){ //远程报告 break; } $info['bg'] = 1; break; case 3: //3审核医生 if(isset($is_remote)){ //远程报告 break; } $info['sh'] = 2; break; case 8: //远程审核医生 if(!isset($is_remote)){ //远程报告 break; } $info['sh'] = 2; break; case 4: //确认医生 $info['qr'] = 3; break; } } return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function get_report_log(){ try{ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $exam_id = $_REQUEST['id']; $report = DB::table('report')->where('exam_id',$exam_id)->field('id')->find(); $log_id = $report['id']; $log = DB::table('report_record')->where('doctor_id',$doctor['id'])->where('report_id',$log_id)->order('ctime asc,type asc')->select(); foreach ($log as $k => $v) { $doc = DB::table('doctors')->where('id',$v['doctor_id'])->field('realname')->find(); $log[$k]['doctor_name'] = $doc['realname']; } return json_encode(['status'=>'ok','code'=>'0000','info'=>$log]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function print_report(){ try{ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $id = $_REQUEST['id']; $info = array(); // 检查日期 住院号 床号 $exam_info = DB::table('exams')->where('id',$id)->field('id,exam_datetime,exam_class,hopitalized_no,bed_no,exam_project,patient_id')->find(); $info['id'] = $exam_info['id']; if(!empty($exam_info['exam_datetime'])){ $datetime = explode(' ',$exam_info['exam_datetime']); $info['exam_datetime'] = $datetime[0]; }else{ $info['exam_datetime'] = ''; } $info['hopitalized_no'] = $exam_info['hopitalized_no']; $info['bed_no'] = $exam_info['bed_no']; // 检查项目 $project = DB::table('exam_project')->where('id',$exam_info['exam_project'])->field('name')->find(); $info['project'] = $project['name']; //检查类 $exam_class = DB::table('constant')->where('id',$exam_info['exam_class'])->field('constant_value')->find(); $info['exam_class'] = $exam_class['constant_value']; // 病历号 姓名 年龄 性别 $patient_info = DB::table('patient_infos')->where('id',$exam_info['patient_id'])->field('temp_patient_id,name,sex,age')->find(); $remote = DB::table('remote_application')->where('exam_id',$id)->field('req_doctor_id')->find(); $info['pnumber'] = $patient_info['temp_patient_id']; $info['name'] = $patient_info['name']; $info['sex'] = $patient_info['sex']; $info['age'] = $patient_info['age']; // 申请医生 $application_name = DB::table('doctors')->where('id',$remote['req_doctor_id'])->field('realname,department_id')->find(); $info['application_name'] = $application_name['realname']; // 申请科室 $department = DB::table('department')->where('id',$application_name['department_id'])->field('department_name')->find(); $info['department_name'] = $department['department_name']; // 报告时间 影像所见 意见建议 $report = DB::table('report')->where('exam_id',$id)->field('report_datetime,impression,description,report_doctor_id,review_doctor_id')->find(); if(!empty($report['report_datetime'])){ $datetime1 = explode(' ',$report['report_datetime']); $info['report_datetime'] = $datetime1[0]; }else{ $info['report_datetime'] = ''; } // $info['report_datetime'] = $report['report_datetime']; $info['impression'] = $report['impression']; $info['description'] = $report['description']; // 报告医生 $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find(); $info['report_doctor'] = $report_doctor['realname']; //审核医生 $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find(); $info['review_doctor'] = $review_doctor['realname']; $hospital = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find(); $info['hospital'] = $hospital['name']; return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function change_film(){ $id = $_REQUEST['id']; $film = $_REQUEST['film_type']; DB::table('exams')->where('id',$id)->update(['film_type'=>$film]); return json_encode(['status'=>'ok','code'=>'0000']); } }