Exams.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?php
  2. namespace app\admin\controller\exams;
  3. use app\admin\controller\institution\Institution;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. /**
  7. * 检查管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Exams extends Backend
  12. {
  13. /**
  14. * ExamsModel模型对象
  15. * @var \app\admin\model\exams\ExamsModel
  16. */
  17. protected $model = null;
  18. /**
  19. * 快速搜索时执行查找的字段
  20. */
  21. protected $searchFields = ['patient.name','patient_num'];
  22. protected $noNeedRight = ['getPrintData'];
  23. protected $noNeedLogin = ['getPrintData'];
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new \app\admin\model\exams\ExamsModel;
  28. }
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields, true);
  42. $join = [
  43. ['patient_infos patient','exams.patient_id = patient.id','LEFT'],
  44. ['institution','exams.institution_id = institution.id','LEFT'],
  45. ['studies','studies.id=exams.study_id','LEFT'],
  46. ['report','report.exam_id=exams.id and report.type=1','LEFT']
  47. ];
  48. $field = [
  49. 'exams.id','exams.institution_id','patient_num','exams.accession_num','exam_datetime','exam_class','body_part','exams.phone','study_id','exams.card_num',
  50. 'exam_status','urgent','film_type','exams.createdAt','exams.updatedAt','exams.status',
  51. 'patient.name','institution.name as institution_name','exams.hopitalized_no','exams.pay_status',
  52. 'report.report_datetime','review_datetime','report_doctor_name','review_doctor_name','studies.studytime'
  53. ];
  54. // 过滤机构
  55. $childInsIds = $this->auth->getMyInsId();
  56. if($childInsIds == false){
  57. $more = false;
  58. } else {
  59. $more = ['exams.institution_id' => ['in', $childInsIds]];
  60. }
  61. $total = $this->model->alias('exams')
  62. // ->join($join)
  63. ->where($more)
  64. ->where($where)
  65. // ->order($sort, $order)
  66. ->count();
  67. if($total < ($offset+10))
  68. {
  69. $limit = $total-$offset;
  70. }
  71. $list = $this->model->alias('exams')
  72. ->join($join)
  73. ->where($more)
  74. ->where($where)
  75. ->order($sort, $order)
  76. ->limit($offset, $limit)
  77. ->field($field)
  78. ->select();
  79. foreach ($list as $k=>$v)
  80. {
  81. $list[$k]['timeDiff'] = '';
  82. if(!empty($v['studytime']))
  83. {
  84. $list[$k]['studytime'] = substr($v['studytime'],0,2).':'.substr($v['studytime'],2,2).':'.substr($v['studytime'],4,2);
  85. }
  86. if(!empty($v['studytime']) && !empty($v['report_datetime']))
  87. {
  88. $studyTime = explode('.',$v['studytime']);
  89. $time = $studyTime[0] ?? '';
  90. if(!empty($time))
  91. {
  92. $difference = strtotime($v['report_datetime']) - strtotime($v['exam_datetime'].$time);
  93. $days = floor($difference / (60 * 60 * 24));
  94. $hours = floor(($difference - ($days * 60 * 60 * 24)) / (60 * 60));
  95. $minutes = floor(($difference - ($days * 60 * 60 * 24) - ($hours * 60 * 60)) / 60);
  96. $seconds = $difference - ($days * 60 * 60 * 24) - ($hours * 60 * 60) - ($minutes * 60);
  97. $list[$k]['timeDiff'] = "{$days}天{$hours}小时{$minutes}分钟{$seconds}秒";
  98. }
  99. }
  100. if($v['institution_id'] !== '04500002')
  101. {
  102. $list[$k]['name'] = $this->name_tm($v['name']);
  103. }
  104. $list[$k]['card_num'] = $this->idcard_tm($v['card_num']);
  105. $list[$k]['phone'] = $this->phone_tm($v['phone']);
  106. }
  107. $list = collection($list)->toArray();
  108. $result = array("total" => $total, "rows" => $list);
  109. return json($result);
  110. }
  111. return $this->view->fetch();
  112. }
  113. public function change_pay($ids)
  114. {
  115. $ins = $this->model->get($ids);
  116. if($this->request->isPost()){
  117. $info = $this->request->post();
  118. $res = $this->model->where('id', $ids)->update([
  119. 'pay_status' => $info['pay_status']
  120. ]);
  121. if(!$res){
  122. $this->error('更新失败','','',3);
  123. }
  124. if($info['pay_status'] == 1)
  125. {
  126. $institution = Db::table('institution')->where('id',$ins['institution_id'])->find();
  127. $money = [
  128. 'money'=>$institution['film_price'],
  129. 'order_type'=>$institution['charge_mode'],
  130. 'type'=>'2',
  131. 'exam_id'=>$ins['id'],
  132. 'institution_id'=>$ins['institution_id'],
  133. 'pay_way'=>'2',
  134. 'status'=>0,
  135. 'order_status'=>1,
  136. 'pay_type'=>'1'
  137. ];
  138. Db::table('money_water')->insert($money);
  139. }
  140. $this->success('修改成功','','',1);
  141. return true;
  142. }
  143. $this->view->ins = $ins;
  144. return $this->view->fetch('change_pay');
  145. }
  146. public function expExcel()
  147. {
  148. list($where) = $this->buildparams($this->searchFields, true);
  149. $data = Db::table('exams')
  150. ->alias('e')
  151. ->join(['report'=>'r'],'r.exam_id=e.id and r.type=1','left')
  152. ->where($where)
  153. ->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')
  154. ->select();
  155. import('phpexcel.PHPExcel', EXTEND_PATH);
  156. $obj = new \PHPExcel();
  157. // 以下内容是excel文件的信息描述信息
  158. $obj->getProperties()->setCreator(''); //设置创建者
  159. $obj->getProperties()->setLastModifiedBy(''); //设置修改者
  160. $obj->getProperties()->setTitle(''); //设置标题
  161. $obj->getProperties()->setSubject(''); //设置主题
  162. $obj->getProperties()->setDescription(''); //设置描述
  163. $obj->getProperties()->setKeywords('');//设置关键词
  164. $obj->getProperties()->setCategory('');//设置类型
  165. // 设置当前sheet
  166. $obj->setActiveSheetIndex(0);
  167. // 设置当前sheet的名称
  168. $obj->getActiveSheet()->setTitle('student');
  169. // 列标
  170. $list = ['A', 'B', 'C', 'D', 'E', 'F', 'G' , 'H'];
  171. // 填充第一行数据
  172. $obj->getActiveSheet()
  173. ->setCellValue($list[0] . '1', '姓名')
  174. ->setCellValue($list[1] . '1', '检查类型')
  175. ->setCellValue($list[2] . '1', '检查号')
  176. ->setCellValue($list[3] . '1', '病历号')
  177. ->setCellValue($list[4] . '1', '检查日期')
  178. ->setCellValue($list[5] . '1', '报告医生')
  179. ->setCellValue($list[6] . '1', '审核医生')
  180. ->setCellValue($list[7] . '1', '确认医生');
  181. // 填充第n(n>=2, n∈N*)行数据
  182. $length = count($data);
  183. for ($i = 0; $i < $length; $i++) {
  184. $obj->getActiveSheet()->setCellValue($list[0] . ($i + 2), $data[$i]['name'], \PHPExcel_Cell_DataType::TYPE_STRING);//将其设置为文本格式
  185. $obj->getActiveSheet()->setCellValue($list[1] . ($i + 2), $data[$i]['exam_class']);
  186. $obj->getActiveSheet()->setCellValue($list[2] . ($i + 2), $data[$i]['accession_num']);
  187. $obj->getActiveSheet()->setCellValue($list[3] . ($i + 2), $data[$i]['patient_num']);
  188. $obj->getActiveSheet()->setCellValue($list[4] . ($i + 2), $data[$i]['exam_datetime']);
  189. $obj->getActiveSheet()->setCellValue($list[5] . ($i + 2), $data[$i]['report_doctor_name']);
  190. $obj->getActiveSheet()->setCellValue($list[6] . ($i + 2), $data[$i]['review_doctor_name']);
  191. $obj->getActiveSheet()->setCellValue($list[7] . ($i + 2), $data[$i]['confirm_doctor_name']);
  192. }
  193. // 设置加粗和左对齐
  194. foreach ($list as $col) {
  195. // 设置第一行加粗
  196. $obj->getActiveSheet()->getStyle($col . '1')->getFont()->setBold(true);
  197. // 设置第1-n行,左对齐
  198. for ($i = 1; $i <= $length + 1; $i++) {
  199. $obj->getActiveSheet()->getStyle($col . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  200. }
  201. }
  202. // 设置列宽
  203. $obj->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  204. $obj->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  205. $obj->getActiveSheet()->getColumnDimension('C')->setWidth(15);
  206. ob_end_clean();
  207. // 导出
  208. // ob_clean();
  209. // if ($fileType == 'xls') {
  210. header('Content-Type: application/vnd.ms-excel');
  211. header('Content-Disposition: attachment;filename="' . time() . '.xls');
  212. header('Cache-Control: max-age=1');
  213. $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
  214. $objWriter->save('php://output');
  215. die;
  216. // } elseif ($fileType == 'xlsx') {
  217. // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  218. // header('Content-Disposition: attachment;filename="' . time() . '.xlsx');
  219. // header('Cache-Control: max-age=1');
  220. // $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
  221. // $objWriter->save('php://output');
  222. // exit;
  223. // }
  224. }
  225. public function exportExcel()
  226. {
  227. set_time_limit(0);
  228. $data = Db::table('exams')
  229. ->field('COUNT(*) c,institution_id,MAX(createdAt) max,MIN(createdAt) min')
  230. ->group('institution_id')
  231. ->order('c desc')
  232. ->select();
  233. $institution = Db::table('institution')->column('id,name');
  234. import('phpexcel.PHPExcel', EXTEND_PATH);
  235. $obj = new \PHPExcel();
  236. // 以下内容是excel文件的信息描述信息
  237. $obj->getProperties()->setCreator(''); //设置创建者
  238. $obj->getProperties()->setLastModifiedBy(''); //设置修改者
  239. $obj->getProperties()->setTitle(''); //设置标题
  240. $obj->getProperties()->setSubject(''); //设置主题
  241. $obj->getProperties()->setDescription(''); //设置描述
  242. $obj->getProperties()->setKeywords('');//设置关键词
  243. $obj->getProperties()->setCategory('');//设置类型
  244. // 设置当前sheet
  245. $obj->setActiveSheetIndex(0);
  246. // 设置当前sheet的名称
  247. $obj->getActiveSheet()->setTitle('student');
  248. // 列标
  249. $list = ['A', 'B', 'C', 'D', 'E', 'F', 'G' , 'H'];
  250. // 填充第一行数据
  251. $obj->getActiveSheet()
  252. ->setCellValue($list[0] . '1', '机构id')
  253. ->setCellValue($list[1] . '1', '机构名称')
  254. ->setCellValue($list[2] . '1', '检查总数')
  255. ->setCellValue($list[3] . '1', '开始上传时间')
  256. ->setCellValue($list[4] . '1', '最后上传时间');
  257. $arr = [];
  258. foreach ($data as $k=>$v)
  259. {
  260. if(!empty($institution[$data[$k]['institution_id']] ?? ''))
  261. {
  262. $arr[] = $v;
  263. }
  264. }
  265. // 填充第n(n>=2, n∈N*)行数据
  266. $length = count($arr);
  267. for ($i = 0; $i < $length; $i++) {
  268. $obj->getActiveSheet()->setCellValue($list[0] . ($i + 2), $arr[$i]['institution_id'], \PHPExcel_Cell_DataType::TYPE_STRING);//将其设置为文本格式
  269. $obj->getActiveSheet()->setCellValue($list[1] . ($i + 2), $institution[$arr[$i]['institution_id']]);
  270. $obj->getActiveSheet()->setCellValue($list[2] . ($i + 2), $arr[$i]['c']);
  271. $obj->getActiveSheet()->setCellValue($list[3] . ($i + 2), $arr[$i]['min']);
  272. $obj->getActiveSheet()->setCellValue($list[4] . ($i + 2), $arr[$i]['max']);
  273. }
  274. // 设置加粗和左对齐
  275. foreach ($list as $col) {
  276. // 设置第一行加粗
  277. $obj->getActiveSheet()->getStyle($col . '1')->getFont()->setBold(true);
  278. // 设置第1-n行,左对齐
  279. for ($i = 1; $i <= $length + 1; $i++) {
  280. $obj->getActiveSheet()->getStyle($col . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  281. }
  282. }
  283. // 设置列宽
  284. $obj->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  285. $obj->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  286. $obj->getActiveSheet()->getColumnDimension('C')->setWidth(10);
  287. $obj->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  288. $obj->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  289. ob_end_clean();
  290. // 导出
  291. // ob_clean();
  292. // if ($fileType == 'xls') {
  293. header('Content-Type: application/vnd.ms-excel');
  294. header('Content-Disposition: attachment;filename="' . time() . '.xls');
  295. header('Cache-Control: max-age=1');
  296. $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
  297. $objWriter->save('php://output');
  298. die;
  299. // } elseif ($fileType == 'xlsx') {
  300. // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  301. // header('Content-Disposition: attachment;filename="' . time() . '.xlsx');
  302. // header('Cache-Control: max-age=1');
  303. // $objWriter = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
  304. // $objWriter->save('php://output');
  305. // exit;
  306. // }
  307. }
  308. public function change_status($ids)
  309. {
  310. $ins = $this->model->get($ids);
  311. if($this->request->isPost()){
  312. $info = $this->request->post();
  313. $res = $this->model->where('id', $ids)->update([
  314. 'exam_status' => $info['exam_status'],
  315. 'patient_num'=>$info['patient_num'],
  316. 'accession_num'=>$info['accession_num']
  317. ]);
  318. if(!$res){
  319. $this->error('更新失败');
  320. }
  321. $this->success();
  322. return true;
  323. }
  324. $this->view->ins = $ins;
  325. return $this->view->fetch('change_status');
  326. }
  327. }