model = new \app\admin\model\manage\Exams; } public function aiReport() { $ids = $_GET['exam']; $service = new DoctorService(); $data = $service->getPrintData($ids); // halt(json_encode(['message'=>$data])); $res = $this->curl_post('http://172.30.254.2:5001',['message'=>$data]); $aiQuality = Db::table('quality_ai')->where('exam_id',$ids)->find(); if(empty($aiQuality)) { Db::table('quality_ai')->insert(['ai_quality'=>$res,'exam_id'=>$ids]); }else{ Db::table('quality_ai')->where('id',$aiQuality['id'])->update(['ai_quality'=>$res]); } $this->success(); } public function curl_post($url, $data) { $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); $return = curl_exec ( $ch ); curl_close ( $ch ); return $return; } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ public function lookReport($ids) { $report = Db::table('report')->where('exam_id',$ids)->where('type',1)->find(); $this->view->assign('row',$report); return $this->view->fetch(); } public function report($ids) { // var_dump(makeNew16Uid()); // var_dump($ids); if ($this->request->isPost()) { $params = $this->request->post("report"); var_dump($params);die; } return $this->view->fetch(); } public function film($type,$ids,$task=1,$tid='') { $ins = Db::table('exams')->where('id',$ids)->value('institution_id'); $row = Db::table('qc_standards')->where('type',$type) ->where('institution_id',$ins) ->where('status',1)->find(); $dimension = Db::table('qc_dimension')->where('standard_id',$row['id'])->where('status',1)->order('sort')->select(); if(!empty($dimension)) { foreach ($dimension as $k=>$v) { $dimension[$k]['option'] = Db::table('qc_options')->where('dimension_id',$v['id'])->column('id,title'); $dimension[$k]['option_id'] = Db::table('qc_results')->where('dimension_id',$v['id'])->where('exam_id',$ids)->where('standard_id',$row['id'])->value('option_id'); } if ($this->request->isPost()) { $params = $this->request->post(); $arr = [ 'qc_type'=>$type, //质控类型 1 技术质控 2诊断质控 'task_type'=>1, //任务类型 1全量质控 2任务质控 'standard_id'=>$params['standard'], 'exam_id'=>$ids ]; if($task == 1) { Db::table('qc_results')->where('qc_type',$type)->where('exam_id',$ids)->where('task_type',$task)->delete(); }elseif ($task == 2) { Db::table('qc_results')->where('qc_type',$type)->where('exam_id',$ids)->delete(); } unset($params['standard']); $newArr = []; foreach ($params as $k=>$v) { $arr['dimension_id'] = $k; foreach ($dimension as $key=>$value) { if($value['id'] == $k) { $arr['dimension_name'] = $value['title']; $arr['weight'] = $value['weight']; } } $arr['option_id'] = $v; $option = Db::table('qc_options')->where('id',$v)->find(); $arr['option_title'] = $option['title']; $arr['score'] = $option['score']; $newArr[] = $arr; } Db::table('qc_results')->insertAll($newArr); $resultService = new ResultService(); $summaryResult = $resultService->calculateSummaryResults($newArr, $row['id']); $tUpdate = []; if($type == 1) { //1技术质控 $tUpdate['study_score'] = $summaryResult['score']; $tUpdate['study_result'] = $summaryResult['title']; }elseif ($type == 2) { //2诊断质控 $tUpdate['report_score'] = $summaryResult['score']; $tUpdate['report_result'] = $summaryResult['title']; } // 获取全量质控的任务数据 $oldTask = Db::table('qc_task_exams')->where('exam_id',$ids)->where('task_type',1)->find(); if(empty($oldTask)) { $newTask = ['exam_id'=>$ids,'task_type'=>1,'type'=>3]; $newId = Db::table('qc_task_exams')->insertGetId($newTask); $newTask['id'] = $newId; $oldTask = $newTask; } $oldTask = array_merge($oldTask,$tUpdate); Db::table('qc_task_exams')->where('exam_id',$ids)->where('task_type',1)->update($tUpdate); $this->completeTaskStatus($oldTask,['id'=>$oldTask['id']]); if($task == 2) { foreach ($newArr as $k=>$v) { $newArr[$k]['task_type'] = 2; } Db::table('qc_results')->insertAll($newArr); if(!empty($tUpdate)) { if(!empty($tid)) { Db::table('qc_task_exams')->where('id',$tid)->update($tUpdate); } } $taskData = Db::table('qc_task_exams')->where('id',$tid)->find(); $this->completeTaskStatus($taskData,['id'=>$tid]); } $recordArr = [ 'qc_type'=>$type, //质控类型 1 技术质控 2诊断质控 'task_type'=>$task, //任务类型 1全量质控 2任务质控 'exam_id'=>$ids, 'createdBy'=>Session::get('admin')['nickname'], 'results'=>json_encode($params), 'result_title'=>$summaryResult['title'], 'result_score'=>$summaryResult['score'], 'result_desc'=>$summaryResult['desc'], ]; if($task == 2) { $recordArr['task_id'] = $taskData['task_id']; $qcNum = Db::table('qc_task_exams')->where('task_id',$taskData['task_id'])->where('complete',1)->count(); Db::table('qc_tasks')->where('id',$recordArr['task_id'])->update(['qc_num'=>$qcNum]); } Db::table('qc_records')->insert($recordArr); $this->success('评价成功'); } } $this->view->assign('dimension',$dimension); $this->view->assign('standard',$row['id']); return $this->view->fetch(); } public function completeTaskStatus($taskData,$where) { $complete = 0; switch ($taskData['type']) { case 1: if(!empty($taskData['study_score'])) { $complete = 1; } break; case 2: if(!empty($taskData['report_score'])) { $complete = 1; } break; case 3: if(!empty($taskData['report_score']) && !empty($taskData['study_score'])) { $complete = 1; } break; } if($complete == 1){Db::table('qc_task_exams')->where($where)->update(['complete'=>1]);} } public function lookResult($type, $ids,$task=1) { $resultService = new ResultService(); $result = Db::table('qc_results')->where('qc_type', $type)->where('task_type', $task)->where('exam_id', $ids)->select(); $newArr = []; $standard_id = false; // halt($result); foreach ($result as $k=>$v) { $arr['dimension'] = $v['dimension_name']; $arr['option'] = $v['option_title']; $arr['score'] = $v['score']; $arr['weight'] = $v['weight']; $standard_id = $v['standard_id']; $newArr[] = $arr; } $summaryResult = $resultService->calculateSummaryResults($newArr, $standard_id); // $weightedAverageScore = $resultService->calculateWeightedAverage($newArr); // $scoreDescObj = $resultService->getScoreDescObjFromAverageScore($weightedAverageScore, ); $this->view->assign('data',$newArr); $this->view->assign('result',$summaryResult); // $this->view->assign('score',$weightedAverageScore); return $this->view->fetch(); } public function lookAiResult($ids) { $resultService = new ResultService(); $result = Db::table('quality_ai')->where('exam_id', $ids)->value('ai_quality'); if(empty($result)) { $this->error('没有生成ai质控'); } $result = str_replace(['\n', '\r'], '', $result); $result = json_decode($result,true); // ["results"]=>array(6) { [0]=> string(1) "e" [1]=> string(1) "e" [2]=> string(1) "e" [3]=> string(1) "c" [4]=> string(1) "b" [5]=> string(1) "c"} // ["basis"]=>array(6) { [0]=> string(57) "缺失医院地址、科室名称、检查设备名称。" [1]=> string(24) "患者病案号缺失。" [2]=> string(21) "检查参数缺失。" [3]=> string(72) "征象描述基本完整,但存在少量错别字或不规范缩写。" [4]=> string(60) "诊断意见基本明确,但可能有少量语言冗余。" [5]=> string(80) "检查时间记录不完整,仅记录日期 `20250206`,未精确到分钟。"} // ["suggests"]=>array(6) { [0]=> string(63) "补充完整医院地址、科室名称、检查设备名称。" [1]=> string(24) "补充病案号信息。" [2]=> string(27) "补充检查参数信息。" [3]=> string(57) "优化征象描述,减少错别字和不规范缩写。" [4]=> string(63) "优化诊断意见,减少语言冗余,确保格式规范。" [5]=> string(61) "检查时间应精确到分钟(如 `2025-02-06 14:30`)。"} // ["summary"]=>string(216) "1. 补充缺失信息:医院地址、科室、设备名称、病案号、检查参数;2. 优化征象描述和诊断意见,减少错别字、不规范缩写和语言冗余;3. 检查时间应精确到分钟。" // halt($result); // $newArr = []; // $standard_id = false; // foreach ($result as $k=>$v) // { // $arr['dimension'] = $v['dimension_name']; // $arr['option'] = $v['option_title']; // $arr['score'] = $v['score']; // $arr['weight'] = $v['weight']; // $standard_id = $v['standard_id']; // $newArr[] = $arr; // } $standard_id = $resultService->getStandardIdByExamId($ids); $res = $resultService->getAiResultsDataByStandardId($result, $standard_id); $newArr = $res[0]; $summary = $res[1]; $summaryResult = $resultService->calculateSummaryResults($newArr, $standard_id); // $weightedAverageScore = $resultService->calculateWeightedAverage($newArr); // $scoreDescObj = $resultService->getScoreDescObjFromAverageScore($weightedAverageScore, ); $this->view->assign('data',$newArr); $this->view->assign('result',$summaryResult); $this->view->assign('summary',$summary); // $this->view->assign('score',$weightedAverageScore); return $this->view->fetch(); } public function reportSelectList() { try{ // 获取列表 $total = Db::table('quality_factor') ->where('type',2) ->count(); $list = Db::table('quality_factor') ->where('type',2) ->field('id,description as name') ->select(); // 格式化 return json(array("total" => $total, "rows" => $list)); } catch ( Exception $exception){ $this->error($exception->getMessage()); } } public function filmSelectList() { try{ // 获取列表 $total = Db::table('quality_factor') ->where('type',1) ->count(); $list = Db::table('quality_factor') ->where('type',1) ->field('id,description as name') ->select(); // 格式化 return json(array("total" => $total, "rows" => $list)); } catch ( Exception $exception){ $this->error($exception->getMessage()); } } public function analysis($ids) { // ids 是exam_id $resultService = new ResultService(); $newArr = $resultService->analysis($ids); $this->view->assign('data',$newArr); return $this->view->fetch(); } }