Report.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. /**
  13. * 科室报告列表
  14. *
  15. * @ApiTitle (科室报告列表)
  16. * @ApiSummary (科室报告列表)
  17. * @ApiSector (远程诊断)
  18. * @ApiMethod (POST)
  19. * @ApiRoute (/inter/report/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[name]", type="string", sample="", description="患者姓名<选填>")
  28. * @ApiParams (name="param[patient_num]", type="string", sample="", description="预约登记exams表id值<选填>")
  29. * @ApiParams (name="param[accession_num]", type="string", sample="", description="检查号<选填>")
  30. * @ApiParams (name="param[exam_status]", type="string", sample="", description="检查状态<选填>")
  31. * @ApiParams (name="param[exam_class]", type="string", sample="", description="检查类<选填>")
  32. * @ApiParams (name="param[exam_datetime]", type="string", sample="", description="申请时间<选填>")
  33. * @ApiParams (name="param[urgent]", 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="msg", type="string", required=true, sample="返回成功", description="返回消息")
  38. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  39. * @ApiReturnParams (name="count", type="object", sample="{}", description="总条数")
  40. * @ApiReturn (data="
  41. {
  42. 'status': ok,
  43. 'code': '0000',
  44. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  45. 'info' : ''
  46. 'count' : '110'
  47. }
  48. *")
  49. **/
  50. public function index(){
  51. try{
  52. $sessionid = Request::instance()->param('sessionid');
  53. $doctor = Cache::get($sessionid);
  54. if(!$doctor){
  55. return ResultTools::faile('1008', '您还未登录',$sessionid);
  56. }
  57. $eclass = DB::table('doctors')->where('id',$doctor['id'])->field('exam_class')->find();
  58. if($eclass['exam_class'] != '*'){
  59. $class = explode(',',$eclass['exam_class']);
  60. $e_class = implode('\',\'',$class);
  61. $where = ' and a.exam_class in (\''.$e_class.'\') ';
  62. }else{
  63. $where = '';
  64. }
  65. // $is_urgent = $_REQUEST['is_remote'];
  66. // $table = '';
  67. $order = ' order by a.urgent desc,a.createdAt desc';
  68. /*if($is_urgent == 1){
  69. //是远程报告
  70. $table = ',remote_application as r ';
  71. $where = ' and a.is_remote=1';
  72. $order = ' order by r.is_urgent desc';
  73. }*/
  74. log::record('-------------');
  75. log::record($_REQUEST);
  76. log::record('-------------');
  77. if(isset($_REQUEST['param'])){
  78. $search = $_REQUEST['param'];
  79. foreach($search as $k => $v){
  80. switch($k){
  81. case 'name':
  82. if(empty($v)){
  83. break;
  84. }
  85. $where .= ' and p.name like \''.$v.'%\'';
  86. break;
  87. case 'local_institution_id':
  88. if(empty($v)){
  89. break;
  90. }
  91. $where .= " and r.".$k."='".$v."' and r.exam_id=a.id";
  92. break;
  93. case 'urgent':
  94. if(empty($v)){
  95. break;
  96. }
  97. if($v == 'true'){
  98. $v = 1;
  99. }else{
  100. break;
  101. }
  102. $where .= " and a.".$k."='".$v."'";
  103. break;
  104. case 'report_result':
  105. if($v == 2){
  106. $where .= " and r.report_result=2";
  107. }elseif($v == 1){
  108. $where .= " and r.report_result=1";
  109. }{
  110. break;
  111. }
  112. break;
  113. case 'exam_datetime':
  114. if(empty($v)){
  115. break;
  116. }
  117. $data1 = str_replace('-', '',$v[0]);
  118. $data2 = str_replace('-', '',$v[1]);
  119. if($data1 == $data2){
  120. $where .= " and a.exam_datetime='$data1'";
  121. }else{
  122. $where .= " and a.exam_datetime between '$data1' and '$data2'";
  123. }
  124. break;
  125. case 'exam_status':
  126. if($v != 10 && !empty($v)){
  127. $where .= " and a.exam_status=".$v;
  128. }else{
  129. $where .= " and a.exam_status>2";
  130. }
  131. break;
  132. case 'exam_class' :
  133. if(empty($v)){
  134. break;
  135. }
  136. $ex = implode('\',\'',$v);
  137. $where .= " and a.exam_class in ('".$ex."')";
  138. break;
  139. case 'report_status':
  140. if($v != 10 && !empty($v)){
  141. $where .= " and ra.report_status=".$v;
  142. }
  143. break;
  144. default :
  145. if(empty($v)){
  146. break;
  147. }
  148. $where .= " and a.".$k."='".$v."'";
  149. }
  150. }
  151. }
  152. $page = $_REQUEST['page'];
  153. $num = $_REQUEST['num'];
  154. $fnum = ($page-1)*$num;
  155. $limit = " limit ".$fnum.",".$num;
  156. /*if(empty($where)){
  157. // 急诊sql 待处理
  158. $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'].")";
  159. //非急诊 待处理
  160. $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'].")";
  161. //已处理
  162. $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'].")";
  163. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  164. }else{*/
  165. $field = 'a.id,a.severe,a.urgent,a.accession_num,a.patient_num,a.report_result,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,a.application_doctor,a.application_department,p.name,p.sex,p.age,ra.report_status,i.name as report_app_name,ep.name as exam_project_name,r.report_datetime,dr.realname as report_doctor,dv.realname as review_doctor';
  166. $list = DB::table('exams')
  167. ->alias('a')
  168. ->join(['patient+info'=>'p'],'p.id=a.patient_id and a.status=1 and a.exam_status>2')
  169. ->join(['institution'=>'i'],'i.id=a.institution_id')
  170. ->join(['report'=>'r'],'a.id=r.exam_id and r.type=1','left')
  171. ->join(['doctors'=>'dr','dr.id=r.report_doctor_id','left'])
  172. ->join(['doctors'=>'dv','dv.id=r.review_doctor_id','left'])
  173. ->join(['remote_application'=>'ra'],'ra.exam_id=a.id','left')
  174. ->join(['exam_project'=>'ep'],'ep.id=a.exam_project','left')
  175. ->where('a.institution_id=\''.$doctor['institution_id'].'\'')
  176. ->where($where)
  177. ->order('a.createdAt desc')
  178. ->limit($limit)
  179. ->buildSql();
  180. var_dump($list);die;
  181. $count = DB::table('exams')
  182. ->alias('a')
  183. ->join(['patient+info'=>'p'],'p.id=a.patient_id and a.status=1 and a.exam_status>2')
  184. ->join(['institution'=>'i'],'i.id=a.institution_id')
  185. ->join(['report'=>'r'],'a.id=r.exam_id and r.type=1','left')
  186. ->join(['doctors'=>'dr','dr.id=r.report_doctor_id','left'])
  187. ->join(['doctors'=>'dv','dv.id=r.review_doctor_id','left'])
  188. ->join(['remote_application'=>'ra'],'ra.exam_id=a.id','left')
  189. ->join(['exam_project'=>'ep'],'ep.id=a.exam_project','left')
  190. ->where('a.institution_id=\''.$doctor['institution_id'].'\'')
  191. ->where($where)
  192. ->count();
  193. // $sql = "SELECT a.id,a.severe,a.urgent,a.accession_num,a.patient_num,a.report_result,a.study_id,a.exam_datetime,a.exam_project,a.exam_status,a.exam_class,a.application_doctor,a.application_department,p.name,p.sex,p.age,ra.report_status FROM (exams as a,patient_infos as p) LEFT JOIN remote_application as ra on ra.exam_id=a.id where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.status=1 and a.exam_status>2 ".$where." order by a.createdAt desc".$limit;
  194. // }
  195. // if($doctor['institution_id'] == '13000003' and $page == 1 and empty($where)){
  196. // if(Cache::get('13000003_2')){
  197. // $list = Cache::get('13000003_2');
  198. // }else{
  199. // $list = DB::query($sql);
  200. // Cache::set('13000003_2',$list,86400);
  201. // }
  202. // }else{
  203. // $list = DB::query($sql);
  204. // }
  205. // $list = DB::query($sql);
  206. // $csql = "SELECT count(1) FROM (exams as a,patient_infos as p) LEFT JOIN remote_application as ra on ra.exam_id=a.id where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id and a.status=1 and a.exam_status>2 ".$where;
  207. // $count = DB::query($csql);
  208. // log::record('请求的sql语句');
  209. // log::record($sql);
  210. // log::record('请求到的数据');
  211. // log::record($list);
  212. // foreach ($list as $k => $v) {
  213. // $cache_key = $doctor['id'].'_'.$v['id'];
  214. // if(Cache::get($cache_key)){
  215. // $list[$k]['status'] = 1;
  216. // }else{
  217. // $list[$k]['status'] = 0;
  218. // }
  219. // $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  220. // $list[$k]['report_app_name'] = $remote_name['name'];
  221. // $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  222. // $list[$k]['exam_project_name'] = $project['name'];
  223. // $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id,review_doctor_id')->find();
  224. // if($report){
  225. // $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  226. // $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  227. // $list[$k]['review_doctor'] = $review_doctor['realname'];
  228. // $list[$k]['report_doctor'] = $report_doctor['realname'];
  229. // $list[$k]['report_datetime'] = $report['report_datetime'];
  230. // }else{
  231. // $list[$k]['report_doctor'] = '';
  232. // $list[$k]['report_datetime'] = '';
  233. // }
  234. // }
  235. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count,'info'=>$list,'sessionid'=>$sessionid]);
  236. }catch(\Exception $e){
  237. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  238. }
  239. }
  240. public function del()
  241. {
  242. $id = $_REQUEST['id'];
  243. $sessionid = Request::instance()->param('sessionid');
  244. $user = Cache::get($sessionid);
  245. $info = DB::table('exams')->where('id',$id)->update(['status'=>0,'del_time'=>date('Y-m-d H:i:s',time()),'del_doctor_name'=>$user['realname']]);
  246. if($info){
  247. return json_encode(['status'=>'ok','code'=>'0000']);
  248. }else{
  249. return json_encode(['status'=>'fail','code'=>'2000','msg'=>'删除失败']);
  250. }
  251. }
  252. }