Registerlist.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Log;
  8. use think\Cache;
  9. class Registerlist extends Base
  10. {
  11. /**
  12. * 预约登记列表
  13. *
  14. * @ApiTitle (预约登记列表)
  15. * @ApiSummary (预约登记列表)
  16. * @ApiSector (远程诊断)
  17. * @ApiMethod (POST)
  18. * @ApiRoute (/inter/registerlist/index)
  19. * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
  20. * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
  21. * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
  22. * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
  23. * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
  24. * @ApiParams (name="page", type="string", required=true, description="当前页")
  25. * @ApiParams (name="num", type="string", required=true, description="每页显示条数")
  26. * @ApiParams (name="param[patient_num]", type="string", sample="", description="预约登记exams表id值<选填>")
  27. * @ApiParams (name="param[accession_num]", type="string", sample="", description="检查号<选填>")
  28. * @ApiParams (name="param[name]", type="string", sample="", description="患者姓名<选填>")
  29. * @ApiParams (name="param[exam_datetime]", type="string", sample="", description="检查时间<选填>")
  30. * @ApiParams (name="param[exam_status]", type="string", sample="", description="检查状态<选填>")
  31. * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
  32. * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
  33. * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
  34. * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
  35. * @ApiReturnParams (name="count", type="object", sample="{}", description="总条数")
  36. * @ApiReturn (data="
  37. {
  38. 'status': ok,
  39. 'code': '0000',
  40. 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
  41. 'info' : ''
  42. 'count' : '110'
  43. }
  44. *")
  45. **/
  46. public function index(){
  47. try{
  48. log::record('------------接收的值--------------------');
  49. log::record($_REQUEST);
  50. log::record('--------------------------------');
  51. $sessionid = $_REQUEST['sessionid'];
  52. $doctor = Cache::get($sessionid);
  53. if(!$doctor){
  54. return ResultTools::faile('1008', '您还未登录');
  55. }
  56. log::record($doctor);
  57. log::record('-------------doctor-------------------');
  58. $where = '';
  59. $page = $_REQUEST['page'];
  60. $num = $_REQUEST['num'];
  61. $fnum = ($page-1)*$num;
  62. $limit = " limit ".$fnum.",".$num;
  63. if(isset($_REQUEST['param'])){
  64. $param = $_REQUEST['param'];
  65. if(!empty($param['exam_status'])){
  66. $where = ' and e.exam_status = '.$param['exam_status'];
  67. }
  68. /*foreach ($search as $k => $v) {
  69. switch($k){
  70. case 'name':
  71. if(empty($v)){
  72. break;
  73. }
  74. $where .= ' and p.name like \''.$v.'%\'';
  75. break;
  76. case 'exam_datetime':
  77. if(empty($v)){
  78. break;
  79. }
  80. $data1 = str_replace('-', '',$v[0]);
  81. $data2 = str_replace('-', '',$v[1]);
  82. if($data1 == $data2){
  83. $where .= " and e.exam_datetime ='$data2'";
  84. }else{
  85. $where .= " and e.exam_datetime between '$data1' and '$data2'";
  86. }
  87. break;
  88. case 'exam_class' :
  89. if(empty($v)){
  90. break;
  91. }
  92. if(is_array($v)){
  93. $ex = implode('\',\'',$v);
  94. }else{
  95. $ex = $v;
  96. }
  97. $where .= " and e.exam_class in ('".$ex."')";
  98. break;
  99. default:
  100. if(empty($v)){
  101. break;
  102. }
  103. $where .= ' and e.'.$k.'=\''.$v.'\'';
  104. break;
  105. }
  106. }*/
  107. }
  108. $sql1 = "SELECT e.id,e.is_remote,e.study_id,e.patient_num,e.institution_id,e.exam_datetime,e.exam_class,e.exam_project,e.exam_status,p.name,p.sex,p.age from exams as e ,patient_infos as p where e.institution_id='".$doctor['institution_id']."' and p.id=e.patient_id";
  109. //
  110. if(isset($param['search']) && !empty($param['search'])){
  111. // 姓名 病历号 检查号
  112. $search1 = ' and p.name like \'%'.$param['search'].'%\' ';
  113. $search2 = ' and e.patient_num=\''.$param['search'].'\' ';
  114. $search3 = ' and e.accession_num=\''.$param['search'].'\' ';
  115. $sql = ($sql1.$search1). ' union '. ($sql1.$search2) .' union '. ($sql1.$search3).$limit;
  116. }else{
  117. $sql = $sql1.$where." order by e.createdAt desc,e.urgent desc ".$limit;
  118. }
  119. log::record('预约登记的sql是--'.$sql);
  120. $list = DB::query($sql);
  121. foreach ($list as $k => $v) {
  122. $report_info = DB::table('report')->where('exam_id',$v['id'])->field(['report_datetime','report_doctor_id'])->find();
  123. $list[$k]['report_datetime'] = $report_info['report_datetime'];
  124. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  125. $list[$k]['exam_project_name'] = $project['name'];
  126. $dinfo = DB::table('doctors')->where('id',$report_info['report_doctor_id'])->field('realname,institution_id')->find();
  127. $list[$k]['report_doctor'] = $dinfo['realname'];
  128. $institution_name = DB::table('institution')->where('id',$dinfo['institution_id'])->cache(300)->field('name')->find();
  129. $list[$k]['institution_name'] = $institution_name['name'];
  130. }
  131. $sql1 = "SELECT count(1) from exams as e ,patient_infos as p where e.institution_id='".$doctor['institution_id']."' and p.id=e.patient_id".$where;
  132. $count = DB::query($sql1);
  133. return json_encode(['status'=>'ok','code'=>'0000','info'=>$list,'count'=>$count[0]['count(1)'],'sessionid'=>$sessionid]);
  134. }catch(\Exception $e){
  135. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  136. }
  137. }
  138. }