model = new \app\admin\model\quality\Quality(); $this->cause = new Cause(); $this->doctorModel = new DoctorModel(); } public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); return $this->view->fetch(); } /** * 医生列表 * @param $type * @return string|\think\response\Json * @throws \think\Exception */ public function doctorList($type) { $ins_id = $this->request->param('ins_id'); $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields); $myWhere = ['institution_id' => $ins_id]; $field = ['id', 'realname', '0 as excellent', '0 as good', '0 as qualified', '0 as poor']; $total = $this->doctorModel ->where($where) ->where($myWhere) ->count(); $list = $this->doctorModel ->where($where) ->where($myWhere) ->order($sort, $order) ->limit($offset, $limit) ->field($field) ->select(); $list = collection($list)->toArray(); // 统计数据 if($list){ $doctor_codes = array_column($list, 'id'); $data = $this->model ->whereIn('report_doctor', $doctor_codes) ->column('report_doctor, pic_quality, report_quality'); if($data){ $type_text = $type == 'pic' ? 'pic_quality' : 'report_quality'; foreach ($list as $key=>$val){ if(isset($data[$val['id']])){ $list[$key]['excellent'] += ($data[$val['id']][$type_text] == 1 ? 1 : 0); $list[$key]['good'] += ($data[$val['id']][$type_text] == 2 ? 1 : 0); $list[$key]['qualified'] += ($data[$val['id']][$type_text] == 3 ? 1 : 0); $list[$key]['poor'] += ($data[$val['id']][$type_text] == 4 ? 1 : 0); $zs = $list[$key]['excellent']+$list[$key]['good']+$list[$key]['qualified']+$list[$key]['poor']; $list[$key]['JPL'] = round(($list[$key]['excellent']/$zs)*100,2).'%'; } } } } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 详情 * @param $ids * @return string|null * @throws \think\Exception */ public function detail($ids) { $controls = $this->model ->where('report_doctor', $ids) ->select(); if(!$controls){ return null; } // 1. 登记统计 $rep = $pic = [ '1' => 0 , '2' => 0 , '3' => 0 , '4' => 0 ]; foreach ($controls as $val){ if($val['pic_quality']){ $pic[$val['pic_quality']] ++; } if($val['report_quality']){ $rep[$val['report_quality']] ++; } } // 2. 初始原因数据 $cause_dict = Db::table('quality_factor')->column('id,type,description'); $pic_cause = []; $rep_cause = []; foreach ($cause_dict as $id => $val){ if($val['type'] == '1'){ $pic_cause[$id] = 0; } else { $rep_cause[$id] = 0; } } // 统计原因数据 $control_ids = array_column($controls, 'id'); $cause = $this->cause ->whereIn('control_id', $control_ids) ->select(); if ($cause) { foreach ($cause as $val) { if ($val['type'] == '1') { $pic_cause[$val['factor_id']] += 1; } else{ $rep_cause[$val['factor_id']] += 1; } } } // 返回 $this->view->cacuse_dict = $cause_dict; $this->view->rep = $rep; $this->view->pic = $pic; $this->view->pic_cause = $pic_cause; $this->view->rep_cause = $rep_cause; return $this->view->fetch(); } }