Registerlist.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. $search = array();
  59. $where = '';
  60. if(isset($_REQUEST['param'])){
  61. $search = $_REQUEST['param'];
  62. foreach ($search as $k => $v) {
  63. /*if($k == 'name' && !empty($v)){
  64. $where .= ' and p.name like \''.$v.'%\'';
  65. }elseif($k == 'exam_datetime' && !empty($v)){
  66. $where .= " and e.exam_datetime between '$v[0]' and '$v[1]'";
  67. }else{
  68. if(!empty($v)){
  69. $where .= ' and e.'.$k.'=\''.$v.'\'';
  70. }
  71. }*/
  72. switch($k){
  73. case 'name':
  74. if(empty($v)){
  75. break;
  76. }
  77. $where .= ' and p.name like \''.$v.'%\'';
  78. break;
  79. case 'exam_datetime':
  80. if(empty($v)){
  81. break;
  82. }
  83. $data1 = str_replace('-', '',$v[0]);
  84. $data2 = str_replace('-', '',$v[1]);
  85. if($data1 == $data2){
  86. $where .= " and e.exam_datetime ='$data2'";
  87. }else{
  88. $where .= " and e.exam_datetime between '$data1' and '$data2'";
  89. }
  90. break;
  91. case 'exam_class' :
  92. if(empty($v)){
  93. break;
  94. }
  95. $ex = implode('\',\'',$v);
  96. $where .= " and e.exam_class in ('".$ex."')";
  97. break;
  98. default:
  99. if(empty($v)){
  100. break;
  101. }
  102. $where .= ' and e.'.$k.'=\''.$v.'\'';
  103. break;
  104. }
  105. }
  106. }
  107. $page = $_REQUEST['page'];
  108. $num = $_REQUEST['num'];
  109. $fnum = ($page-1)*$num;
  110. $limit = " limit ".$fnum.",".$num;
  111. log::record("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".$where);
  112. $sql = "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".$where." order by e.createdAt desc,e.urgent desc ".$limit;
  113. $list = DB::query($sql);
  114. foreach ($list as $k => $v) {
  115. $report_info = DB::table('report')->where('exam_id',$v['id'])->field(['report_datetime','report_doctor_id'])->find();
  116. $list[$k]['report_datetime'] = $report_info['report_datetime'];
  117. $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
  118. $list[$k]['exam_project_name'] = $project['name'];
  119. $dinfo = DB::table('doctors')->where('id',$report_info['report_doctor_id'])->field('realname,institution_id')->find();
  120. $list[$k]['report_doctor'] = $dinfo['realname'];
  121. $institution_name = DB::table('institution')->where('id',$dinfo['institution_id'])->cache(300)->field('name')->find();
  122. $list[$k]['institution_name'] = $institution_name['name'];
  123. }
  124. $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;
  125. $count = DB::query($sql1);
  126. return json_encode(['status'=>'ok','code'=>'0000','info'=>$list,'count'=>$count[0]['count(1)'],'sessionid'=>$sessionid]);
  127. }catch(\Exception $e){
  128. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  129. }
  130. }
  131. }