ReportService.php 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  1. <?php
  2. namespace app\api\servies\report;
  3. use app\api\actions\ZskkCache;
  4. use app\api\dao\xz\XzDao;
  5. use app\api\model\api\ApiModel;
  6. use app\api\model\institution\InstitutionModel;
  7. use app\api\model\interpret\InterpretModel;
  8. use app\api\model\visit\VisitModel;
  9. use app\api\request\ZskkDefaultRequest;
  10. use app\api\response\ZskkErrorResponse;
  11. use app\api\servies\wechat\WechatService;
  12. use app\api\servies\xz\XzService;
  13. use app\api\servies\ZskkDefaultService;
  14. use app\api\utils\UUIDUtils;
  15. use app\api\validate\report\ReportValidate;
  16. use app\api\dao\report\ReportDao;
  17. use app\api\servies\common\CommonService;
  18. use app\common\library\send_message;
  19. use app\common\library\uploadToCloud;
  20. use PHPMailer\PHPMailer\PHPMailer;
  21. use think\facade\Cache;
  22. use think\facade\Config;
  23. use think\facade\Log;
  24. use think\Db;
  25. use think\db\exception;
  26. /**
  27. * 后台控制器基类
  28. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  29. */
  30. class ReportService extends ZskkDefaultService {
  31. protected $logName = "ExamService";
  32. private $reportDao = null;
  33. private $xz = null;
  34. public function __construct(ReportDao $reportDao,XzDao $xzDao) {
  35. parent::__construct();
  36. $this->reportDao = $reportDao;
  37. $this->xz = $xzDao;
  38. }
  39. public function check($token,$status)
  40. {
  41. $user = $this->reportDao->getUser($token);
  42. $user_id = $user['id'];
  43. $save = $this->reportAuthentication($user_id, 'save', $user['institution_id'],2);
  44. $audit = $this->reportAuthentication($user_id, 'audit', $user['institution_id'],2);
  45. $confirm = $this->reportAuthentication($user_id, 'confirm', $user['institution_id'],2);
  46. if($status != 9)
  47. {
  48. if(!($save || $audit || $confirm))
  49. {
  50. return '2';
  51. }
  52. }
  53. return '1';
  54. }
  55. public function getReportDetail($examId,$isRemote,$token,$ra_id)
  56. {
  57. if(empty($ra_id)){
  58. //本地报告详情
  59. $detail = $this->reportDao->getReportInfo($examId);
  60. $data = json_decode(json_encode($detail),true);
  61. if(!isset($data['report_id']) || $data['report_id'] == ''){
  62. $report_info = [
  63. 'id'=>UUIDUtils::uuid(),
  64. 'exam_id'=>$examId,
  65. 'createdAt'=>date('Y-m-d H:i:s',time()),
  66. 'type'=>1
  67. ];
  68. $this->reportDao->InsertReport($report_info);
  69. // $url = 'http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$report_info['id'].'&version=3';
  70. // $this->curl_get($url);
  71. $detail['report_id'] = $report_info['id'];
  72. }
  73. }else{
  74. //远程报告详情
  75. $detail = $this->reportDao->getRemoteReportInfo($ra_id);
  76. }
  77. $institution = $this->reportDao->getInstitutionData(['id'=>$detail['institution_id']],['report_subtitle','report_title','hr_info']);
  78. $detail['report_title'] = $institution['report_title'] ?? '';
  79. $detail['report_subtitle'] = $institution['report_subtitle'] ?? '';
  80. $detail['hr_info'] = $institution['hr_info'] ?? '';
  81. $time = date('Y-m-d H:i:s',time());
  82. //过期时间 大于当前 则 还没过期
  83. $where = "effective_date > '$time'";
  84. $dcm = $this->reportDao->getDcmPathData($where,$detail['study_id']);
  85. $detail['dcm_path'] = $dcm['dcm_path'] ?? '';
  86. $detail['dcm_type'] = $dcm['dcm_type'] ?? '1';
  87. if($detail['dcm_type'] != 1)
  88. {
  89. $detail['dcm_path'] = $this->makeFileUrl($dcm['dcm_path'],$dcm['dcm_type']);
  90. }
  91. // 医生姓名
  92. $detail['report_doctor_id'] = $detail['report_doctor_id'] ?? '';
  93. $detail['review_doctor_id'] = $detail['review_doctor_id'] ?? '';
  94. $detail['confirm_doctor_id'] = $detail['confirm_doctor_id'] ?? '';
  95. $detail['local_institution_name'] = $detail['local_institution_name'] ?? '';
  96. $detail['req_doctor_name'] = $detail['req_doctor_name'] ?? '';
  97. $detail['remote_department'] = $detail['remote_department'] ?? '';
  98. $detail['report_id'] = $detail['report_id'] ?? '';
  99. $detail['report_doctor_name'] = $detail['report_doctor_name'] ?? '';
  100. $detail['review_doctor_name'] = $detail['review_doctor_name'] ?? '';
  101. $detail['confirm_doctor_name'] = $detail['confirm_doctor_name'] ?? '';
  102. $detail['remote_application_id'] = $detail['remote_application_id'] ?? '';
  103. $detail['report_use_autograph'] = $detail['report_use_autograph'] ?? '0';
  104. $detail['review_use_autograph'] = $detail['review_use_autograph'] ?? '0';
  105. $detail['confirm_use_autograph'] = $detail['confirm_use_autograph'] ?? '0';
  106. $detail['report_autograph'] = ($detail['report_use_autograph'] == 1) ? (empty($detail['report_autograph']) ? '' : $this->makeFileUrl($detail['report_autograph'],$detail['report_autograph_type'])) : '';
  107. $detail['review_autograph'] = ($detail['review_use_autograph'] == 1) ? (empty($detail['review_autograph']) ? '' : $this->makeFileUrl($detail['review_autograph'],$detail['review_autograph_type'])) : '';
  108. $detail['confirm_autograph'] = ($detail['confirm_use_autograph'] == 1) ? (empty($detail['confirm_autograph']) ? '' : $this->makeFileUrl($detail['confirm_autograph'],$detail['confirm_autograph_type'])) : '';
  109. if(!empty($detail['report_doctor_id'])){
  110. $insName = $this->reportDao->getInstitution($detail['report_doctor_id']);
  111. $detail['institution'] = $insName['name'];
  112. $detail['introduce'] = $insName['introduce'];
  113. }else{
  114. $detail['institution'] = '';
  115. $detail['introduce'] = '';
  116. }
  117. $detail['exam_id'] = $examId;
  118. $detail['is_remote'] = $isRemote;
  119. // 操作痕迹
  120. if(empty($detail['report_id'])){
  121. $trace = [];
  122. }else{
  123. $trace = $this->reportDao->getTrace($detail['report_id']);
  124. }
  125. if(!isset($detail['exam_status'])){
  126. $detail['exam_status'] = '';
  127. }
  128. $detail['trace'] = $trace;
  129. // 当报告处于完成状态时 不在显示暂存的草稿
  130. if($detail['exam_status'] ?? '') {
  131. if ($detail['exam_status'] == 9)
  132. {
  133. return $detail;
  134. }
  135. }
  136. if($detail['report_status'] ?? '')
  137. {
  138. if ($detail['report_status'] == 9)
  139. {
  140. return $detail;
  141. }
  142. }
  143. // 草稿存储
  144. $userId = $this->reportDao->getUserId($token);
  145. $cacheToken = $this->getStageKey($detail['report_id'],$userId);
  146. $stage = $this->reportDao->getStage($cacheToken);
  147. if(!empty($stage)){
  148. $detail['impression'] = $stage['impression'];
  149. $detail['description'] = $stage['description'];
  150. }
  151. return $detail;
  152. }
  153. public function getWjDetail($examId,$isRemote)
  154. {
  155. if($isRemote == 1){
  156. //远程
  157. $remote = 'not null';
  158. }else{
  159. $remote = 'null';
  160. }
  161. $detail = $this->reportDao->getReportInfo($examId/**,$remote*/);
  162. // 医生姓名
  163. if(empty($detail)){
  164. $detail['report_doctor_id'] = '';
  165. $detail['review_doctor_id'] = '';
  166. $detail['confirm_doctor_id'] = '';
  167. $detail['report_id'] = '';
  168. $detail['report_doctor_name'] = '';
  169. $detail['review_doctor_name'] = '';
  170. $detail['confirm_doctor_name'] = '';
  171. }
  172. if(!empty($detail['report_doctor_id'])){
  173. $insName = $this->reportDao->getInstitution($detail['report_doctor_id']);
  174. $detail['institution'] = $insName['name'];
  175. $detail['introduce'] = $insName['introduce'];
  176. }else{
  177. $detail['institution'] = '';
  178. $detail['introduce'] = '';
  179. }
  180. $detail['exam_id'] = $examId;
  181. $detail['is_remote'] = $isRemote;
  182. if(!isset($detail['exam_status'])){
  183. $detail['exam_status'] = '';
  184. }
  185. $detail['trace'] = '';
  186. return $detail;
  187. }
  188. public function save_progress($id,$token,$content,$type)
  189. {
  190. $doctor = $this->reportDao->getUser($token);
  191. $bbs = [
  192. 'id'=>UUIDUtils::uuid(),
  193. 'initiator'=>$doctor['id'],
  194. 'remote_application_id'=>$id,
  195. 'content'=>$doctor['realname'].$content,
  196. 'createdAt'=>date('Y-m-d H:i:s',time()),
  197. 'type'=>$type
  198. ];
  199. $this->reportDao->saveBbs($bbs);
  200. }
  201. public function updateReport($examId, $data, $type, $reportType, $token , $ra_id = null )
  202. {
  203. // Db::startTrans();
  204. try{
  205. // 判断报告权限
  206. $exam = $this->reportDao->getExam($examId);
  207. $phone = $exam['phone'] ?? '';
  208. $studyId = $exam['study_id'];
  209. $user = $this->reportDao->getUser($token);
  210. $user_id = $user['id'];
  211. $result = $this->reportAuthentication($user_id, $type, $exam['institution_id'],$reportType);
  212. if(!$result){
  213. $this->throwError('权限未分配,请联系管理员',0005);
  214. }
  215. $rt = ($reportType == 1) ? 2 : 1;
  216. $report = $this->reportDao->getReport($examId,$rt,$ra_id);
  217. $report = json_decode(json_encode($report,true),true);
  218. $reportId = $report['id'] ?? null;
  219. // 书写报告时新增report表数据
  220. if(empty($reportId)){
  221. if($type == 'save'){
  222. $insert_data = [
  223. 'id' => UUIDUtils::uuid(),
  224. 'exam_id' => $examId,
  225. 'createdAt' => date('Y-m-d H:i:s'),
  226. 'report_result' => 1,
  227. 'type' => $rt,
  228. 'remote_application_id' => $ra_id
  229. ];
  230. $insert_res = $this->reportDao->insertReport($insert_data);
  231. // $url = 'http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$insert_data['id'].'&version=3';
  232. // $this->curl_get($url);
  233. if($insert_res == false){
  234. // Db::rollback();
  235. $this->throwError('insert_report_error',0004);
  236. }
  237. $reportId = $insert_data['id'];
  238. }
  239. }else{
  240. switch ($type)
  241. {
  242. case 'save':
  243. //已写报告 禁止其他医生点击书写按钮
  244. if ($user_id !== $report['report_doctor_id'] && !empty($report['report_doctor_id']))
  245. {
  246. $this->throwError('该报告已被其他医师书写,请刷新当前有页面进行查看!',0712);
  247. }
  248. break;
  249. case 'audit':
  250. //已审报告 禁止其他医生点击审核按钮
  251. if ($user_id !== $report['review_doctor_id'] && !empty($report['review_doctor_id']))
  252. {
  253. $this->throwError('该报告已被其他医师审核,请刷新当前有页面进行查看!',0712);
  254. }
  255. break;
  256. }
  257. }
  258. if($user['institution_id'] == '43600001')
  259. {
  260. if($type == 'save' || $type == 'audit')
  261. {
  262. // 添加锁定状态
  263. $middle = [
  264. 'institution_id'=>$user['institution_id'],
  265. 'status'=>0,
  266. 'doctor_id'=>$user['id'],
  267. 'doctor_name'=>$user['realname'],
  268. 'exam_id'=>$examId,
  269. 'is_sync'=>0,
  270. 'report_id'=>$reportId
  271. ];
  272. $middleInfo = $this->reportDao->getMiddle(['exam_id'=>$examId]);
  273. $middleWhere = [];
  274. if($middleInfo)
  275. {
  276. unset($middle['is_sync']);
  277. $middleWhere = ['exam_id'=>$examId];
  278. }
  279. $this->reportDao->saveRmiddle($middle,$middleWhere);
  280. }elseif($type == 'confirm'){
  281. $middleWhere = ['exam_id'=>$examId];
  282. $middleInfo = $this->reportDao->getMiddle(['exam_id'=>$examId]);
  283. if($middleInfo)
  284. {
  285. $middle = [
  286. 'status'=>1,
  287. 'is_sync'=>0
  288. ];
  289. $this->reportDao->saveRmiddle($middle,$middleWhere);
  290. }else{
  291. $middle = [
  292. 'institution_id'=>$user['institution_id'],
  293. 'status'=>1,
  294. 'doctor_id'=>$user['id'],
  295. 'doctor_name'=>$user['realname'],
  296. 'exam_id'=>$examId,
  297. 'is_sync'=>0,
  298. 'report_id'=>$reportId
  299. ];
  300. $this->reportDao->saveRmiddle($middle);
  301. }
  302. }
  303. }
  304. // 修改基本信息
  305. $notUpdateType = [
  306. 'confirm'
  307. ];
  308. // 不需要更改的类型
  309. if(!in_array($type, $notUpdateType)){
  310. switch ($data['sex']){
  311. case 'M':
  312. case '男':
  313. $sex = 'M';
  314. break;
  315. case 'F':
  316. case '女':
  317. $sex = 'F';
  318. break;
  319. default:
  320. $sex = $data['sex'];
  321. break;
  322. }
  323. $update = [
  324. 'name' => $data['name'],
  325. 'sex' => $sex,
  326. 'age' => $data['age'],
  327. 'exam_class' => $data['exam_class'],
  328. 'exam_project' => $data['exam_project'] ?? null,
  329. ];
  330. if($rt == 1){
  331. $update['phone'] = $data['phone'];
  332. $exam_res = $this->reportDao->updateExamMsg($examId, $exam['patient_id'], $update);
  333. if($exam_res == false){
  334. // Db::rollback();
  335. $this->throwError('update_msg_error',0003);
  336. }
  337. }else{
  338. $update['phone'] = $data['phone'];
  339. $remote_res = $this->reportDao->updateRemote($ra_id, $update);
  340. if($remote_res == false){
  341. // Db::rollback();
  342. $this->throwError('update_msg_error',0003);
  343. }
  344. }
  345. }
  346. // 修改报告数据
  347. $report_up = [
  348. 'impression' => $data['impression'] ?? null,
  349. 'description' => $data['description'] ?? null,
  350. 'report_result' => $data['report_result'] ?? null,
  351. 'hr_status' => $data['hr_status'] ?? 1
  352. ];
  353. $sms = $this->reportDao->getInstitutionSms($user['institution_id']);
  354. switch ($reportType){
  355. case '2':
  356. // 本地报告
  357. $report_res = $this->updateReportData($examId, $report_up, $type, $exam['exam_status'], $user, $reportType);
  358. break;
  359. case '1':
  360. // 远程报告
  361. $report_res = $this->updateReportData($examId, $report_up, $type, $exam['exam_status'], $user, $reportType , $ra_id);
  362. break;
  363. default :
  364. $report_res = false;
  365. break;
  366. }
  367. if($type == 'confirm'){
  368. $this->reportDao->delCache($reportId.'_local');
  369. if($sms == '1' && !empty($phone)){
  370. $insName = $this->reportDao->getInstitutionName($user['institution_id']);
  371. // 发送确认短信
  372. $sms = $this->sendSms($phone,$reportId,$examId,$studyId,$insName,$user['institution_id']);
  373. }
  374. $wechat_url = Config::get('wechat_url');
  375. // 二维码生成
  376. $url = $wechat_url.'/wx_patient/api/unifyGetWxQrcode?reportId='.$reportId.'&version=3';
  377. $this->curl_get($url);
  378. if($reportType == 1 && !empty($ra_id)){
  379. //远程确认区间
  380. $money = $this->reportDao->getOrderMoney($ra_id);
  381. if($money != 0){
  382. $current_money = $this->reportDao->getCurrentMoney($user['institution_id']);
  383. $max_money = $current_money + $money;
  384. $this->reportDao->updateInstititonMoney($user['institution_id'],$max_money);
  385. }
  386. //修改订单状态为已确认
  387. $this->reportDao->updateOrder($ra_id,Config::get('ORDER_STATUS')['CONFIRM']);
  388. $wechat = New WechatService();
  389. $order_id = $this->reportDao->getOrderId($ra_id);
  390. // 微信推送确认
  391. $w = $wechat->pushWechatComplete($order_id);
  392. }
  393. //确认推送微信公众号
  394. if(!empty($exam['id'])){
  395. $data = $this->xz->getPushInfo($exam['id']);
  396. $pushType = 6;
  397. $cont = [
  398. 'name'=>$exam['name'],
  399. 'exam_id'=>$exam['id'],
  400. 'modality'=>$exam['exam_class'],
  401. 'examDate'=>$exam['exam_datetime'],
  402. 'report_id'=>$reportId
  403. ];
  404. $content = json_encode($cont,true);
  405. $openids = $this->xz->getOpenId($data);
  406. foreach ($openids as $k=>$v){
  407. // 推送4.0公众号消息
  408. $this->new_wechat_push($v,$pushType,$content);
  409. }
  410. }
  411. }
  412. if($report_res == false){
  413. // Db::rollback();
  414. $this->throwError('update_report_error',0006);
  415. }
  416. if(isset($reportId) && !empty($reportId)){
  417. // 草稿
  418. $key = $this->getStageKey($reportId, $user_id);
  419. $stage = $this->reportDao->getStage($key);
  420. if($stage){
  421. $this->reportDao->delStage($key);
  422. }
  423. }
  424. // 成功
  425. // Db::commit();
  426. // if($type == 'confirm'){
  427. // $this->getExamPush($examId);
  428. // }
  429. return true;
  430. } catch (Exception $exception){
  431. $this->throwError($exception->getMessage(),0001);
  432. }
  433. }
  434. public function rejectAudit($id,$reason,$user)
  435. {
  436. $field = ['*'];
  437. $write = $this->reportDao->getReportById($id,$field);
  438. //获取当前医生账号权限
  439. $now_authority = $this->reportDao->getDoctorClass($user['id']);
  440. $now_authority = explode(',',$now_authority);
  441. if(!in_array('3',$now_authority))
  442. {
  443. $this->throwError('do_not_have_permission',0005);
  444. }
  445. $update = ['report'];
  446. // 更改状态为审核驳回
  447. $this->reportDao->updateExamStatus($write['exam_id'],12);
  448. $this->reportDao->updateReport($write['exam_id'],1,['review_doctor_id'=>null,'review_doctor_name'=>null,'review_datetime'=>null]);
  449. $data = [
  450. 'id' => UUIDUtils::uuid(),
  451. 'title' => '您写的报告有最新消息,请注意查收',
  452. 'content' => $user['realname'].'医师驳回了您写得报告,驳回原因是:'.$reason,
  453. 'count' => '1',
  454. 'type' => '9',
  455. 'ctime' => date('Y-m-d H:i:s', time()),
  456. 'exam_id' => $write['exam_id'],
  457. 'doctor_id'=>$write['report_doctor_id']
  458. ];
  459. $this->reportDao->insertMessage($data);
  460. return true;
  461. }
  462. public function sendSms($phone,$reportId,$examId,$studyId,$institution,$insId)
  463. {
  464. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  465. $id = UUIDUtils::uuid();
  466. if(empty($phone)){
  467. $send_message = 0;
  468. }else{
  469. //发送短信
  470. $note = [
  471. 'long_url'=>'https://wc.pacsonline.cn/#/jump?id='.$id
  472. ];
  473. $noteId = $this->reportDao->insertNote($note);
  474. $nid = base64_encode(str_pad(base_convert($noteId,10,36),6,'0',STR_PAD_LEFT));
  475. if($insId == '43600001')
  476. {
  477. $send = send_message::sendEZShortMessage($phone,$code,$nid);
  478. }elseif($insId == '03060002'){
  479. $send = send_message::sendReportShortMessage($phone,$institution);
  480. }else{
  481. $send = send_message::sendExam2ShortPatient($phone,$code,$institution,$nid);
  482. }
  483. $data = json_decode(json_encode($send),true);
  484. if($data['Code'] == 'OK'){
  485. $send_message = 1;
  486. }else{
  487. $send_message = 0;
  488. }
  489. }
  490. // $share = [
  491. // 'id'=>$id,
  492. // 'report_id'=>$reportId,
  493. // 'exam_id'=>$examId,
  494. // 'code'=>$code,
  495. // 'send_time'=>time(),
  496. // 'expires_time'=>time()+86400*7,
  497. // 'send_message'=>$send_message,
  498. // 'url'=>'',
  499. // 'phone'=>$phone,
  500. // 'study_id'=> $studyId
  501. // ];
  502. $share = [
  503. 'id'=>$id,
  504. 'examId'=>$examId,
  505. 'status'=>1,
  506. 'overdueTime'=>7,
  507. 'code'=>$code,
  508. 'short_url'=>'',
  509. 'phone'=>$phone,
  510. 'report_isset'=>1,
  511. 'study_id'=>$studyId,
  512. 'send_message'=>$send_message,
  513. ];
  514. $this->reportDao->insertShare($share);
  515. $smsLog = [
  516. 'exam_id'=>$examId,
  517. 'institution_id'=>$insId,
  518. 'send_message'=>$send_message,
  519. 'phone'=>$phone,
  520. ];
  521. $this->reportDao->insertSMSLog($smsLog);
  522. }
  523. public function getExamPush($id)
  524. {
  525. try{
  526. $xzData = $this->reportDao->getXzData($id);
  527. $report = $this->reportDao->getReport($id,1);
  528. $reportName = $this->reportDao->getDoctorName($report['report_doctor_id']);
  529. $reviewName = $this->reportDao->getDoctorName($report['review_doctor_id']);
  530. $studyUid = $this->reportDao->getUid($id);
  531. $accessionNum = $this->reportDao->getAccession($id);
  532. $info = [
  533. 'report'=>[
  534. 'department'=>$xzData['department'],
  535. 'clinicalDoctor'=>$xzData['clinicalDoctor'],
  536. 'symptom'=>$xzData['symptom'],
  537. 'reportDate'=>$report['report_datetime'],
  538. 'description'=>$report['description'],
  539. 'impression'=>$report['impression'],
  540. 'reportDoctor'=>$reportName,
  541. 'reviewDoctor'=>$reviewName,
  542. 'studyInstanceUId'=>$studyUid,
  543. 'modality'=>$xzData['modality'],
  544. 'accessionNumber'=>$accessionNum
  545. ],
  546. 'applicationFormNo'=>$xzData['applicationFormNo'],
  547. 'clinicId'=>$xzData['clinicId'],
  548. ];
  549. $data = json_encode($info);
  550. $url = 'http://wjw.yidab.cn:801/pacs/pushExamReport.do';
  551. // $url = 'http://wjw.yidab.cn:801/wjw-test/pacs/pushExamReport.do';
  552. $return = $this->curlJsonPost($url,$data);
  553. return $return;
  554. }catch(\Exception $e){
  555. return json_encode(['code'=>'1','message'=>$e->getMessage()]);
  556. }
  557. }
  558. public function reportAuthentication($user_id, $type, $institution_id = null,$type_report)
  559. {
  560. // 获取权限列表
  561. $doctor_authority = [
  562. 'clinical' => 1, // 临床医生
  563. 'report' => 2, // 报告医生
  564. 'audit' => 3, // 审核医生
  565. 'confirm' => 4, // 确认医生
  566. 'register' => 5, // 登记医生
  567. 'remote_apply' => 6, // 远程申请医生
  568. 'remote_report' => 7, // 远程报告医生
  569. 'remote_audit' => 8, // 远程审核医生
  570. 'local_reject' => 9, // 本地完成状态打回已写医生
  571. 'local_del' => 10, // 本地影像删除
  572. ];
  573. // 当前账号权限
  574. $now_authority = $this->reportDao->getDoctorClass($user_id);
  575. if(empty($now_authority)){
  576. return false;
  577. }
  578. $now_authority = explode(',', $now_authority);
  579. // 判断权限
  580. switch ($type){
  581. case 'save':
  582. if($type_report == '2'){
  583. $require = $doctor_authority['report'];
  584. }else{
  585. $require = $doctor_authority['remote_report'];
  586. }
  587. if(!in_array($require, $now_authority)){
  588. return false;
  589. }
  590. break;
  591. case 'audit':
  592. if($type_report == '2'){
  593. $require = $doctor_authority['audit'];
  594. }else{
  595. $require = $doctor_authority['remote_audit'];
  596. }
  597. if(!in_array($require, $now_authority)){
  598. return false;
  599. }
  600. break;
  601. case 'confirm':
  602. $require = $doctor_authority['confirm'];
  603. if(!in_array($require, $now_authority)){
  604. return false;
  605. }
  606. break;
  607. case 'reject':
  608. $require = $doctor_authority['local_reject'];
  609. if(!in_array($require, $now_authority)){
  610. return false;
  611. }
  612. break;
  613. case 'del':
  614. $require = $doctor_authority['local_del'];
  615. if(!in_array($require, $now_authority)){
  616. return false;
  617. }
  618. break;
  619. default :
  620. return false;
  621. }
  622. // 成功
  623. return true;
  624. }
  625. public function stageReport($exam_id, $token, $data, $isRemote,$report_id)
  626. {
  627. try{
  628. if($isRemote == 2){
  629. // 本地
  630. $remote = 1;
  631. }else{
  632. // 远程 1区间
  633. $remote = 2;
  634. }
  635. if(!$report_id){
  636. // 创建一条数据
  637. $insert_data = [
  638. 'id' => UUIDUtils::uuid(),
  639. 'exam_id' => $exam_id,
  640. 'createdAt' => date('Y-m-d H:i:s'),
  641. 'report_result' => 1,
  642. 'type' => $remote
  643. ];
  644. if($remote == 2){ //远程进入
  645. $applicationId = $this->reportDao->getApplicationId($exam_id);
  646. $insert_data['remote_application_id'] = $applicationId;
  647. }
  648. $res = $this->reportDao->insertReport($insert_data);
  649. // $url = 'http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$insert_data['id'].'&version=3';
  650. // $this->curl_get($url);
  651. if($res == false){
  652. $this->throwError('insert_report_error',0006);
  653. }
  654. $report_id = $insert_data['id'];
  655. }
  656. // 存储
  657. $user_id = $this->reportDao->getUserId($token);
  658. $key = $this->getStageKey($report_id, $user_id);
  659. $this->reportDao->saveCache($key,$data,604800);
  660. // 成功
  661. return $key;
  662. } catch (Exception $exception){
  663. $this->throwError($exception->getMessage(),0001);
  664. }
  665. }
  666. public function getPrintData($reportId,$is_remote)
  667. {
  668. try{
  669. $wechat = Config::get('wechat_url');
  670. $url = $wechat.'/wx_patient/api/unifyGetWxQrcode?reportId='.$reportId.'&version=3';
  671. $this->curl_get($url);
  672. $detail = $this->reportDao->getPrintInfo($reportId,$is_remote);
  673. $field = ['is_use_autograph','autograph','autograph_type'];
  674. if(empty($detail['report_doctor_id']))
  675. {
  676. $detail['report_use_autograph'] = '';
  677. $detail['report_autograph'] = '';
  678. }else{
  679. $report_autograph = $this->reportDao->getDoctorInfo($detail['report_doctor_id'],$field);
  680. $detail['report_use_autograph'] = $report_autograph['is_use_autograph'] ?? '';
  681. $detail['report_autograph'] = empty($report_autograph['autograph'] ?? '') ? '' : $this->makeFileUrl($report_autograph['autograph'],$report_autograph['autograph_type']);
  682. $detail['report_autograph_type'] = $report_autograph['autograph_type'];
  683. }
  684. if(empty($detail['review_doctor_id']))
  685. {
  686. $detail['review_use_autograph'] = '';
  687. $detail['review_autograph'] = '';
  688. }else{
  689. $review_autograph = $this->reportDao->getDoctorInfo($detail['review_doctor_id'],$field);
  690. $detail['review_use_autograph'] = $review_autograph['is_use_autograph'] ?? '';
  691. $detail['review_autograph'] = empty($review_autograph['autograph'] ?? '') ? '' : $this->makeFileUrl($review_autograph['autograph'],$review_autograph['autograph_type']);
  692. $detail['review_autograph_type'] = $review_autograph['autograph_type'];
  693. }
  694. if($detail['exam_class'] == 'DX' && ($detail['institution_id'] ?? '') == '73000003')
  695. {
  696. $detail['exam_class'] = 'DR';
  697. }
  698. $detail['age'] = str_replace('W','周',str_replace('D','天',str_replace('M','月',str_replace('Y','岁',ltrim($detail['age'],'0')))));
  699. return $detail;
  700. } catch (Exception $exception){
  701. $this->throwError($exception->getMessage(),0001);
  702. }
  703. }
  704. public function makeChineseData($data)
  705. {
  706. switch ($data['sex'])
  707. {
  708. case 'F':
  709. $sex = '女';
  710. break;
  711. case 'M':
  712. $sex = '男';
  713. break;
  714. default:
  715. $sex = '未知';
  716. }
  717. $arr = [
  718. '医院名称'=>$data['institution_name'],
  719. '地址'=>'',
  720. '科室名称'=>'',
  721. '检查设备名称'=>'',
  722. '检查时间'=>$data['exam_datetime'],
  723. '审核时间'=>$data['review_datetime'],
  724. '姓名'=>$data['name'],
  725. '性别'=>$sex,
  726. '年龄'=>$data['age'],
  727. '检查号'=>$data['accession_num'],
  728. '病案号'=>'',
  729. '检查项目'=>$data['exam_project'],
  730. '检查方法'=>$data['exam_class'],
  731. '检查部位'=>$data['body_part'],
  732. '检查参数'=>'',
  733. '征象描述'=>$data['description'],
  734. '结论和建议'=>$data['impression'],
  735. ];
  736. return $arr;
  737. }
  738. public function getQrCode($code,$examId)
  739. {
  740. $url = 'https://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?examId='.$examId.'&version=3';
  741. if(empty($code))
  742. {
  743. $qrCode = $this->curl_get($url);
  744. }else{
  745. $arr = json_decode($code,true);
  746. $time = strtotime($arr['expipy']);
  747. if(time() > $time)
  748. {
  749. $qrCode = $this->curl_get($url);
  750. }else{
  751. $qrCode = $code;
  752. }
  753. }
  754. return json_decode($qrCode,true);
  755. }
  756. public function updateReportData($exam_id, $data, $type, $exam_status, $user, $report_type,$id = null)
  757. {
  758. try{
  759. $status = '';
  760. $doctorId = '';
  761. if($id !== null){
  762. $remote = $this->reportDao->getReportStatus($id);
  763. $status = $remote['report_status'];
  764. $doctorId = $remote['remote_doctor_id'];
  765. }
  766. // 判断类型
  767. switch ($type){
  768. case 'save': // 本地保存
  769. if($report_type == 2){
  770. $write = $this->reportDao->getExam($exam_id);
  771. if($write['write_report'] != 1)
  772. {
  773. //不等于1 则走正常流程
  774. if($exam_status != 3 && $exam_status != 7 && $exam_status != 12){
  775. $this->throwError('流程顺序错误,无法书写报告','0033');
  776. }
  777. }
  778. }else{
  779. // 远程
  780. if($doctorId != $user['id']){
  781. $this->throwError('非受邀医生无法书写报告','0034');
  782. }
  783. if($status != 6 && $status != 7){
  784. $this->throwError('流程顺序错误,无法书写报告','0033');
  785. }
  786. $this->saveProgressLog($user,6,$id);
  787. }
  788. $update = [
  789. 'impression' => $data['impression'],
  790. 'description' => $data['description'],
  791. 'hr_status' => $data['hr_status'],
  792. 'report_result' => $data['report_result'],
  793. 'report_datetime' => date('Y-m-d H:i:s'),
  794. 'report_doctor_id'=> $user['id'],
  795. 'report_doctor_name' =>$user['realname']
  796. ];
  797. $exam_up_status = 7;
  798. $trace_type = 1;
  799. break;
  800. case 'audit':
  801. if($report_type == 2){
  802. if($exam_status != 8 && $exam_status != 7){
  803. $this->throwError('流程顺序错误,无法审核报告','0033');
  804. }
  805. }else{
  806. if($status != 8 && $status != 7){
  807. $this->throwError('流程顺序错误,无法审核报告','0033');
  808. }
  809. $this->saveProgressLog($user,7,$id);
  810. }
  811. $update = [
  812. 'impression' => $data['impression'],
  813. 'description' => $data['description'],
  814. 'hr_status' => $data['hr_status'],
  815. 'report_result' => $data['report_result'],
  816. 'review_datetime' => date('Y-m-d H:i:s'),
  817. 'review_doctor_id'=> $user['id'],
  818. 'review_doctor_name'=>$user['realname']
  819. ];
  820. $exam_up_status = 8;
  821. $trace_type = 2;
  822. break; // 本地审核
  823. case 'confirm':
  824. if($report_type == 2){
  825. if($exam_status != 8){
  826. $this->throwError('流程顺序错误,无法确认报告','0033');
  827. }
  828. }else{
  829. if($status != 10){
  830. $this->throwError('流程顺序错误,无法确认报告','0033');
  831. }
  832. $this->saveProgressLog($user,9,$id);
  833. }
  834. if(!empty($id)){
  835. $this->reportDao->readMessage($id);
  836. }
  837. $update = [
  838. 'confirm_datetime' => date('Y-m-d H:i:s'),
  839. 'confirm_doctor_id'=> $user['id'],
  840. 'confirm_doctor_name'=>$user['realname']
  841. ];
  842. $exam_up_status = 9;
  843. $trace_type = 3;
  844. break; // 本地确认
  845. default:
  846. return false;
  847. }
  848. // 判断远程还是本地
  849. switch ($report_type){
  850. case '2'; //本地
  851. $result = $this->reportDao->updateReport($exam_id,1,$update);
  852. // 修改状态
  853. $this->reportDao->updateExamStatus($exam_id,$exam_up_status);
  854. break;
  855. case '1':
  856. $result = $this->reportDao->updateRemoteReport($id,$update);
  857. // 修改远程状态
  858. $this->reportDao->updateRemoteStauts($id,$exam_up_status);
  859. $this->reportDao->updateremoteExamStatus($exam_id,$exam_up_status);
  860. break;
  861. default :
  862. return false;
  863. }
  864. if(!$result){
  865. return false;
  866. }
  867. if($report_type == '2'){
  868. $rid = $this->reportDao->getReportId($exam_id,1);
  869. }else{
  870. $rid = $this->reportDao->getRemoteReportId($id);
  871. }
  872. /*$detail = $this->reportDao->getReport($exam_id,$report_type);
  873. $cacheToken = $this->getStageKey($rid,$user_id,$detail['exam_status']);
  874. $stage = $this->reportDao->remoteStage($cacheToken);*/
  875. // 添加报告痕迹
  876. $trace = [
  877. 'id' => UUIDUtils::uuid(),
  878. 'impression' => $update['impression'] ?? '',
  879. 'description' => $update['description'] ?? '',
  880. 'report_result' => $update['report_result'] ?? '',
  881. 'report_id' => $rid,
  882. 'createdAt' => date('Y-m-d H:i:s'),
  883. 'doctor_id' => $user['id'],
  884. 'type' => $trace_type
  885. ];
  886. $result = $this->reportDao->insertReportRecord($trace);
  887. if(!$result){
  888. return false;
  889. }
  890. // 成功
  891. return true;
  892. } catch (DbException $exception){
  893. $this->throwError($exception->getMessage(),0001);
  894. }
  895. }
  896. public function saveProgressLog($doctor,$step,$id)
  897. {
  898. $pay_log = [
  899. 'id'=>UUIDUtils::uuid(),
  900. 'operator_id'=>$doctor['id'],
  901. 'operator_name'=>$doctor['realname'],
  902. 'current_step'=>$step,
  903. 'application_id'=>$id
  904. ];
  905. $this->reportDao->savePregressLog($pay_log);
  906. }
  907. public function save_video_url($params)
  908. {
  909. $data = [
  910. 'exam_id'=>$params['exam_id'],
  911. 'status'=>1
  912. ];
  913. $where = ['id'=>$params['id']];
  914. $return = $this->reportDao->saveVideo($data,$where);
  915. return $return;
  916. }
  917. public function cancel_video($id)
  918. {
  919. $info = $this->reportDao->cancel_video($id);
  920. return $info;
  921. }
  922. public function getVideo($params)
  923. {
  924. $id = $params['exam_id'] ?? null;
  925. if(!$id)
  926. {
  927. $this->throwError('无效的id值','0064');
  928. }
  929. $video = $this->reportDao->getVideo($id);
  930. foreach ($video as $k=>$v)
  931. {
  932. $video[$k]['video_url'] = $this->makeFileUrl($v['video_url'],$v['video_type'],'inline');
  933. }
  934. return $video;
  935. }
  936. public function checkWrite($params,$doctor,$cache)
  937. {
  938. $data = ['id'=>$params['report_id'],'name'=>$doctor['realname'],'did'=>$doctor['id']];
  939. if(empty($cache))
  940. {
  941. $this->reportDao->setCache($params['report_id'].'_local',$data,7200);
  942. }else{
  943. if($doctor['id'] !== $cache['did'])
  944. {
  945. //当前医生不属于第一个进入且存储的医生
  946. $this->throwError($cache['name'],'0067');
  947. }
  948. }
  949. return true;
  950. }
  951. // https://query.pacsonline.cn/query/url?&study_id='.$study.'&version=V1.2.0.0
  952. public function getDcmZip($study,$email='',$come='',$examId='',$examClass='')
  953. {
  954. ignore_user_abort(true); // 后台运行,不受前端断开连接影响
  955. set_time_limit(0); //
  956. ob_end_clean();//清除之前的缓冲内容,这是必需的,如果之前的缓存不为空的话,里面可能有http头或者其它内容,导致后面的内容不能及时的输出
  957. header("Connection: close");//告诉浏览器,连接关闭了,这样浏览器就不用等待服务器的响应
  958. header("HTTP/1.1 200 OK"); //可以发送200状态码,以这些请求是成功的,要不然可能浏览器会重试,特别是有代理的情况下
  959. ob_start();//开始当前代码缓冲
  960. if(empty($come))
  961. {
  962. $result = [
  963. 'code' => 0,
  964. 'msg' => '请求成功',
  965. 'data' => '文件生成中',
  966. 'error' => null,
  967. 'timestamp' => time(),
  968. 'random' => null,
  969. 'signature' => null,
  970. 'request_timestamp' => ZskkDefaultRequest::instance()->header()['zskk-timestamp'] ?? null
  971. ];
  972. echo json_encode($result);
  973. }
  974. //下面输出http的一些头信息
  975. $size = ob_get_length();
  976. header("Content-Length: $size");
  977. ob_end_flush();//输出当前缓冲
  978. flush();//输出PHP缓冲
  979. //在Yii2框架下,上面代码可能不会立即返回给客户端,所以需要加如下的代码,即可实现立即返回给客户端
  980. //具体可查看此文章:http://www.lampnick.com/php/375
  981. if (function_exists("fastcgi_finish_request")) {
  982. fastcgi_finish_request(); /* 响应完成, 关闭连接 */
  983. }
  984. ignore_user_abort(true); // 后台运行,这个只是运行浏览器关闭,并不是直接就中止返回200状态。
  985. try {
  986. set_time_limit(0);
  987. ini_set('memory_limit','1280M');
  988. $study = str_replace('&node_type=1','',$study);
  989. $this->reportDao->insertDcmCompress(['status'=>1,'study_id'=>$study]);
  990. $path = $this->runRack($study,1);
  991. $typeData = $this->reportDao->getDcmPathData([],$study);
  992. $type = $typeData['dcm_type'] ?? 1;
  993. if(strrpos($path,'zip') !== false && file_exists($path))
  994. {
  995. $type = $this->uploadZip($path,$study);
  996. }
  997. if(!empty($email) /* && $come == 'weChat' */)
  998. {
  999. if(strrpos($path,'zip') !== false)
  1000. {
  1001. $name = $this->reportDao->getPatientName($study);
  1002. // 存在zip压缩文件
  1003. $this->sendEmail($email,$path,$name,$type);
  1004. $this->reportDao->insertDcmCompress(['status'=>9,'study_id'=>$study]);
  1005. log::record('邮件发送完毕');
  1006. $this->reportDao->updateEmailStatus($email,$study);
  1007. }
  1008. }
  1009. if($come == 'ai')
  1010. {
  1011. if(strrpos($path,'zip') !== false)
  1012. {
  1013. // 存在zip压缩文件
  1014. $url = 'http://deeplearning.lib.sjtu.edu.cn/';
  1015. // $url = 'http://127.0.0.1:5000/';
  1016. $data = [
  1017. 'zip' => new \CURLFile(APP_PATH.'/'.$path),
  1018. 'exam_id'=>$examId,'exam_class'=>$examClass];
  1019. $re = $this->curlPost($url,$data);
  1020. if($re == false)
  1021. {
  1022. log::record("返回值为false");
  1023. return "返回值为false";
  1024. }
  1025. $reData = json_decode($re,true);
  1026. if(empty($reData[0] ?? null))
  1027. {
  1028. log::record('ai接口返回错误,返回信息'.$re);
  1029. return $re;
  1030. }
  1031. $reportData = [
  1032. 'id'=>UUIDUtils::uuid(),
  1033. 'impression'=>$reData[0]['diagnosis'],
  1034. 'description'=>$reData[0]['describe'],
  1035. 'type'=>3,
  1036. 'exam_id'=>$examId,
  1037. 'report_doctor_name'=>'ai报告医生',
  1038. 'review_doctor_name'=>'ai报告医生',
  1039. 'confirm_doctor_name'=>'ai报告医生',
  1040. 'report_datetime'=>date('Y-m-d H:i:s'),
  1041. 'review_datetime'=>date('Y-m-d H:i:s'),
  1042. 'confirm_datetime'=>date('Y-m-d H:i:s')
  1043. ];
  1044. $aiData = $this->reportDao->getReport($examId,3);
  1045. if($aiData)
  1046. {
  1047. //修改ai报告
  1048. $this->reportDao->updateReport($examId,3,$reportData);
  1049. }else{
  1050. $this->reportDao->insertReport($reportData);
  1051. }
  1052. return $re;
  1053. }
  1054. }
  1055. }catch (\think\Exception $e)
  1056. {
  1057. try {
  1058. $this->reportDao->insertDcmCompress(['status'=>999,'study_id'=>$study,'msg'=>$e->getMessage(),'email'=>$email]);
  1059. }catch (\think\Exception $exception)
  1060. {
  1061. $this->reportDao->insertDcmCompress(['status'=>998,'study_id'=>$study,'msg'=>mb_convert_encoding($e->getMessage(), 'UTF-8', 'GBK'),'email'=>$email]);
  1062. }
  1063. }
  1064. }
  1065. public function sendDcm($sendData,$study,$examId='',$examClass='')
  1066. {
  1067. $this->reportDao->saveDcmReportData($sendData,$examId,1,$this->ts_time());
  1068. $exam = $this->reportDao->getExam($examId);
  1069. $url = 'http://deeplearning.lib.sjtu.edu.cn/';
  1070. // $url = 'http://127.0.0.1:5000/';
  1071. // $url = 'http://49.7.230.34:5000/';
  1072. $query = Config::get('query_url');
  1073. $data = [
  1074. 'down_url' => $query.'/query/down?&study_id='.$study.'&version=V1.2.0.0',
  1075. // 'zip' => new \CURLFile(APP_PATH.'/'.$path),
  1076. 'exam_id'=>$examId,
  1077. 'exam_class'=>$examClass,
  1078. 'exam_project'=>empty($exam['exam_project']) ? '' : $exam['exam_project'],
  1079. 'is_chest'=>($exam['body_part'] == 'CHEST' || strpos($exam['body_part'],'胸') !== false) ? 1 : 0
  1080. ];
  1081. $this->reportDao->saveDcmReportData(json_encode($data),$examId,2,$this->ts_time());
  1082. $re = $this->curlPost($url,$data);
  1083. $this->reportDao->saveDcmReportData('',$examId,3,$this->ts_time());
  1084. $this->reportDao->saveDcmReportData('',$examId,4,$this->ts_time());
  1085. return $re;
  1086. }
  1087. public function testGetDcmZip($study,$email='',$come='',$examId='',$examClass='')
  1088. {
  1089. $path = $this->runDirRack($study,$examId);
  1090. if($come == 'ai')
  1091. {
  1092. if(strrpos($path,'zip') !== false)
  1093. {
  1094. // 存在zip压缩文件
  1095. $url = 'http://deeplearning.lib.sjtu.edu.cn/';
  1096. // $url = 'http://127.0.0.1:5000/';
  1097. $data = [
  1098. 'zip' => new \CURLFile(APP_PATH.'/'.$path),
  1099. 'exam_id'=>$examId,'exam_class'=>$examClass];
  1100. $re = $this->curlPost($url,$data);
  1101. if($re == false)
  1102. {
  1103. log::record("返回值为false");
  1104. return "返回值为false";
  1105. }
  1106. $reData = json_decode($re,true);
  1107. if(empty($reData[0] ?? null))
  1108. {
  1109. log::record('ai接口返回错误,返回信息'.$re);
  1110. return $re;
  1111. }
  1112. $reportData = [
  1113. 'id'=>UUIDUtils::uuid(),
  1114. 'impression'=>$reData[0]['diagnosis'],
  1115. 'description'=>$reData[0]['describe'],
  1116. 'type'=>3,
  1117. 'exam_id'=>$examId,
  1118. 'report_doctor_name'=>'ai报告医生',
  1119. 'review_doctor_name'=>'ai报告医生',
  1120. 'confirm_doctor_name'=>'ai报告医生',
  1121. 'report_datetime'=>date('Y-m-d H:i:s'),
  1122. 'review_datetime'=>date('Y-m-d H:i:s'),
  1123. 'confirm_datetime'=>date('Y-m-d H:i:s')
  1124. ];
  1125. $aiData = $this->reportDao->getReport($examId,3);
  1126. if($aiData)
  1127. {
  1128. //修改ai报告
  1129. $this->reportDao->updateReport($examId,3,$reportData);
  1130. }else{
  1131. $this->reportDao->insertReport($reportData);
  1132. }
  1133. return $re;
  1134. }else{
  1135. return $path;
  1136. }
  1137. }
  1138. return '生成压缩文件失败,返回'.$path.',请联系开发人员';
  1139. }
  1140. public function runDirRack($study,$examId)
  1141. {
  1142. $dcm = $this->getCache($study.'_zip');
  1143. if(!empty($dcm))
  1144. {
  1145. Log::record('已生成过'.$dcm);
  1146. return '生成中';
  1147. }
  1148. ini_set('max_execution_time', 6000);
  1149. $time = date('Y-m-d H:i:s',time());
  1150. //过期时间 大于当前 则 还没过期
  1151. $where = "effective_date > '$time'";
  1152. $dcm = $this->reportDao->getDcmPath($where,$study);
  1153. if(!empty($dcm))
  1154. {
  1155. log::record('存在历史dcm地址'.$dcm);
  1156. return $dcm;
  1157. }
  1158. $this->setCache($study.'_zip',$study,600);
  1159. log::record('不存在历史地址则继续'.$study);
  1160. $query = Config::get('query_url');
  1161. //外网地址 需要network 走带宽
  1162. $url = $query."/query/down?network=1&study_id=$study&version=V1.2.0.0";
  1163. //内网地址
  1164. // $url = 'https://query.pacsonline.cn/query/down?&study_id='.$study.'&version=V1.2.0.0';
  1165. $data = $this->curl_get($url);
  1166. $data = json_decode($data);
  1167. if(empty($data))
  1168. {
  1169. log::record('没有找到dcm信息');
  1170. return 'dcm信息没有找到';
  1171. }
  1172. $date = time();
  1173. $create = ROOT_PATH . 'public' . DS . 'download'.DS.$date;
  1174. log::record('压缩中');
  1175. $path = $this->zipDir($data,$create,$date,$study,$examId);
  1176. log::record('压缩成功');
  1177. return $path;
  1178. }
  1179. public function zipDir($data,$create,$date,$study,$examId)
  1180. {
  1181. ini_set('max_execution_time', 6000);
  1182. $fileList = [];
  1183. foreach ($data as $k=>$v)
  1184. {
  1185. $v = (array)$v;
  1186. $path = $this->downLoad($v['url'],$create.DS.$v['seriesuid'].DS.$k,$create.DS.$v['seriesuid']);
  1187. $fileList[] = ['path'=>$path,'series'=>$v['seriesuid']];
  1188. }
  1189. $zipPath = ROOT_PATH . 'public' . DS .'zip';
  1190. $filename = $zipPath.DS."$examId.zip";
  1191. if (!file_exists($zipPath)) {
  1192. mkdir($zipPath, 0777,true);
  1193. @chmod($zipPath, 0777);
  1194. }
  1195. $zip = new \ZipArchive();
  1196. $zip->open($filename,\ZipArchive::CREATE); //打开压缩包
  1197. foreach($fileList as $file){
  1198. $zip->addFile($file['path'],$file['series'].DS.basename($file['path'])); //向压缩包中添加文件
  1199. }
  1200. $zip->close(); //关闭压缩包
  1201. $insert = [
  1202. 'dcm_path'=>'zip/'.$examId.".zip",
  1203. 'study_id'=>$study,
  1204. 'effective_date'=>date('Y-m-d H:i:s',time()+864000), //10天有效期
  1205. ];
  1206. $this->reportDao->insertDcmPath($insert);
  1207. return 'zip/'.$examId.".zip";
  1208. }
  1209. public function runRack($study,$come='')
  1210. {
  1211. if($come != 1)
  1212. {
  1213. $dcm = $this->getCache($study.'_zip');
  1214. if(!empty($dcm))
  1215. {
  1216. Log::record('已生成过'.$dcm);
  1217. return '生成中';
  1218. }
  1219. }
  1220. ini_set('max_execution_time', 6000);
  1221. $time = date('Y-m-d H:i:s',time());
  1222. //过期时间 大于当前 则 还没过期
  1223. $where = "effective_date > '$time'";
  1224. $dcm = $this->reportDao->getDcmPath($where,$study);
  1225. if(!empty($dcm))
  1226. {
  1227. log::record('存在历史dcm地址'.$dcm);
  1228. return $dcm;
  1229. }
  1230. $this->setCache($study.'_zip',$study,600);
  1231. log::record('不存在历史地址则继续'.$study);
  1232. $query = Config::get('query_url');
  1233. //外网地址 需要network 走带宽
  1234. // $url = "https://query.pacsonline.cn/query/url?network=1&study_id=$study&version=V1.2.0.0";
  1235. //内网地址
  1236. $url = $query.'/query/url?&study_id='.$study.'&version=V1.2.0.0';
  1237. $data = $this->curl_get($url);
  1238. $data = json_decode($data);
  1239. if(empty($data))
  1240. {
  1241. log::record('没有找到dcm信息');
  1242. return '';
  1243. }
  1244. $this->reportDao->insertDcmCompress(['status'=>2,'study_id'=>$study]);
  1245. $date = time();
  1246. $create = ROOT_PATH . 'public' . DS . 'download'.DS.$date;
  1247. log::record('压缩中');
  1248. $path = $this->zip($data,$create,$date,$study);
  1249. log::record('压缩成功');
  1250. return $path;
  1251. }
  1252. public function zip($data,$create,$date,$study)
  1253. {
  1254. ini_set('max_execution_time', 6000);
  1255. $fileList = [];
  1256. $exam = $this->reportDao->getExamByStudy($study);
  1257. $this->reportDao->insertDcmCompress(['status'=>3,'study_id'=>$study]);
  1258. if($exam['institution_id'] == '06300009')
  1259. {
  1260. $patient_num = $exam['patient_num'];
  1261. $name = $exam['name'];
  1262. //工人医院需要解密
  1263. if (!file_exists($create)) {
  1264. mkdir($create, 0777,true);
  1265. @chmod($create, 0777);
  1266. }
  1267. $ts = system("python3.8 /data/code/ris_server/utils/down/main.py '$patient_num' '$study' '$name' $date");
  1268. if($ts)
  1269. {
  1270. $files = scandir($create);
  1271. foreach ($files as $v)
  1272. {
  1273. if($v == '.' || $v == '..')
  1274. {
  1275. continue;
  1276. }
  1277. $fileList[] = $create.DS.$v;
  1278. }
  1279. }
  1280. }else{
  1281. foreach ($data as $k=>$v)
  1282. {
  1283. try{
  1284. $path = $this->downLoad($v,$create.DS.$k,$create);
  1285. $fileList[] = $path;
  1286. }catch (\Exception $e){
  1287. continue;
  1288. }
  1289. }
  1290. $zipPath = ROOT_PATH . 'public' . DS .'zip';
  1291. $filename = $zipPath.DS."$date.zip";
  1292. if (!file_exists($zipPath)) {
  1293. mkdir($zipPath, 0777,true);
  1294. @chmod($zipPath, 0777);
  1295. }
  1296. $this->reportDao->insertDcmCompress(['status'=>4,'study_id'=>$study]);
  1297. $zip = new \ZipArchive();
  1298. $zip->open($filename,\ZipArchive::CREATE); //打开压缩包
  1299. foreach($fileList as $file){
  1300. $zip->addFile($file,basename($file)); //向压缩包中添加文件
  1301. }
  1302. $zip->close(); //关闭压缩包
  1303. $filesDcm = scandir($create);
  1304. foreach ($filesDcm as $file) {
  1305. if ($file != '.' && $file != '..') {
  1306. $pathDcm = $create . '/' . $file;
  1307. @unlink($pathDcm);
  1308. }
  1309. }
  1310. @rmdir($create);
  1311. }
  1312. $this->reportDao->insertDcmCompress(['status'=>5,'study_id'=>$study]);
  1313. $path_url = 'zip/'.$date.".zip";
  1314. $insert = [
  1315. 'dcm_path'=>$path_url,
  1316. 'study_id'=>$study,
  1317. 'effective_date'=>date('Y-m-d H:i:s',time()+864000), //10天有效期
  1318. ];
  1319. $this->reportDao->insertDcmPath($insert);
  1320. $this->delCache($study.'_zip');
  1321. $this->reportDao->insertDcmCompress(['status'=>6,'study_id'=>$study]);
  1322. return $path_url;
  1323. }
  1324. public function uploadZip($path_url,$study)
  1325. {
  1326. $this->reportDao->insertDcmCompress(['status'=>7,'study_id'=>$study]);
  1327. $upload = new uploadToCloud();
  1328. $s = $upload->upload($path_url,$path_url,'3','2','2','2');
  1329. if(($s['@metadata']['statusCode'] ?? '') == '200')
  1330. {
  1331. $this->reportDao->insertDcmCompress(['status'=>8,'study_id'=>$study]);
  1332. gc_collect_cycles();
  1333. $this->reportDao->updateDcmPath(['study_id'=>$study],['dcm_type'=>4]);
  1334. unlink($path_url);
  1335. return 4;
  1336. }
  1337. return '1';
  1338. }
  1339. public function changeReport($param,$token)
  1340. {
  1341. $user = $this->reportDao->getUser($token);
  1342. $result = $this->reportAuthentication($user['id'], 'reject', $user['institution_id'],2);
  1343. if(!$result){
  1344. $this->throwError('权限未分配,请联系管理员',0005);
  1345. }
  1346. $id = $param['id'];
  1347. $info = $this->reportDao->updateExamStatus($id,7);
  1348. $this->reportDao->updateReport($id,1,['review_doctor_id'=>null]);
  1349. $data = [
  1350. 'exam_id'=>$id,
  1351. 'doctor_id'=>$user['id'],
  1352. 'doctor_name'=>$user['realname']
  1353. ];
  1354. $this->reportDao->insertReject($data);
  1355. return $info;
  1356. }
  1357. public function checkLock($params,$token)
  1358. {
  1359. return '';
  1360. $user = $this->getCache($token);
  1361. $id = $params['id'];
  1362. $info = $this->reportDao->checkLock($id);
  1363. if($user['id'] == $info['doctor_id'])
  1364. {
  1365. return '';
  1366. }else{
  1367. return $info['doctor_name'];
  1368. }
  1369. }
  1370. public function sendEmail($email,$dcmPath,$name,$type=1)
  1371. {
  1372. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  1373. try {
  1374. //服务器配置
  1375. $mail->CharSet ="UTF-8"; //设定邮件编码
  1376. $mail->SMTPDebug = 0; // 调试模式输出
  1377. $mail->isSMTP(); // 使用SMTP
  1378. $mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
  1379. $mail->SMTPAuth = true; // 允许 SMTP 认证
  1380. $mail->Username = 'company@pacsonline.cn'; // SMTP 用户名 即邮箱的用户名
  1381. $mail->Password = 'Zskk1234'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  1382. $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
  1383. $mail->Port = 465;
  1384. // $mail->SMTPOptions = [
  1385. // 'ssl' => [
  1386. // 'verify_peer' => false,
  1387. // 'verify_peer_name' => false,
  1388. // 'allow_self_signed' => true
  1389. // ]
  1390. // ];
  1391. $mail->SMTPOptions = array(
  1392. 'ssl' => array(
  1393. 'verify_peer' => false,
  1394. 'verify_peer_name' => false,
  1395. 'allow_self_signed' => true
  1396. )
  1397. );
  1398. // 服务器端口 25 或者465 具体要看邮箱服务器支持
  1399. $mail->setFrom('company@pacsonline.cn', '冠医云'); //发件人
  1400. $mail->addAddress($email, ''); // 收件人
  1401. //$mail->addAddress('ellen@example.com'); // 可添加多个收件人
  1402. $mail->addReplyTo('company@pacsonline.cn', '冠医云'); //回复的时候回复给哪个邮箱 建议和发件人一致
  1403. //$mail->addCC('cc@example.com'); //抄送
  1404. //$mail->addBCC('bcc@example.com'); //密送
  1405. $zipPath = ROOT_PATH . 'public';
  1406. // $maxsize = 45 * 1024 * 1024;
  1407. $mail->Subject = $name.'影像';
  1408. // if(filesize($zipPath.'/'.$dcmPath) < $maxsize)
  1409. // {
  1410. // //发送附件
  1411. //// $mail->addAttachment($zipPath.'a.zip'); // 添加附件
  1412. // $mail->addAttachment($zipPath.'/'.$dcmPath, $name.'.zip'); // 发送附件并且重命名
  1413. // $mail->Body = "链接将于".date('Y-m-d',time()+10*24*3600)."失效,请即时下载";
  1414. // $mail->AltBody = "链接将于".date('Y-m-d',time()+10*24*3600)."失效,请即时下载";
  1415. // }else{
  1416. //发送链接地址
  1417. //Content
  1418. $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
  1419. if($type == 4)
  1420. {
  1421. $dcmPath = $this->makeFileUrl($dcmPath,$type,'attachment','+3 days');
  1422. $dcmPath = ltrim($dcmPath,'/');
  1423. $mail->Body = "<a href='https://tempjn2.eos.jinan-4.cmecloud.cn/$dcmPath'>下载".$name."影像</a>"."<br>链接将于".date('Y-m-d',time()+3*24*3600)."失效,请及时下载";
  1424. }else
  1425. {
  1426. $mail->Body = "<a href='https://risserver3.pacsonline.cn/$dcmPath'>下载".$name."影像</a>"."<br>链接将于".date('Y-m-d',time()+3*24*3600)."失效,请及时下载";
  1427. }
  1428. // $mail->AltBody = '如果邮件客户端不支持HTML则显示此内容';
  1429. // }
  1430. $mail->send();
  1431. return '邮件发送成功';
  1432. } catch (Exception $e) {
  1433. // return '邮件发送失败: ';
  1434. return '邮件发送失败: '.$mail->ErrorInfo;
  1435. }
  1436. }
  1437. public function getAiReport($param)
  1438. {
  1439. $id = $param['exam_id'];
  1440. $data = $this->reportDao->getReport($id,3);
  1441. return $data;
  1442. }
  1443. public function deleteAiReport($param)
  1444. {
  1445. $id = $param['exam_id'];
  1446. $data = $this->reportDao->deleteAiReport($id,3);
  1447. return $data;
  1448. }
  1449. public function makeExcel()
  1450. {
  1451. set_time_limit(0);
  1452. ini_set('memory_limit', '512M');
  1453. $objPHPExcel = new \PHPExcel();
  1454. $ins = InstitutionModel::where('interpret',1)->select();
  1455. $date = date('Y-m-d',strtotime('tuesday last week'));
  1456. $dateArea = [$date,date('Y-m-d',strtotime($date)+86400),date('Y-m-d',strtotime($date)+86400*2),date('Y-m-d',strtotime($date)+86400*3),date('Y-m-d',strtotime($date)+86400*4),date('Y-m-d',strtotime($date)+86400*5),date('Y-m-d',strtotime($date)+86400*6)];
  1457. // $dateArea = [$date];
  1458. $sheet = 0;
  1459. foreach ($dateArea as $date)
  1460. {
  1461. $forData = [];
  1462. $where = "createdAt between '$date 00:00:00' and '$date 23:59:59' ";
  1463. foreach ($ins as $k=>$v)
  1464. {
  1465. $data = VisitModel::where($where)->where('source',1)->where('institution_id',$v['id'])->select();
  1466. $dataA = 0;
  1467. $dataB = [];
  1468. foreach ($data as $kk=>$vv)
  1469. {
  1470. if($vv['source'] == 1)
  1471. {
  1472. $dataA++;
  1473. $dataB[$vv['exam_id']] = 1;
  1474. }
  1475. }
  1476. $allData = InterpretModel::where('createDate',$date)->where('institution_id',$v['id'])->field('exam_id,type,source')->select();
  1477. $dataD = [];
  1478. $dataF = [];
  1479. $dataH = [];
  1480. $dataJ = [];
  1481. $dataC = 0;
  1482. $dataE = 0;
  1483. $dataG = 0;
  1484. $dataI = 0;
  1485. $dataN = 0;
  1486. $dataO = [];
  1487. $dataP = 0;
  1488. $dataQ = [];
  1489. $dataR = 0;
  1490. $dataS = [];
  1491. $dataT = 0;
  1492. $dataU = [];
  1493. $dataV = 0;
  1494. $dataW = [];
  1495. $dataX = 0;
  1496. $dataY = [];
  1497. foreach ($allData as $value)
  1498. {
  1499. if($value['source'] == 1)
  1500. {
  1501. //公众号
  1502. if($value['type'] == 1){
  1503. $dataC++;
  1504. $dataD[$value['exam_id']] = 1;
  1505. }elseif ($value['type'] == 2){
  1506. $dataE++;
  1507. $dataF[$value['exam_id']] = 1;
  1508. }elseif($value['type'] == 3){
  1509. $dataN++;
  1510. $dataO[$value['exam_id']] = 1;
  1511. }elseif($value['type'] == 4){
  1512. $dataP++;
  1513. $dataQ[$value['exam_id']] = 1;
  1514. }elseif($value['type'] == 5){
  1515. $dataR++;
  1516. $dataS[$value['exam_id']] = 1;
  1517. }
  1518. }else{
  1519. //外链
  1520. if($value['type'] == 1){
  1521. $dataG++;
  1522. $dataH[$value['exam_id']] = 1;
  1523. }elseif ($value['type'] == 2){
  1524. $dataI++;
  1525. $dataJ[$value['exam_id']] = 1;
  1526. }elseif($value['type'] == 3){
  1527. $dataT++;
  1528. $dataU[$value['exam_id']] = 1;
  1529. }elseif($value['type'] == 4){
  1530. $dataV++;
  1531. $dataW[$value['exam_id']] = 1;
  1532. }elseif($value['type'] == 5){
  1533. $dataX++;
  1534. $dataY[$value['exam_id']] = 1;
  1535. }
  1536. }
  1537. }
  1538. $data2 = VisitModel::where($where)->where('source',2)->where('institution_id',$v['id'])->select();
  1539. $dataL = 0; // 公众号外链详情PV
  1540. $dataM = []; // 公众号外链详情uv
  1541. foreach ($data2 as $kk=>$vv)
  1542. {
  1543. if($vv['source'] == 1)
  1544. {
  1545. $dataL++;
  1546. $dataM[$vv['exam_id']] = 1;
  1547. }
  1548. }
  1549. $insert = [
  1550. $v['name'],$dataA,count($dataB),$dataC,count($dataD),$dataE,count($dataF),$dataG,count($dataH),$dataI,count($dataJ),$dataL,count($dataM),$dataN,count($dataO),$dataP,count($dataQ),$dataR,count($dataS),$dataT,count($dataU),$dataV,count($dataW),$dataX,count($dataY),
  1551. ];
  1552. $forData[] = $insert;
  1553. }
  1554. // 添加Worksheet2
  1555. if($sheet != 0)
  1556. {
  1557. $objPHPExcel->createSheet();
  1558. $objPHPExcel->setActiveSheetIndex($sheet);
  1559. }
  1560. $objPHPExcel->getActiveSheet()->setTitle('数据统计'.$date);
  1561. $objPHPExcel->getActiveSheet()->setCellValue('A1', '医院');
  1562. $objPHPExcel->getActiveSheet()->setCellValue('B1', '公众号详情访问pv');
  1563. $objPHPExcel->getActiveSheet()->setCellValue('C1', '公众号详情访问uv');
  1564. $objPHPExcel->getActiveSheet()->setCellValue('D1', '公众号报告解读按钮点击pv');
  1565. $objPHPExcel->getActiveSheet()->setCellValue('E1', '公众号报告解读按钮点击uv');
  1566. $objPHPExcel->getActiveSheet()->setCellValue('F1', '公众号同意调用pv');
  1567. $objPHPExcel->getActiveSheet()->setCellValue('G1', '公众号同意调用uv');
  1568. $objPHPExcel->getActiveSheet()->setCellValue('H1', '外链详情点击pv');
  1569. $objPHPExcel->getActiveSheet()->setCellValue('I1', '外链详情点击uv');
  1570. $objPHPExcel->getActiveSheet()->setCellValue('J1', '外链报告解读按钮点击pv');
  1571. $objPHPExcel->getActiveSheet()->setCellValue('K1', '外链报告解读按钮点击uv');
  1572. $objPHPExcel->getActiveSheet()->setCellValue('L1', '外链同意调用pv');
  1573. $objPHPExcel->getActiveSheet()->setCellValue('M1', '外链同意调用uv');
  1574. $objPHPExcel->getActiveSheet()->setCellValue('N1', '公众号列表调用pv');
  1575. $objPHPExcel->getActiveSheet()->setCellValue('O1', '公众号列表调用uv');
  1576. $objPHPExcel->getActiveSheet()->setCellValue('P1', '列表报告解读按钮调用pv');
  1577. $objPHPExcel->getActiveSheet()->setCellValue('Q1', '列表报告解读按钮调用uv');
  1578. $objPHPExcel->getActiveSheet()->setCellValue('R1', '列表同意调用pv');
  1579. $objPHPExcel->getActiveSheet()->setCellValue('S1', '列表同意调用uv');
  1580. $objPHPExcel->getActiveSheet()->setCellValue('T1', '外链列表调用调用pv');
  1581. $objPHPExcel->getActiveSheet()->setCellValue('U1', '外链列表调用调用uv');
  1582. $objPHPExcel->getActiveSheet()->setCellValue('V1', '外链列表报告解读按钮调用pv');
  1583. $objPHPExcel->getActiveSheet()->setCellValue('W1', '外链列表报告解读按钮调用uv');
  1584. $objPHPExcel->getActiveSheet()->setCellValue('X1', '外链同意调用pv');
  1585. $objPHPExcel->getActiveSheet()->setCellValue('Y1', '外链同意调用uv');
  1586. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  1587. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  1588. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  1589. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  1590. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  1591. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
  1592. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
  1593. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
  1594. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
  1595. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
  1596. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
  1597. $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
  1598. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
  1599. $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
  1600. $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
  1601. $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(20);
  1602. $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(20);
  1603. $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(20);
  1604. $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(20);
  1605. $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(20);
  1606. $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(20);
  1607. $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(20);
  1608. $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(20);
  1609. $objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(20);
  1610. $objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(20);
  1611. $i = 2;
  1612. foreach ($forData as $k=>$v)
  1613. {
  1614. $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $v[0]);
  1615. $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $v[1]);
  1616. $objPHPExcel->getActiveSheet()->setCellValue('C'.$i, $v[2]);
  1617. $objPHPExcel->getActiveSheet()->setCellValue('D'.$i, $v[3]);
  1618. $objPHPExcel->getActiveSheet()->setCellValue('E'.$i, $v[4]);
  1619. $objPHPExcel->getActiveSheet()->setCellValue('F'.$i, $v[5]);
  1620. $objPHPExcel->getActiveSheet()->setCellValue('G'.$i, $v[6]);
  1621. $objPHPExcel->getActiveSheet()->setCellValue('H'.$i, $v[11]);
  1622. $objPHPExcel->getActiveSheet()->setCellValue('I'.$i, $v[12]);
  1623. $objPHPExcel->getActiveSheet()->setCellValue('J'.$i, $v[7]);
  1624. $objPHPExcel->getActiveSheet()->setCellValue('K'.$i, $v[8]);
  1625. $objPHPExcel->getActiveSheet()->setCellValue('L'.$i, $v[9]);
  1626. $objPHPExcel->getActiveSheet()->setCellValue('M'.$i, $v[10]);
  1627. $objPHPExcel->getActiveSheet()->setCellValue('N'.$i, $v[13]);
  1628. $objPHPExcel->getActiveSheet()->setCellValue('O'.$i, $v[13]);
  1629. $objPHPExcel->getActiveSheet()->setCellValue('P'.$i, $v[13]);
  1630. $objPHPExcel->getActiveSheet()->setCellValue('Q'.$i, $v[13]);
  1631. $objPHPExcel->getActiveSheet()->setCellValue('R'.$i, $v[13]);
  1632. $objPHPExcel->getActiveSheet()->setCellValue('S'.$i, $v[13]);
  1633. $objPHPExcel->getActiveSheet()->setCellValue('T'.$i, $v[13]);
  1634. $objPHPExcel->getActiveSheet()->setCellValue('U'.$i, $v[13]);
  1635. $objPHPExcel->getActiveSheet()->setCellValue('V'.$i, $v[13]);
  1636. $objPHPExcel->getActiveSheet()->setCellValue('W'.$i, $v[13]);
  1637. $objPHPExcel->getActiveSheet()->setCellValue('X'.$i, $v[13]);
  1638. $objPHPExcel->getActiveSheet()->setCellValue('Y'.$i, $v[13]);
  1639. $i++;
  1640. }
  1641. $sheet++;
  1642. }
  1643. $folderPath = 'excel/';
  1644. // 检查文件夹是否存在,如果不存在则创建
  1645. if (!is_dir($folderPath)) {
  1646. mkdir($folderPath, 0777, true); // 递归创建文件夹
  1647. }
  1648. $name = 'wechat_data'.date('Ymd').rand(1000,9999).'.xlsx';
  1649. // header('Content-Type: application/vnd.ms-excel');
  1650. // header('Content-Disposition: attachment;filename="' . time() . '.xlsx"');
  1651. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  1652. $objWriter->save($folderPath.$name);
  1653. return $folderPath.$name;
  1654. }
  1655. public function makeZskkExcel()
  1656. {
  1657. set_time_limit(0);
  1658. ini_set('memory_limit', '512M');
  1659. $objPHPExcel = new \PHPExcel();
  1660. $ins = $this->reportDao->getInsKeywordIds();
  1661. // $ins = ['52200001','52200002'];
  1662. $insWhere[] = ['institution_id','in',$ins];
  1663. $title = '数据统计'. date('Ymd',strtotime('monday last week')).'-'.date('Ymd',strtotime('monday last week')+86400*6);
  1664. $dateStart = date('Y-m-d 00:00:00',strtotime('monday last week'));
  1665. $dateFinish = date('Y-m-d 00:00:00',strtotime('monday last week')+86400*7);
  1666. $dateWhere = "createdAt between '$dateStart' and '$dateFinish'";
  1667. //1.新增检查, 2.可推送检查,3.实际推送检查,4.推送微信用户, 5.打开界面,6.点击视频,7.点击咨询,8.实际咨询
  1668. $all = $this->reportDao->getExamCount($dateWhere,$insWhere);
  1669. $allPush = $this->reportDao->getAllPush($dateWhere);
  1670. $realPush = 0;
  1671. $wechat = [];
  1672. foreach ($allPush as $v)
  1673. {
  1674. if(!empty($v['openid']))
  1675. {
  1676. $realPush++;
  1677. $wechat[$v['openid']] = 1;
  1678. }
  1679. }
  1680. $wechatPush = count($wechat);
  1681. $allVisit = $this->reportDao->getAllVisit($dateWhere /*,$insWhere*/);
  1682. $pv1 = 0;
  1683. $pv2 = 0;
  1684. $pv3 = 0;
  1685. $uv1 = [];
  1686. $uv2 = [];
  1687. $uv3 = [];
  1688. foreach ($allVisit as $v)
  1689. {
  1690. if($v['type'] == 1)
  1691. {
  1692. $pv1++;
  1693. $uv1[$v['openid']] = 1;
  1694. }elseif($v['type'] == 2)
  1695. {
  1696. $pv2++;
  1697. $uv2[$v['openid']] = 1;
  1698. }elseif ($v['type'] == 3)
  1699. {
  1700. $pv3++;
  1701. $uv3[$v['openid']] = 1;
  1702. }
  1703. }
  1704. $objPHPExcel->getActiveSheet()->setTitle($title);
  1705. $objPHPExcel->getActiveSheet()->setCellValue('A1', '新增检查');
  1706. $objPHPExcel->getActiveSheet()->setCellValue('B1', '可推送检查');
  1707. $objPHPExcel->getActiveSheet()->setCellValue('C1', '实际推送检查');
  1708. $objPHPExcel->getActiveSheet()->setCellValue('D1', '推送微信用户');
  1709. $objPHPExcel->getActiveSheet()->setCellValue('E1', '打开界面pv');
  1710. $objPHPExcel->getActiveSheet()->setCellValue('F1', '打开界面uv');
  1711. $objPHPExcel->getActiveSheet()->setCellValue('G1', '点击视频pv');
  1712. $objPHPExcel->getActiveSheet()->setCellValue('H1', '点击视频uv');
  1713. $objPHPExcel->getActiveSheet()->setCellValue('I1', '点击咨询pv');
  1714. $objPHPExcel->getActiveSheet()->setCellValue('J1', '点击咨询uv');
  1715. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  1716. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  1717. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  1718. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  1719. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  1720. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
  1721. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
  1722. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
  1723. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
  1724. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
  1725. $objPHPExcel->getActiveSheet()->setCellValue('A2', $all);
  1726. $objPHPExcel->getActiveSheet()->setCellValue('B2', count($allPush));
  1727. $objPHPExcel->getActiveSheet()->setCellValue('C2', $realPush);
  1728. $objPHPExcel->getActiveSheet()->setCellValue('D2', $wechatPush);
  1729. $objPHPExcel->getActiveSheet()->setCellValue('E2', $pv1);
  1730. $objPHPExcel->getActiveSheet()->setCellValue('F2', count($uv1));
  1731. $objPHPExcel->getActiveSheet()->setCellValue('G2', $pv2);
  1732. $objPHPExcel->getActiveSheet()->setCellValue('H2', count($uv2));
  1733. $objPHPExcel->getActiveSheet()->setCellValue('I2', $pv3);
  1734. $objPHPExcel->getActiveSheet()->setCellValue('J2', count($uv3));
  1735. $folderPath = 'excel/';
  1736. // 检查文件夹是否存在,如果不存在则创建
  1737. if (!is_dir($folderPath)) {
  1738. mkdir($folderPath, 0777, true); // 递归创建文件夹
  1739. }
  1740. // $name = 'wechat_data'.date('Ymd').rand(1000,9999).'.xlsx';
  1741. // $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  1742. // $objWriter->save($folderPath.$name);
  1743. // return $folderPath.$name;
  1744. header('Content-Type: application/vnd.ms-excel');
  1745. header('Content-Disposition: attachment;filename="' . time() . '.xlsx"');
  1746. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  1747. $objWriter->save('php://output');
  1748. }
  1749. public function sendTxEmail()
  1750. {
  1751. ignore_user_abort(true); // 后台运行,不受前端断开连接影响
  1752. set_time_limit(0); //
  1753. ob_end_clean();//清除之前的缓冲内容,这是必需的,如果之前的缓存不为空的话,里面可能有http头或者其它内容,导致后面的内容不能及时的输出
  1754. header("Connection: close");//告诉浏览器,连接关闭了,这样浏览器就不用等待服务器的响应
  1755. header("HTTP/1.1 200 OK"); //可以发送200状态码,以这些请求是成功的,要不然可能浏览器会重试,特别是有代理的情况下
  1756. ob_start();//开始当前代码缓冲
  1757. if(empty($come))
  1758. {
  1759. $result = [
  1760. 'code' => 0,
  1761. 'msg' => '请求成功',
  1762. 'data' => '文件生成中',
  1763. 'error' => null,
  1764. 'timestamp' => time(),
  1765. 'random' => null,
  1766. 'signature' => null,
  1767. 'request_timestamp' => ZskkDefaultRequest::instance()->header()['zskk-timestamp'] ?? null
  1768. ];
  1769. echo json_encode($result);
  1770. }
  1771. //下面输出http的一些头信息
  1772. $size = ob_get_length();
  1773. header("Content-Length: $size");
  1774. ob_end_flush();//输出当前缓冲
  1775. flush();//输出PHP缓冲
  1776. //在Yii2框架下,上面代码可能不会立即返回给客户端,所以需要加如下的代码,即可实现立即返回给客户端
  1777. //具体可查看此文章:http://www.lampnick.com/php/375
  1778. if (function_exists("fastcgi_finish_request")) {
  1779. fastcgi_finish_request(); /* 响应完成, 关闭连接 */
  1780. }
  1781. ignore_user_abort(true); // 后台运行,这个只是运行浏览器关闭,并不是直接就中止返回200状态。
  1782. $path = $this->makeExcel();
  1783. $email1 = 'majj@tongxinzhiyi.cn';
  1784. $email2 = 'lix@tongxinzhiyi.cn';
  1785. $email3 = 'guoxh@tongxinzhiyi.cn';
  1786. $email4 = '912540678@qq.com';
  1787. $this->sendWechatEmail($path,$email1);
  1788. $this->sendWechatEmail($path,$email2);
  1789. $this->sendWechatEmail($path,$email3);
  1790. $this->sendWechatEmail($path,$email4);
  1791. }
  1792. public function sendZskkEmail()
  1793. {
  1794. // ignore_user_abort(true); // 后台运行,不受前端断开连接影响
  1795. // set_time_limit(0); //
  1796. // ob_end_clean();//清除之前的缓冲内容,这是必需的,如果之前的缓存不为空的话,里面可能有http头或者其它内容,导致后面的内容不能及时的输出
  1797. // header("Connection: close");//告诉浏览器,连接关闭了,这样浏览器就不用等待服务器的响应
  1798. // header("HTTP/1.1 200 OK"); //可以发送200状态码,以这些请求是成功的,要不然可能浏览器会重试,特别是有代理的情况下
  1799. // ob_start();//开始当前代码缓冲
  1800. // if(empty($come))
  1801. // {
  1802. // $result = [
  1803. // 'code' => 0,
  1804. // 'msg' => '请求成功',
  1805. // 'data' => '文件生成中',
  1806. // 'error' => null,
  1807. // 'timestamp' => time(),
  1808. // 'random' => null,
  1809. // 'signature' => null,
  1810. // 'request_timestamp' => ZskkDefaultRequest::instance()->header()['zskk-timestamp'] ?? null
  1811. // ];
  1812. // echo json_encode($result);
  1813. // }
  1814. ////下面输出http的一些头信息
  1815. // $size = ob_get_length();
  1816. // header("Content-Length: $size");
  1817. // ob_end_flush();//输出当前缓冲
  1818. // flush();//输出PHP缓冲
  1819. ////在Yii2框架下,上面代码可能不会立即返回给客户端,所以需要加如下的代码,即可实现立即返回给客户端
  1820. ////具体可查看此文章:http://www.lampnick.com/php/375
  1821. // if (function_exists("fastcgi_finish_request")) {
  1822. // fastcgi_finish_request(); /* 响应完成, 关闭连接 */
  1823. // }
  1824. // ignore_user_abort(true); // 后台运行,这个只是运行浏览器关闭,并不是直接就中止返回200状态。
  1825. // $path =
  1826. $this->makeZskkExcel();
  1827. // $email4 = '912540678@qq.com';
  1828. // $this->sendWechatEmail($path,$email4);
  1829. }
  1830. public function sendWechatEmail($path, $email)
  1831. {
  1832. set_time_limit(0);
  1833. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  1834. try {
  1835. //服务器配置
  1836. $mail->CharSet ="UTF-8"; //设定邮件编码
  1837. $mail->SMTPDebug = 0; // 调试模式输出
  1838. $mail->isSMTP(); // 使用SMTP
  1839. $mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
  1840. $mail->SMTPAuth = true; // 允许 SMTP 认证
  1841. $mail->Username = 'company@pacsonline.cn'; // SMTP 用户名 即邮箱的用户名
  1842. $mail->Password = 'Zskk1234'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  1843. $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
  1844. $mail->Port = 465;
  1845. $mail->SMTPOptions = array(
  1846. 'ssl' => array(
  1847. 'verify_peer' => false,
  1848. 'verify_peer_name' => false,
  1849. 'allow_self_signed' => true
  1850. )
  1851. );
  1852. // 服务器端口 25 或者465 具体要看邮箱服务器支持
  1853. $mail->setFrom('company@pacsonline.cn', '冠医云'); //发件人
  1854. $mail->addAddress($email, ''); // 收件人
  1855. $mail->addReplyTo('company@pacsonline.cn', '冠医云'); //回复的时候回复给哪个邮箱 建议和发件人一致
  1856. $url = 'https://risserver3.pacsonline.cn/'.$path;
  1857. $mail->Subject = '公众号访问数据';
  1858. //$mail->addCC('cc@example.com'); //抄送
  1859. $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
  1860. $mail->Body = "<a href='".$url."'>公众号数据文件</a>"."<br>请注意接收";
  1861. $mail->send();
  1862. return '邮件发送成功';
  1863. } catch (Exception $e) {
  1864. // return '邮件发送失败: ';
  1865. return '邮件发送失败: '.$mail->ErrorInfo;
  1866. }
  1867. }
  1868. public function sendSms2Yq($params)
  1869. {
  1870. $phone = $params['phone'];
  1871. $institution = $params['institution'];
  1872. $idcard = $params['idcard'];
  1873. $key = $phone.$idcard;
  1874. if(Cache::get($key))
  1875. {
  1876. return '存在发送记录';
  1877. }
  1878. Cache::set($key,1,86400);
  1879. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  1880. if(empty($phone) || empty($idcard)){
  1881. return '';
  1882. }else{
  1883. $idcard = base64_encode($idcard);
  1884. //发送短信
  1885. $note = [
  1886. 'long_url'=>'http://111.53.165.106:9605/mobile_jcjy/#/ReportSearch?data='.$idcard
  1887. ];
  1888. $noteId = $this->reportDao->insertNote($note);
  1889. $nid = base64_encode(str_pad(base_convert($noteId,10,36),6,'0',STR_PAD_LEFT));
  1890. $send = send_message::sendExam2YqPatient($phone,$institution,$nid);
  1891. $data = json_decode(json_encode($send),true);
  1892. if($data['Code'] == 'OK'){
  1893. return '短信发送成功';
  1894. }else{
  1895. return '短信发送失败';
  1896. }
  1897. }
  1898. }
  1899. }