Report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->cache(300)->field('doctor_class')->find();
  58. // $is_urgent = $_REQUEST['is_remote'];
  59. $where = '';
  60. // $table = '';
  61. $order = ' order by a.urgent desc,a.createdAt desc';
  62. /*if($is_urgent == 1){
  63. //是远程报告
  64. $table = ',remote_application as r ';
  65. $where = ' and a.is_remote=1';
  66. $order = ' order by r.is_urgent desc';
  67. }*/
  68. log::record('-------------');
  69. log::record($_REQUEST);
  70. log::record('-------------');
  71. if(isset($_REQUEST['param'])){
  72. $search = $_REQUEST['param'];
  73. foreach($search as $k => $v){
  74. switch($k){
  75. case 'name':
  76. if(empty($v)){
  77. break;
  78. }
  79. $where .= ' and p.name like \''.$v.'%\'';
  80. break;
  81. case 'local_institution_id':
  82. if(empty($v)){
  83. break;
  84. }
  85. $where .= " and r.".$k."='".$v."' and r.exam_id=a.id";
  86. break;
  87. case 'urgent':
  88. if(empty($v)){
  89. break;
  90. }
  91. if($v == 'true'){
  92. $v = 1;
  93. }else{
  94. break;
  95. }
  96. $where .= " and a.".$k."='".$v."'";
  97. break;
  98. case 'report_result':
  99. if($v == 2){
  100. $where .= " and r.report_result=2";
  101. }elseif($v == 1){
  102. $where .= " and r.report_result=1";
  103. }{
  104. break;
  105. }
  106. break;
  107. case 'exam_datetime':
  108. if(empty($v)){
  109. break;
  110. }
  111. $data1 = str_replace('-', '',$v[0]);
  112. $data2 = str_replace('-', '',$v[1]);
  113. $where = " and a.exam_datetime between '$data1' and '$data2'";
  114. break;
  115. case 'exam_status':
  116. if($v != 10 && !empty($v)){
  117. $where .= " and a.exam_status=".$v;
  118. }
  119. break;
  120. case 'exam_class' :
  121. if(empty($v)){
  122. break;
  123. }
  124. $ex = implode('\',\'',$v);
  125. $where .= " and a.exam_class in ('".$ex."')";
  126. break;
  127. default :
  128. if(empty($v)){
  129. break;
  130. }
  131. $where .= " and a.".$k."='".$v."'";
  132. }
  133. }
  134. }
  135. $page = $_REQUEST['page'];
  136. $num = $_REQUEST['num'];
  137. $fnum = ($page-1)*$num;
  138. $limit = " limit ".$fnum.",".$num;
  139. /*if(empty($where)){
  140. // 急诊sql 待处理
  141. $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'].")";
  142. //非急诊 待处理
  143. $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'].")";
  144. //已处理
  145. $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'].")";
  146. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  147. }else{*/
  148. $sql = "SELECT a.id,a.urgent,a.is_remote,a.accession_num,a.exam_report,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 ".$where." order by a.createdAt desc".$limit;
  149. // }
  150. $list = DB::query($sql);
  151. $csql = "SELECT count(1) FROM exams as a,patient_infos as p where a.institution_id='".$doctor['institution_id']."' and p.id=a.patient_id ".$where;
  152. $count = DB::query($csql);
  153. log::record('请求的sql语句');
  154. log::record($sql);
  155. log::record('请求到的数据');
  156. log::record($list);
  157. foreach ($list as $k => $v) {
  158. $cache_key = $doctor['id'].'_'.$v['id'];
  159. if(Cache::get($cache_key)){
  160. $list[$k]['status'] = 1;
  161. }else{
  162. $list[$k]['status'] = 0;
  163. }
  164. if($v['is_remote'] == 1){
  165. // 远程报告 获取发送的报告医院
  166. $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
  167. $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
  168. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  169. $list[$k]['exam_project_name'] = $project['name'];
  170. $list[$k]['report_app_name'] = $remote_name['name'];
  171. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  172. if($report){
  173. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  174. $list[$k]['report_doctor'] = $report_doctor['realname'];
  175. $list[$k]['report_datetime'] = $report['report_datetime'];
  176. }
  177. }else{
  178. $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
  179. $list[$k]['report_app_name'] = $remote_name['name'];
  180. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  181. $list[$k]['exam_project_name'] = $project['name'];
  182. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  183. if($report){
  184. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  185. $list[$k]['report_doctor'] = $report_doctor['realname'];
  186. $list[$k]['report_datetime'] = $report['report_datetime'];
  187. }else{
  188. $list[$k]['report_doctor'] = '';
  189. $list[$k]['report_datetime'] = '';
  190. }
  191. }
  192. }
  193. /*if($is_urgent == 1){
  194. //远程报告申请机构
  195. $doctor = Cache::get('doctor');
  196. //当前科室ID和name
  197. $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
  198. // 子科室ID name
  199. $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
  200. $institution[] = $p_institution;
  201. if($child_institution){
  202. foreach ($child_institution as $k => $v) {
  203. $institution[] = $v;
  204. }
  205. }
  206. $list['institution'] = $institution;
  207. }*/
  208. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  209. }catch(\Exception $e){
  210. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  211. }
  212. }
  213. }