Report.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. $sql = "SELECT a.id,a.severe,a.urgent,a.is_remote,a.accession_num,a.patient_num,a.exam_report,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 ".$where." order by a.createdAt desc".$limit;
  166. // }
  167. // if($doctor['institution_id'] == '13000003' and $page == 1 and empty($where)){
  168. // if(Cache::get('13000003_2')){
  169. // $list = Cache::get('13000003_2');
  170. // }else{
  171. // $list = DB::query($sql);
  172. // Cache::set('13000003_2',$list,86400);
  173. // }
  174. // }else{
  175. // $list = DB::query($sql);
  176. // }
  177. $list = DB::query($sql);
  178. $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 ".$where;
  179. $count = DB::query($csql);
  180. log::record('请求的sql语句');
  181. log::record($sql);
  182. log::record('请求到的数据');
  183. log::record($list);
  184. foreach ($list as $k => $v) {
  185. $cache_key = $doctor['id'].'_'.$v['id'];
  186. if(Cache::get($cache_key)){
  187. $list[$k]['status'] = 1;
  188. }else{
  189. $list[$k]['status'] = 0;
  190. }
  191. if($v['is_remote'] == 1){
  192. // 远程报告 获取发送的报告医院
  193. $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
  194. $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
  195. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  196. $list[$k]['exam_project_name'] = $project['name'];
  197. $list[$k]['report_app_name'] = $remote_name['name'];
  198. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id,review_doctor_id')->find();
  199. if($report){
  200. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  201. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  202. $list[$k]['review_doctor'] = $review_doctor['realname'];
  203. $list[$k]['report_doctor'] = $report_doctor['realname'];
  204. $list[$k]['report_datetime'] = $report['report_datetime'];
  205. }
  206. }else{
  207. $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
  208. $list[$k]['report_app_name'] = $remote_name['name'];
  209. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  210. $list[$k]['exam_project_name'] = $project['name'];
  211. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id,review_doctor_id')->find();
  212. if($report){
  213. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  214. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  215. $list[$k]['review_doctor'] = $review_doctor['realname'];
  216. $list[$k]['report_doctor'] = $report_doctor['realname'];
  217. $list[$k]['report_datetime'] = $report['report_datetime'];
  218. }else{
  219. $list[$k]['report_doctor'] = '';
  220. $list[$k]['report_datetime'] = '';
  221. }
  222. }
  223. }
  224. /*if($is_urgent == 1){
  225. //远程报告申请机构
  226. $doctor = Cache::get('doctor');
  227. //当前科室ID和name
  228. $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
  229. // 子科室ID name
  230. $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
  231. $institution[] = $p_institution;
  232. if($child_institution){
  233. foreach ($child_institution as $k => $v) {
  234. $institution[] = $v;
  235. }
  236. }
  237. $list['institution'] = $institution;
  238. }*/
  239. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  240. }catch(\Exception $e){
  241. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  242. }
  243. }
  244. public function del()
  245. {
  246. $id = $_REQUEST['id'];
  247. $sessionid = Request::instance()->param('sessionid');
  248. $user = Cache::get($sessionid);
  249. $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']]);
  250. if($info){
  251. return json_encode(['status'=>'ok','code'=>'0000']);
  252. }else{
  253. return json_encode(['status'=>'fail','code'=>'2000','msg'=>'删除失败']);
  254. }
  255. }
  256. }