BiServies.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\zskk\servies;
  4. use app\admin\model\dict\Commondata;
  5. use app\admin\servies\bi\BaseQcBiServies;
  6. use app\zskk\model\BiInspectReport;
  7. use app\zskk\model\ExamReport;
  8. use app\zskk\model\HrRecord;
  9. use app\zskk\model\InspectReport;
  10. use app\zskk\model\MedicalInformation;
  11. use think\facade\Cache;
  12. class BiServies extends BaseQcBiServies
  13. {
  14. public $examModel = null;
  15. public $inspectModel = null;
  16. public $inspecItemtModel = null;
  17. public $hrrecordModel = null;
  18. public $medicalInformation = null;
  19. public function __construct(ExamReport $examModel,InspectReport $inspectModel,HrRecord $hrrecordModel,MedicalInformation $medicalInformation, BiInspectReport $biInspectReport)
  20. {
  21. // parent::__construct();
  22. $this->examModel = $examModel;
  23. $this->inspectModel = $inspectModel;
  24. $this->hrrecordModel = $hrrecordModel;
  25. $this->medicalInformation = $medicalInformation;
  26. $this->inspecItemtModel = $biInspectReport;
  27. }
  28. public function getMedicalData()
  29. {
  30. $data = $this->medicalInformation->field('DIAGNOSENAME,count(*) as c')->limit(50)->group('DIAGNOSENAME')->select()->toArray();
  31. $arr = [];
  32. foreach ($data as $v)
  33. {
  34. $diagnose = explode(';',$v['DIAGNOSENAME']);
  35. foreach ($diagnose as $value)
  36. {
  37. if(isset($arr[$value]))
  38. {
  39. $arr[$value] ++;
  40. }else{
  41. $arr[$value] = 1;
  42. }
  43. }
  44. }
  45. $return = [];
  46. foreach ($arr as $k=>$v)
  47. {
  48. $return[] = ['name'=>$k,'value'=>$v];
  49. }
  50. return $return;
  51. }
  52. public function getAllNum()
  53. {
  54. $exam = $this->_getExamCount();
  55. $inspect = $this->_getInspectCount();
  56. $arr = [];
  57. foreach ($exam as $k=>$v)
  58. {
  59. $data = [];
  60. $data['name']=$k;
  61. $data['exam'] = $v;
  62. if($inspect[$k] ?? '')
  63. {
  64. $data['inspect'] = $inspect[$k];
  65. }else{
  66. $data['inspect'] = 0;
  67. }
  68. $arr[$data['exam']+$data['inspect']] = $data;
  69. }
  70. krsort($arr);
  71. $array = array_slice($arr, 0, 20);
  72. return $array;
  73. }
  74. public function getExamData()
  75. {
  76. $uploadNum = $this->_getExamUpload();
  77. $hrNum = $this->_getExamHr();
  78. $data = [];
  79. foreach ($hrNum as $k=>$v)
  80. {
  81. $arr = [];
  82. $arr['upload'] = $k;
  83. $arr['num'] = $v;
  84. $arr['hr'] = $uploadNum[$k] ?? 0;
  85. $data[] = $arr;
  86. }
  87. return $data;
  88. }
  89. public function _getExamUpload()
  90. {
  91. return $this->examModel->group('DEVICETYPE_CODE')->where("DEVICETYPE_CODE != ''")->column('count(*)','DEVICETYPE_CODE');
  92. }
  93. public function _getExamHr()
  94. {
  95. return $this->hrrecordModel->alias('h')
  96. ->join(['dict_exam_project'=>'d'],'d.XM_CODE=h.ITEMNAMECODE')
  97. ->group('d.modality')
  98. ->column('count(*)','modality');
  99. }
  100. public function _getExamCount()
  101. {
  102. return $this->examModel->group('ORGNAME')->column('count(*)','ORGNAME');
  103. }
  104. public function _getInspectCount()
  105. {
  106. return $this->inspectModel->group('ORGNAME')->column('count(*)','ORGNAME');
  107. }
  108. public function getRepeatExam()
  109. {
  110. $handelData = $this->getRepeatDatas($this->examModel,'HR_ITEMNAME');
  111. // 获取患者数量
  112. $count = $this->getPatientCount([]);
  113. $MPIS = $handelData['MPIS'];
  114. // 重复报告数量
  115. $repeat = count($MPIS);
  116. $percent = round($repeat/$count*100);
  117. return ['percent'=>$percent];
  118. }
  119. public function getRepeatDatas($model,$itemname)
  120. {
  121. $this->baseModel = $model;
  122. $this->hrItemnameKey = $itemname;
  123. // 获取重复数据
  124. $repeatDatas = $this->getRepeatData([]);
  125. // 处理重复数据
  126. $handelData = $this->handleRepeatData($repeatDatas);
  127. return $handelData;
  128. }
  129. public function getRepeatExamProject()
  130. {
  131. $handelData = $this->getRepeatDatas($this->examModel,'HR_ITEMNAME');
  132. return array_slice($handelData['LAB_HR_ITEMNAMES'],0,10);
  133. }
  134. public function getRepeatInspect()
  135. {
  136. $handelData = $this->getRepeatDatas($this->inspectModel,'LAB_HR_ITEMNAME');
  137. // 获取患者数量
  138. $count = $this->getPatientCount([]);
  139. $MPIS = $handelData['MPIS'];
  140. // 重复报告数量
  141. $repeat = count($MPIS);
  142. $percent = round($repeat/$count*100);
  143. return ['percent'=>$percent];
  144. }
  145. public function getRepeatInspectDoctor()
  146. {
  147. $handelData = $this->getRepeatDatas($this->inspectModel,'LAB_HR_ITEMNAME');
  148. $MPIS = $handelData['MPIS'];
  149. // 医生情况
  150. $doctor = $this->getDoctor([], $MPIS);
  151. return $this->makeIdReturn($doctor['doctor']['items'],$doctor['doctor']['all']);
  152. }
  153. public function makeIdReturn($data,$all)
  154. {
  155. $i = 1;
  156. foreach ($data as $k=>$v)
  157. {
  158. $data[$k]['id'] = $i;
  159. $data[$k]['percent'] = round($v['value']/$all*100).'%';
  160. $data[$k]['value'] = $v['value'].'次';
  161. $i++;
  162. }
  163. return $data;
  164. }
  165. public function getRepeatExamDoctor()
  166. {
  167. $handelData = $this->getRepeatDatas($this->examModel,'HR_ITEMNAME');
  168. $MPIS = $handelData['MPIS'];
  169. // 医生情况
  170. $doctor = $this->getDoctor([], $MPIS);
  171. return $this->makeIdReturn($doctor['doctor']['items'],$doctor['doctor']['all']);
  172. }
  173. public function getRepeatInspectProject()
  174. {
  175. $handelData = $this->getRepeatDatas($this->inspectModel,'LAB_HR_ITEMNAME');
  176. return array_slice($handelData['LAB_HR_ITEMNAMES'],0,10);
  177. }
  178. public function getAllBhrReason()
  179. {
  180. $record = $this->hrrecordModel->where('HR_STATUS',2)->group('BHR_REASON')->field('BHR_REASON,count(*)')->select()->toArray();
  181. // foreach ($record as $k=>$v)
  182. // {
  183. // $record[$k]['BHR_REASON'] = mb_substr($v['BHR_REASON'],0,3);
  184. // }
  185. return $record;
  186. }
  187. public function getHrExamItem()
  188. {
  189. $this->hrBaseModel = $this->hrrecordModel;
  190. $this->ITEMNAMETYPE = 1;
  191. $hr = $this->getHrItem([]);
  192. $arr = $hr['items'];
  193. foreach ($arr as $k=>$v)
  194. {
  195. $arr[$k]['percent'] = round($v['value']/$hr['all']*100).'%';
  196. }
  197. return $arr;
  198. }
  199. public function getHrInspectItem()
  200. {
  201. $this->hrBaseModel = $this->hrrecordModel;
  202. $this->ITEMNAMETYPE = 2;
  203. $hr = $this->getHrItem([]);
  204. $arr = $hr['items'];
  205. foreach ($arr as $k=>$v)
  206. {
  207. $arr[$k]['percent'] = round($v['value']/$hr['all']*100).'%';
  208. }
  209. return $arr;
  210. }
  211. public function unLookRepeatInspectDoctor()
  212. {
  213. $handelData = $this->getRepeatDatas($this->inspectModel,'LAB_HR_ITEMNAME');
  214. $MPIS = $handelData['MPIS'];
  215. // 医生情况
  216. $doctor = $this->getDoctor([], $MPIS);
  217. // 有互认提示但未查看,直接进行了重复检查检验的医生构成比
  218. return $this->makeLookReturn($doctor['un_call_doctor']['items']);
  219. }
  220. public function unLookRepeatExamDoctor()
  221. {
  222. $handelData = $this->getRepeatDatas($this->examModel,'HR_ITEMNAME');
  223. $MPIS = $handelData['MPIS'];
  224. // 医生情况
  225. $doctor = $this->getDoctor([], $MPIS);
  226. // 有互认提示但未查看,直接进行了重复检查检验的医生构成比
  227. return $this->makeLookReturn($doctor['un_call_doctor']['items']);
  228. }
  229. public function LookRepeatExamDoctor()
  230. {
  231. $handelData = $this->getRepeatDatas($this->examModel,'HR_ITEMNAME');
  232. $MPIS = $handelData['MPIS'];
  233. // 医生情况
  234. $doctor = $this->getDoctor([], $MPIS);
  235. // 有互认提示并已查看,也进行了重复检查检验的医生构成比
  236. return $this->makeLookReturn($doctor['call_doctor']['items']);
  237. }
  238. public function makeLookReturn($data)
  239. {
  240. $arr = [];
  241. foreach ($data as $k=>$v)
  242. {
  243. $arr[$k]['label'] = $v['label'];
  244. $arr[$k]['数量'] = $v['value'];
  245. }
  246. return $arr;
  247. }
  248. public function getLeida()
  249. {
  250. $types = $this->inspecItemtModel->field('count(*) c, ITEMTYPE')->group('ITEMTYPE')->select()->toArray();
  251. $hrs = $this->hrrecordModel->field('count(*) c, ITEMTYPE')->group('ITEMTYPE')->select()->toArray();
  252. $model = new Commondata();
  253. $dicts = $model
  254. ->field(['code','name'])
  255. ->where('type', '13')
  256. ->where('status', 1)
  257. ->order('weigh asc, id asc')
  258. ->select()
  259. ->toArray();
  260. $indicator = array();
  261. $hr = [
  262. 'name' => '互认',
  263. ];
  264. $type = [
  265. 'name' => '上传',
  266. ];
  267. foreach($dicts as $dict) {
  268. $key = 'key'.$dict['code'];
  269. $tmp = [
  270. 'key' => $key,
  271. 'name' => $dict['name'],
  272. 'max' => 0
  273. ];
  274. $hr[$key] = 0;
  275. $type[$key] = 0;
  276. $max = 0;
  277. foreach($types as $_type) {
  278. if('key'.$_type['ITEMTYPE'] == $key) {
  279. $type[$key] = $_type['c'];
  280. }
  281. $max = max($max, $_type['c']);
  282. }
  283. foreach($hrs as $_hr) {
  284. if('key'.$_hr['ITEMTYPE'] == $key) {
  285. $hr[$key] = $_hr['c'];
  286. }
  287. $max = max($max, $_hr['c']);
  288. }
  289. $indicator[] = $tmp;
  290. }
  291. foreach($indicator as &$_indicator) {
  292. $_indicator['max'] = $max;
  293. }
  294. $data = [
  295. 'indicator' => $indicator,
  296. 'val' => [
  297. $type, $hr
  298. ]
  299. ];
  300. // $data = [
  301. // 'indicator' => [
  302. // ['key' => 'key1', 'max' => 10000, 'name' => 'Name1'],
  303. // ['key' => 'key2', 'max' => 10000, 'name' => 'Name2'],
  304. // ['key' => 'key3', 'max' => 10000, 'name' => 'Name3'],
  305. // ['key' => 'key4', 'max' => 10000, 'name' => 'Name4'],
  306. // ['key' => 'key5', 'max' => 10000, 'name' => 'Name5'],
  307. // ['key' => 'key6', 'max' => 10000, 'name' => 'Name6'],
  308. // ],
  309. // 'val' => [
  310. // [
  311. // 'name' => '上传',
  312. // 'key1' => 2342,
  313. // 'key2' => 2452,
  314. // 'key3' => 4335,
  315. // 'key4' => 7469,
  316. // 'key5' => 6572,
  317. // 'key6' => 9864,
  318. // ],
  319. // [
  320. // 'name' => '互认',
  321. // 'key1' => 1342,
  322. // 'key2' => 5452,
  323. // 'key3' => 3335,
  324. // 'key4' => 4469,
  325. // 'key5' => 6572,
  326. // 'key6' => 2864,
  327. // ]
  328. // ]
  329. // ];
  330. return $data;
  331. // halt($data);
  332. }
  333. public function getBhrInstitution()
  334. {
  335. $data = $this->hrrecordModel->group('ORGNAME')->field('count(*) c,ORGNAME')->order('c desc')->limit(20)->select();
  336. foreach ($data as $k=>$v)
  337. {
  338. $data[$k]['id'] = $k+1;
  339. $data[$k]['c'] = $v['c'].'次';
  340. }
  341. return $data;
  342. }
  343. }