BiServies.php 12 KB

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