Reciveremote.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\inter\controller;
  3. use app\common\library\UUIDs;
  4. use think\Cache;
  5. use think\Controller;
  6. use think\Db;
  7. use think\Log;
  8. class Reciveremote extends Base
  9. {
  10. public function index()
  11. {
  12. try{
  13. log::record('---------工作列表--------');
  14. log::record($_REQUEST);
  15. $sessionid = $_REQUEST['sessionid'];
  16. $doctor = Cache::get($sessionid);
  17. log::record($doctor);
  18. $app_info = DB::table('remote_application')->where('remote_institution_id', $doctor['institution_id'])->select();
  19. foreach ($app_info as $k => $v) {
  20. $exam_id = $v['exam_id'];
  21. $report = DB::table('report')->where('exam_id', $exam_id)->find();
  22. if (!$report) {
  23. $data = array();
  24. $data['id'] = UUIDs::uuid16();
  25. $data['exam_id'] = $exam_id;
  26. $data['ctime'] = date('Y-m-d H:i:s',time());
  27. DB::table('report')->insert($data);
  28. }
  29. }
  30. $where = '';
  31. if(isset($_REQUEST['param'])){
  32. $param = $_REQUEST['param'];
  33. foreach ($param as $k => $v) {
  34. switch ($k) {
  35. case 'patient_num':
  36. $where .= " and e." . $k . "='" . $v . "' ";
  37. break;
  38. case 'exam_class' :
  39. if(empty($v)){
  40. break;
  41. }
  42. $ex = implode('\',\'',$v);
  43. $where .= " and e.exam_class in ('".$ex."')";
  44. break;
  45. case 'name':
  46. $where .= " and p.name like '".$v."%' ";
  47. break;
  48. case 'applicationtime':
  49. $where .= " and ra.req_date_time between '$v[0]' and '$v[1]'";
  50. break;
  51. case 'is_urgent':
  52. if($v == 0){
  53. break;
  54. }
  55. $where .= " and ra.is_urgent=".$v;
  56. break;
  57. case 'report_result':
  58. if($v == 2){
  59. $where .= " and r.report_result=2";
  60. }elseif($v == 1){
  61. $where .= " and r.report_result=1";
  62. }{
  63. break;
  64. }
  65. break;
  66. case 'exam_status':
  67. if($v != 10){
  68. $where .= " and e.exam_status=".$v;
  69. }
  70. break;
  71. }
  72. }
  73. }
  74. log::record($where);
  75. $page = $_REQUEST['page'];
  76. $num = $_REQUEST['num'];
  77. $fnum = ($page-1)*$num;
  78. $limit = " limit ".$fnum.",".$num;
  79. /*if(empty($where)){
  80. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find();
  81. if(empty($dclass['doctor_class'])){
  82. $dclass['doctor_class'] = 0;
  83. }
  84. log::record($dclass);
  85. $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'].")";
  86. $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'].")";
  87. $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'].")";
  88. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  89. }else{*/
  90. $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";
  91. // }
  92. log::record($sql);
  93. $list = DB::query($sql);
  94. $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;
  95. $count = DB::query($csql);
  96. foreach ($list as $k => $v) {
  97. //申请医院
  98. $local_institution = DB::table('institution')->where('id',$v['local_institution_id'])->cache(300)->field('name')->find();
  99. $list[$k]['local_institution_name'] = $local_institution['name'];
  100. //检查类型
  101. $check_class = DB::table('constant')->where('id',$v['exam_class'])->cache(300)->field('constant_value as name')->find();
  102. $list[$k]['class_name'] = $check_class['name'];
  103. //检查子类
  104. $subclass_name = DB::table('exam_subclass')->where('id',$v['exam_sub_class'])->cache(300)->field('name')->find();
  105. $list[$k]['subclass_name'] = $subclass_name['name'];
  106. //检查部位
  107. $body_part = DB::table('bodypart')->where('id',$v['body_part'])->cache(300)->field('name')->find();
  108. $list[$k]['body_name'] = $body_part['name'];
  109. //检查设备
  110. $device = DB::table('device')->where('id',$v['device'])->cache(300)->field('name')->find();
  111. $list[$k]['device_name'] = $device['name'];
  112. //报告医生
  113. $report_doctor = DB::table('doctors')->where('id',$v['report_doctor_id'])->field('realname')->find();
  114. $list[$k]['report_doctor_id'] = $report_doctor['realname'];
  115. $list[$k]['datetime'] = $v['req_date_time'];
  116. $list[$k]['rdatetime'] = $v['report_datetime'];
  117. }
  118. if($list){
  119. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  120. }else{
  121. return json_encode(['status'=>'fail','code'=>'1020','count'=>$count[0]['count(1)'],'msg'=>'没有数据','sessionid'=>$sessionid]);
  122. }
  123. }catch(\Exception $e){
  124. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  125. }
  126. }
  127. //接受 3
  128. public function accept(){
  129. $sessionid = $_REQUEST['sessionid'];
  130. $doctor = Cache::get($sessionid);
  131. $id = $_REQUEST['id'];
  132. DB::table('exam')->where('id',$id)->update(['exam_status'=>6]);
  133. DB::table('report')->where('exam_id',$id)->update(['report_doctor_id',$doctor['id']]);
  134. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已接受']);
  135. }
  136. //驳回 7
  137. public function reject(){
  138. // $sessionid = $_REQUEST['sessionid'];
  139. // $doctor = Cache::get($sessionid);
  140. $id = $_REQUEST['id'];
  141. DB::table('exam')->where('id',$id)->update(['exam_status'=>5]);
  142. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已驳回']);
  143. }
  144. //确认 5
  145. public function confirm(){
  146. $sessionid = $_REQUEST['sessionid'];
  147. $doctor = Cache::get($sessionid);
  148. $id = $_REQUEST['id'];
  149. DB::table('exam')->where('id',$id)->update(['exam_status'=>9]);
  150. DB::table('report')->where('exam_id',$id)->update(['confirm_doctor_id'=>$doctor['id'],'confirm_datetime'=>date('Y-m-d H:i:s')]);
  151. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  152. }
  153. // 审核
  154. public function examine(){
  155. $id = $_REQUEST['id'];
  156. DB::table('exam')->where('id',$id)->update(['exam_status'=>8]);
  157. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  158. }
  159. }