RemoteService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <?php
  2. namespace app\api\servies\remote;
  3. use app\api\common\ServerResponse;
  4. use app\api\response\ZskkErrorResponse;
  5. use app\api\servies\ZskkDefaultService;
  6. use app\api\validate\remote\RemoteValidate;
  7. use app\api\dao\remote\RemoteDao;
  8. use think\facade\Log;
  9. /**
  10. * 后台控制器基类
  11. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  12. */
  13. class RemoteService extends ZskkDefaultService {
  14. protected $logName = "RemoteService";
  15. private $remote = null;
  16. public function __construct(RemoteDao $remoteDao) {
  17. parent::__construct();
  18. $this->remote = $remoteDao;
  19. }
  20. public function getUser($token)
  21. {
  22. $user = $this->remote->getUser($token);
  23. return $user;
  24. }
  25. public function get_today_report($id){
  26. $today = date('Y-m-d 00:00:00',time());
  27. $number = $this->remote->getReportNum($id,$today);
  28. return $number;
  29. }
  30. public function get_all_report($id){
  31. $number = $this->remote->getAllNum($id);
  32. return $number;
  33. }
  34. public function get_institution_num($id){
  35. $count = $this->remote->getCountNum($id,'local_institution_id');
  36. return $count;
  37. // $field = ['local_institution_id'];
  38. // $remote = $this->remote->getRemoteInfo($ids,$field);
  39. // $institution_num = count($remote);
  40. // return $institution_num;
  41. }
  42. // public function get_local_institution($id){
  43. // $ids = $this->get_ids($id);
  44. // $field = ['local_institution_id'];
  45. // $remote = $this->remote->getRemoteInfo($ids,$field);
  46. // $ins_ids = array();
  47. // foreach ($remote as $k => $v) {
  48. // $ins_ids[] = $v['local_institution_id'];
  49. // }
  50. // $info = $this->remote->getInstitutionInfo($ins_ids);
  51. // return $info;
  52. // }
  53. public function get_local_ins($institution)
  54. {
  55. $field = ['local_institution_id'];
  56. $remote = $this->remote->getRemoteByIns($institution,$field);
  57. $ins_ids = array();
  58. foreach ($remote as $k => $v) {
  59. $ins_ids[] = $v['local_institution_id'];
  60. }
  61. $info = $this->remote->getInstitutionInfo($ins_ids);
  62. return $info;
  63. }
  64. public function get_patient_num($id){
  65. $count = $this->remote->getCountNum($id,'r.id');
  66. return $count;
  67. // $patient = $this->remote->getPatient($ids);
  68. // $patient_num = count(json_decode(json_encode($patient),true));
  69. // return $patient_num;
  70. /* $field = ['exam_id'];
  71. $exam = $this->remote->getRemoteInfo($ids,$field);
  72. $pids = array();
  73. foreach($exam as $k=>$v){
  74. $pids[] = $v['exam_id'];
  75. }
  76. $patientField = ['patient_num'];
  77. $patient = $this->remote->getExamInfo($pids,$patientField);
  78. $patient_num = count(json_decode(json_encode($patient),true));
  79. return $patient_num;*/
  80. }
  81. // public function get_ids($id,$field){
  82. // $institution = $this->remote->getApplicationId($id,$field);
  83. // $ids = array();
  84. // foreach($institution as $k=>$v){
  85. // $ids[] = $v['remote_application_id'];
  86. // }
  87. // return $ids;
  88. // }
  89. public function getwhere($params)
  90. {
  91. if(isset($params['search']) && !empty($params['search'])){
  92. $field = ['local_institution_id','name','sex','req_date_time','report_datetime','is_urgent','exam_class','report_status'];
  93. $data = [];
  94. $data['more_search'] = $params['search'];
  95. $where = $this->getListSpecificWhere($data,$field);
  96. // 精准搜索
  97. // $where = $this->get_where_search($params['search']);
  98. }elseif(isset($params['fuzzy']) && !empty($params['fuzzy'])){
  99. $field = ['name','accession_num','patient_num','body_part_text'];
  100. // 模糊搜索
  101. $data = [];
  102. $data['fuzzy_search'] = $params['fuzzy'];
  103. $where = $this->getListFuzzyWhere($data,$field);
  104. // $where = $this->get_fuzzy_search($params['fuzzy']);
  105. }else{
  106. $where = '';
  107. }
  108. return $where;
  109. }
  110. public function get_where_search($param){
  111. $where = '';
  112. foreach ($param as $k => $v) {
  113. switch ($k) {
  114. case 'local_institution_id':
  115. if(empty($v['value'])){
  116. break;
  117. }
  118. $where .= " and ra." . $k . "='" . $v['value'] . "' ";
  119. break;
  120. case 'name':
  121. if(empty($v['value'])){
  122. break;
  123. }
  124. $where .= " and name like '".$v['value']."%' ";
  125. break;
  126. case 'sex':
  127. if(empty($v['value'])){
  128. break;
  129. }
  130. $where .= " and sex=".$v['value'];
  131. break;
  132. case 'req_date_time':
  133. if(empty($v['value'])){
  134. break;
  135. }
  136. $time1 = $v['value'][0];
  137. $time2 = $v['value'][1];
  138. $where .= " and ra.req_date_time between '$time1' and '$time2'";
  139. break;
  140. case 'report_datetime':
  141. if(empty($v['value'])){
  142. break;
  143. }
  144. $time11 = $v['value'][0];
  145. $time22 = $v['value'][1];
  146. $where .= " and r.report_datetime between '$time11' and '$time22'";
  147. break;
  148. case 'is_urgent':
  149. if(empty($v['value'])){
  150. break;
  151. }
  152. $where .= " and ra.is_urgent=".$v['value'];
  153. break;
  154. case 'exam_class':
  155. if(empty($v['value'])){
  156. break;
  157. }
  158. $where .= " and exam_class=".$v['value'];
  159. break;
  160. case 'report_status':
  161. if(empty($v['value'])){
  162. break;
  163. }
  164. if($v != 10){
  165. $where .= " and ra.report_status=".$v['value'];
  166. }
  167. break;
  168. }
  169. }
  170. return $where;
  171. }
  172. // 获取模糊搜索条件
  173. public function get_fuzzy_search($fuzzy){
  174. $where = "(name like '%$fuzzy%' or patient_num='$fuzzy' or accession_num='$fuzzy') ";
  175. return $where;
  176. }
  177. public function getLimit($params)
  178. {
  179. $page = $params['page'];
  180. $num = $params['num'];
  181. $fnum = ($page-1)*$num;
  182. $limit = " limit ".$fnum.",".$num;
  183. return $limit;
  184. }
  185. public function getTimeWhere($params)
  186. {
  187. $twhere = '';
  188. if(isset($params['today']) && !empty($params['today'])){
  189. $date1 = date('Y-m-d 00:00:00');
  190. $date2 = date('Y-m-d 23:59:59');
  191. $twhere = "ra.req_date_time between '$date1' and '$date2'";
  192. }
  193. return $twhere;
  194. }
  195. public function getTodayInfo($doctor,$fuzzyWhere,$params)
  196. {
  197. $data = $this->makeTodayWhere($doctor);
  198. if(empty($data)){
  199. //没有写、审核权限
  200. return [];
  201. }
  202. $where = $data['where'];
  203. $where_status = $data['where_status'];
  204. $report_where = $data['report_where'];
  205. $review_where = $data['review_where'];
  206. if($doctor['exam_class'] == '*')
  207. {
  208. $class_where = [];
  209. }else{
  210. $class_where[] = ['exam_class','in',explode(',',$doctor['exam_class'])];
  211. }
  212. $info = $this->remote->getTodayInfo($doctor,$where,$where_status,$report_where,$review_where,$class_where,$fuzzyWhere,$params);
  213. return $info;
  214. }
  215. // 处理未完成状态的where条件
  216. public function makeTodayWhere($doctor)
  217. {
  218. $where = [];
  219. $where_status = [];
  220. $report_where = [];
  221. $review_where = [];
  222. if($doctor['is_admin'] == 1){
  223. $where[] = ['ra.report_status','in','4,6,7,8']; //申请 接收 已写 已审
  224. $data = ['where'=>$where,'where_status'=>$where_status,'report_where'=>$report_where,'review_where'=>$review_where];
  225. return $data;
  226. }else{
  227. //医院内是否存在管理员
  228. $institution_admin = $this->remote->getDoctorAdmin($doctor['institution_id']);
  229. // 医生权限类
  230. $doctor_class = $this->remote->getDoctorClass($doctor['id']);
  231. if(strpos($doctor_class, '7,8') !== false){
  232. //有 写 审核 权限
  233. $where_status[] = ['ra.report_status','in','4,6'];
  234. if($institution_admin){
  235. //医院内存在超级管理员
  236. $where['ra.remote_doctor_id'] = $doctor['id'];
  237. }else{
  238. $did = $doctor['id'];
  239. $where = "remote_doctor_id = '$did' OR `remote_doctor_id` = '' OR `remote_doctor_id` IS NULL";
  240. // $where[] = ['remote_doctor_id', ['=', $doctor['id']], ['=', ''],['=',null], 'or'];
  241. }
  242. //所有已写
  243. $report_where['report_status'] = '7';
  244. //当前医生的审核
  245. $review_where['report_status'] = '8';
  246. $review_where['review_doctor_id'] = $doctor['id'];
  247. $data = ['where'=>$where,'where_status'=>$where_status,'report_where'=>$report_where,'review_where'=>$review_where];
  248. return $data;
  249. }else{
  250. if(strpos($doctor_class, '8') !== false){
  251. //有远程审核权限
  252. //所有已写
  253. $report_where['report_status'] = '7';
  254. //当前医生的审核
  255. $review_where['report_status'] = '8';
  256. $review_where['review_doctor_id'] = $doctor['id'];
  257. $data = ['where'=>$where,'where_status'=>$where_status,'report_where'=>$report_where,'review_where'=>$review_where];
  258. return $data;
  259. }elseif(strpos($doctor_class, '7') !== false){
  260. //没有远程审核权限
  261. $where_status[] = ['ra.report_status','in','4,6'];
  262. if($institution_admin){
  263. //医院内存在超级管理员
  264. $where['ra.remote_doctor_id'] = $doctor['id'];
  265. }else{
  266. $did = $doctor['id'];
  267. $where = "remote_doctor_id = '$did' OR `remote_doctor_id` = '' OR `remote_doctor_id` IS NULL";
  268. // $where[] = ['remote_doctor_id', ['=', $doctor['id']], ['=', ''],['=',null], 'or'];
  269. }
  270. $data = ['where'=>$where,'where_status'=>$where_status,'report_where'=>$report_where,'review_where'=>$review_where];
  271. return $data;
  272. }else{
  273. //没有写、审核权限 返回空
  274. return [];
  275. }
  276. }
  277. }
  278. }
  279. public function getAllInfo($params,$doctor,$where)
  280. {
  281. if($doctor['exam_class'] == '*')
  282. {
  283. $class_where = [];
  284. }else{
  285. $class_where[] = ['exam_class','in',$doctor['exam_class']];
  286. }
  287. if($params['zt'] == 0){ //所有
  288. $info = $this->getAll($params,$doctor,$where,$class_where);
  289. return $info;
  290. }elseif ($params['zt'] == 1){ //未完成
  291. $info = $this->getIncomplete($params,$doctor,$where,$class_where);
  292. return $info;
  293. }elseif ($params['zt'] == 2){ //已确认
  294. $info = $this->getConfirm($params,$doctor,$class_where,$where);
  295. return $info;
  296. }elseif ($params['zt'] == 3){ //已驳回
  297. $info = $this->getReject($params,$doctor,$class_where,$where);
  298. return $info;
  299. }
  300. }
  301. //全部诊断 全部tab页
  302. public function getAll($params,$doctor,$search,$class_where)
  303. {
  304. $where_status = [];
  305. $where = [];
  306. $report_status = [];
  307. $report_where = [];
  308. $remote_where = [];
  309. //医院内是否存在管理员
  310. $institution_admin = $this->remote->getDoctorAdmin($doctor['institution_id']);
  311. // 医生权限类
  312. $doctor_class = $this->remote->getDoctorClass($doctor['id']);
  313. if($doctor['is_admin'] == 1){
  314. //超级管理员 展示所有的信息
  315. $where_status[] = ['ra.report_status','not in','2,3'];
  316. $info = $this->remote->getAllInfo($params,$doctor,$where,$where_status,$report_where,$remote_where,$report_status,$search,$class_where);
  317. return $info;
  318. }else{
  319. if(strpos($doctor_class, '7,8') !== false){
  320. //既是写 又是审
  321. if($institution_admin){
  322. //医院内存在超级管理员
  323. $remote_where['ra.remote_doctor_id'] = $doctor['id'];
  324. $report_status['ra.report_status'] = '7';
  325. //
  326. $report_where['review_doctor_id'] = $doctor['id'];
  327. $info = $this->remote->getAllInfo($params,$doctor,$where,$where_status,$report_where,$report_status,$remote_where,$search,$class_where);
  328. return $info;
  329. }else{
  330. // 无管理员
  331. //受邀人是自己或者为空 状态为申请和接收
  332. $remote_where['ra.remote_doctor_id'] = $doctor['id']; //申请人是自己
  333. $where_status['ra.report_status'] = '4';
  334. $where['remote_doctor_id'] = null;
  335. $report_where[] = ['ra.report_status','in','7,8,9,10'];
  336. $info = $this->remote->getAllInfo($params,$doctor,$where,$where_status,$report_where,$report_status,$remote_where,$search,$class_where);
  337. return $info;
  338. }
  339. }else{
  340. if(strpos($doctor_class, '8') !== false){
  341. //有远程审核权限
  342. if($institution_admin){
  343. //医院内存在超级管理员
  344. $report_status = '7';
  345. $report_where['review_doctor_id'] = $doctor['id'];
  346. }else{
  347. //无管理
  348. $report_status[] = ['report_status','in','7,8,9,10'];
  349. }
  350. $info = $this->remote->getAllInfo($params,$doctor,$where,$where_status,$report_where,$report_status,$remote_where,$search,$class_where);
  351. return $info;
  352. }elseif(strpos($doctor_class, '7') !== false){
  353. // 只有写权限
  354. if($institution_admin){
  355. //医院内存在超级管理员
  356. $remote_where['ra.remote_doctor_id'] = $doctor['id'];
  357. }else{
  358. //无管理
  359. $remote_where['ra.remote_doctor_id'] = $doctor['id'];
  360. //
  361. $where_status['ra.report_status'] = '4';
  362. $where['remote_doctor_id'] = '';
  363. }
  364. $info = $this->remote->getAllInfo($params,$doctor,$where,$where_status,$report_where,$report_status,$remote_where,$search,$class_where);
  365. return $info;
  366. }
  367. }
  368. }
  369. }
  370. // 全部诊断 未完成
  371. public function getIncomplete($params,$doctor,$search,$class_where)
  372. {
  373. $data = $this->makeTodayWhere($doctor);
  374. $where = $data['where'] ?? '';
  375. $where_status = $data['where_status'] ?? '';
  376. $report_where = $data['report_where'] ?? '';
  377. $review_where = $data['review_where'] ?? '';
  378. $info = $this->remote->getIncomplete($params,$doctor,$where,$where_status,$report_where,$review_where,$class_where,$search);
  379. return $info;
  380. }
  381. //全部诊断 已确认
  382. public function getConfirm($params,$doctor,$class_where,$where)
  383. {
  384. $report_where = [];
  385. $review_where = [];
  386. $review_status = [];
  387. $report_status = [];
  388. $report_review_where = [];
  389. $doctor_class = $this->remote->getDoctorClass($doctor['id']);
  390. if($doctor['is_admin'] == 1){
  391. //超级管理员
  392. $report_status[] = ['report_status','in','9,10'];
  393. $info = $this->remote->getConfirm($params,$doctor,$report_where,$review_where,$review_status,$report_status,$report_review_where,$class_where,$where);
  394. return $info;
  395. }else{
  396. if(strpos($doctor_class, '7,8') !== false){
  397. //既是写 又是审
  398. //作为审核 审核医生是自己
  399. $review_where['review_doctor_id'] = $doctor['id'];
  400. //作为审核 状态大于审核 (本地确认,远程确认)
  401. $review_status[] = ['report_status','in','9,10'];
  402. //作为报告 审核医生不是自己
  403. $report_review_where[] = ['review_doctor_id','<>',$doctor['id']];
  404. //作为报告 写报告是自己
  405. $report_where['report_doctor_id'] = $doctor['id'];
  406. //作为报告 状态大于写报告 (审核,远程确认,本地确认)
  407. $report_status[] = ['report_status','in','8,9,10'];
  408. $info = $this->remote->getConfirm($params,$doctor,$report_where,$review_where,$review_status,$report_status,$report_review_where,$class_where,$where);
  409. return $info;
  410. }else{
  411. if(strpos($doctor_class, '8') !== false){
  412. //审核医生
  413. //作为审核 审核医生是自己
  414. $review_where['review_doctor_id'] = $doctor['id'];
  415. //作为审核 状态大于审核 (本地确认,远程确认)
  416. $review_status[] = ['report_status','in','9,10'];
  417. $info = $this->remote->getConfirm($params,$doctor,$report_where,$review_where,$review_status,$report_status,$report_review_where,$class_where,$where);
  418. return $info;
  419. }elseif (strpos($doctor_class, '7') !== false){
  420. //写报告医生
  421. //作为报告 审核医生不是自己
  422. $report_review_where[] = ['review_doctor_id','<>',$doctor['id']];
  423. //作为报告 写报告是自己
  424. $report_where['report_doctor_id'] = $doctor['id'];
  425. //作为报告 状态大于写报告 (审核,远程确认,本地确认)
  426. $report_status[] = ['report_status','in','8,9,10'];
  427. $info = $this->remote->getConfirm($params,$doctor,$report_where,$review_where,$review_status,$report_status,$report_review_where,$class_where,$where);
  428. return $info;
  429. }
  430. }
  431. }
  432. }
  433. //全部诊断 已驳回
  434. public function getReject($params,$doctor,$class_where,$where)
  435. {
  436. $info = ['total'=>[],'count'=>0];
  437. $doctor_class = $this->remote->getDoctorClass($doctor['id']);
  438. if(strpos($doctor_class, '7') !== false || $doctor['is_admin'] == '1'){
  439. // 只有存在写权限或者医院管理员 才有驳回数据
  440. $info = $this->remote->getRejectList($params,$doctor,$class_where,$where);
  441. }
  442. return $info;
  443. }
  444. public function getOne($params,$doctor)
  445. {
  446. $info = $this->remote->getOne($params);
  447. $info['study_id'] = $info['study_id'].'&node_type='.$info['node_type'];
  448. $rid = $this->remote->getReportId($params['id']);
  449. $info['rid'] = $rid;
  450. $local_doctor = $this->remote->getDoctorName($info['req_doctor_id']);
  451. $institution = $this->remote->getInstitutionName($info['local_institution_id']);
  452. $remote_time = $this->remote->getInstitutionApplyTime($info['remote_institution_id']);
  453. $info['local_institution'] = $institution;
  454. $info['req_doctor'] = $local_doctor;
  455. $info['remote_time'] = $remote_time;
  456. $admin = $this->remote->getDoctorAdmin($doctor['institution_id']);
  457. if($info['report_status'] == 7 || $info['report_status'] == 8){
  458. $class = $this->remote->getDoctorClass($doctor['id']);
  459. if(strpos($class,'8')){
  460. $info['operator'] = 1;
  461. }else{
  462. $info['operator'] = 0;
  463. }
  464. if($info['report_status'] == 7 && strpos($class,'7')){
  465. $info['operator'] = 1;
  466. }
  467. }else{
  468. if($info['remote_doctor_id'] == $doctor['id'] || $doctor['is_admin'] == 1 || (empty($admin) && empty($info['remote_doctor_id']))){
  469. $info['operator'] = 1;
  470. }else{
  471. $info['operator'] = 0;
  472. }
  473. }
  474. return $info;
  475. }
  476. public function getRemote($id,$userId)
  477. {
  478. $info = $this->remote->getRemote($id);
  479. $info['report_id'] = $info['id'];
  480. $info['is_remote'] = 1;
  481. $info['is_creating_dcm'] = empty($this->getCache($info['study_id'].'_zip')) ? 0 : 1;
  482. $time = date('Y-m-d H:i:s',time());
  483. //过期时间 大于当前 则 还没过期
  484. $where = "effective_date > '$time'";
  485. $dcm = $this->remote->getDcmPath($where,$info['study_id']);
  486. $info['dcm_path'] = empty($dcm) ? '' : $dcm;
  487. if($info['id'] == null){
  488. $trace = '';
  489. }else{
  490. $info['trace'] = $this->remote->getTtace($info['id']);
  491. $cacheToken = $this->getStageKey($info['id'],$userId);
  492. $stage = $this->remote->getCache($cacheToken);
  493. if(!empty($stage)) {
  494. $info['impression'] = $stage['impression'];
  495. $info['description'] = $stage['description'];
  496. }
  497. }
  498. return $info;
  499. }
  500. public function distribute($doctor,$params)
  501. {
  502. if($doctor['is_admin'] != '1'){
  503. $this->throwError('只有管理员才可以进行分配','0042');
  504. }
  505. $field = ['report_status'];
  506. $status = $this->remote->getApplicationById($params['id'],$field);
  507. if($status['report_status'] != '4'){
  508. $this->throwError('该数据已经被接收处理,无法进行分配','0043');
  509. }
  510. $info = $this->remote->distribute($params);
  511. return $info;
  512. }
  513. public function getDoctorList($institution_id)
  514. {
  515. $info = $this->remote->getDoctorList($institution_id);
  516. return $info;
  517. }
  518. public function getVideoList($user)
  519. {
  520. $list = $this->remote->getVideoList($user['id']);
  521. foreach ($list as $k=>$v)
  522. {
  523. $list[$k]['video_url'] = $this->makeFileUrl($v['video_url'],$v['video_type'],'inline');
  524. $file = explode('/',$v['video_url']);
  525. $name = explode('.',$file[count($file)-1]);
  526. $list[$k]['video_name'] = $name[0] ?? '';
  527. }
  528. return $list;
  529. }
  530. public function getExamList($user,$params)
  531. {
  532. if(!($params['page'] ?? null))
  533. {
  534. $this->throwError('无法识别当前页数','0043');
  535. }
  536. $page = $params['page'];
  537. $class_where = [];
  538. $where_status[] = ['report_status','in','4,6,7,8,10'];
  539. if($user['is_admin'] == 1)
  540. {
  541. //获取所有的检查
  542. $class_where =[];
  543. }else{
  544. if($user['exam_class'] == '*')
  545. {
  546. $class_where = [];
  547. }else{
  548. $class_where[] = ['exam_class','in',explode(',',$user['exam_class'])];
  549. }
  550. }
  551. $list = $this->remote->getExamList($where_status,$class_where,$page,$user);
  552. return $list;
  553. }
  554. public function rejectStatus($id)
  555. {
  556. $info = $this->remote->rejectStatus($id);
  557. return $info;
  558. }
  559. }