123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <?php
- namespace app\api\servies\exam;
- use app\api\actions\ZskkCache;
- use app\api\response\ZskkErrorResponse;
- use app\api\servies\report\ReportService;
- use app\api\servies\ZskkDefaultService;
- use app\api\utils\UUIDUtils;
- use app\api\validate\exam\ExamValidate;
- use app\api\dao\exam\ExamDao;
- use app\api\servies\common\CommonService;
- use think\facade\Config;
- use think\facade\Log;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class ExamService extends ZskkDefaultService {
- protected $logName = "ExamService";
- private $examDao = null;
- private $reportService = null;
- public function __construct(ExamDao $examDao,ReportService $reportService) {
- parent::__construct();
- $this->examDao = $examDao;
- $this->reportService = $reportService;
- }
- public function getExamLIst($params,$token)
- {
- $report_where = '';
- $user = $this->examDao->getCache($token);
- if(empty($user))
- {
- $this->throwError('登陆信息失效,请重新进行登陆','0099');
- }
- $institutionId = $user['institution_id'];
- $fuzzyField = ['name','patient_num','accession_num'];
- // $fuzzyWhere = $this->getListFuzzyWhere($params,$fuzzyField);
- $fuzzyWhere = '';
- if(!empty($params['fuzzy_search']))
- {
- $fuzzy = $params['fuzzy_search'];
- $fuzzyWhere = "name = '$fuzzy' or patient_num = '$fuzzy' or accession_num = '$fuzzy' ";
- }
- // 获取具体筛选 where 条件
- $moreField = ['exam_datetime','name','accession_num','patient_num','exam_class','exam_status','report_status','exam_project','application_department','name_fuzzy'];
- $moreWhere = $this->getListSpecificWhere($params, $moreField);
- if($params['status'] == 3){
- $class_where = $this->examDao->getRemoteExamClass($user['exam_class']);
- // 发起了远程
- // $report_where = " report_status>3 and report_status != 11";
- $data = $this->examDao->getRemoteExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where);
- }else{
- // $ins = $this->examDao->getInsInfo($institutionId);
- $class_where = $this->examDao->getExamClass($user['exam_class']);
- $gradeWhere = [];
- if($user['doctor_grade'] == 1)
- {
- //管理级查看所有
- }elseif($user['doctor_grade'] == 2)
- {
- //科室级查看当前科室
- $depart = $this->examDao->getDoctorDepart($user['department_id']);
- $gradeWhere[] = ['application_department','in',$depart];
- }elseif($user['doctor_grade'] == 3)
- {
- //医生级查看当前医生的
- $name = $user['realname'];
- $gradeWhere = "application_doctor='$name'";
- }
- // if($ins['is_auto_mode'] == '0')
- // {
- // $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- //
- // }else{
- if($user['is_admin'] == 1)
- {
- //医院管理员 可以查看当前类型的所有
- $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- }else{
- //获取医生权限
- $userId = $user['id'];
- // $doctor_class = $this->examDao->getDoctorClass($userId);
- $doctor_class = '2,3,4,5,6,7,8,9,10';
- $data = [];
- // 写审确认 自己的+所有审、确认
- // 写审 自己的+所有审、确认
- // 写确认 自己的+所有审、确认
- // 审确认 所有已写、审、确认
- // 审 所有已写、审、确认
- // 确认 所有审、确认
- // 写 自己的+确认
- if(strpos($doctor_class, '2') !== false && (strpos($doctor_class, '3') !== false || strpos($doctor_class, '4') !== false)){
- //既是写 又是审或者确认 获取自己的 + 所有已写、已审核、已完成的
- $report_where = "doctor_sign='$userId' or doctor_sign='' or exam_status=7 or exam_status=8 or exam_status=12 or exam_status=9";
- $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- }
- if(strpos($doctor_class, '2') === false && (strpos($doctor_class, '3') !== false || strpos($doctor_class, '4') !== false)){
- //没有写权限但是 有审核权限或者确认权限 获取所有审、已完成的
- $report_where = "exam_status=8 or exam_status=9";
- if(strpos($doctor_class, '3') !== false)
- {
- //有审核权限 添加所有已写的
- $report_where .= " or exam_status=7 or exam_status=12";
- }
- $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- }
- if(strpos($doctor_class, '2') !== false && strpos($doctor_class, '3') === false && strpos($doctor_class, '4') === false){
- //只有写权限
- $report_where = "doctor_sign='$userId' or doctor_sign='' or exam_status=9";
- $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- }
- if(strpos($doctor_class, '1') !== false && strpos($doctor_class, '2') === false && strpos($doctor_class, '3') === false && strpos($doctor_class, '4') === false){
- //只有临床权限
- $report_where = '';
- $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
- }
- }
- // }
- $custom_field = $data['custom_field'] ?? '';
- $custom = [];
- if($custom_field !== '')
- {
- $field = explode(',',$custom_field);
- foreach ($field as $k=>$v)
- {
- if(!(Config::get('ins_custom_field')[$v] ?? null))
- {
- continue;
- }
- $custom[$k]['props'] = $v;
- $custom[$k]['name'] = Config::get('ins_custom_field')[$v];
- }
- }
- $data['custom_field'] = $custom;
- }
- if(!empty($data['list']))
- {
- foreach ($data['list'] as $k=>$v)
- {
- $data['list'][$k]['insConfig'] = '';
- if(!empty($v['patient_source']))
- {
- $sourceArr = Config::get('patient_source');
- $sourceInfo = $sourceArr[$v['patient_source']] ?? [];
- if(!empty($sourceInfo))
- {
- $data['list'][$k]['insConfig'] = $sourceInfo['name'];
- }
- }
- }
- }
- return $data;
- }
- public function getRemoteLIst($params,$token)
- {
- $institutionId = $this->examDao->getInstitution($token);
- $data = $this->examDao->getRemoteList($params['examId'],$institutionId);
- return $data;
- }
- public function saveExam($params)
- {
- $id = $this->examDao->checkIsSet($params['study_id']);
- if($id){
- //存在则修改
- $update = ['exam_status'=>'3','updatedAt'=>date('Y-m-d H:i:s',time())];
- $this->examDao->updateExam($id,$update);
- } else {
- //不存在则创建
- $data = [
- 'id'=>UUIDUtils::uuid(),
- 'patient_id'=>$params['patient_id'],
- 'study_id'=>$params['study_id'],
- 'accession_num'=>$params['accession_num'],
- 'studyuid'=>$params['studyuid'],
- 'birthday'=>$params['birthday'] ?? '',
- 'exam_datetime'=>$params['exam_datetime'],
- 'exam_class'=>$params['exam_class'],
- 'body_part'=>$params['body_part'],
- 'institution_id'=>$params['institution_id'],
- 'device_name'=>$params['device_name'],
- 'patient_num'=>$params['patient_num'],
- 'createdAt'=>date('Y-m-d H:i:s',time()),
- 'exam_status'=>3
- ];
- $this->examDao->insertExam($data);
- $id = $data['id'];
- }
- return $id;
- }
- public function getReport($params,$doctor)
- {
- $search = $params['fuzzy_search'] ?? null;
- if(empty($search))
- {
- $this->throwError('无效的请求参数,请求不能为空','0012');
- }
- $field = ['impression','description'];
- $where = $this->getListFuzzyWhere($params,$field);
- $report = $this->examDao->getReport($where,$doctor['institution_id']);
- foreach ($report as $k=>$v)
- {
- $replace = "<span style='color:red'>$search</span>";
- $report[$k]['impression'] = str_replace($search,$replace,$v['impression']);
- $report[$k]['description'] = str_replace($search,$replace,$v['description']);
- }
- return $report;
- }
- public function changeDoctor($params,$doctor)
- {
- if($doctor['is_admin'] !== '1')
- {
- $this->throwError('非管理员无法分配');
- }
- $info = $this->examDao->changeDoctor($params['doctor'],$params['exam_id']);
- return $info;
- }
- public function getFilmAnnex($id,$exam_datetime,$code)
- {
- $data = $this->examDao->getFilmAnnex($id,$exam_datetime,$code);
- return $data;
- }
- public function del_exam($params,$token)
- {
- $user = $this->getCache($token);
- $result = $this->reportService->reportAuthentication($user['id'],'del',$user['institution_id'],2);
- if(!$result){
- $this->throwError('权限未分配,请联系管理员',0005);
- }
- $data = [
- 'doctor_id'=>$user['id'],
- 'exam_id'=>$params['id'],
- 'study_id'=>$params['study_id']
- ];
- $this->examDao->insertDcmDel($data);
- $data = $this->examDao->del_exam($params['id']);
- $study = $params['study_id'];
- $institution = $params['institution_id'];
- $query = Config::get('query_url');
- $url = $query."/delete/study?key=ZSKK_DELETE&address=&study_id=$study&institution_id=$institution";
- $this->curl_get_time1($url);
- return $data;
- }
- function curl_get_time1($url){
- $header = array(
- 'Accept: application/json',
- );
- $curl = curl_init();
- //设置抓取的url
- curl_setopt($curl, CURLOPT_URL, $url);
- //设置头文件的信息作为数据流输出
- curl_setopt($curl, CURLOPT_HEADER, 0);
- // 超时设置,以秒为单位
- curl_setopt($curl, CURLOPT_TIMEOUT, 1);
- // 设置请求头
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- //设置获取的信息以文件流的形式返回,而不是直接输出。
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- //执行命令
- $data = curl_exec($curl);
- return $data;
- }
- public function getSyncAi($params)
- {
- $where[] = ['exam_id','in',explode(',',$params['exam_id'])];
- $ids = $this->examDao->getSyncAi($where);
- return $ids;
- }
- public function getAiNode($params)
- {
- if(empty($params['study_id'] ?? ''))
- {
- return [];
- }
- $where = ['study_id'=>$params['study_id']];
- $node = $this->examDao->getAiNode($where);
- if(empty($node))
- {
- return [];
- }
- return $node;
- }
- }
|