where('remote_institution_id', $doctor['institution_id'])->select(); foreach ($app_info as $k => $v) { $exam_id = $v['exam_id']; $report = DB::table('report')->where('exam_id', $exam_id)->find(); if (!$report) { $data = array(); $data['id'] = UUIDs::uuid16(); $data['exam_id'] = $exam_id; $data['ctime'] = date('Y-m-d H:i:s',time()); DB::table('report')->insert($data); } } $where = ''; if(isset($_REQUEST['param'])){ $param = $_REQUEST['param']; foreach ($param as $k => $v) { switch ($k) { case 'patient_num': $where .= " and e." . $k . "='" . $v . "' "; break; case 'exam_class' : if(empty($v)){ break; } $ex = implode('\',\'',$v); $where .= " and e.exam_class in ('".$ex."')"; break; case 'name': $where .= " and p.name like '".$v."%' "; break; case 'applicationtime': $where .= " and ra.req_date_time between '$v[0]' and '$v[1]'"; break; case 'is_urgent': if($v == 0){ break; } $where .= " and ra.is_urgent=".$v; break; case 'report_result': if($v == 2){ $where .= " and r.report_result=2"; }elseif($v == 1){ $where .= " and r.report_result=1"; }{ break; } break; case 'exam_status': if($v != 10){ $where .= " and e.exam_status=".$v; } break; } } } log::record($where); $page = $_REQUEST['page']; $num = $_REQUEST['num']; $fnum = ($page-1)*$num; $limit = " limit ".$fnum.",".$num; /*if(empty($where)){ $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find(); if(empty($dclass['doctor_class'])){ $dclass['doctor_class'] = 0; } log::record($dclass); $sql1 = "SELECT e.exam_status,e.exam_class,e.body_part,e.device,e.exam_sub_class,e.exam_datetime,p.name,p.sex,p.temp_patient_id,p.age,ra.*,r.report_doctor_id,r.report_datetime,r.report_result,e.id from exam as e,remote_application as ra,patient_info as p,report as r where ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id'] . "' and ra.is_urgent=1 and e.exam_status in (".$dclass['doctor_class'].")"; $sql2 = "SELECT e.exam_status,e.exam_class,e.body_part,e.device,e.exam_sub_class,e.exam_datetime,p.name,p.sex,p.temp_patient_id,p.age,ra.*,r.report_doctor_id,r.report_datetime,r.report_result,e.id from exam as e,remote_application as ra,patient_info as p,report as r where ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id'] . "' and ra.is_urgent=0 and e.exam_status in (".$dclass['doctor_class'].")"; $sql3 = "SELECT e.exam_status,e.exam_class,e.body_part,e.device,e.exam_sub_class,e.exam_datetime,p.name,p.sex,p.temp_patient_id,p.age,ra.*,r.report_doctor_id,r.report_datetime,r.report_result,e.id from exam as e,remote_application as ra,patient_info as p,report as r where ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id'] . "'and e.exam_status not in (".$dclass['doctor_class'].")"; $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit; }else{*/ $sql = "SELECT e.exam_status,e.exam_class,e.exam_sub_class,e.body_part,e.device,e.exam_datetime,p.name,p.sex,p.temp_patient_id,p.age,ra.*,r.report_doctor_id,r.report_datetime,r.report_result,e.id from exam as e,remote_application as ra,patient_info as p,report as r where ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id']."'".$where." order by field(e.exam_status,6,7,8,4,9),ra.is_urgent desc,e.ctime desc"; // } log::record($sql); $list = DB::query($sql); $csql = "SELECT count(1) from exam as e,remote_application as ra,patient_info as p,report as r where ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id']."'".$where; $count = DB::query($csql); foreach ($list as $k => $v) { //申请医院 $local_institution = DB::table('institution')->where('id',$v['local_institution_id'])->cache(300)->field('name')->find(); $list[$k]['local_institution_name'] = $local_institution['name']; //检查类型 $check_class = DB::table('constant')->where('id',$v['exam_class'])->cache(300)->field('constant_value as name')->find(); $list[$k]['class_name'] = $check_class['name']; //检查子类 $subclass_name = DB::table('exam_subclass')->where('id',$v['exam_sub_class'])->cache(300)->field('name')->find(); $list[$k]['subclass_name'] = $subclass_name['name']; //检查部位 $body_part = DB::table('bodypart')->where('id',$v['body_part'])->cache(300)->field('name')->find(); $list[$k]['body_name'] = $body_part['name']; //检查设备 $device = DB::table('device')->where('id',$v['device'])->cache(300)->field('name')->find(); $list[$k]['device_name'] = $device['name']; //报告医生 $report_doctor = DB::table('doctors')->where('id',$v['report_doctor_id'])->field('realname')->find(); $list[$k]['report_doctor_id'] = $report_doctor['realname']; $list[$k]['datetime'] = $v['req_date_time']; $list[$k]['rdatetime'] = $v['report_datetime']; } if($list){ return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]); }else{ return json_encode(['status'=>'fail','code'=>'1020','count'=>$count[0]['count(1)'],'msg'=>'没有数据','sessionid'=>$sessionid]); } }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } //接受 3 public function accept(){ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $id = $_REQUEST['id']; DB::table('exam')->where('id',$id)->update(['exam_status'=>6]); DB::table('report')->where('exam_id',$id)->update(['report_doctor_id',$doctor['id']]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已接受']); } //驳回 7 public function reject(){ // $sessionid = $_REQUEST['sessionid']; // $doctor = Cache::get($sessionid); $id = $_REQUEST['id']; DB::table('exam')->where('id',$id)->update(['exam_status'=>5]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已驳回']); } //确认 5 public function confirm(){ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $id = $_REQUEST['id']; DB::table('exam')->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')]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']); } // 审核 public function examine(){ $id = $_REQUEST['id']; DB::table('exam')->where('id',$id)->update(['exam_status'=>8]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']); } }