123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <?php
- namespace app\admin\controller\exams;
- use app\admin\controller\institution\Institution;
- use app\common\controller\Backend;
- use think\Db;
- /**
- * 检查管理
- *
- * @icon fa fa-circle-o
- */
- class Exams extends Backend
- {
-
- /**
- * ExamsModel模型对象
- * @var \app\admin\model\exams\ExamsModel
- */
- protected $model = null;
- /**
- * 快速搜索时执行查找的字段
- */
- protected $searchFields = ['patient.name','patient_num'];
- protected $noNeedRight = ['getPrintData'];
- protected $noNeedLogin = ['getPrintData'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\exams\ExamsModel;
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields, true);
- $join = [
- ['patient_infos patient','exams.patient_id = patient.id','LEFT'],
- ['institution','exams.institution_id = institution.id','LEFT'],
- ['studies','studies.id=exams.study_id','LEFT'],
- ['report','report.exam_id=exams.id and report.type=1','LEFT']
- ];
- $field = [
- 'exams.id','exams.institution_id','patient_num','exams.accession_num','exam_datetime','exam_class','body_part','exams.phone','study_id','exams.card_num',
- 'exam_status','urgent','film_type','exams.createdAt','exams.updatedAt','exams.status',
- 'patient.name','institution.name as institution_name','exams.hopitalized_no','exams.pay_status',
- 'report.report_datetime','review_datetime','report_doctor_name','review_doctor_name','studies.studytime'
- ];
- // 过滤机构
- $childInsIds = $this->auth->getMyInsId();
- if($childInsIds == false){
- $more = false;
- } else {
- $more = ['exams.institution_id' => ['in', $childInsIds]];
- }
- $total = $this->model->alias('exams')
- // ->join($join)
- ->where($more)
- ->where($where)
- // ->order($sort, $order)
- ->count();
- if($total < ($offset+10))
- {
- $limit = $total-$offset;
- }
- $list = $this->model->alias('exams')
- ->join($join)
- ->where($more)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->field($field)
- ->select();
- foreach ($list as $k=>$v)
- {
- $list[$k]['timeDiff'] = '';
- if(!empty($v['studytime']))
- {
- $list[$k]['studytime'] = substr($v['studytime'],0,2).':'.substr($v['studytime'],2,2).':'.substr($v['studytime'],4,2);
- }
- if(!empty($v['studytime']) && !empty($v['report_datetime']))
- {
- $studyTime = explode('.',$v['studytime']);
- $time = $studyTime[0] ?? '';
- if(!empty($time))
- {
- $difference = strtotime($v['report_datetime']) - strtotime($v['exam_datetime'].$time);
- $days = floor($difference / (60 * 60 * 24));
- $hours = floor(($difference - ($days * 60 * 60 * 24)) / (60 * 60));
- $minutes = floor(($difference - ($days * 60 * 60 * 24) - ($hours * 60 * 60)) / 60);
- $seconds = $difference - ($days * 60 * 60 * 24) - ($hours * 60 * 60) - ($minutes * 60);
- $list[$k]['timeDiff'] = "{$days}天{$hours}小时{$minutes}分钟{$seconds}秒";
- }
- }
- if($v['institution_id'] !== '04500002')
- {
- $list[$k]['name'] = $this->name_tm($v['name']);
- }
- $list[$k]['card_num'] = $this->idcard_tm($v['card_num']);
- $list[$k]['phone'] = $this->phone_tm($v['phone']);
- }
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- public function change_pay($ids)
- {
- $ins = $this->model->get($ids);
- if($this->request->isPost()){
- $info = $this->request->post();
- $res = $this->model->where('id', $ids)->update([
- 'pay_status' => $info['pay_status']
- ]);
- if(!$res){
- $this->error('更新失败','','',3);
- }
- if($info['pay_status'] == 1)
- {
- $institution = Db::table('institution')->where('id',$ins['institution_id'])->find();
- $money = [
- 'money'=>$institution['film_price'],
- 'order_type'=>$institution['charge_mode'],
- 'type'=>'2',
- 'exam_id'=>$ins['id'],
- 'institution_id'=>$ins['institution_id'],
- 'pay_way'=>'2',
- 'status'=>0,
- 'order_status'=>1,
- 'pay_type'=>'1'
- ];
- Db::table('money_water')->insert($money);
- }
- $this->success('修改成功','','',1);
- return true;
- }
- $this->view->ins = $ins;
- return $this->view->fetch('change_pay');
- }
- public function expExcel()
- {
- list($where) = $this->buildparams($this->searchFields, true);
- $data = Db::table('exams')
- ->alias('e')
- ->join(['report'=>'r'],'r.exam_id=e.id and r.type=1','left')
- ->where($where)
- ->field('e.name,e.exam_class,e.accession_num,e.patient_num,e.exam_datetime,r.report_doctor_name,r.review_doctor_name,r.confirm_doctor_name')
- ->select();
- import('phpexcel.PHPExcel', EXTEND_PATH);
- $obj = new \PHPExcel();
- // 以下内容是excel文件的信息描述信息
- $obj->getProperties()->setCreator(''); //设置创建者
- $obj->getProperties()->setLastModifiedBy(''); //设置修改者
- $obj->getProperties()->setTitle(''); //设置标题
- $obj->getProperties()->setSubject(''); //设置主题
- $obj->getProperties()->setDescription(''); //设置描述
- $obj->getProperties()->setKeywords('');//设置关键词
- $obj->getProperties()->setCategory('');//设置类型
- // 设置当前sheet
- $obj->setActiveSheetIndex(0);
- // 设置当前sheet的名称
- $obj->getActiveSheet()->setTitle('student');
- // 列标
- $list = ['A', 'B', 'C', 'D', 'E', 'F', 'G' , 'H'];
- // 填充第一行数据
- $obj->getActiveSheet()
- ->setCellValue($list[0] . '1', '姓名')
- ->setCellValue($list[1] . '1', '检查类型')
- ->setCellValue($list[2] . '1', '检查号')
- ->setCellValue($list[3] . '1', '病历号')
- ->setCellValue($list[4] . '1', '检查日期')
- ->setCellValue($list[5] . '1', '报告医生')
- ->setCellValue($list[6] . '1', '审核医生')
- ->setCellValue($list[7] . '1', '确认医生');
- // 填充第n(n>=2, n∈N*)行数据
- $length = count($data);
- for ($i = 0; $i < $length; $i++) {
- $obj->getActiveSheet()->setCellValue($list[0] . ($i + 2), $data[$i]['name'], \PHPExcel_Cell_DataType::TYPE_STRING);//将其设置为文本格式
- $obj->getActiveSheet()->setCellValue($list[1] . ($i + 2), $data[$i]['exam_class']);
- $obj->getActiveSheet()->setCellValue($list[2] . ($i + 2), $data[$i]['accession_num']);
- $obj->getActiveSheet()->setCellValue($list[3] . ($i + 2), $data[$i]['patient_num']);
- $obj->getActiveSheet()->setCellValue($list[4] . ($i + 2), $data[$i]['exam_datetime']);
- $obj->getActiveSheet()->setCellValue($list[5] . ($i + 2), $data[$i]['report_doctor_name']);
- $obj->getActiveSheet()->setCellValue($list[6] . ($i + 2), $data[$i]['review_doctor_name']);
- $obj->getActiveSheet()->setCellValue($list[7] . ($i + 2), $data[$i]['confirm_doctor_name']);
- }
- // 设置加粗和左对齐
- foreach ($list as $col) {
- // 设置第一行加粗
- $obj->getActiveSheet()->getStyle($col . '1')->getFont()->setBold(true);
- // 设置第1-n行,左对齐
- for ($i = 1; $i <= $length + 1; $i++) {
- $obj->getActiveSheet()->getStyle($col . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- }
- // 设置列宽
- $obj->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $obj->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $obj->getActiveSheet()->getColumnDimension('C')->setWidth(15);
- ob_end_clean();
- // 导出
- // ob_clean();
- // if ($fileType == 'xls') {
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="' . time() . '.xls');
- header('Cache-Control: max-age=1');
- $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
- $objWriter->save('php://output');
- die;
- // } elseif ($fileType == 'xlsx') {
- // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- // header('Content-Disposition: attachment;filename="' . time() . '.xlsx');
- // header('Cache-Control: max-age=1');
- // $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
- // $objWriter->save('php://output');
- // exit;
- // }
- }
- public function exportExcel()
- {
- set_time_limit(0);
- $data = Db::table('exams')
- ->field('COUNT(*) c,institution_id,MAX(createdAt) max,MIN(createdAt) min')
- ->group('institution_id')
- ->order('c desc')
- ->select();
- $institution = Db::table('institution')->column('id,name');
- import('phpexcel.PHPExcel', EXTEND_PATH);
- $obj = new \PHPExcel();
- // 以下内容是excel文件的信息描述信息
- $obj->getProperties()->setCreator(''); //设置创建者
- $obj->getProperties()->setLastModifiedBy(''); //设置修改者
- $obj->getProperties()->setTitle(''); //设置标题
- $obj->getProperties()->setSubject(''); //设置主题
- $obj->getProperties()->setDescription(''); //设置描述
- $obj->getProperties()->setKeywords('');//设置关键词
- $obj->getProperties()->setCategory('');//设置类型
- // 设置当前sheet
- $obj->setActiveSheetIndex(0);
- // 设置当前sheet的名称
- $obj->getActiveSheet()->setTitle('student');
- // 列标
- $list = ['A', 'B', 'C', 'D', 'E', 'F', 'G' , 'H'];
- // 填充第一行数据
- $obj->getActiveSheet()
- ->setCellValue($list[0] . '1', '机构id')
- ->setCellValue($list[1] . '1', '机构名称')
- ->setCellValue($list[2] . '1', '检查总数')
- ->setCellValue($list[3] . '1', '开始上传时间')
- ->setCellValue($list[4] . '1', '最后上传时间');
- $arr = [];
- foreach ($data as $k=>$v)
- {
- if(!empty($institution[$data[$k]['institution_id']] ?? ''))
- {
- $arr[] = $v;
- }
- }
- // 填充第n(n>=2, n∈N*)行数据
- $length = count($arr);
- for ($i = 0; $i < $length; $i++) {
- $obj->getActiveSheet()->setCellValue($list[0] . ($i + 2), $arr[$i]['institution_id'], \PHPExcel_Cell_DataType::TYPE_STRING);//将其设置为文本格式
- $obj->getActiveSheet()->setCellValue($list[1] . ($i + 2), $institution[$arr[$i]['institution_id']]);
- $obj->getActiveSheet()->setCellValue($list[2] . ($i + 2), $arr[$i]['c']);
- $obj->getActiveSheet()->setCellValue($list[3] . ($i + 2), $arr[$i]['min']);
- $obj->getActiveSheet()->setCellValue($list[4] . ($i + 2), $arr[$i]['max']);
- }
- // 设置加粗和左对齐
- foreach ($list as $col) {
- // 设置第一行加粗
- $obj->getActiveSheet()->getStyle($col . '1')->getFont()->setBold(true);
- // 设置第1-n行,左对齐
- for ($i = 1; $i <= $length + 1; $i++) {
- $obj->getActiveSheet()->getStyle($col . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- }
- // 设置列宽
- $obj->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $obj->getActiveSheet()->getColumnDimension('B')->setWidth(30);
- $obj->getActiveSheet()->getColumnDimension('C')->setWidth(10);
- $obj->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- $obj->getActiveSheet()->getColumnDimension('E')->setWidth(20);
- ob_end_clean();
- // 导出
- // ob_clean();
- // if ($fileType == 'xls') {
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="' . time() . '.xls');
- header('Cache-Control: max-age=1');
- $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
- $objWriter->save('php://output');
- die;
- // } elseif ($fileType == 'xlsx') {
- // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- // header('Content-Disposition: attachment;filename="' . time() . '.xlsx');
- // header('Cache-Control: max-age=1');
- // $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
- // $objWriter->save('php://output');
- // exit;
- // }
- }
- public function change_status($ids)
- {
- $ins = $this->model->get($ids);
- if($this->request->isPost()){
- $info = $this->request->post();
- $res = $this->model->where('id', $ids)->update([
- 'exam_status' => $info['exam_status'],
- 'patient_num'=>$info['patient_num'],
- 'accession_num'=>$info['accession_num']
- ]);
- if(!$res){
- $this->error('更新失败');
- }
- $this->success();
- return true;
- }
- $this->view->ins = $ins;
- return $this->view->fetch('change_status');
- }
- }
|