Report.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. }
  129. break;
  130. case 'exam_class' :
  131. if(empty($v)){
  132. break;
  133. }
  134. $ex = implode('\',\'',$v);
  135. $where .= " and a.exam_class in ('".$ex."')";
  136. break;
  137. default :
  138. if(empty($v)){
  139. break;
  140. }
  141. $where .= " and a.".$k."='".$v."'";
  142. }
  143. }
  144. }
  145. $page = $_REQUEST['page'];
  146. $num = $_REQUEST['num'];
  147. $fnum = ($page-1)*$num;
  148. $limit = " limit ".$fnum.",".$num;
  149. /*if(empty($where)){
  150. // 急诊sql 待处理
  151. $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'].")";
  152. //非急诊 待处理
  153. $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'].")";
  154. //已处理
  155. $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'].")";
  156. $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
  157. }else{*/
  158. $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;
  159. // }
  160. $list = DB::query($sql);
  161. $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;
  162. $count = DB::query($csql);
  163. log::record('请求的sql语句');
  164. log::record($sql);
  165. log::record('请求到的数据');
  166. log::record($list);
  167. foreach ($list as $k => $v) {
  168. $cache_key = $doctor['id'].'_'.$v['id'];
  169. if(Cache::get($cache_key)){
  170. $list[$k]['status'] = 1;
  171. }else{
  172. $list[$k]['status'] = 0;
  173. }
  174. if($v['is_remote'] == 1){
  175. // 远程报告 获取发送的报告医院
  176. $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
  177. $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
  178. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  179. $list[$k]['exam_project_name'] = $project['name'];
  180. $list[$k]['report_app_name'] = $remote_name['name'];
  181. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  182. if($report){
  183. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  184. $list[$k]['report_doctor'] = $report_doctor['realname'];
  185. $list[$k]['report_datetime'] = $report['report_datetime'];
  186. }
  187. }else{
  188. $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
  189. $list[$k]['report_app_name'] = $remote_name['name'];
  190. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  191. $list[$k]['exam_project_name'] = $project['name'];
  192. $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
  193. if($report){
  194. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  195. $list[$k]['report_doctor'] = $report_doctor['realname'];
  196. $list[$k]['report_datetime'] = $report['report_datetime'];
  197. }else{
  198. $list[$k]['report_doctor'] = '';
  199. $list[$k]['report_datetime'] = '';
  200. }
  201. }
  202. }
  203. /*if($is_urgent == 1){
  204. //远程报告申请机构
  205. $doctor = Cache::get('doctor');
  206. //当前科室ID和name
  207. $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
  208. // 子科室ID name
  209. $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
  210. $institution[] = $p_institution;
  211. if($child_institution){
  212. foreach ($child_institution as $k => $v) {
  213. $institution[] = $v;
  214. }
  215. }
  216. $list['institution'] = $institution;
  217. }*/
  218. return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
  219. }catch(\Exception $e){
  220. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  221. }
  222. }
  223. }