Report.php 14 KB

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