ExamService.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. namespace app\api\servies\exam;
  3. use app\api\actions\ZskkCache;
  4. use app\api\response\ZskkErrorResponse;
  5. use app\api\servies\report\ReportService;
  6. use app\api\servies\ZskkDefaultService;
  7. use app\api\utils\UUIDUtils;
  8. use app\api\validate\exam\ExamValidate;
  9. use app\api\dao\exam\ExamDao;
  10. use app\api\servies\common\CommonService;
  11. use think\facade\Config;
  12. use think\facade\Log;
  13. /**
  14. * 后台控制器基类
  15. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  16. */
  17. class ExamService extends ZskkDefaultService {
  18. protected $logName = "ExamService";
  19. private $examDao = null;
  20. private $reportService = null;
  21. public function __construct(ExamDao $examDao,ReportService $reportService) {
  22. parent::__construct();
  23. $this->examDao = $examDao;
  24. $this->reportService = $reportService;
  25. }
  26. public function getExamLIst($params,$token)
  27. {
  28. $report_where = '';
  29. $user = $this->examDao->getCache($token);
  30. if(empty($user))
  31. {
  32. $this->throwError('登陆信息失效,请重新进行登陆','0099');
  33. }
  34. $institutionId = $user['institution_id'];
  35. $fuzzyField = ['name','patient_num','accession_num'];
  36. // $fuzzyWhere = $this->getListFuzzyWhere($params,$fuzzyField);
  37. $fuzzyWhere = '';
  38. if(!empty($params['fuzzy_search']))
  39. {
  40. $fuzzy = $params['fuzzy_search'];
  41. $fuzzyWhere = "name = '$fuzzy' or patient_num = '$fuzzy' or accession_num = '$fuzzy' ";
  42. }
  43. // 获取具体筛选 where 条件
  44. $moreField = ['exam_datetime','name','accession_num','patient_num','exam_class','exam_status','report_status','exam_project','application_department','name_fuzzy'];
  45. $moreWhere = $this->getListSpecificWhere($params, $moreField);
  46. if($params['status'] == 3){
  47. $class_where = $this->examDao->getRemoteExamClass($user['exam_class']);
  48. // 发起了远程
  49. // $report_where = " report_status>3 and report_status != 11";
  50. $data = $this->examDao->getRemoteExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where);
  51. }else{
  52. // $ins = $this->examDao->getInsInfo($institutionId);
  53. $class_where = $this->examDao->getExamClass($user['exam_class']);
  54. $gradeWhere = [];
  55. if($user['doctor_grade'] == 1)
  56. {
  57. //管理级查看所有
  58. }elseif($user['doctor_grade'] == 2)
  59. {
  60. //科室级查看当前科室
  61. $depart = $this->examDao->getDoctorDepart($user['department_id']);
  62. $gradeWhere[] = ['application_department','in',$depart];
  63. }elseif($user['doctor_grade'] == 3)
  64. {
  65. //医生级查看当前医生的
  66. $name = $user['realname'];
  67. $gradeWhere = "application_doctor='$name'";
  68. }
  69. // if($ins['is_auto_mode'] == '0')
  70. // {
  71. // $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  72. //
  73. // }else{
  74. if($user['is_admin'] == 1)
  75. {
  76. //医院管理员 可以查看当前类型的所有
  77. $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  78. }else{
  79. //获取医生权限
  80. $userId = $user['id'];
  81. // $doctor_class = $this->examDao->getDoctorClass($userId);
  82. $doctor_class = '2,3,4,5,6,7,8,9,10';
  83. $data = [];
  84. // 写审确认 自己的+所有审、确认
  85. // 写审 自己的+所有审、确认
  86. // 写确认 自己的+所有审、确认
  87. // 审确认 所有已写、审、确认
  88. // 审 所有已写、审、确认
  89. // 确认 所有审、确认
  90. // 写 自己的+确认
  91. if(strpos($doctor_class, '2') !== false && (strpos($doctor_class, '3') !== false || strpos($doctor_class, '4') !== false)){
  92. //既是写 又是审或者确认 获取自己的 + 所有已写、已审核、已完成的
  93. $report_where = "doctor_sign='$userId' or doctor_sign='' or exam_status=7 or exam_status=8 or exam_status=12 or exam_status=9";
  94. $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  95. }
  96. if(strpos($doctor_class, '2') === false && (strpos($doctor_class, '3') !== false || strpos($doctor_class, '4') !== false)){
  97. //没有写权限但是 有审核权限或者确认权限 获取所有审、已完成的
  98. $report_where = "exam_status=8 or exam_status=9";
  99. if(strpos($doctor_class, '3') !== false)
  100. {
  101. //有审核权限 添加所有已写的
  102. $report_where .= " or exam_status=7 or exam_status=12";
  103. }
  104. $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  105. }
  106. if(strpos($doctor_class, '2') !== false && strpos($doctor_class, '3') === false && strpos($doctor_class, '4') === false){
  107. //只有写权限
  108. $report_where = "doctor_sign='$userId' or doctor_sign='' or exam_status=9";
  109. $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  110. }
  111. if(strpos($doctor_class, '1') !== false && strpos($doctor_class, '2') === false && strpos($doctor_class, '3') === false && strpos($doctor_class, '4') === false){
  112. //只有临床权限
  113. $report_where = '';
  114. $data = $this->examDao->getExamList($institutionId, $fuzzyWhere, $moreWhere,$class_where, $params,$report_where,$gradeWhere);
  115. }
  116. }
  117. // }
  118. $custom_field = $data['custom_field'] ?? '';
  119. $custom = [];
  120. if($custom_field !== '')
  121. {
  122. $field = explode(',',$custom_field);
  123. foreach ($field as $k=>$v)
  124. {
  125. if(!(Config::get('ins_custom_field')[$v] ?? null))
  126. {
  127. continue;
  128. }
  129. $custom[$k]['props'] = $v;
  130. $custom[$k]['name'] = Config::get('ins_custom_field')[$v];
  131. }
  132. }
  133. $data['custom_field'] = $custom;
  134. }
  135. if(!empty($data['list']))
  136. {
  137. foreach ($data['list'] as $k=>$v)
  138. {
  139. $data['list'][$k]['insConfig'] = '';
  140. if(!empty($v['patient_source']))
  141. {
  142. $sourceArr = Config::get('patient_source');
  143. $sourceInfo = $sourceArr[$v['patient_source']] ?? [];
  144. if(!empty($sourceInfo))
  145. {
  146. $data['list'][$k]['insConfig'] = $sourceInfo['name'];
  147. }
  148. }
  149. }
  150. }
  151. return $data;
  152. }
  153. public function getRemoteLIst($params,$token)
  154. {
  155. $institutionId = $this->examDao->getInstitution($token);
  156. $data = $this->examDao->getRemoteList($params['examId'],$institutionId);
  157. return $data;
  158. }
  159. public function saveExam($params)
  160. {
  161. $id = $this->examDao->checkIsSet($params['study_id']);
  162. if($id){
  163. //存在则修改
  164. $update = ['exam_status'=>'3','updatedAt'=>date('Y-m-d H:i:s',time())];
  165. $this->examDao->updateExam($id,$update);
  166. } else {
  167. //不存在则创建
  168. $data = [
  169. 'id'=>UUIDUtils::uuid(),
  170. 'patient_id'=>$params['patient_id'],
  171. 'study_id'=>$params['study_id'],
  172. 'accession_num'=>$params['accession_num'],
  173. 'studyuid'=>$params['studyuid'],
  174. 'birthday'=>$params['birthday'] ?? '',
  175. 'exam_datetime'=>$params['exam_datetime'],
  176. 'exam_class'=>$params['exam_class'],
  177. 'body_part'=>$params['body_part'],
  178. 'institution_id'=>$params['institution_id'],
  179. 'device_name'=>$params['device_name'],
  180. 'patient_num'=>$params['patient_num'],
  181. 'createdAt'=>date('Y-m-d H:i:s',time()),
  182. 'exam_status'=>3
  183. ];
  184. $this->examDao->insertExam($data);
  185. $id = $data['id'];
  186. }
  187. return $id;
  188. }
  189. public function getReport($params,$doctor)
  190. {
  191. $search = $params['fuzzy_search'] ?? null;
  192. if(empty($search))
  193. {
  194. $this->throwError('无效的请求参数,请求不能为空','0012');
  195. }
  196. $field = ['impression','description'];
  197. $where = $this->getListFuzzyWhere($params,$field);
  198. $report = $this->examDao->getReport($where,$doctor['institution_id']);
  199. foreach ($report as $k=>$v)
  200. {
  201. $replace = "<span style='color:red'>$search</span>";
  202. $report[$k]['impression'] = str_replace($search,$replace,$v['impression']);
  203. $report[$k]['description'] = str_replace($search,$replace,$v['description']);
  204. }
  205. return $report;
  206. }
  207. public function changeDoctor($params,$doctor)
  208. {
  209. if($doctor['is_admin'] !== '1')
  210. {
  211. $this->throwError('非管理员无法分配');
  212. }
  213. $info = $this->examDao->changeDoctor($params['doctor'],$params['exam_id']);
  214. return $info;
  215. }
  216. public function getFilmAnnex($id,$exam_datetime,$code)
  217. {
  218. $data = $this->examDao->getFilmAnnex($id,$exam_datetime,$code);
  219. return $data;
  220. }
  221. public function del_exam($params,$token)
  222. {
  223. $user = $this->getCache($token);
  224. $result = $this->reportService->reportAuthentication($user['id'],'del',$user['institution_id'],2);
  225. if(!$result){
  226. $this->throwError('权限未分配,请联系管理员',0005);
  227. }
  228. $data = [
  229. 'doctor_id'=>$user['id'],
  230. 'exam_id'=>$params['id'],
  231. 'study_id'=>$params['study_id']
  232. ];
  233. $this->examDao->insertDcmDel($data);
  234. $data = $this->examDao->del_exam($params['id']);
  235. $study = $params['study_id'];
  236. $institution = $params['institution_id'];
  237. $query = Config::get('query_url');
  238. $url = $query."/delete/study?key=ZSKK_DELETE&address=&study_id=$study&institution_id=$institution";
  239. $this->curl_get_time1($url);
  240. return $data;
  241. }
  242. function curl_get_time1($url){
  243. $header = array(
  244. 'Accept: application/json',
  245. );
  246. $curl = curl_init();
  247. //设置抓取的url
  248. curl_setopt($curl, CURLOPT_URL, $url);
  249. //设置头文件的信息作为数据流输出
  250. curl_setopt($curl, CURLOPT_HEADER, 0);
  251. // 超时设置,以秒为单位
  252. curl_setopt($curl, CURLOPT_TIMEOUT, 1);
  253. // 设置请求头
  254. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  255. //设置获取的信息以文件流的形式返回,而不是直接输出。
  256. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  257. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  258. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  259. //执行命令
  260. $data = curl_exec($curl);
  261. return $data;
  262. }
  263. public function getSyncAi($params)
  264. {
  265. $where[] = ['exam_id','in',explode(',',$params['exam_id'])];
  266. $ids = $this->examDao->getSyncAi($where);
  267. return $ids;
  268. }
  269. public function getAiNode($params)
  270. {
  271. if(empty($params['study_id'] ?? ''))
  272. {
  273. return [];
  274. }
  275. $where = ['study_id'=>$params['study_id']];
  276. $node = $this->examDao->getAiNode($where);
  277. if(empty($node))
  278. {
  279. return [];
  280. }
  281. return $node;
  282. }
  283. }