Report.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\inter\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use app\common\library\ResultTools;
  7. use think\Cache;
  8. use think\Log;
  9. use think\Request;
  10. class Report extends Base
  11. {
  12. public function index(){
  13. try{
  14. $sessionid = Request::instance()->param('sessionid');
  15. $doctor = Cache::get($sessionid);
  16. if(!$doctor){
  17. return ResultTools::faile('1008', '您还未登录',$sessionid);
  18. }
  19. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find();
  20. // $is_urgent = $_REQUEST['is_remote'];
  21. $where = '';
  22. // $table = '';
  23. $order = ' order by a.urgent desc,a.ctime desc';
  24. /*if($is_urgent == 1){
  25. //是远程报告
  26. $table = ',remote_application as r ';
  27. $where = ' and a.is_remote=1';
  28. $order = ' order by r.is_urgent desc';
  29. }*/
  30. log::record('-------------');
  31. log::record($_REQUEST);
  32. log::record('-------------');
  33. if(isset($_REQUEST['param'])){
  34. $search = $_REQUEST['param'];
  35. foreach($search as $k => $v){
  36. switch($k){
  37. case 'name':
  38. if(empty($v)){
  39. break;
  40. }
  41. $where .= ' and p.name like \''.$v.'%\'';
  42. break;
  43. case 'local_institution_id':
  44. if(empty($v)){
  45. break;
  46. }
  47. $where .= " and r.".$k."='".$v."' and r.exam_id=a.id";
  48. break;
  49. case 'urgent':
  50. if(empty($v)){
  51. break;
  52. }
  53. if($v == 'true'){
  54. $v = 1;
  55. }else{
  56. break;
  57. }
  58. $where .= " and a.".$k."='".$v."'";
  59. break;
  60. case 'exam_datetime':
  61. if(empty($v)){
  62. break;
  63. }
  64. $where = " and a.exam_datetime between '$v[0]' and '$v[1]'";
  65. break;
  66. case 'exam_status':
  67. if($v != 10 && !empty($v)){
  68. $where .= " and a.exam_status=".$v;
  69. }
  70. break;
  71. default :
  72. if(empty($v)){
  73. break;
  74. }
  75. $where .= " and a.".$k."='".$v."'";
  76. }
  77. }
  78. }
  79. $page = $_REQUEST['page'];
  80. $num = $_REQUEST['num'];
  81. $fnum = ($page-1)*$num;
  82. $limit = " limit ".$fnum.",".$num;
  83. /*if(empty($where)){
  84. // 急诊sql 待处理
  85. $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'].")";
  86. //非急诊 待处理
  87. $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'].")";
  88. //已处理
  89. $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'].")";
  90. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  91. }else{*/
  92. $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;
  93. // }
  94. $list = DB::query($sql);
  95. $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;
  96. $count = DB::query($csql);
  97. log::record('请求的sql语句');
  98. log::record($sql);
  99. log::record('请求到的数据');
  100. log::record($list);
  101. foreach ($list as $k => $v) {
  102. if($v['is_remote'] == 1){
  103. // 远程报告 获取发送的报告医院
  104. $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
  105. $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
  106. $list[$k]['report_app_name'] = $remote_name['name'];
  107. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  108. if($report){
  109. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  110. $list[$k]['report_doctor'] = $report_doctor['realname'];
  111. $list[$k]['report_datetime'] = $report['report_datetime'];
  112. }
  113. }else{
  114. $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
  115. $list[$k]['report_app_name'] = $remote_name['name'];
  116. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  117. if($report){
  118. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  119. $list[$k]['report_doctor'] = $report_doctor['realname'];
  120. $list[$k]['report_datetime'] = $report['report_datetime'];
  121. }else{
  122. $list[$k]['report_doctor'] = '';
  123. $list[$k]['report_datetime'] = '';
  124. }
  125. }
  126. }
  127. /*if($is_urgent == 1){
  128. //远程报告申请机构
  129. $doctor = Cache::get('doctor');
  130. //当前科室ID和name
  131. $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
  132. // 子科室ID name
  133. $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
  134. $institution[] = $p_institution;
  135. if($child_institution){
  136. foreach ($child_institution as $k => $v) {
  137. $institution[] = $v;
  138. }
  139. }
  140. $list['institution'] = $institution;
  141. }*/
  142. if($list){
  143. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  144. }else{
  145. return json_encode(['status'=>'fail','code'=>'1020','count'=>$count[0]['count(1)'],'msg'=>'没有数据','sessionid'=>$sessionid]);
  146. }
  147. }catch(\Exception $e){
  148. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  149. }
  150. }
  151. }