Report.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.createdAt 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 'report_result':
  61. if($v == 2){
  62. $where .= " and r.report_result=2";
  63. }elseif($v == 1){
  64. $where .= " and r.report_result=1";
  65. }{
  66. break;
  67. }
  68. break;
  69. case 'exam_datetime':
  70. if(empty($v)){
  71. break;
  72. }
  73. $where = " and a.exam_datetime between '$v[0]' and '$v[1]'";
  74. break;
  75. case 'exam_status':
  76. if($v != 10 && !empty($v)){
  77. $where .= " and a.exam_status=".$v;
  78. }
  79. break;
  80. default :
  81. if(empty($v)){
  82. break;
  83. }
  84. $where .= " and a.".$k."='".$v."'";
  85. }
  86. }
  87. }
  88. $page = $_REQUEST['page'];
  89. $num = $_REQUEST['num'];
  90. $fnum = ($page-1)*$num;
  91. $limit = " limit ".$fnum.",".$num;
  92. /*if(empty($where)){
  93. // 急诊sql 待处理
  94. $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 exams as a,patient_infos 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'].")";
  95. //非急诊 待处理
  96. $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 exams as a,patient_infos 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'].")";
  97. //已处理
  98. $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 exams as a,patient_infos as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.exam_status not in (".$dclass['doctor_class'].")";
  99. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  100. }else{*/
  101. $sql = "SELECT a.id,a.urgent,a.is_remote,a.patient_num,a.exam_report,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,p.name,p.sex,p.age FROM exams as a,patient_infos as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id ".$where." order by a.createdAt desc".$limit;
  102. // }
  103. $list = DB::query($sql);
  104. $csql = "SELECT count(1) FROM exams as a,patient_infos as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id ".$where;
  105. $count = DB::query($csql);
  106. log::record('请求的sql语句');
  107. log::record($sql);
  108. log::record('请求到的数据');
  109. log::record($list);
  110. foreach ($list as $k => $v) {
  111. if($v['is_remote'] == 1){
  112. // 远程报告 获取发送的报告医院
  113. $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
  114. $remote_name = DB::table('institution')->where('id',$remote['remote_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. }
  122. }else{
  123. $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
  124. $list[$k]['report_app_name'] = $remote_name['name'];
  125. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  126. if($report){
  127. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  128. $list[$k]['report_doctor'] = $report_doctor['realname'];
  129. $list[$k]['report_datetime'] = $report['report_datetime'];
  130. }else{
  131. $list[$k]['report_doctor'] = '';
  132. $list[$k]['report_datetime'] = '';
  133. }
  134. }
  135. }
  136. /*if($is_urgent == 1){
  137. //远程报告申请机构
  138. $doctor = Cache::get('doctor');
  139. //当前科室ID和name
  140. $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
  141. // 子科室ID name
  142. $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
  143. $institution[] = $p_institution;
  144. if($child_institution){
  145. foreach ($child_institution as $k => $v) {
  146. $institution[] = $v;
  147. }
  148. }
  149. $list['institution'] = $institution;
  150. }*/
  151. if($list){
  152. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  153. }else{
  154. return json_encode(['status'=>'fail','code'=>'1020','count'=>$count[0]['count(1)'],'msg'=>'没有数据','sessionid'=>$sessionid]);
  155. }
  156. }catch(\Exception $e){
  157. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  158. }
  159. }
  160. }