Writereport.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <?php
  2. namespace app\inter\controller;
  3. //use Doctrine\Common\Cache\Cache;
  4. use think\Controller;
  5. use think\Db;
  6. use think\Session;
  7. use app\common\library\UUIDs;
  8. use think\Cache;
  9. use think\Log;
  10. use app\common\library\Verify;
  11. class WriteReport extends Base
  12. {
  13. public function index(){
  14. try{
  15. log::record('-----请求值-----');
  16. log::record($_REQUEST);
  17. log::record('-----请求值-----');
  18. $sessionid = $_REQUEST['sessionid'];
  19. if(isset($_REQUEST['is_remote']) && !empty($_REQUEST['is_remote'])){
  20. $is_remote = $_REQUEST['is_remote'];
  21. }else{
  22. $is_remote = 0;
  23. }
  24. $doctor = Cache::get($sessionid);
  25. $institution = DB::table('institution')->where('id',$doctor['institution_id'])->field('name,report_subtitle')->find();
  26. $param = $_REQUEST['param'];
  27. $id = $param['id'];
  28. $info = DB::table('exams')->where('id',$id)->field(['id','study_id','exam_class','exam_datetime','exam_sub_class','body_part','accession_num','patient_id'])->find();
  29. $exam_class = DB::table('constant')->where('id',$info['exam_class'])->field('constant_value')->find();
  30. $info['exam_class'] = $exam_class['constant_value'];
  31. $exam_subclass = DB::table('exam_subclass')->where('id',$info['exam_sub_class'])->field('name')->find();
  32. $info['exam_sub_class'] = $exam_subclass['name'];
  33. $patient_info = DB::table('patient_infos')->where('id',$info['patient_id'])->field(['id','temp_patient_id','name','sex','age'])->find();
  34. $info['pid'] = $patient_info['temp_patient_id'];
  35. $info['name'] = $patient_info['name'];
  36. $info['sex'] = $patient_info['sex'];
  37. $info['age'] = $patient_info['age'];
  38. $info['hospital_name'] = $institution['name'];
  39. $info['hospital_title'] = $institution['report_subtitle'];
  40. $info['images'] = isset($param['images']) ? $param['images'] : '';
  41. $report = DB::table('report')->where('exam_id',$id)->field('report_datetime,report_doctor_id,review_datetime,review_doctor_id,impression,description')->find();
  42. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  43. $info['report_doctor'] = $report_doctor['realname'];
  44. $info['report_datetime'] = $report['report_datetime'];
  45. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  46. $info['review_doctor'] = $review_doctor['realname'];
  47. $info['review_datetime'] = $report['review_datetime'];
  48. $info['description'] = $report['description'];
  49. $info['impression'] = $report['impression'];
  50. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'is_remote'=>$is_remote]);
  51. }catch(\Exception $e){
  52. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  53. }
  54. }
  55. public function upload($files){
  56. // 获取表单上传文件
  57. foreach($files as $file){
  58. // 移动到框架应用根目录/public/uploads/ 目录下
  59. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  60. if($info){
  61. return $info->getSaveName();
  62. // 成功上传后 获取上传信息
  63. // 输出 jpg
  64. // echo $info-> getExtension();
  65. // 输出 42a79759f284b767dfcb2a0197904287.jpg
  66. // echo $info->getFilename();
  67. }else{
  68. // 上传失败获取错误信息
  69. // echo $file->getError();
  70. }
  71. }
  72. }
  73. public function write(){
  74. try{
  75. $sessionid = $_REQUEST['sessionid'];
  76. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  77. // 是远程写报告 7
  78. $return = Verify::check_role($sessionid,7);
  79. }else{
  80. // 本地写报告权限 2
  81. $return = Verify::check_role($sessionid,2);
  82. }
  83. if($return != 1){
  84. return json_encode(['status'=>'fail','code'=>'1029','msg'=>'没有操作权限']);
  85. }
  86. $param = $_REQUEST['param'];
  87. // Verify::wreportCheck($param);
  88. $doctor = Cache::get($sessionid);
  89. $remote_app = DB::table('remote_application')->where('exam_id',$param['id'])->field('remote_doctor_id')->find();
  90. if(!empty($remote_app['remote_doctor_id'])){
  91. if($remote_app['remote_doctor_id'] != $doctor['id']){
  92. // return json_encode(['status'=>'fail','code'=>'1029','msg'=>'已被指定报告医生,您没有操作权限']);
  93. }
  94. }
  95. $this->uuids = new UUIDs();
  96. $id = $this->uuids->uuid16();
  97. //初步报告生成
  98. $film_type = isset($param['film_type']) ? $param['film_type'] : '';
  99. DB::table('exams')->where('id',$param['id'])->update(['exam_status'=>7,'film_type'=>$film_type]);
  100. $patient_info = array();
  101. $patient_info['id'] = isset($param['pid']) ? $param['pid'] : '';
  102. $patient_info['name'] = isset($param['name']) ? $param['name'] : '';
  103. $patient_info['age'] = isset($param['age']) ? $param['age'] : '';
  104. $patient_info['sex'] = isset($param['sex']) ? $param['sex'] : '';
  105. $patient = DB::table('patient_infos')->where('id',$param['pid'])->update($patient_info);
  106. $info = array();
  107. $info['exam_id'] = $param['id'];
  108. $info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  109. $info['description'] = isset($param['description']) ? $param['description'] : '';
  110. if(isset($param['r_result']) && $param['r_result'] == 'true'){
  111. $info['report_result'] = 2;
  112. }else{
  113. $info['report_result'] = 1;
  114. }
  115. $info['report_datetime'] = date('Y-m-d H:i:s',time());
  116. $info['report_doctor_id'] = $doctor['id'];
  117. $report_info = DB::table('report')->where('exam_id',$param['id'])->find();
  118. if($report_info){
  119. $report = DB::table('report')->where('exam_id',$param['id'])->update($info);
  120. }else{
  121. $info['id'] = $id;
  122. $report = DB::table('report')->insert($info);
  123. }
  124. //写入log日志
  125. $log = array();
  126. $log['id'] = UUIDs::uuid16();
  127. $log['impression'] = isset($param['impression']) ? $param['impression'] : '';
  128. $log['description'] = isset($param['description']) ? $param['description'] : '';
  129. $log['report_id'] = $id;
  130. $log['ctime'] = date('Y-m-d H:i:s',time());
  131. $log['doctor_id'] = $doctor['id'];
  132. $log['type'] = 1; //写报告
  133. $report_log = DB::table('report_record')->insert($log);
  134. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'保存成功','sessionid'=>$sessionid]);
  135. }catch(\Exception $e){
  136. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  137. }
  138. }
  139. public function public_template(){
  140. $sessionid = $_REQUEST['sessionid'];
  141. $doctor = Cache::get($sessionid);
  142. $exam = $_REQUEST['exam_class'];
  143. //第一级 公共模板
  144. $info = $this->get_template(1,$doctor['id'],$exam);
  145. echo json_encode($info);
  146. }
  147. public function private_template(){
  148. $sessionid = $_REQUEST['sessionid'];
  149. $doctor = Cache::get($sessionid);
  150. $exam = $_REQUEST['exam_class'];
  151. //第一级 公共模板
  152. $info = $this->get_template(2,$doctor['id'],$exam);
  153. echo json_encode($info);
  154. }
  155. public function get_template($public,$id,$exam){
  156. // 查询exam_class表
  157. $examCla = DB::table('constant')->where('id',$exam)->field('constant_value as name')->find();
  158. if($public == 1){
  159. $t = DB::table('templates')->where('is_public',$public)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select();
  160. }else{
  161. // 私有模板 添加创建人条件
  162. $t = DB::table('templates')->where('is_public',$public)->where('create_user',$id)->where('exam_class_id',$examCla['name'])->field(['id','title as label','impression','description','parent_id'])->select();
  163. }
  164. if(!$t){
  165. return '';
  166. }
  167. $data = array();
  168. foreach ($t as $k => $v) {
  169. if($v['parent_id'] == 0){
  170. $data[] = $v;
  171. }
  172. }
  173. foreach ($data as $k => $v) {
  174. unset($data[$k]['impression']);
  175. unset($data[$k]['description']);
  176. unset($data[$k]['parent_id']);
  177. }
  178. foreach ($t as $k => $v) {
  179. foreach ($data as $key => $value) {
  180. if($v['parent_id'] == $value['id']){
  181. unset($t[$k]['parent_id']);
  182. $data[$key]['children'][] = $t[$k];
  183. }
  184. }
  185. }
  186. if($data){
  187. return $data;
  188. }
  189. }
  190. //确认 5
  191. public function confirm(){
  192. try{
  193. $sessionid = $_REQUEST['sessionid'];
  194. $doctor = Cache::get($sessionid);
  195. $id = $_REQUEST['id'];
  196. $status = DB::table('exams')->where('id',$id)->field('exam_status')->find();
  197. if($status['exam_status'] < 8 ){
  198. return json_encode(['status'=>'fail','code'=>'1033','msg'=>'只能确认通过审核的报告']);
  199. }elseif($status['exam_status'] == 9){
  200. return json_encode(['status'=>'fail','code'=>'1034','msg'=>'已经确认过该报告,不可再次确认']);
  201. }
  202. DB::table('exams')->where('id',$id)->update(['exam_status'=>9]);
  203. DB::table('report')->where('exam_id',$id)->update(['confirm_doctor_id'=>$doctor['id'],'confirm_datetime'=>date('Y-m-d H:i:s')]);
  204. // 添加 确认log日志
  205. $info = array();
  206. $info['id'] = UUIDs::uuid16();
  207. $info['ctime'] = date('Y-m-d H:i:s',time());
  208. $info['doctor_id'] = $doctor['id'];
  209. $info['type'] = 3;
  210. $info['report_id'] = '';
  211. DB::table('report_record')->insert($info);
  212. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已确认']);
  213. }catch(\Exception $e){
  214. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  215. }
  216. }
  217. // 审核
  218. public function examine(){
  219. try{
  220. $id = $_REQUEST['id'];
  221. $status = DB::table('exams')->where('id',$id)->field('exam_status')->find();
  222. if($status['exam_status'] < 7){
  223. return json_encode(['status'=>'fail','code'=>'1032','msg'=>'只能审核已提交的报告']);
  224. }elseif($status['exam_status']>7){
  225. return json_encode(['status'=>'fail','code'=>'1035','msg'=>'报告已通过审核步骤,请勿重复操作']);
  226. }
  227. $report = DB::table('report')->where('exam_id',$id)->field('id')->find();
  228. $param = $_REQUEST['param'];
  229. $sessionid = $_REQUEST['sessionid'];
  230. $doctor = Cache::get($sessionid);
  231. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  232. // 是远程审核报告 8
  233. $return = Verify::check_role($sessionid,8);
  234. }else{
  235. // 本地审核权限 3
  236. $return = Verify::check_role($sessionid,3);
  237. }
  238. $report_info = array();
  239. $report_info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  240. $report_info['description'] = isset($param['description']) ? $param['description'] : '';
  241. $report_info['report_result'] = isset($param['r_result']) ? $param['r_result'] : '';
  242. $report_info['review_datetime'] = date('Y-m-d H:i:s',time());
  243. $report_info['review_doctor_id'] = $doctor['id'];
  244. DB::table('report')->where('id',$report['id'])->update($report_info);
  245. $info = array();
  246. $info['id'] = UUIDs::uuid16();
  247. $info['type'] = 2; //审核
  248. $info['ctime'] = date('Y-m-d H:i:s',time());
  249. $info['doctor_id'] = $doctor['id'];
  250. $info['impression'] = isset($param['impression']) ? $param['impression'] : '';
  251. $info['description'] = isset($param['description']) ? $param['description'] : '';
  252. $info['report_id'] = $report['id'];
  253. DB::table('report_record')->insert($info);
  254. DB::table('exams')->where('id',$id)->update(['exam_status'=>8]);
  255. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已审核']);
  256. }catch(\Exception $e){
  257. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  258. }
  259. }
  260. public function getrole(){
  261. try{
  262. if(isset($_REQUEST['is_remote']) && $_REQUEST['is_remote'] == 1){
  263. $is_remote = $_REQUEST['is_remote'];
  264. }
  265. $sessionid = $_REQUEST['sessionid'];
  266. $doctor = Cache::get($sessionid);
  267. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->field('doctor_class')->find();
  268. $doctor_class = explode(',',$dclass['doctor_class']);
  269. $info = array();
  270. foreach ($doctor_class as $k=>$v) {
  271. switch($v){
  272. case 2: //报告医生
  273. if(isset($is_remote)){
  274. //远程报告
  275. break;
  276. }
  277. $info['bg'] = 1;
  278. break;
  279. case 7: //远程报告医生
  280. if(!isset($is_remote)){
  281. //远程报告
  282. break;
  283. }
  284. $info['bg'] = 1;
  285. break;
  286. case 3: //3审核医生
  287. if(isset($is_remote)){
  288. //远程报告
  289. break;
  290. }
  291. $info['sh'] = 2;
  292. break;
  293. case 8: //远程审核医生
  294. if(!isset($is_remote)){
  295. //远程报告
  296. break;
  297. }
  298. $info['sh'] = 2;
  299. break;
  300. case 4: //确认医生
  301. $info['qr'] = 3;
  302. break;
  303. }
  304. }
  305. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
  306. }catch(\Exception $e){
  307. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  308. }
  309. }
  310. public function get_report_log(){
  311. try{
  312. $sessionid = $_REQUEST['sessionid'];
  313. $doctor = Cache::get($sessionid);
  314. $exam_id = $_REQUEST['id'];
  315. $report = DB::table('report')->where('exam_id',$exam_id)->field('id')->find();
  316. $log_id = $report['id'];
  317. $log = DB::table('report_record')->where('doctor_id',$doctor['id'])->where('report_id',$log_id)->order('ctime asc,type asc')->select();
  318. foreach ($log as $k => $v) {
  319. $doc = DB::table('doctors')->where('id',$v['doctor_id'])->field('realname')->find();
  320. $log[$k]['doctor_name'] = $doc['realname'];
  321. }
  322. return json_encode(['status'=>'ok','code'=>'0000','info'=>$log]);
  323. }catch(\Exception $e){
  324. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  325. }
  326. }
  327. public function print_report(){
  328. try{
  329. $sessionid = $_REQUEST['sessionid'];
  330. $doctor = Cache::get($sessionid);
  331. $id = $_REQUEST['id'];
  332. $info = array();
  333. // 检查日期 住院号 床号
  334. $exam_info = DB::table('exams')->where('id',$id)->field('id,exam_datetime,exam_class,hopitalized_no,bed_no,exam_project,patient_id')->find();
  335. $info['id'] = $exam_info['id'];
  336. if(!empty($exam_info['exam_datetime'])){
  337. $datetime = explode(' ',$exam_info['exam_datetime']);
  338. $info['exam_datetime'] = $datetime[0];
  339. }else{
  340. $info['exam_datetime'] = '';
  341. }
  342. $info['hopitalized_no'] = $exam_info['hopitalized_no'];
  343. $info['bed_no'] = $exam_info['bed_no'];
  344. // 检查项目
  345. $project = DB::table('exam_project')->where('id',$exam_info['exam_project'])->field('name')->find();
  346. $info['project'] = $project['name'];
  347. //检查类
  348. $exam_class = DB::table('constant')->where('id',$exam_info['exam_class'])->field('constant_value')->find();
  349. $info['exam_class'] = $exam_class['constant_value'];
  350. // 病历号 姓名 年龄 性别
  351. $patient_info = DB::table('patient_infos')->where('id',$exam_info['patient_id'])->field('temp_patient_id,name,sex,age')->find();
  352. $remote = DB::table('remote_application')->where('exam_id',$id)->field('req_doctor_id')->find();
  353. $info['pnumber'] = $patient_info['temp_patient_id'];
  354. $info['name'] = $patient_info['name'];
  355. $info['sex'] = $patient_info['sex'];
  356. $info['age'] = $patient_info['age'];
  357. // 申请医生
  358. $application_name = DB::table('doctors')->where('id',$remote['req_doctor_id'])->field('realname,department_id')->find();
  359. $info['application_name'] = $application_name['realname'];
  360. // 申请科室
  361. $department = DB::table('department')->where('id',$application_name['department_id'])->field('department_name')->find();
  362. $info['department_name'] = $department['department_name'];
  363. // 报告时间 影像所见 意见建议
  364. $report = DB::table('report')->where('exam_id',$id)->field('report_datetime,impression,description,report_doctor_id,review_doctor_id')->find();
  365. if(!empty($report['report_datetime'])){
  366. $datetime1 = explode(' ',$report['report_datetime']);
  367. $info['report_datetime'] = $datetime1[0];
  368. }else{
  369. $info['report_datetime'] = '';
  370. }
  371. // $info['report_datetime'] = $report['report_datetime'];
  372. $info['impression'] = $report['impression'];
  373. $info['description'] = $report['description'];
  374. // 报告医生
  375. $report_doctor = DB::table('doctors')->where('id',$report['report_doctor_id'])->field('realname')->find();
  376. $info['report_doctor'] = $report_doctor['realname'];
  377. //审核医生
  378. $review_doctor = DB::table('doctors')->where('id',$report['review_doctor_id'])->field('realname')->find();
  379. $info['review_doctor'] = $review_doctor['realname'];
  380. $hospital = DB::table('institution')->where('id',$doctor['institution_id'])->field('name')->find();
  381. $info['hospital'] = $hospital['name'];
  382. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
  383. }catch(\Exception $e){
  384. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  385. }
  386. }
  387. public function change_film(){
  388. $id = $_REQUEST['id'];
  389. $film = $_REQUEST['film_type'];
  390. DB::table('exams')->where('id',$id)->update(['film_type'=>$film]);
  391. return json_encode(['status'=>'ok','code'=>'0000']);
  392. }
  393. }