Reciveremote.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. // select count(*) from remote_application ra left join remote_order ro on ro.id = (select id from remote_order rot where rot.application_id = ra.id order by timestamp desc limit 1) where ra.remote_institution_id='09b4765b26ba8b7c' and (report_status = '4' or report_status = '6' or report_status = '7' or report_status = '8' or report_status = '9') and (ra.remote_doctor_id='b5bed8f973852c22' or ra.remote_doctor_id = '') and (ro.status is null or ro.status = 2 or ro.status = 3)
  9. // select is_urgent, report_status, req_date_time from remote_application ra left join remote_order ro on ro.id = (select id from remote_order rot where rot.application_id = ra.id order by timestamp desc limit 1) where ra.remote_institution_id='09b4765b26ba8b7c' and (report_status = '4' or report_status = '6' or report_status = '7' or report_status = '8' or report_status = '9') and (ra.remote_doctor_id='b5bed8f973852c22' or ra.remote_doctor_id = '') and (ro.status is null or ro.status = 2 or ro.status = 3) order by (ra.is_urgent = '1' and ra.report_status = '4') desc, (ra.is_urgent = '1' and ra.report_status = '6') desc, (ra.is_urgent = '1' and ra.report_status = '7'), ra.req_date_time desc limit 20
  10. class Reciveremote extends Base
  11. {
  12. /**
  13. * 远程申请列表
  14. *
  15. * @ApiTitle (远程申请列表)
  16. * @ApiSummary (远程申请列表)
  17. * @ApiSector (远程诊断)
  18. * @ApiMethod (POST)
  19. * @ApiRoute (/inter/reciveremote/index)
  20. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  21. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  22. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  23. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  24. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  25. * @ApiParams (name="page", type="string", required=true, description="当前页")
  26. * @ApiParams (name="num", type="string", required=true, description="每页显示条数")
  27. * @ApiParams (name="param[patient_num]", type="string", sample="", description="预约登记exams表id值<选填>")
  28. * @ApiParams (name="param[exam_class]", type="string", sample="", description="检查类<选填>")
  29. * @ApiParams (name="param[name]", type="string", sample="", description="患者姓名<选填>")
  30. * @ApiParams (name="param[applicationtime]", type="string", sample="", description="申请时间<选填>")
  31. * @ApiParams (name="param[is_urgent]", type="string", sample="", description="是否急诊<选填>")
  32. * @ApiParams (name="param[report_result]", type="string", sample="", description="检查结果<选填>")
  33. * @ApiParams (name="param[exam_status]", type="string", sample="", description="检查状态<选填>")
  34. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  35. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  36. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  37. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  38. * @ApiReturnParams (name="count", type="object", sample="{}", description="总条数")
  39. * @ApiReturn (data="
  40. {
  41. 'status': ok,
  42. 'code': '0000',
  43. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  44. 'info' : ''
  45. 'count' : '110'
  46. }
  47. *")
  48. **/
  49. // public function index()
  50. // {
  51. // try{
  52. // log::record('---------工作列表--------');
  53. // log::record($_REQUEST);
  54. // $sessionid = $_REQUEST['sessionid'];
  55. // $doctor = Cache::get($sessionid);
  56. // log::record($doctor);
  57. // $app_info = DB::table('remote_application')->where('remote_institution_id', $doctor['institution_id'])->select();
  58. // foreach ($app_info as $k => $v) {
  59. // $exam_id = $v['exam_id'];
  60. // $report = DB::table('report')->where('exam_id', $exam_id)->where('remote_application_id',$v['id'])->find();
  61. // if (!$report) {
  62. // $data = array();
  63. // $data['id'] = UUIDs::uuid16();
  64. // $data['exam_id'] = $exam_id;
  65. // $data['remote_application_id'] = $v['id'];
  66. // $data['type'] = 2;
  67. // $data['createdAt'] = date('Y-m-d H:i:s',time());
  68. // DB::table('report')->insert($data);
  69. // }
  70. // }
  71. // $where = '';
  72. // if(isset($_REQUEST['param'])){
  73. // $param = $_REQUEST['param'];
  74. // foreach ($param as $k => $v) {
  75. // switch ($k) {
  76. // case 'patient_num':
  77. // $where .= " and e." . $k . "='" . $v . "' ";
  78. // break;
  79. // case 'exam_class' :
  80. // if(empty($v)){
  81. // break;
  82. // }
  83. // $ex = implode('\',\'',$v);
  84. // $where .= " and e.exam_class in ('".$ex."')";
  85. // break;
  86. // case 'name':
  87. // $where .= " and p.name like '".$v."%' ";
  88. // break;
  89. // case 'applicationtime':
  90. // if(empty($v)){
  91. // break;
  92. // }
  93. // $where .= " and ra.req_date_time between '$v[0]' and '$v[1]'";
  94. // break;
  95. // case 'is_urgent':
  96. // if($v == 0){
  97. // break;
  98. // }
  99. // $where .= " and ra.is_urgent=".$v;
  100. // break;
  101. // case 'report_result':
  102. // if($v == 2){
  103. // $where .= " and r.report_result=2";
  104. // }elseif($v == 1){
  105. // $where .= " and r.report_result=1";
  106. // }{
  107. // break;
  108. // }
  109. // break;
  110. // case 'exam_status':
  111. // if($v != 10){
  112. // $where .= " and ra.report_status=".$v;
  113. // }
  114. // break;
  115. // }
  116. // }
  117. // }
  118. // $doc_class = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->value('doctor_class');
  119. // if(strpos('8',$doc_class) !== false){
  120. // $dwhere = ' or ra.report_status=7 ';
  121. // }else{
  122. // $dwhere = '';
  123. // }
  124. // log::record($where);
  125. // $page = $_REQUEST['page'];
  126. // $num = $_REQUEST['num'];
  127. // $fnum = ($page-1)*$num;
  128. // $limit = " limit ".$fnum.",".$num;
  129. // /*if(empty($where)){
  130. // $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find();
  131. // if(empty($dclass['doctor_class'])){
  132. // $dclass['doctor_class'] = 0;
  133. // }
  134. // log::record($dclass);
  135. // $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 exams as e,remote_application as ra,patient_infos 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'].")";
  136. // $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 exams as e,remote_application as ra,patient_infos 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'].")";
  137. // $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 exams as e,remote_application as ra,patient_infos 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'].")";
  138. // $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit; //ra.report_status,6,7,8,4,9,5,12
  139. // }else{*/
  140. // $sql = "SELECT e.id,e.severe,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.id as ra_id,ra.*,r.id as report_id,r.report_doctor_id,r.report_datetime,r.report_result,e.id from exams as e,remote_application as ra,patient_infos as p,report as r where (ra.remote_doctor_id='".$doctor['id']."' or ra.remote_doctor_id=''".$dwhere.") and ra.exam_id=e.id and e.patient_id=p.id and r.exam_id=e.id and r.remote_application_id=ra.id and ra.report_status !='' and ra.remote_institution_id='" . $doctor['institution_id']."'".$where." order by req_date_time desc,ra.is_urgent desc,ra.req_date_time desc".$limit;
  141. // // }
  142. // log::record($sql);
  143. // $list = DB::query($sql);
  144. // $csql = "SELECT count(1) from exams as e,remote_application as ra,patient_infos as p,report as r where (ra.remote_doctor_id='".$doctor['id']."' or ra.remote_doctor_id=''".$dwhere.") and r.remote_application_id=ra.id and ra.exam_id=e.id and ra.report_status !='' and e.patient_id=p.id and r.exam_id=e.id and ra.remote_institution_id='" . $doctor['institution_id']."'".$where;
  145. // $count = DB::query($csql);
  146. // foreach ($list as $k => $v) {
  147. // $cache_key = $doctor['id'].'_'.$v['id'];
  148. // if(Cache::get($cache_key)){
  149. // $list[$k]['status'] = 1;
  150. // }else{
  151. // $list[$k]['status'] = 0;
  152. // }
  153. // //申请医院
  154. // $local_institution = DB::table('institution')->where('id',$v['local_institution_id'])->cache(300)->field('name')->find();
  155. // $list[$k]['local_institution_name'] = $local_institution['name'];
  156. // //检查类型
  157. // $check_class = DB::table('constant')->where('id',$v['exam_class'])->cache(300)->field('constant_value as name')->find();
  158. // $list[$k]['class_name'] = $check_class['name'];
  159. // //检查子类
  160. // $subclass_name = DB::table('exam_subclass')->where('id',$v['exam_sub_class'])->cache(300)->field('name')->find();
  161. // $list[$k]['subclass_name'] = $subclass_name['name'];
  162. // //检查部位
  163. // $body_part = DB::table('bodypart')->where('id',$v['body_part'])->cache(300)->field('name')->find();
  164. // $list[$k]['body_name'] = $body_part['name'];
  165. // //检查设备
  166. // $device = DB::table('device')->where('id',$v['device'])->cache(300)->field('name')->find();
  167. // $list[$k]['device_name'] = $device['name'];
  168. // //报告医生
  169. // $report_doctor = DB::table('doctors')->where('id',$v['report_doctor_id'])->field('realname')->find();
  170. // $list[$k]['report_doctor_id'] = $report_doctor['realname'];
  171. // $list[$k]['datetime'] = $v['req_date_time'];
  172. // $list[$k]['rdatetime'] = $v['report_datetime'];
  173. // }
  174. // return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  175. // }catch(\Exception $e){
  176. // return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  177. // }
  178. // $remote_institution_id = '09b4765b26ba8b7c';
  179. // $remote_doctor_id = 'b5bed8f973852c22';
  180. // $filed = 'ra.id as ra_id, ra.anamnesis, ra.application_desc, ra.attachment, ra.clin_diag, ra.clin_symp, ra.createdAt, ra.exam_id, ra.family_ill, ra.illness_desc, ra.is_urgent, ra.local_institution_id, ra.marrital, ra.phys_sign, ra.remark, ra.remote_doctor_id, ra.remote_institution_id, ra.report_status, ra.req_date_time, ra.req_doctor_id, ra.status, e.body_part, e.exam_class, e.device, e.exam_datetime, e.id as exam_id, e.exam_status, e.exam_sub_class, e.id, e.severe, e.patient_id, r.report_datetime as rdatetime, r.report_datetime, r.report_doctor_id, r.id as report_id, r.report_result, pi.age, pi.name, pi.sex, i.name as local_institution_name';
  181. // $table = 'remote_application ra left join remote_order ro on ro.id = (select id from remote_order rot where rot.application_id = ra.id order by timestamp desc limit 1) left join exams e on ra.exam_id = e.id left join report r on ra.id = r.remote_application_id left join patient_infos pi on e.patient_id = pi.id left join institution i on ra.local_institution_id = i.id';
  182. // $where1 = "ra.remote_institution_id=:remote_institution_id";
  183. // $where2 = "(ra.report_status = '4' or report_status = '6' or report_status = '7' or report_status = '8' or report_status = '9')";
  184. // $where3 = "(ra.remote_doctor_id= :remote_doctor_id or ra.remote_doctor_id = '')";
  185. // $where4 = "(ro.status is null or ro.status = 2 or ro.status = 3)";
  186. // $order = "(ra.is_urgent = '1' and ra.report_status = '4') desc, (ra.is_urgent = '1' and ra.report_status = '6') desc, (ra.is_urgent = '1' and ra.report_status = '7'), ra.req_date_time desc";
  187. // $limit = ":start :number";
  188. // $where = $where1.$where2.$where3.$where4;
  189. // $sql = "select ".$filed." from ".$table." where ".$where." order by ".$order." limit ".$limit;
  190. // $options = [
  191. // "remote_institution_id" => $remote_institution_id,
  192. // "remote_doctor_id" => $remote_doctor_id,
  193. // "start" => 0,
  194. // "number" => 20
  195. // ];
  196. // DB::execute($sql, $options);
  197. // // $db->execute(SQLServerHelp::SET_LIS_DEPARTEMT_SQL,$departemt);
  198. // }
  199. // }
  200. public function index()
  201. {
  202. try{
  203. log::record('---------工作列表--------');
  204. log::record($_REQUEST);
  205. $sessionid = $_REQUEST['sessionid'];
  206. $doctor = Cache::get($sessionid);
  207. log::record($doctor);
  208. $remote_institution_id = $doctor['institution_id'];
  209. $remote_doctor_id = $doctor['id'];
  210. $page = $_REQUEST['page'];
  211. $num = $_REQUEST['num'];
  212. $filed = 'ra.id as ra_id, ra.anamnesis, ra.application_desc, ra.attachment, ra.clin_diag, ra.clin_symp, ra.createdAt, ra.exam_id, ra.family_ill, ra.illness_desc, ra.is_urgent, ra.local_institution_id, ra.marrital, ra.phys_sign, ra.remark, ra.remote_doctor_id, ra.remote_institution_id, ra.report_status, ra.req_date_time, ra.req_doctor_id, ra.status, e.body_part, e.exam_class, e.device, e.exam_datetime, e.id as exam_id, e.exam_status, e.exam_sub_class, e.id, e.severe, e.patient_id, r.report_datetime as rdatetime, r.report_datetime, r.report_doctor_id, r.id as report_id, r.report_result, pi.age, pi.name, pi.sex, i.name as local_institution_name';
  213. $table = 'remote_application ra left join remote_order ro on ro.id = (select id from remote_order rot where rot.application_id = ra.id order by timestamp desc limit 1) left join exams e on ra.exam_id = e.id left join report r on ra.id = r.remote_application_id left join patient_infos pi on e.patient_id = pi.id left join institution i on ra.local_institution_id = i.id';
  214. $where1 = "ra.remote_institution_id=:remote_institution_id";
  215. $where2 = "(`ra`.`report_status` = '4' or `ra`.`report_status` = '6' or `ra`.`report_status` = '7' or `ra`.`report_status` = '8' or `ra`.`report_status` = '9')";
  216. $where3 = "(ra.remote_doctor_id= :remote_doctor_id or ra.remote_doctor_id = '')";
  217. $where4 = "(ro.status is null or ro.status = 2 or ro.status = 3)";
  218. $order = "(ra.is_urgent = '1' and ra.report_status = '4') desc, (ra.is_urgent = '1' and ra.report_status = '6') desc, (ra.is_urgent = '1' and ra.report_status = '7'), ra.req_date_time desc";
  219. $limit = ":start :number";
  220. $where = $where1." and ".$where2." and ".$where3." and ".$where4;
  221. $sql = "select ".$filed." from ".$table." where ".$where." order by ".$order." limit ".$limit;
  222. $options = [
  223. "remote_institution_id" => $remote_institution_id,
  224. "remote_doctor_id" => $remote_doctor_id,
  225. "start" => ($page - 1) * $num,
  226. "number" => $num
  227. ];
  228. $res = DB::execute($sql, $options);
  229. var_dump($res);
  230. // $db->execute(SQLServerHelp::SET_LIS_DEPARTEMT_SQL,$departemt);
  231. } catch(\Exception $e) {
  232. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  233. }
  234. }
  235. // select
  236. // ra.id as ra_id, ra.anamnesis, ra.application_desc, ra.attachment, ra.clin_diag, ra.clin_symp, ra.createdAt, ra.exam_id, ra.family_ill, ra.illness_desc, ra.is_urgent, ra.local_institution_id, ra.marrital, ra.phys_sign, ra.remark, ra.remote_doctor_id, ra.remote_institution_id, ra.report_status, ra.req_date_time, ra.req_doctor_id, ra.status,
  237. // e.body_part, e.exam_class, e.device, e.exam_datetime, e.id as exam_id, e.exam_status, e.exam_sub_class, e.id, e.severe, e.patient_id,
  238. // r.report_datetime as rdatetime, r.report_datetime, r.report_doctor_id, r.id as report_id, r.report_result,
  239. // pi.age, pi.name, pi.sex,
  240. // i.name as local_institution_name
  241. // from
  242. // remote_application ra
  243. // left join
  244. // remote_order ro
  245. // on
  246. // ro.id = (
  247. // select
  248. // id
  249. // from
  250. // remote_order rot
  251. // where
  252. // rot.application_id = ra.id
  253. // order by timestamp desc limit 1
  254. // )
  255. // left join
  256. // exams e
  257. // on
  258. // ra.exam_id = e.id
  259. // left join
  260. // report r
  261. // on
  262. // ra.id = r.remote_application_id
  263. // left join
  264. // patient_infos pi
  265. // on
  266. // e.patient_id = pi.id
  267. // left join
  268. // institution i
  269. // on
  270. // ra.local_institution_id = i.id
  271. // where
  272. // ra.remote_institution_id='09b4765b26ba8b7c'
  273. // and
  274. // (report_status = '4' or report_status = '6' or report_status = '7' or report_status = '8' or report_status = '9')
  275. // and
  276. // (ra.remote_doctor_id='b5bed8f973852c22' or ra.remote_doctor_id = '')
  277. // and
  278. // (ro.status is null or ro.status = 2 or ro.status = 3)
  279. // order by
  280. // (ra.is_urgent = '1' and ra.report_status = '4') desc,
  281. // (ra.is_urgent = '1' and ra.report_status = '6') desc,
  282. // (ra.is_urgent = '1' and ra.report_status = '7'),
  283. // ra.req_date_time desc
  284. // -- 4、申请 5、驳回 6、接收、7、初步报告 8、审核报告 9、确认、
  285. //接受 3
  286. /*public function accept(){
  287. $sessionid = $_REQUEST['sessionid'];
  288. $doctor = Cache::get($sessionid);
  289. $id = $_REQUEST['id'];
  290. DB::table('exams')->where('id',$id)->update(['exam_status'=>6]);
  291. DB::table('report')->where('exam_id',$id)->update(['report_doctor_id',$doctor['id']]);
  292. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已接受']);
  293. }
  294. //驳回 7
  295. public function reject(){
  296. // $sessionid = $_REQUEST['sessionid'];
  297. // $doctor = Cache::get($sessionid);
  298. $id = $_REQUEST['id'];
  299. DB::table('exams')->where('id',$id)->update(['exam_status'=>5]);
  300. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已驳回']);
  301. }
  302. //确认 5
  303. public function confirm(){
  304. $sessionid = $_REQUEST['sessionid'];
  305. $doctor = Cache::get($sessionid);
  306. $id = $_REQUEST['id'];
  307. DB::table('exams')->where('id',$id)->update(['exam_status'=>9]);
  308. DB::table('report')->where('exam_id',$id)->update(['confirm_doctor_id'=>$doctor['id'],'confirm_datetime'=>date('Y-m-d H:i:s')]);
  309. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  310. }
  311. // 审核
  312. public function examine(){
  313. $id = $_REQUEST['id'];
  314. DB::table('exams')->where('id',$id)->update(['exam_status'=>8]);
  315. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  316. }*/
  317. }