123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace app\admin\controller\quality;
- use app\admin\model\doctors\DoctorModel;
- use app\admin\model\quality\Cause;
- use app\common\controller\Backend;
- use app\common\library\SysLogs;
- use think\Db;
- /**
- * 质控相关
- * @icon fa fa-institution
- */
- class Quality extends Backend
- {
- protected $model = null;
- protected $cause = null;
- protected $doctorModel = null;
- protected $searchFields = [
- 'realname'
- ];
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
|