123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace app\inter\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use app\common\library\ResultTools;
- use think\Cache;
- use think\Log;
- use think\Request;
- class Report extends Base
- {
- public function index(){
- try{
- $sessionid = Request::instance()->param('sessionid');
- $doctor = Cache::get($sessionid);
- if(!$doctor){
- return ResultTools::faile('1008', '您还未登录',$sessionid);
- }
- $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find();
- // $is_urgent = $_REQUEST['is_remote'];
- $where = '';
- // $table = '';
- $order = ' order by a.urgent desc,a.ctime desc';
- /*if($is_urgent == 1){
- //是远程报告
- $table = ',remote_application as r ';
- $where = ' and a.is_remote=1';
- $order = ' order by r.is_urgent desc';
- }*/
- log::record('-------------');
- log::record($_REQUEST);
- log::record('-------------');
- if(isset($_REQUEST['param'])){
- $search = $_REQUEST['param'];
- foreach($search as $k => $v){
- switch($k){
- case 'name':
- if(empty($v)){
- break;
- }
- $where .= ' and p.name like \''.$v.'%\'';
- break;
- case 'local_institution_id':
- if(empty($v)){
- break;
- }
- $where .= " and r.".$k."='".$v."' and r.exam_id=a.id";
- break;
- case 'urgent':
- if(empty($v)){
- break;
- }
- if($v == 'true'){
- $v = 1;
- }else{
- break;
- }
- $where .= " and a.".$k."='".$v."'";
- break;
- case 'exam_datetime':
- if(empty($v)){
- break;
- }
- $where = " and a.exam_datetime between '$v[0]' and '$v[1]'";
- break;
- case 'exam_status':
- if($v != 10 && !empty($v)){
- $where .= " and a.exam_status=".$v;
- }
- break;
- default :
- if(empty($v)){
- break;
- }
- $where .= " and a.".$k."='".$v."'";
- }
- }
- }
- $page = $_REQUEST['page'];
- $num = $_REQUEST['num'];
- $fnum = ($page-1)*$num;
- $limit = " limit ".$fnum.",".$num;
- /*if(empty($where)){
- // 急诊sql 待处理
- $sql1 = "SELECT a.id,a.urgent,a.is_remote,a.patient_num,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,p.name,p.sex,p.age FROM exam as a,patient_info as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.urgent=1 and a.exam_status in (".$dclass['doctor_class'].")";
- //非急诊 待处理
- $sql2 = "SELECT a.id,a.urgent,a.is_remote,a.patient_num,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,p.name,p.sex,p.age FROM exam as a,patient_info as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.urgent!=1 and a.exam_status in (".$dclass['doctor_class'].")";
- //已处理
- $sql3 = "SELECT a.id,a.urgent,a.is_remote,a.patient_num,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,p.name,p.sex,p.age FROM exam as a,patient_info as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.exam_status not in (".$dclass['doctor_class'].")";
- $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
- }else{*/
- $sql = "SELECT a.id,a.urgent,a.is_remote,a.patient_num,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,p.name,p.sex,p.age FROM exam as a,patient_info as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id ".$where."order by a.ctime desc".$limit;
- // }
- $list = DB::query($sql);
- $csql = "SELECT count(1) FROM exam as a,patient_info as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id ".$where;
- $count = DB::query($csql);
- log::record('请求的sql语句');
- log::record($sql);
- log::record('请求到的数据');
- log::record($list);
- foreach ($list as $k => $v) {
- if($v['is_remote'] == 1){
- // 远程报告 获取发送的报告医院
- $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
- $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
- $list[$k]['report_app_name'] = $remote_name['name'];
- $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
- if($report){
- $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
- $list[$k]['report_doctor'] = $report_doctor['realname'];
- $list[$k]['report_datetime'] = $report['report_datetime'];
- }
- }else{
- $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
- $list[$k]['report_app_name'] = $remote_name['name'];
- $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
- if($report){
- $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
- $list[$k]['report_doctor'] = $report_doctor['realname'];
- $list[$k]['report_datetime'] = $report['report_datetime'];
- }else{
- $list[$k]['report_doctor'] = '';
- $list[$k]['report_datetime'] = '';
- }
- }
- }
- /*if($is_urgent == 1){
- //远程报告申请机构
- $doctor = Cache::get('doctor');
- //当前科室ID和name
- $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
- // 子科室ID name
- $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
- $institution[] = $p_institution;
- if($child_institution){
- foreach ($child_institution as $k => $v) {
- $institution[] = $v;
- }
- }
- $list['institution'] = $institution;
- }*/
- 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()]);
- }
- }
- }
|