Reciveremote.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. $doc_class = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->value('doctor_class');
  213. // Log::record('医生id');
  214. // Log::record($remote_doctor_id);
  215. // Log::record(strpos('8', $doc_class));
  216. if(strpos($doc_class, '8') !== false){
  217. $where2 = "((`ra`.`report_status` = '7' or `ra`.`report_status` = '8' or `ra`.`report_status` = '9') or ((`ra`.`report_status` = '4' or `ra`.`report_status` = '6') and (`ra`.`remote_doctor_id`= ? or `ra`.`remote_doctor_id` = '')))";
  218. } else {
  219. $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') and (`ra`.`remote_doctor_id`= ? or `ra`.`remote_doctor_id` = '')";
  220. }
  221. $filed = "`d`.`realname` as `report_doctor_id`, `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`.`exam_class` as `class_name`, `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` as `r_report_doctor_id`, `r`.`id` as `report_id`, `r`.`report_result`, `pi`.`age`, `pi`.`name`, `pi`.`sex`, `pi`.`temp_patient_id`, `i`.`name` as `local_institution_name`";
  222. $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` left join `doctors` `d` on `r`.`report_doctor_id` = `d`.`id`";
  223. $where1 = "`ra`.`remote_institution_id` = ?";
  224. $where3 = "(`ro`.`status` is null or `ro`.`status` = 2 or `ro`.`status` = 3)";
  225. $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";
  226. $limit = "?, ?";
  227. $options = [
  228. $remote_institution_id,$remote_doctor_id
  229. ];
  230. $queryWhere = "";
  231. if(isset($_REQUEST['param'])){
  232. $param = $_REQUEST['param'];
  233. foreach ($param as $k => $v) {
  234. switch ($k) {
  235. case 'patient_num':
  236. $queryWhere.= " and `e`.`patient_num` like ?";
  237. $options[] = '%'.$v.'%';
  238. break;
  239. case 'exam_class' :
  240. if(empty($v)){
  241. break;
  242. }
  243. $length = sizeof($v);
  244. if($length === 1) {
  245. $queryWhere.= " and `e`.`exam_class` = ?";
  246. $options[] = $v[0];
  247. break;
  248. }
  249. $index = 1;
  250. $queryWhere.= " and (`e`.`exam_class` = ?";
  251. $options[] = $v[0];
  252. while($index < $length) {
  253. $queryWhere.= " or `e`.`exam_class` = ?";
  254. $options[] = $v[$index];
  255. $index++;
  256. }
  257. $queryWhere.= ')';
  258. // $queryWhere.= " and `e`.`exam_class` in ?";
  259. // $ex = implode("or `e`.`exam_class` = ", $v);
  260. // $val = "('".$ex."')";
  261. // // $where .= " and e.exam_class in ('".$ex."')";
  262. // $options[] = $val;
  263. // var_dump($val);
  264. break;
  265. case 'name':
  266. $queryWhere.= " and `pi`.`name` like ?";
  267. $options[] = '%'.$v.'%';
  268. break;
  269. case 'applicationtime':
  270. if(empty($v)){
  271. break;
  272. }
  273. $queryWhere.= " and `ra`.`req_date_time` between ? and ?";
  274. $options[] = $v[0];
  275. $options[] = $v[1];
  276. break;
  277. case 'is_urgent':
  278. if($v == 0){
  279. break;
  280. }
  281. $queryWhere.= " and `ra`.`is_urgent` = ?";
  282. $options[] = $v[0];
  283. break;
  284. case 'report_result':
  285. if($v == 1 || $v == 2) {
  286. $queryWhere.= " and `r`.`report_result` = ?";
  287. $options[] = $v[0];
  288. }
  289. break;
  290. case 'exam_status':
  291. if($v != 10){
  292. $queryWhere.= " and `ra`.`report_status` = ?";
  293. $options[] = $v[0];
  294. }
  295. break;
  296. }
  297. }
  298. }
  299. $where = $where1." and ".$where2." and ".$where3.$queryWhere;
  300. $listSql = "select ".$filed." from ".$table." where ".$where." order by ".$order." limit ".$limit;
  301. $countSql = "select count(*) as count from ".$table." where ".$where;
  302. log::record("----countSql----");
  303. log::record($countSql);
  304. log::record("----countSql----");
  305. log::record("---countSql-options----");
  306. log::record($options);
  307. log::record("---countSql-options----");
  308. $count = DB::query($countSql, $options);
  309. // var_dump($count);
  310. $options[] = ($page - 1) * $num;
  311. $options[] = $num;
  312. log::record("----sql----");
  313. log::record($listSql);
  314. log::record("----sql----");
  315. log::record("----options----");
  316. log::record($options);
  317. log::record("----options----");
  318. $list = DB::query($listSql, $options);
  319. foreach($list as $v) {
  320. if(empty($v['report_id'])) {
  321. $data = array();
  322. $data['id'] = UUIDs::uuid16();
  323. $data['exam_id'] = $v['exam_id'];
  324. $data['remote_application_id'] = $v['ra_id'];
  325. $data['type'] = 2;
  326. $data['createdAt'] = date('Y-m-d H:i:s',time());
  327. DB::table('report')->insert($data);
  328. $v['report_id'] = $data['id'];
  329. }
  330. }
  331. // var_dump($res);
  332. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count'],'info'=>$list,'sessionid'=>$sessionid]);
  333. } catch(\Exception $e) {
  334. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  335. }
  336. }
  337. // select
  338. // 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,
  339. // 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,
  340. // r.report_datetime as rdatetime, r.report_datetime, r.report_doctor_id, r.id as report_id, r.report_result,
  341. // pi.age, pi.name, pi.sex,
  342. // i.name as local_institution_name
  343. // from
  344. // remote_application ra
  345. // left join
  346. // remote_order ro
  347. // on
  348. // ro.id = (
  349. // select
  350. // id
  351. // from
  352. // remote_order rot
  353. // where
  354. // rot.application_id = ra.id
  355. // order by timestamp desc limit 1
  356. // )
  357. // left join
  358. // exams e
  359. // on
  360. // ra.exam_id = e.id
  361. // left join
  362. // report r
  363. // on
  364. // ra.id = r.remote_application_id
  365. // left join
  366. // patient_infos pi
  367. // on
  368. // e.patient_id = pi.id
  369. // left join
  370. // institution i
  371. // on
  372. // ra.local_institution_id = i.id
  373. // where
  374. // ra.remote_institution_id='09b4765b26ba8b7c'
  375. // and
  376. // (report_status = '4' or report_status = '6' or report_status = '7' or report_status = '8' or report_status = '9')
  377. // and
  378. // (ra.remote_doctor_id='b5bed8f973852c22' or ra.remote_doctor_id = '')
  379. // and
  380. // (ro.status is null or ro.status = 2 or ro.status = 3)
  381. // order by
  382. // (ra.is_urgent = '1' and ra.report_status = '4') desc,
  383. // (ra.is_urgent = '1' and ra.report_status = '6') desc,
  384. // (ra.is_urgent = '1' and ra.report_status = '7'),
  385. // ra.req_date_time desc
  386. // -- 4、申请 5、驳回 6、接收、7、初步报告 8、审核报告 9、确认、
  387. //接受 3
  388. /*public function accept(){
  389. $sessionid = $_REQUEST['sessionid'];
  390. $doctor = Cache::get($sessionid);
  391. $id = $_REQUEST['id'];
  392. DB::table('exams')->where('id',$id)->update(['exam_status'=>6]);
  393. DB::table('report')->where('exam_id',$id)->update(['report_doctor_id',$doctor['id']]);
  394. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已接受']);
  395. }
  396. //驳回 7
  397. public function reject(){
  398. // $sessionid = $_REQUEST['sessionid'];
  399. // $doctor = Cache::get($sessionid);
  400. $id = $_REQUEST['id'];
  401. DB::table('exams')->where('id',$id)->update(['exam_status'=>5]);
  402. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已驳回']);
  403. }
  404. //确认 5
  405. public function confirm(){
  406. $sessionid = $_REQUEST['sessionid'];
  407. $doctor = Cache::get($sessionid);
  408. $id = $_REQUEST['id'];
  409. DB::table('exams')->where('id',$id)->update(['exam_status'=>9]);
  410. DB::table('report')->where('exam_id',$id)->update(['confirm_doctor_id'=>$doctor['id'],'confirm_datetime'=>date('Y-m-d H:i:s')]);
  411. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  412. }
  413. // 审核
  414. public function examine(){
  415. $id = $_REQUEST['id'];
  416. DB::table('exams')->where('id',$id)->update(['exam_status'=>8]);
  417. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  418. }*/
  419. }