RemoteModel.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. namespace app\api\model\remote;
  3. use app\api\model\dcmpath\DcmpathModel;
  4. use app\api\model\video\VideoModel;
  5. use app\api\model\doctor\DoctorModel;
  6. use app\api\model\doctorclass\DoctorClassModel;
  7. use app\api\model\exam\ExamModel;
  8. use app\api\model\inspect\InspectModel;
  9. use app\api\model\institution\InstitutionModel;
  10. use app\api\model\institution\PublicInstitutionModel;
  11. use app\api\model\record\RecordModel;
  12. use app\api\model\report\PublicReportModel;
  13. use app\api\model\report\ReportModel;
  14. use app\api\model\ZskkDefaultModel;
  15. use think\facade\Log;
  16. class RemoteModel extends ZskkDefaultModel {
  17. protected $connection = 'db_config_public';
  18. protected $table= 'remote_application';
  19. protected $logName = "RemoteModel";
  20. public function getReportNum($id,$time)
  21. {
  22. $number = PublicReportModel::where('report_datetime','>',$time)->where('report_doctor_id',$id)->count();
  23. return $number;
  24. }
  25. public function getAllNum($id)
  26. {
  27. $number = PublicReportModel::where('report_doctor_id',$id)->where('type',2)->count();
  28. return $number;
  29. }
  30. public function getCountNum($id,$field)
  31. {
  32. $ids = PublicReportModel::alias('r')
  33. ->join(['remote_application'=>'a'],'a.id=r.remote_application_id')
  34. ->where('report_doctor_id',$id)
  35. ->distinct($field)
  36. ->field($field)
  37. ->select();
  38. return count($ids);
  39. }
  40. public function getRemoteInfo($ids,$field)
  41. {
  42. $remote = $this->distinct(true)->where('id','in',$ids)->field($field)->select();
  43. return $remote;
  44. }
  45. public function getRemoteByIns($institution,$field)
  46. {
  47. $info = $this->where('remote_institution_id',$institution)->field($field)->select();
  48. return $info;
  49. }
  50. public function getInstitutionInfo($ids)
  51. {
  52. $info = PublicInstitutionModel::where('id','in',$ids)->field('id,name')->select();
  53. return $info;
  54. }
  55. public function getExamInfo($ids,$field)
  56. {
  57. $info = ExamModel::distinct(true)->where('id','in',$ids)->field($field)->select();
  58. return $info;
  59. }
  60. public function getPatient($ids)
  61. {
  62. $info = RemoteModel::distinct(true)->where('id','in',$ids)->field('patient_num')->select();
  63. return $info;
  64. }
  65. public function querySql($sql)
  66. {
  67. $info = $this->query($sql);
  68. }
  69. public function getTodayTnfo($doctor,$where,$where_status,$report_where,$review_where,$class_where,$fuzzyWhere,$params)
  70. {
  71. $field = [
  72. 'ra.*',
  73. 'r.id AS rid'
  74. ];
  75. if(isset($params['num']) && !empty($params['num']))
  76. {
  77. $page = $params['page'];
  78. $num = $params['num'];
  79. $total = $this->alias('ra')
  80. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  81. ->where(function ($query) use($where, $where_status,$report_where,$review_where) {
  82. $query->where(function ($query) use($where, $where_status) {
  83. $query->where($where)
  84. ->where($where_status);
  85. })
  86. ->whereOr($report_where)
  87. ->whereOr(function ($query) use($review_where) {
  88. $query->where($review_where);
  89. });
  90. })
  91. ->where($class_where)
  92. ->where($fuzzyWhere)
  93. ->where('ra.status',0)
  94. ->where('ra.remote_institution_id',$doctor['institution_id'])
  95. ->page($page,$num)
  96. ->order('ra.req_date_time desc')
  97. ->field($field)
  98. ->select();
  99. }else{
  100. $total = $this->alias('ra')
  101. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  102. ->where(function ($query) use($where, $where_status,$report_where,$review_where) {
  103. $query->where(function ($query) use($where, $where_status) {
  104. $query->where($where)
  105. ->where($where_status);
  106. })
  107. ->whereOr($report_where)
  108. ->whereOr(function ($query) use($review_where) {
  109. $query->where($review_where);
  110. });
  111. })
  112. ->where($class_where)
  113. ->where($fuzzyWhere)
  114. ->where('ra.status',0)
  115. ->where('ra.remote_institution_id',$doctor['institution_id'])
  116. ->order('ra.req_date_time desc')
  117. ->field($field)
  118. ->select();
  119. }
  120. $count = $this->alias('ra')
  121. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  122. ->where(function ($query) use($where, $where_status,$report_where,$review_where) {
  123. $query->where(function ($query) use($where, $where_status) {
  124. $query->where($where)
  125. ->where($where_status);
  126. })
  127. ->whereOr($report_where)
  128. ->whereOr(function ($query) use($review_where) {
  129. $query->where($review_where);
  130. });
  131. })
  132. ->where($class_where)
  133. ->where($fuzzyWhere)
  134. ->where('ra.status',0)
  135. ->where('ra.remote_institution_id',$doctor['institution_id'])
  136. ->count();
  137. $info = ['total'=>$total,'count'=>$count];
  138. return $info;
  139. }
  140. //未完成 列表
  141. public function getIncomplete($params,$doctor,$where,$where_status,$report_where,$review_where,$class_where,$search)
  142. {
  143. $field = [
  144. 'ra.*',
  145. 'r.id AS rid'
  146. ];
  147. $date1 = [];
  148. $date2 = [];
  149. if(($search[0] ?? null) && is_array($search))
  150. {
  151. $date1[] = $search[0];
  152. unset($search[0]);
  153. };
  154. if(($search[1] ?? null) && is_array($search))
  155. {
  156. $date2[] = $search[1];
  157. unset($search[1]);
  158. };
  159. // $order = NEW \think\db\Expression("field(ra.report_status ,6,7,8,4)");
  160. $total = $this->alias('ra')
  161. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  162. ->where(function ($query) use($where, $where_status,$report_where,$review_where) {
  163. $query->where(function ($query) use($where, $where_status) {
  164. $query->where($where)
  165. ->where($where_status);
  166. })
  167. ->whereOr($report_where)
  168. ->whereOr(function ($query) use($review_where) {
  169. $query->where($review_where);
  170. });
  171. })
  172. ->where($class_where)
  173. ->where($date1)
  174. ->where($date2)
  175. ->where($search)
  176. ->where('ra.status',0)
  177. ->where('ra.remote_institution_id',$doctor['institution_id'])
  178. ->page($params['page'],$params['num'])
  179. ->order('ra.req_date_time desc')
  180. ->field($field)
  181. ->select();
  182. $count = $this->alias('ra')
  183. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  184. ->where(function ($query) use($where, $where_status,$report_where,$review_where) {
  185. $query->where(function ($query) use($where, $where_status) {
  186. $query->where($where)
  187. ->where($where_status);
  188. })
  189. ->whereOr($report_where)
  190. ->whereOr(function ($query) use($review_where) {
  191. $query->where($review_where);
  192. });
  193. })
  194. ->where($class_where)
  195. ->where($date1)
  196. ->where($date2)
  197. ->where($search)
  198. ->where('ra.status',0)
  199. ->where('ra.remote_institution_id',$doctor['institution_id'])
  200. ->count();
  201. $info = ['total'=>$total,'count'=>$count];
  202. return $info;
  203. }
  204. public function getConfirm($params,$doctor,$report_where,$review_where,$review_status,$report_status,$report_review_where,$class_where,$where)
  205. {
  206. $field = [
  207. 'ra.*',
  208. 'r.id AS rid'
  209. ];
  210. $date1 = [];
  211. $date2 = [];
  212. if(($where[0] ?? null) && is_array($where))
  213. {
  214. $date1[] = $where[0];
  215. unset($where[0]);
  216. };
  217. if(($where[1] ?? null) && is_array($where))
  218. {
  219. $date2[] = $where[1];
  220. unset($where[1]);
  221. };
  222. $total = $this->alias('ra')
  223. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  224. ->where(function ($query) use($report_where,$review_where,$review_status,$report_status,$report_review_where) {
  225. $query->where(function ($query) use($report_where, $report_status,$report_review_where) {
  226. $query->where($report_where) ->where($report_status) ->where($report_review_where);
  227. })
  228. ->whereOr(function ($query) use($review_where,$review_status) {
  229. $query->where($review_where)->where($review_status);
  230. });
  231. })
  232. ->where($class_where)
  233. ->where($date1)
  234. ->where($date2)
  235. ->where($where)
  236. ->where('ra.remote_institution_id',$doctor['institution_id'])
  237. ->where('ra.status',0)
  238. ->page($params['page'],$params['num'])
  239. ->order('ra.req_date_time desc')
  240. ->field($field)
  241. ->select();
  242. $count = $this->alias('ra')
  243. ->join(['report'=>'r'],'r.remote_application_id=ra.id','left')
  244. ->where(function ($query) use($report_where,$review_where,$review_status,$report_status,$report_review_where) {
  245. $query->where(function ($query) use($report_where, $report_status,$report_review_where) {
  246. $query->where($report_where)
  247. ->where($report_status)
  248. ->where($report_review_where);
  249. })
  250. ->whereOr(function ($query) use($review_where,$review_status) {
  251. $query->where($review_where)->where($review_status);
  252. });
  253. })
  254. ->where($class_where)
  255. ->where($date1)
  256. ->where($date2)
  257. ->where($where)
  258. ->where('ra.remote_institution_id',$doctor['institution_id'])
  259. ->where('ra.status',0)
  260. ->count();
  261. $info = ['total'=>$total,'count'=>$count];
  262. return $info;
  263. }
  264. public function getDoctorName($id)
  265. {
  266. $name = DoctorModel::where('id',$id)->value('realname');
  267. return $name;
  268. }
  269. public function getInstitutionName($id)
  270. {
  271. $name = InstitutionModel::where('id',$id)->value('name');
  272. return $name;
  273. }
  274. public function getInstitutionApplyTime($id)
  275. {
  276. $time = InstitutionModel::where('id',$id)->value('handling_time');
  277. return $time;
  278. }
  279. public function getDoctorAdmin($id)
  280. {
  281. $admin = DoctorModel::where('institution_id',$id)->where('is_admin',1)->value('id');
  282. return $admin;
  283. }
  284. public function getDoctorClass($id)
  285. {
  286. $doctor_class = DoctorClassModel::where('doctor_id',$id)->value('doctor_class');
  287. return $doctor_class;
  288. }
  289. public function getAllInfo($params,$doctor,$where,$where_status,$report_where,$report_status,$remote_where,$search,$class_where)
  290. {
  291. $field = [
  292. 'ra.*',
  293. 'r.id AS rid'
  294. ];
  295. $date1 = [];
  296. $date2 = [];
  297. if(($search[0] ?? null) && is_array($search))
  298. {
  299. $date1[] = $search[0];
  300. unset($search[0]);
  301. };
  302. if(($search[1] ?? null) && is_array($search))
  303. {
  304. $date2[] = $search[1];
  305. unset($search[1]);
  306. };
  307. // $order = NEW \think\db\Expression("field(ra.report_status ,6,7,8,4,9,5,12,10,13)");
  308. $total = $this->alias('ra')
  309. ->join(['report'=>'r'],'r.remote_application_id=ra.id','LEFT')
  310. ->where(function ($query) use($where,$where_status,$report_where,$report_status,$remote_where) {
  311. $query->where(function ($query) use($where,$where_status) {
  312. $query->where($where)
  313. ->where($where_status);
  314. })
  315. ->whereOr($remote_where)
  316. ->whereOr($report_status)
  317. ->whereOr($report_where);
  318. })
  319. ->where($class_where)
  320. ->where($date1)
  321. ->where($date2)
  322. ->where('ra.remote_institution_id',$doctor['institution_id'])
  323. ->where($search)
  324. ->where('ra.report_status','not in','1,2,3,11')
  325. ->where('ra.status',0)
  326. ->page($params['page'],$params['num'])
  327. ->order('ra.req_date_time desc')
  328. ->field($field)
  329. ->select();
  330. $count = $this->alias('ra')
  331. ->join(['report'=>'r'],'r.remote_application_id=ra.id','LEFT')
  332. ->where(function ($query) use($where,$where_status,$report_where,$report_status,$remote_where) {
  333. $query->where(function ($query) use($where,$where_status) {
  334. $query->where($where)
  335. ->where($where_status);
  336. })
  337. ->whereOr($remote_where)
  338. ->whereOr($report_status)
  339. ->whereOr($report_where);
  340. })
  341. ->where($class_where)
  342. ->where($date1)
  343. ->where($date2)
  344. ->where('ra.remote_institution_id',$doctor['institution_id'])
  345. ->where($search)
  346. ->where('ra.report_status','not in','1,2,3,11')
  347. ->where('ra.status',0)
  348. ->count();
  349. $info = ['total'=>$total,'count'=>$count];
  350. return $info;
  351. }
  352. public function getRejectList($params,$doctor,$class_where,$where)
  353. {
  354. $where_status['ra.report_status'] = '5';
  355. $doctorWhere = [];
  356. if($doctor['is_admin'] != 1){
  357. $doctorWhere['remote_doctor_id'] = $doctor['id'];
  358. }
  359. $date1 = [];
  360. $date2 = [];
  361. if(($search[0] ?? null) && is_array($search))
  362. {
  363. $date1[] = $where[0];
  364. unset($where[0]);
  365. };
  366. if(($search[1] ?? null))
  367. {
  368. $date2[] = $where[1];
  369. unset($where[1]);
  370. };
  371. $field = [
  372. 'ra.*'
  373. ];
  374. $total = $this->alias('ra')
  375. ->where($where_status)
  376. ->where($doctorWhere)
  377. ->where('ra.remote_institution_id',$doctor['institution_id'])
  378. ->where($class_where)
  379. ->where($where)
  380. ->where($date1)
  381. ->where($date2)
  382. ->where('ra.status',0)
  383. ->page($params['page'],$params['num'])
  384. ->order('ra.req_date_time desc')
  385. ->field($field)
  386. ->select();
  387. $count = $this->alias('ra')
  388. ->where($where_status)
  389. ->where($doctorWhere)
  390. ->where($where)
  391. ->where($date1)
  392. ->where($date2)
  393. ->where('ra.status',0)
  394. ->where('ra.remote_institution_id',$doctor['institution_id'])
  395. ->where($class_where)
  396. ->count();
  397. $info = ['total'=>$total,'count'=>$count];
  398. return $info;
  399. }
  400. public function getOne($params)
  401. {
  402. $info = $this
  403. ->where('id', $params['id'])
  404. ->find();
  405. return $info;
  406. }
  407. public function getReportId($id)
  408. {
  409. $rid = PublicReportModel::where('remote_application_id',$id)->value('id');
  410. return $rid;
  411. }
  412. public function getRemote($id)
  413. {
  414. $info = $this->alias('re')
  415. ->join(['report'=>'r'],'r.remote_application_id=re.id','LEFT')
  416. ->where('re.id',$id)
  417. ->find();
  418. return $info;
  419. }
  420. public function getDcmPath($where,$study)
  421. {
  422. $info = DcmpathModel::where($where)->where('study_id',$study)->value('dcm_path');
  423. return $info;
  424. }
  425. public function getTtace($id)
  426. {
  427. $data = RecordModel::alias('r')
  428. ->join(['doctors'=>'d'], 'r.doctor_id = d.id')
  429. ->where('r.report_id', $id)
  430. ->field('r.impression, r.description, r.createdAt AS handle_time, d.realname, r.type')
  431. ->select();
  432. return $data;
  433. }
  434. public function getApplicationById($id,$field)
  435. {
  436. try{
  437. $info = $this->where('id',$id)->field($field)->find();
  438. return $info;
  439. }catch(Exception $e){
  440. $this->throwError($e->getMessage(),0001);
  441. }
  442. }
  443. public function distribute($params)
  444. {
  445. try{
  446. $info = $this->where('id',$params['id'])->update(['remote_doctor_id'=>$params['doctor_id'],'remote_doctor_name'=>$params['doctor_name']]);
  447. return $info;
  448. }catch(Exception $e){
  449. $this->throwError($e->getMessage(),0001);
  450. }
  451. }
  452. public function getDoctorList($id)
  453. {
  454. try{
  455. $list = DoctorModel::where('institution_id',$id)->field('id,realname')->select();
  456. return $list;
  457. }catch(Exception $e){
  458. $this->throwError($e->getMessage(),0001);
  459. }
  460. }
  461. public function getVideoList($doctor)
  462. {
  463. $list = VideoModel::where('doctor_id',$doctor)->select()->toArray();
  464. return $list;
  465. }
  466. public function getExamList($where_status,$class_where,$page,$doctor)
  467. {
  468. $field = [
  469. 'id',
  470. 'exam_id',
  471. 'name',
  472. 'exam_class',
  473. 'req_date_time',
  474. 'req_doctor_name',
  475. 'local_institution_name',
  476. 'patient_num',
  477. 'accession_num'
  478. ];
  479. $list = $this->where($where_status)
  480. ->where($class_where)
  481. ->where('remote_institution_id',$doctor['institution_id'])
  482. ->where('status <> 2')
  483. ->page($page,10)
  484. ->field($field)
  485. ->order('req_date_time desc')
  486. ->select()
  487. ->toArray();
  488. return $list;
  489. }
  490. public function rejectStatus($id)
  491. {
  492. return $this->where('id',$id)->update(['report_status'=>6]);
  493. }
  494. }