123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- namespace app\inter\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use app\common\library\ResultTools;
- use think\Cache;
- use think\Log;
- use think\Request;
- class Report extends Base
- {
- /**
- * 科室报告列表
- *
- * @ApiTitle (科室报告列表)
- * @ApiSummary (科室报告列表)
- * @ApiSector (远程诊断)
- * @ApiMethod (POST)
- * @ApiRoute (/inter/report/index)
- * @ApiHeaders (name="sign", type="string", required=true, description="请求头-校验key")
- * @ApiHeaders (name="nonce", type="string", required=true, description="请求头-随机数")
- * @ApiHeaders (name="timestamp", type=string, required=true, description="请求头-时间戳s")
- * @ApiParams (name="sessionid", type="string", required=true, description="参数json字符串")
- * @ApiParams (name="param", type="string", required=true, description="参数json字符串")
- * @ApiParams (name="page", type="string", required=true, description="当前页")
- * @ApiParams (name="num", type="string", required=true, description="每页显示条数")
- * @ApiParams (name="param[name]", type="string", sample="", description="患者姓名<选填>")
- * @ApiParams (name="param[patient_num]", type="string", sample="", description="预约登记exams表id值<选填>")
- * @ApiParams (name="param[accession_num]", type="string", sample="", description="检查号<选填>")
- * @ApiParams (name="param[exam_status]", type="string", sample="", description="检查状态<选填>")
- * @ApiParams (name="param[exam_class]", type="string", sample="", description="检查类<选填>")
- * @ApiParams (name="param[exam_datetime]", type="string", sample="", description="申请时间<选填>")
- * @ApiParams (name="param[urgent]", type="string", sample="", description="是否急诊<选填>")
- * @ApiReturnParams (name="status", type="integer", required=true, sample="0", description="返回码 fail 失败 ok成功"))
- * @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回状态码")
- * @ApiReturnParams (name="info", type="string", required=true, sample="返回成功", description="返回信息")
- * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功", description="返回消息")
- * @ApiReturnParams (name="sessionid", type="object", sample="{}", description="缓存的数据key")
- * @ApiReturnParams (name="count", type="object", sample="{}", description="总条数")
- * @ApiReturn (data="
- {
- 'status': ok,
- 'code': '0000',
- 'sessionid': 'a17z7a7a8f9g9rh9d89jio',
- 'info' : ''
- 'count' : '110'
- }
- *")
- **/
- public function index(){
- try{
- $sessionid = Request::instance()->param('sessionid');
- $doctor = Cache::get($sessionid);
- if(!$doctor){
- return ResultTools::faile('1008', '您还未登录',$sessionid);
- }
- $eclass = DB::table('doctors')->where('id',$doctor['id'])->field('exam_class')->find();
- if($eclass['exam_class'] != '*'){
- $class = explode(',',$eclass['exam_class']);
- $e_class = implode('\',\'',$class);
- $where = ' and a.exam_class in (\''.$e_class.'\') ';
- }else{
- $where = '';
- }
- // $is_urgent = $_REQUEST['is_remote'];
- // $table = '';
- $order = ' order by a.urgent desc,a.createdAt desc';
- /*if($is_urgent == 1){
- //是远程报告
- $table = ',remote_application as r ';
- $where = ' and a.is_remote=1';
- $order = ' order by r.is_urgent desc';
- }*/
- log::record('-------------');
- log::record($_REQUEST);
- log::record('-------------');
- if(isset($_REQUEST['param'])){
- $search = $_REQUEST['param'];
- foreach($search as $k => $v){
- switch($k){
- case 'name':
- if(empty($v)){
- break;
- }
- $where .= ' and p.name like \''.$v.'%\'';
- break;
- case 'local_institution_id':
- if(empty($v)){
- break;
- }
- $where .= " and r.".$k."='".$v."' and r.exam_id=a.id";
- break;
- case 'urgent':
- if(empty($v)){
- break;
- }
- if($v == 'true'){
- $v = 1;
- }else{
- break;
- }
- $where .= " and a.".$k."='".$v."'";
- break;
- case 'report_result':
- if($v == 2){
- $where .= " and r.report_result=2";
- }elseif($v == 1){
- $where .= " and r.report_result=1";
- }{
- break;
- }
- break;
- case 'exam_datetime':
- if(empty($v)){
- break;
- }
- $data1 = str_replace('-', '',$v[0]);
- $data2 = str_replace('-', '',$v[1]);
- if($data1 == $data2){
- $where .= " and a.exam_datetime='$data1'";
- }else{
- $where .= " and a.exam_datetime between '$data1' and '$data2'";
- }
- break;
- case 'exam_status':
- if($v != 10 && !empty($v)){
- $where .= " and a.exam_status=".$v;
- }
- break;
- case 'exam_class' :
- if(empty($v)){
- break;
- }
- $ex = implode('\',\'',$v);
- $where .= " and a.exam_class in ('".$ex."')";
- break;
- default :
- if(empty($v)){
- break;
- }
- $where .= " and a.".$k."='".$v."'";
- }
- }
- }
- $page = $_REQUEST['page'];
- $num = $_REQUEST['num'];
- $fnum = ($page-1)*$num;
- $limit = " limit ".$fnum.",".$num;
- /*if(empty($where)){
- // 急诊sql 待处理
- $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'].")";
- //非急诊 待处理
- $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'].")";
- //已处理
- $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'].")";
- $sql = '('.$sql1.') union ('.$sql2.') union ('.$sql3.')'.$limit;
- }else{*/
- $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;
- // }
- $list = DB::query($sql);
- $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;
- $count = DB::query($csql);
- log::record('请求的sql语句');
- log::record($sql);
- log::record('请求到的数据');
- log::record($list);
- foreach ($list as $k => $v) {
- $cache_key = $doctor['id'].'_'.$v['id'];
- if(Cache::get($cache_key)){
- $list[$k]['status'] = 1;
- }else{
- $list[$k]['status'] = 0;
- }
- if($v['is_remote'] == 1){
- // 远程报告 获取发送的报告医院
- $remote = DB::table('remote_application')->where('exam_id',$v['id'])->field('remote_institution_id')->find();
- $remote_name = DB::table('institution')->where('id',$remote['remote_institution_id'])->cache(300)->field('name')->find();
- $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
- $list[$k]['exam_project_name'] = $project['name'];
- $list[$k]['report_app_name'] = $remote_name['name'];
- $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
- if($report){
- $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
- $list[$k]['report_doctor'] = $report_doctor['realname'];
- $list[$k]['report_datetime'] = $report['report_datetime'];
- }
- }else{
- $remote_name = DB::table('institution')->where('id',$doctor['institution_id'])->cache(300)->field('name')->find();
- $list[$k]['report_app_name'] = $remote_name['name'];
- $project = DB::table('exam_project')->where('id',$v['exam_project'])->field('name')->find();
- $list[$k]['exam_project_name'] = $project['name'];
- $report = DB::table('report')->where('exam_id',$v['id'])->field('report_datetime,report_doctor_id')->find();
- if($report){
- $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
- $list[$k]['report_doctor'] = $report_doctor['realname'];
- $list[$k]['report_datetime'] = $report['report_datetime'];
- }else{
- $list[$k]['report_doctor'] = '';
- $list[$k]['report_datetime'] = '';
- }
- }
- }
- /*if($is_urgent == 1){
- //远程报告申请机构
- $doctor = Cache::get('doctor');
- //当前科室ID和name
- $p_institution = DB::table('institution')->where('id',$doctor['institution_id'])->field(['id','name'])->find();
- // 子科室ID name
- $child_institution = DB::table('institution')->where('parent_institution',$doctor['institution_id'])->field(['id','name'])->select();
- $institution[] = $p_institution;
- if($child_institution){
- foreach ($child_institution as $k => $v) {
- $institution[] = $v;
- }
- }
- $list['institution'] = $institution;
- }*/
- return json_encode(['status'=>'ok','code'=>'0000','count'=>$count[0]['count(1)'],'info'=>$list,'sessionid'=>$sessionid]);
- }catch(\Exception $e){
- return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
- }
- }
- }
|