Quality.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\admin\controller\quality;
  3. use app\admin\model\doctors\DoctorModel;
  4. use app\admin\model\quality\Cause;
  5. use app\common\controller\Backend;
  6. use app\common\library\SysLogs;
  7. use think\Db;
  8. /**
  9. * 质控相关
  10. * @icon fa fa-institution
  11. */
  12. class Quality extends Backend
  13. {
  14. protected $model = null;
  15. protected $cause = null;
  16. protected $doctorModel = null;
  17. protected $searchFields = [
  18. 'realname'
  19. ];
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\quality\Quality();
  24. $this->cause = new Cause();
  25. $this->doctorModel = new DoctorModel();
  26. }
  27. public function index()
  28. {
  29. //设置过滤方法
  30. $this->request->filter(['strip_tags']);
  31. return $this->view->fetch();
  32. }
  33. /**
  34. * 医生列表
  35. * @param $type
  36. * @return string|\think\response\Json
  37. * @throws \think\Exception
  38. */
  39. public function doctorList($type)
  40. {
  41. $ins_id = $this->request->param('ins_id');
  42. $this->request->filter(['strip_tags']);
  43. if ($this->request->isAjax()) {
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields);
  45. $myWhere = ['institution_id' => $ins_id];
  46. $field = ['id', 'realname', '0 as excellent', '0 as good', '0 as qualified', '0 as poor'];
  47. $total = $this->doctorModel
  48. ->where($where)
  49. ->where($myWhere)
  50. ->count();
  51. $list = $this->doctorModel
  52. ->where($where)
  53. ->where($myWhere)
  54. ->order($sort, $order)
  55. ->limit($offset, $limit)
  56. ->field($field)
  57. ->select();
  58. $list = collection($list)->toArray();
  59. // 统计数据
  60. if($list){
  61. $doctor_codes = array_column($list, 'id');
  62. $data = $this->model
  63. ->whereIn('report_doctor', $doctor_codes)
  64. ->column('report_doctor, pic_quality, report_quality');
  65. if($data){
  66. $type_text = $type == 'pic' ? 'pic_quality' : 'report_quality';
  67. foreach ($list as $key=>$val){
  68. if(isset($data[$val['id']])){
  69. $list[$key]['excellent'] += ($data[$val['id']][$type_text] == 1 ? 1 : 0);
  70. $list[$key]['good'] += ($data[$val['id']][$type_text] == 2 ? 1 : 0);
  71. $list[$key]['qualified'] += ($data[$val['id']][$type_text] == 3 ? 1 : 0);
  72. $list[$key]['poor'] += ($data[$val['id']][$type_text] == 4 ? 1 : 0);
  73. $zs = $list[$key]['excellent']+$list[$key]['good']+$list[$key]['qualified']+$list[$key]['poor'];
  74. $list[$key]['JPL'] = round(($list[$key]['excellent']/$zs)*100,2).'%';
  75. }
  76. }
  77. }
  78. }
  79. $result = array("total" => $total, "rows" => $list);
  80. return json($result);
  81. }
  82. return $this->view->fetch();
  83. }
  84. /**
  85. * 详情
  86. * @param $ids
  87. * @return string|null
  88. * @throws \think\Exception
  89. */
  90. public function detail($ids)
  91. {
  92. $controls = $this->model
  93. ->where('report_doctor', $ids)
  94. ->select();
  95. if(!$controls){
  96. return null;
  97. }
  98. // 1. 登记统计
  99. $rep = $pic = [
  100. '1' => 0 ,
  101. '2' => 0 ,
  102. '3' => 0 ,
  103. '4' => 0
  104. ];
  105. foreach ($controls as $val){
  106. if($val['pic_quality']){
  107. $pic[$val['pic_quality']] ++;
  108. }
  109. if($val['report_quality']){
  110. $rep[$val['report_quality']] ++;
  111. }
  112. }
  113. // 2. 初始原因数据
  114. $cause_dict = Db::table('quality_factor')->column('id,type,description');
  115. $pic_cause = [];
  116. $rep_cause = [];
  117. foreach ($cause_dict as $id => $val){
  118. if($val['type'] == '1'){
  119. $pic_cause[$id] = 0;
  120. } else {
  121. $rep_cause[$id] = 0;
  122. }
  123. }
  124. // 统计原因数据
  125. $control_ids = array_column($controls, 'id');
  126. $cause = $this->cause
  127. ->whereIn('control_id', $control_ids)
  128. ->select();
  129. if ($cause) {
  130. foreach ($cause as $val) {
  131. if ($val['type'] == '1') {
  132. $pic_cause[$val['factor_id']] += 1;
  133. } else{
  134. $rep_cause[$val['factor_id']] += 1;
  135. }
  136. }
  137. }
  138. // 返回
  139. $this->view->cacuse_dict = $cause_dict;
  140. $this->view->rep = $rep;
  141. $this->view->pic = $pic;
  142. $this->view->pic_cause = $pic_cause;
  143. $this->view->rep_cause = $rep_cause;
  144. return $this->view->fetch();
  145. }
  146. }