ButtService.php 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. <?php
  2. namespace app\api\servies\butt;
  3. use app\api\change\PinyinChange;
  4. use app\api\dao\applets\AppletsDao;
  5. use app\api\dao\report\ReportDao;
  6. use app\api\dao\register\RegisterDao;
  7. use app\api\model\debug\DebugModel;
  8. use app\api\servies\application\ApplicationService;
  9. use app\api\servies\report\ReportService;
  10. use app\api\servies\ZskkDefaultService;
  11. use app\api\dao\butt\ButtDao;
  12. use app\api\utils\UUIDUtils;
  13. use app\common\library\Gm;
  14. use app\common\library\PublicPhone;
  15. use app\common\library\send_message;
  16. use PHPMailer\PHPMailer\PHPMailer;
  17. use think\Db;
  18. use think\Exception;
  19. use think\facade\Config;
  20. use think\facade\Log;
  21. use think\exception\DbException;
  22. use think\validate\ValidateRule;
  23. /**
  24. * 后台控制器基类
  25. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  26. */
  27. class ButtService extends ZskkDefaultService {
  28. protected $logName = "ButtService";
  29. private $butt = null;
  30. private $applets = null;
  31. private $application = null;
  32. private $reportDao = null;
  33. private $registerDao = null;
  34. public function __construct(ButtDao $buttDao,AppletsDao $appletsDao,ApplicationService $application,ReportDao $reportDao,RegisterDao $registerDao) {
  35. parent::__construct();
  36. $this->butt = $buttDao;
  37. $this->applets = $appletsDao;
  38. $this->application = $application;
  39. $this->reportDao = $reportDao;
  40. $this->registerDao = $registerDao;
  41. }
  42. public function save_report($params)
  43. {
  44. // try{
  45. $time1 = time();
  46. Log::record('当前传参为'.json_encode($params));
  47. // Db::startTrans();
  48. if(isset($params['type']) && !empty($params['type']))
  49. {
  50. if(empty(Config::get('report_save_type')[$params['type']]))
  51. {
  52. $this->throwError('非规则内的type值',0002);
  53. }
  54. if(empty($params['code']) || empty($params['institution_id']))
  55. {
  56. $this->throwError('参数错误',0003);
  57. }
  58. $search = [Config::get('report_save_type')[$params['type']]=>$params['code']];
  59. $exams = $this->butt->getExamBySearch($search,$params['institution_id']);
  60. // if(count($exams) !== 1)
  61. // {
  62. // $this->throwError('存在复数的检查,请联系管理员',0004);
  63. // }
  64. // $exam = $exams[0];
  65. }else{
  66. $exam = $this->butt->getExamById($params['exam_id']);
  67. $exams[] = $exam;
  68. }
  69. if(empty($exams))
  70. {
  71. $this->throwError('找不到检查',0004);
  72. }
  73. $id = '';
  74. foreach ($exams as $exam)
  75. {
  76. // if($exam['exam_status'] != '3'){
  77. // $this->throwError('报告重复','0999');
  78. // }
  79. $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
  80. $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
  81. $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
  82. $report = [
  83. 'id'=>UUIDUtils::uuid(),
  84. 'exam_id'=>$exam['id'],
  85. 'report_doctor_id'=>$reportDoctor,
  86. 'report_doctor_name'=>$params['report_doctor_name'],
  87. 'report_datetime'=>$params['report_datetime'],
  88. 'review_doctor_id'=>$reviewDoctor,
  89. 'review_doctor_name'=>$params['review_doctor_name'],
  90. 'review_datetime'=>$params['review_datetime'],
  91. 'confirm_doctor_id'=>$confirmDoctor,
  92. 'confirm_doctor_name'=>$params['confirm_doctor_name'],
  93. 'confirm_datetime'=>$params['confirm_datetime'],
  94. 'description'=>$params['description'],
  95. 'impression'=>$params['impression'],
  96. 'report_result'=>$params['report_result'],
  97. 'type'=>1
  98. ];
  99. $id = $report['id'];
  100. $report_id = $this->butt->checkReport($exam['id']);
  101. if(!empty($report_id)){
  102. unset($report['id']);
  103. $id = $report_id;
  104. $this->butt->saveReport($report,$report_id);
  105. $report['id'] = $report_id;
  106. }else{
  107. $this->butt->saveReport($report);
  108. }
  109. $url = 'https://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
  110. // exec("nohup /bin/curl '$url' > /dev/null &");
  111. // $this->curl_get($url);
  112. $examData = [
  113. 'exam_status'=>9,
  114. 'application_department'=>$params['application_department'] ?? null,
  115. 'application_doctor'=>$params['application_doctor'] ?? null,
  116. 'clin_diag'=>$params['clin_diag'] ?? null,
  117. 'clin_symp'=>$params['clin_symp'] ?? null,
  118. 'name'=>$params['name'],
  119. 'report_result'=>$params['report_result'] ?? ''
  120. ];
  121. if(isset($params['patient_source']) && !empty($params['patient_source']))
  122. {
  123. $examData['patient_source'] = $params['patient_source'];
  124. }
  125. if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
  126. {
  127. $examData['hopitalized_no'] = $params['hopitalized_no'];
  128. }
  129. if(isset($params['out_patient']) && !empty($params['out_patient']))
  130. {
  131. $examData['out_patient'] = $params['out_patient'];
  132. }
  133. if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
  134. {
  135. $examData['his_patient_id'] = $params['his_patient_id'];
  136. }
  137. $patient = [];
  138. if(isset($params['exam_class']) && !empty($params['exam_class']))
  139. {
  140. $examData['exam_class'] = $params['exam_class'];
  141. if($params['institution_id'] == '16100014')
  142. {
  143. if($examData['exam_class' == 'RF'])
  144. {
  145. $examData['exam_class'] = 'DX';
  146. }
  147. }
  148. }
  149. if(isset($params['phone']) && !empty($params['phone']))
  150. {
  151. $examData['phone'] = $params['phone'];
  152. $patient['phone'] = $params['phone'];
  153. }
  154. if(isset($params['card_num']) && !empty($params['card_num']))
  155. {
  156. $examData['card_num'] = $params['card_num'];
  157. $patient['card_num'] = $params['card_num'];
  158. }
  159. if(isset($params['exam_project']) && !empty($params['exam_project']))
  160. {
  161. $examData['exam_project'] = $params['exam_project'];
  162. if(empty($exam['body_part_text'] ?? ''))
  163. {
  164. $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
  165. }
  166. }
  167. if(isset($params['exam_method']) && !empty($params['exam_method']))
  168. {
  169. $examData['exam_method'] = $params['exam_method'];
  170. }
  171. //medical_code 国家医保信息平台人员管理码
  172. //body_part_code 检查部位代码
  173. //device_code 医保医用设备代码
  174. $examData['medical_code'] = $params['medical_code'] ?? str_pad(0, 26, "0", STR_PAD_LEFT);
  175. $examData['body_part_code'] = $params['body_part_code'] ?? str_pad(0, 9, "0", STR_PAD_LEFT);
  176. $examData['device_code'] = $params['device_code'] ?? str_pad(0, 13, "0", STR_PAD_LEFT);
  177. $study = $this->butt->getStudyByExamId($exam['id']);
  178. if(!empty($study['studytime'] ?? ''))
  179. {
  180. $studyDate = $study['studytime'];
  181. $examData['exam_datetime_code'] = $exam['exam_datetime'].substr($studyDate, 0, 4);
  182. }
  183. $this->butt->updateExam($examData,$exam['id']);
  184. PublicPhone::savePublicSearch($params['phone'] ?? '',$exam['id'] ?? '');
  185. $patientId = $exam['patient_id'];
  186. $patient['name'] = $params['name'];
  187. $this->butt->updatePatient($patient,$patientId);
  188. $institution = $this->butt->getIns($exam['institution_id']);
  189. if($institution['keyword_switch'] == 1)
  190. {
  191. $wechat = [
  192. 'type'=>7,
  193. 'id'=>$exam['id'],
  194. 'report_id'=>$id,
  195. ];
  196. $wechat = json_encode($wechat);
  197. $wechatUrl = 'https://ws4.pacsonline.cn/sendWechatMsg?params='.$wechat;
  198. $this->curl_get($wechatUrl);
  199. }
  200. Log::record('当前医院是否发送短信'.$institution['patient_sms']);
  201. if($institution['patient_sms'] == 1)
  202. {
  203. log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
  204. $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
  205. if(empty($telSend))
  206. {
  207. log::record('手机号'.($params['phone'] ?? $exam['phone']),'没有发送过短信');
  208. // 为空 没有发送过短信
  209. $this->sendSms(($params['phone'] ?? $exam['phone']),$exam['id'],$exam['study_id'],$exam['institution_id'],3,($params['exam_class'] ?? $exam['exam_class']),$exam['exam_datetime']);
  210. }
  211. }
  212. if(in_array($exam['institution_id'],['13000003','04500002']))
  213. {
  214. $newExam = $this->butt->getExamById($exam['id']);
  215. $this->saveHrData($newExam,$report,$institution);
  216. }
  217. }
  218. // DB::commit();
  219. $time2 = time();
  220. $time = $time2-$time1;
  221. $this->saveMonitorReport($params,$institution);
  222. //$this->butt->insertSpecialLog($time,'butt/saveReport');
  223. return $id;
  224. // } catch (\Exception $exception){
  225. // DB::rollback();
  226. // $this->throwError($exception->getMessage(),0001);
  227. // }
  228. }
  229. public function saveMonitorReport($params,$institution)
  230. {
  231. $arr = [];
  232. $arr['institution_id'] = $institution['id'];
  233. $arr['institution_name'] = $institution['name'];
  234. $arr['name'] = $params['name'];
  235. $this->butt->saveMonitorReport($arr);
  236. }
  237. public function saveHrData($exam, $report,$institution)
  238. {
  239. $hrItems = $this->butt->getHrItems($exam['exam_project']);
  240. if(empty($hrItems))
  241. {
  242. return '';
  243. }
  244. if($this->getCache('hrToken'))
  245. {
  246. // 已获取过登陆 todo
  247. $return = $this->getCache('hrToken');
  248. }else{
  249. $return = $this->getHrToken();
  250. if($return == 'error')
  251. {
  252. // 错误 todo
  253. return 'error';
  254. }
  255. }
  256. $header = array ("Content-Type: application/json;charset=utf-8","Authorization: Bearer $return");
  257. $arr = $this->makeHrData($exam,$report,$institution,$hrItems);
  258. $hrInfo = $this->request_by_curl("https://8001.pacsonline.cn/zskk/api/postExamReport",json_encode($arr),$header);
  259. }
  260. public function makeHrData($exam, $report,$institution,$hrItems)
  261. {
  262. switch ($exam['sex'])
  263. {
  264. case 'M':
  265. $sex = '1';
  266. break;
  267. case 'F':
  268. $sex = '2';
  269. break;
  270. case 'O':
  271. $sex = '9';
  272. break;
  273. default:
  274. $sex = '0';
  275. break;
  276. }
  277. $arrA = [
  278. 'AA'=>$exam['name'], // 姓名
  279. 'AB'=>'01', // 证件类型编码
  280. 'AC'=>$exam['card_num'], // 证件号码
  281. 'AD'=>$sex, // 性别编码
  282. 'AE'=>$exam['birthday'], // 出生日期
  283. ];
  284. switch ($exam['patient_source'])
  285. {
  286. case '1':
  287. $source = '2';
  288. break;
  289. case '2':
  290. $source = '3';
  291. break;
  292. case '3':
  293. $source = '1';
  294. break;
  295. case '4':
  296. $source = '4';
  297. break;
  298. default:
  299. $source = '';
  300. break;
  301. }
  302. $arrB = [
  303. 'BA'=>$source, //就诊类型编码 1 门诊 2 急诊 3 住院 4 体检 9 其他
  304. 'BB'=>$exam['patient_num'], //就诊卡号
  305. 'BC'=>$exam['patient_num'], //就诊号
  306. 'BD'=>$exam['institution_id'], //医院主索引
  307. 'BE'=>$exam['exam_datetime'], //就诊时间 todo
  308. 'BF'=>$exam['application_department'], //就诊科室名称
  309. 'BG'=>$exam['clin_symp'], //主诉 使用症状
  310. 'BH'=>$exam['age'], //年龄
  311. 'BI'=>$exam['institution_id'], //机构编码
  312. 'BJ'=>$institution['name'], //机构名称
  313. 'BK'=>'', //诊断编码
  314. 'BL'=>'', //DIAGNOSENAME
  315. 'BM'=>$exam['application_doctor'], //DOCTORNAME
  316. 'BN'=>$exam['application_doctor'], //DOCTORCODE
  317. ];
  318. switch ($report['report_result'])
  319. {
  320. case '1':
  321. $result = '1';
  322. break;
  323. case '2':
  324. $result = '2';
  325. break;
  326. default:
  327. $result = '9';
  328. break;
  329. }
  330. $arrC = [
  331. 'CA'=>$exam['study_id'], //申请单编号/医嘱编号
  332. 'CB'=>$report['id'], //报告单编号
  333. 'CC'=>$exam['exam_class'], //检查类型
  334. 'CD'=>$exam['exam_project'], //检查项目名称 todo
  335. 'CE'=>$hrItems['code'], //检查项目编码
  336. 'CF'=>$exam['body_part_text'], //检查部位
  337. 'CG'=>$report['description'], //检查所见/影像所见
  338. 'CH'=>$report['impression'], //影像诊断/意见
  339. 'CI'=>$result, //检查结果类别
  340. 'CJ'=>'', //互认范围
  341. 'CK'=>$hrItems['code'], //互认项目编码
  342. 'CL'=>$institution['name'], //报告机构
  343. 'CM'=>$exam['institution_id'], //报告机构编码
  344. 'CN'=>'影像科', //报告科室名称
  345. 'CO'=>$report['report_doctor_name'], //报告医生姓名
  346. 'CP'=>$report['review_doctor_name'], //审核医师姓名
  347. 'CQ'=>$report['report_datetime'], //报告时间
  348. 'CR'=>$exam['exam_datetime'], //检查时间
  349. 'CS'=>'', //报告单内容
  350. 'CT'=>$hrItems['name'], //互认项目
  351. ];
  352. $arr = [
  353. 'A'=>$arrA,
  354. 'B'=>$arrB,
  355. 'C'=>[$arrC]
  356. ];
  357. $key = 'zLxapoeqWYpoeqWY';
  358. $json = base64_encode(json_encode($arr));
  359. $jm = Gm::encrypt($key,$json);
  360. return ['data'=>$jm];
  361. }
  362. public function getHrToken()
  363. {
  364. $clientid = '12371600494581158K';
  365. $clientsecret = '837ffb03803b72cd99a941770fb6b2be';
  366. $arr = ['request_time'=>time(),'request_no'=>time(),'data'=>['clientid'=>$clientid,'clientsecret'=>$clientsecret]];
  367. $return = $this->request_by_curl("https://8001.pacsonline.cn/zskk/api/getToken",json_encode($arr));
  368. $return = json_decode($return,true);
  369. if($return['code'] == 1)
  370. {
  371. // 请求成功
  372. $this->setCache('hrToken',$return['data']['token'],3500);
  373. return $return['data']['token'];
  374. }else{
  375. return 'error';
  376. }
  377. }
  378. public function sendS($phone,$datetime,$insName,$exam_class,$id)
  379. {
  380. $appid = '111345'; //appid参数
  381. $appkey = 'ccf6327cf227f5f54292dd1bf9479852'; //appkey参数
  382. $to = $phone; //收信人 手机号码
  383. // $project_id = 'CzMP41'; //模板ID
  384. // $project_id = '9AafR2'; //模板ID
  385. $project_id = '1Wzd84'; //模板ID
  386. $vars = json_encode(array( //模板对应变量
  387. 'val1'=>$datetime,'val2'=>$insName,'val3'=>$exam_class,'val4'=>$id
  388. )); //收信人 手机号码
  389. // $project_id = '3mPW44'; //模板ID
  390. // $vars = json_encode(array( //模板对应变量
  391. // 'var1'=>$insName,'var2'=>$exam_class,'var3'=>$id //模板对应变量
  392. //// 'val1'=>$datetime,'val2'=>$insName,'val3'=>$exam_class,'val4'=>$id
  393. // ));
  394. $post_data = array(
  395. "appid" => $appid,
  396. "signature" => $appkey,
  397. "to" => $to,
  398. "project" => $project_id,
  399. "vars" => $vars
  400. );
  401. $ch = curl_init();
  402. curl_setopt_array($ch, array(
  403. CURLOPT_URL => 'https://api-v4.mysubmail.com/sms/xsend.json',
  404. CURLOPT_RETURNTRANSFER => 1,
  405. CURLOPT_POST => 0,
  406. CURLOPT_POSTFIELDS => $post_data,
  407. CURLOPT_HEADER => 0,
  408. CURLOPT_SSL_VERIFYHOST=>false,
  409. CURLOPT_SSL_VERIFYPEER=>false,
  410. ));
  411. $output = curl_exec($ch);
  412. $data = json_decode($output,true);
  413. return $data;
  414. }
  415. public function sendSms($phone,$examId,$studyId,$institution,$source,$exam_class='',$exam_datetime='')
  416. {
  417. $data = $this->butt->getInsById($institution);
  418. $name = $data['name'];
  419. if(!empty($data['filter']))
  420. {
  421. $filter = json_decode($data['filter'],true);
  422. if(!empty($filter) && !empty($filter['exam_class'] ?? ''))
  423. {
  424. $class = explode(',',$filter['exam_class']);
  425. if(in_array($exam_class,$class))
  426. {
  427. return '';
  428. }
  429. }
  430. }
  431. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  432. $id = UUIDUtils::uuid();
  433. if(empty($phone)){
  434. $send_message = 0;
  435. }else{
  436. //发送短信
  437. // $send = send_message::sendExam2Patient($phone,$code,$name,$id);
  438. $note = [
  439. // 'long_url'=>'https://wc4.pacsonline.cn/#/jump?id='.$id
  440. 'long_url'=>'https://wc4.pacsonline.cn/#/reportInfo/report?id='.$id.'&short=1&is_dcm=1&isAnonymous=0&isEncrypt=0'
  441. ];
  442. $noteId = $this->reportDao->insertNote($note);
  443. $nid = base64_encode(str_pad(base_convert($noteId,10,36),6,'0',STR_PAD_LEFT));
  444. $return = $this->sendS($phone,$exam_datetime,$name,$exam_class,$nid);
  445. // if($institution == '43600001')
  446. // {
  447. // if($exam_class == 'US'){
  448. // return '';
  449. // }
  450. // $send = send_message::sendEZShortMessage($phone,$code,$nid);
  451. // }elseif($institution == '03060002'){
  452. // $send = send_message::sendReportShortMessage($phone,$name);
  453. // }else{
  454. // $send = send_message::sendExam2ShortPatient($phone,$code,$name,$nid);
  455. // }
  456. // $data = json_decode(json_encode($send),true);
  457. // if($data['Code'] == 'OK'){
  458. // $send_message = 1;
  459. // }else{
  460. // $send_message = 0;
  461. // }
  462. // $data = json_decode($return,true);
  463. if($return['status'] == 'success'){
  464. $send_message = 1;
  465. }else{
  466. $send_message = 0;
  467. }
  468. $share = [
  469. 'id'=>$id,
  470. 'examId'=>$examId,
  471. 'status'=>1,
  472. 'overdueTime'=>5475,
  473. 'code'=>$code,
  474. 'short_url'=>'',
  475. 'phone'=>$phone,
  476. 'report_isset'=>1,
  477. 'study_id'=>$studyId,
  478. 'source'=>$source,
  479. 'send_message'=>$send_message,
  480. ];
  481. $this->reportDao->insertShare($share);
  482. $smsLog = [
  483. 'exam_id'=>$examId,
  484. 'institution_id'=>$institution,
  485. 'send_message'=>$send_message,
  486. 'phone'=>$phone,
  487. 'status'=>$send_message
  488. ];
  489. $this->reportDao->insertSMSLog($smsLog);
  490. }
  491. }
  492. public function save_exam($params)
  493. {
  494. try{
  495. $exam = $this->butt->getExamById($params['exam_id']);
  496. if($exam['exam_status'] != '3'){
  497. $this->throwError('报告重复','0999');
  498. }
  499. // $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
  500. // $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
  501. // $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
  502. // $report = [
  503. // 'id'=>UUIDUtils::uuid(),
  504. // 'exam_id'=>$params['exam_id'],
  505. // 'report_doctor_id'=>$this->butt->getDcotorId($params['report_doctor_name'],$exam['institution_id']),
  506. // 'report_doctor_name'=>$params['report_doctor_name'],
  507. // 'report_datetime'=>$params['report_datetime'],
  508. // 'review_doctor_id'=>$this->butt->getDcotorId($params['review_doctor_name'],$exam['institution_id']),
  509. // 'review_doctor_name'=>$params['review_doctor_name'],
  510. // 'review_datetime'=>$params['review_datetime'],
  511. // 'confirm_doctor_id'=>$this->butt->getDcotorId($params['confirm_doctor_name'],$exam['institution_id']),
  512. // 'confirm_doctor_name'=>$params['confirm_doctor_name'],
  513. // 'confirm_datetime'=>$params['confirm_datetime'],
  514. // 'description'=>$params['description'],
  515. // 'impression'=>$params['impression'],
  516. // 'report_result'=>$params['report_result'],
  517. // 'type'=>1
  518. // ];
  519. // $id = $report['id'];
  520. // $report_id = $this->butt->checkReport($params['exam_id']);
  521. // if(!empty($report_id)){
  522. // unset($report['id']);
  523. // $this->butt->saveReport($report,$report_id);
  524. // }else{
  525. // $this->butt->saveReport($report);
  526. // }
  527. // $url = 'http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
  528. // $this->curl_get($url);
  529. $params['phone'] = trim($params['phone']);
  530. $examData = [
  531. 'application_department'=>$params['application_department'] ?? null,
  532. 'application_doctor'=>$params['application_doctor'] ?? null,
  533. 'clin_diag'=>$params['clin_diag'] ?? null,
  534. 'clin_symp'=>$params['clin_symp'] ?? null,
  535. 'name'=>$params['name'],
  536. 'phone'=>$params['phone'],
  537. 'card_num'=>$params['card_num'] ?? null,
  538. 'patient_source'=>$params['patient_source'] ?? null
  539. ];
  540. if(isset($params['exam_project']) && !empty($params['exam_project'])){
  541. $examData['exam_project'] = $params['exam_project'];
  542. if(empty($exam['body_part_text'] ?? ''))
  543. {
  544. $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
  545. }
  546. }
  547. if(isset($params['device_name']) && !empty($params['device_name'])){
  548. $examData['device_name'] = $params['device_name'];
  549. }
  550. if(isset($params['exam_class']) && !empty($params['exam_class']))
  551. {
  552. $examData['exam_class'] = $params['exam_class'];
  553. }
  554. if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
  555. {
  556. $examData['hopitalized_no'] = $params['hopitalized_no'];
  557. }
  558. if(isset($params['out_patient']) && !empty($params['out_patient']))
  559. {
  560. $examData['out_patient'] = $params['out_patient'];
  561. }
  562. if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
  563. {
  564. $examData['his_patient_id'] = $params['his_patient_id'];
  565. }
  566. if(isset($params['exam_method']) && !empty($params['exam_method']))
  567. {
  568. $examData['exam_method'] = $params['exam_method'];
  569. }
  570. $examData['sync_exam'] = 1;
  571. $this->butt->updateExam($examData,$params['exam_id']);
  572. $institution = $this->butt->getIns($exam['institution_id']);
  573. Log::record('当前医院是否发送短信'.$institution['patient_sms']);
  574. if($institution['patient_sms'] == 1)
  575. {
  576. // log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
  577. // $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
  578. // if(empty($telSend))
  579. // {
  580. // log::record('手机号'.$params['phone'],'没有发送过短信');
  581. // // 为空 没有发送过短信
  582. // $this->sendSms($params['phone'],$exam['id'],$exam['study_id'],$exam['institution_id'],2);
  583. // }
  584. }
  585. $patientId = $exam['patient_id'];
  586. $patient = [
  587. 'name'=>$params['name'],
  588. 'phone'=>$params['phone'],
  589. 'card_num'=>$params['card_num'] ?? null
  590. ];
  591. $this->butt->updatePatient($patient,$patientId);
  592. $this->saveMonitorExam($params,$institution);
  593. return $params['exam_id'];
  594. } catch (DbException $exception){
  595. $this->throwError($exception->getMessage(),0001);
  596. }
  597. }
  598. public function save_register($params)
  599. {
  600. try{
  601. $field = [
  602. 'application_department',
  603. 'application_doctor',
  604. 'clin_diag',
  605. 'clin_symp',
  606. 'name',
  607. 'phone',
  608. 'card_num',
  609. 'patient_source',
  610. 'exam_project',
  611. 'exam_class',
  612. 'hopitalized_no',
  613. 'out_patient',
  614. 'his_patient_id',
  615. 'exam_method',
  616. 'studyuid',
  617. 'accession_num',
  618. 'patient_num',
  619. 'institution_id',
  620. 'age',
  621. 'exam_datetime'
  622. ];
  623. $examData = $this->makeRegisterExamData($params,$field);
  624. $examData['id'] = UUIDUtils::uuid();
  625. $examData['patient_id'] = UUIDUtils::uuid();
  626. if(isset($params['is_dcm']) && $params['is_dcm'] == 2)
  627. {
  628. $examData['is_dcm'] = 2;
  629. }
  630. $this->butt->insertExam($examData);
  631. $patient = [
  632. 'id'=>$examData['patient_id'],
  633. 'name'=>$params['name'],
  634. 'phone'=>$params['phone'] ?? null,
  635. 'card_num'=>$params['card_num'] ?? null,
  636. 'temp_patient_id'=>$params['patient_num'] ?? null,
  637. 'institution_id'=>$params['institution_id'],
  638. 'age'=>$params['age'] ?? null
  639. ];
  640. $this->butt->insertPatient($patient);
  641. return $examData['id'];
  642. } catch (DbException $exception){
  643. $this->throwError($exception->getMessage(),0001);
  644. }
  645. }
  646. public function saveFiles($params)
  647. {
  648. $fileData = [];
  649. if(isset($params['data']) && !empty($params['data']))
  650. {
  651. $data = [
  652. 'exam_id'=>$params['id']
  653. ];
  654. $url = json_decode($params['data'],true);
  655. foreach ($url as $v)
  656. {
  657. $data['type']=$v['type'];
  658. $data['url']=$v['url'];
  659. $fileData[] = $data;
  660. }
  661. }
  662. if(empty($fileData))
  663. {
  664. return '';
  665. }
  666. $return = $this->butt->saveFileData($fileData);
  667. $this->butt->updateExam(['exam_status'=>3],$params['id']);
  668. return $return;
  669. }
  670. public function makeRegisterExamData($data,$field)
  671. {
  672. $examData = [];
  673. foreach ($field as $v)
  674. {
  675. if(isset($data[$v]) && !empty($data[$v]))
  676. {
  677. $examData[$v] = $data[$v];
  678. }
  679. }
  680. return $examData;
  681. }
  682. public function getReportDoctor($name,$institution)
  683. {
  684. if($name == ''){
  685. return '';
  686. }
  687. $id = $this->butt->getDcotorId($name,$institution);
  688. if(empty($id)){
  689. $doctor = [
  690. 'id'=>UUIDUtils::uuid(),
  691. 'realname'=>$name,
  692. 'institution_id'=>$institution,
  693. 'password'=>md5('zskk1234'),
  694. 'username'=>'none'
  695. ];
  696. $this->butt->makeDcotor($doctor);
  697. return $doctor['id'];
  698. }
  699. return $id;
  700. }
  701. public function getExam($params)
  702. {
  703. $timeWhere = '';
  704. if(isset($params['createdAt']) && !empty($params['createdAt']))
  705. {
  706. $time = explode(',',$params['createdAt']);
  707. $timeWhere = "createdAt between '$time[0]' and '$time[1]'";
  708. }
  709. if(isset($params['exam_status']) && !empty($params['exam_status']))
  710. {
  711. $status = explode(',',$params['exam_status']);
  712. }else{
  713. $status = [3];
  714. }
  715. $where = [];
  716. if(isset($params['is_sync']) && $params['is_sync'] == '0')
  717. {
  718. $where = ['sync_exam'=>'0'];
  719. }
  720. $data = $this->butt->getExams($params['institution_id'],$params['num'],$where,$timeWhere,$status);
  721. return $data;
  722. }
  723. public function getReports($params)
  724. {
  725. $timeWhere = '';
  726. if(isset($params['date']) && !empty($params['date']))
  727. {
  728. $time = explode(',',$params['date']);
  729. $timeWhere = "confirm_datetime between '$time[0]' and '$time[1]'";
  730. }
  731. $data = $this->butt->getReports($params['institution_id'],$params['page'],$params['num'],$timeWhere);
  732. foreach ($data as $k=>$v)
  733. {
  734. $data[$k]['impression'] = strip_tags($v['impression']);
  735. $data[$k]['description'] = strip_tags($v['description']);
  736. }
  737. return $data;
  738. }
  739. public function getConfirmExams($params)
  740. {
  741. $data = $this->butt->getConfirmExams($params['institution_id'],$params['num']);
  742. return $data;
  743. }
  744. public function sendDingDing()
  745. {
  746. $time = time()* 1000;
  747. $secret = 'SECc2b5ad43721741fe16f6ac39ed423b047668fd691c01f9a051037bf4733a09e8';
  748. $m = $time."\n".$secret;
  749. $s = hash_hmac('sha256', $m, $secret, true);
  750. $a = base64_encode($s);
  751. $b = urlencode($a);
  752. $dingurl = Config::get('dingding_url');
  753. $url =$dingurl."/robot/send?access_token=2030ac71bf6811a7caad9a34899e686df9bef4e45d1c990b14339ba65c333776&timestamp=$time&sign=$b";
  754. $message = '';
  755. $user_wechat = $this->butt->getUserWechat();
  756. $message .= "累计公众号关注人数:".$user_wechat['all'];
  757. $yestWechat = $this->butt->getYestNumber(); //获取昨日的已关注数量
  758. if((int)$user_wechat['now'] >= (int)$yestWechat){
  759. $user_different = "增加".((int)$user_wechat['now']-(int)$yestWechat).'人';
  760. }else{
  761. $user_different = "减少".((int)$yestWechat-(int)$user_wechat['now']).'人';
  762. }
  763. $message .= "\n公众号实时关注总人数为".$user_wechat['now'].'人';
  764. $message .= "\n公众号实时关注人数较昨日".$user_different;
  765. $exams = $this->butt->getExamData();
  766. $message .= "\n昨日新增数字胶片量:".$exams['yest']."张";
  767. // $message .= "\n昨日财务流水:".($exams['yest']*20);
  768. $message .= "\n累计数字胶片量:".$exams['all']."张";
  769. $message .= "\n胶片增长率:".$exams['percentage']."%";
  770. $picNumber = $this->butt->getPicNumber();
  771. $message .= "\n昨日查阅数字胶片量:".$picNumber['yestAll']."次(昨日患者共计查阅胶片次数)";
  772. $message .= "\n昨日新增查阅数字胶片量:".$picNumber['yest']."次(去重查阅)";
  773. $institutionInfo = $this->butt->getInsInfo();
  774. $message .= "\n新增医院数:".$institutionInfo['yest']."家 ";
  775. // 新增医院名称
  776. if($institutionInfo['yest'] > 0){
  777. foreach ($institutionInfo['name'] as $k=>$v){
  778. $message .= $v['name'].' ';
  779. }
  780. }
  781. $message .= "\n累计医院数:".$institutionInfo['all']."家";
  782. $ins_all_info = $this->butt->getAllInsInfo();
  783. $b = $ins_all_info['patient_num'];
  784. $d = $ins_all_info['accession_num'];
  785. $e = $ins_all_info['phone'];
  786. $f= $ins_all_info['card_num'];
  787. $g = $ins_all_info['hopitalized_no'];
  788. $c = [];
  789. foreach ($b as $k=>$v)
  790. {
  791. if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
  792. {
  793. $c[$v['institution_id']]['num']++;
  794. }else{
  795. $c[$v['institution_id']]['num'] = 1;
  796. $c[$v['institution_id']]['name'] = $v['name'];
  797. $c[$v['institution_id']]['code'] = $v['patient_num'];
  798. }
  799. }
  800. foreach ($d as $k=>$v)
  801. {
  802. if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['accession_num']){
  803. continue;
  804. }
  805. if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
  806. {
  807. $c[$v['institution_id']]['num']++;
  808. }else{
  809. $c[$v['institution_id']]['num'] = 1;
  810. $c[$v['institution_id']]['name'] = $v['name'];
  811. $c[$v['institution_id']]['code'] = $v['accession_num'];
  812. }
  813. }
  814. foreach ($e as $k=>$v)
  815. {
  816. if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['phone']){
  817. continue;
  818. }
  819. if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
  820. {
  821. $c[$v['institution_id']]['num']++;
  822. }else{
  823. $c[$v['institution_id']]['num'] = 1;
  824. $c[$v['institution_id']]['name'] = $v['name'];
  825. $c[$v['institution_id']]['code'] = $v['phone'];
  826. }
  827. }
  828. foreach ($f as $k=>$v)
  829. {
  830. if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['card_num']){
  831. continue;
  832. }
  833. if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
  834. {
  835. $c[$v['institution_id']]['num']++;
  836. }else{
  837. $c[$v['institution_id']]['num'] = 1;
  838. $c[$v['institution_id']]['name'] = $v['name'];
  839. $c[$v['institution_id']]['code'] = $v['card_num'];
  840. }
  841. }
  842. foreach ($g as $k=>$v)
  843. {
  844. if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['hopitalized_no']){
  845. continue;
  846. }
  847. if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
  848. {
  849. $c[$v['institution_id']]['num']++;
  850. }else{
  851. $c[$v['institution_id']]['num'] = 1;
  852. $c[$v['institution_id']]['name'] = $v['name'];
  853. $c[$v['institution_id']]['code'] = $v['hopitalized_no'];
  854. }
  855. }
  856. $message .= "\n新增医院名称与每日每家新增量:";
  857. $i = 1;
  858. foreach ($c as $key => $row)
  859. {
  860. $volume[$key] = $row['num'];
  861. }
  862. array_multisort($volume, SORT_DESC, $c);
  863. foreach ($c as $k=>$v){
  864. if($i > 49)
  865. {
  866. continue;
  867. }
  868. $ins_name = $v['name'];
  869. $ins_num = $v['num'];
  870. if($i < 10)
  871. {
  872. $a = $i." ";
  873. }else{
  874. $a = $i;
  875. }
  876. $message .= "\n $a:$ins_name \n \t\t 新增胶片查阅量:$ins_num";
  877. $i++;
  878. }
  879. $data = array ('msgtype' => 'text','text' => array ('content' => $message));
  880. $data_string = json_encode($data);
  881. $result = $this->request_by_curl($url, $data_string);
  882. Log::record('钉钉返回'.$result);
  883. $message0 = '医院昨日检查/报告/报告率统计:';
  884. $allIns = $this->butt->getAllIns();
  885. $yestExams = $this->butt->getYestExams();
  886. $YestCompleteExams = $this->butt->getYestCompleteExams();
  887. foreach ($yestExams as $v)
  888. {
  889. $message0 .= "\n ".($allIns[$v['institution_id']] ?? '').':'.$v['c'].'/'.($YestCompleteExams[$v['institution_id']] ?? 0).'/'.(number_format(($YestCompleteExams[$v['institution_id']] ?? 0)/$v['c'],2)*100).'%';
  890. }
  891. $data0 = array ('msgtype' => 'text','text' => array ('content' => $message0));
  892. $data_string0 = json_encode($data0);
  893. $result = $this->request_by_curl($url, $data_string0);
  894. $ding = [
  895. 'wechat_bind_all'=>$user_wechat['all'],
  896. 'wechat_yestday_focus'=>$user_wechat['now'],
  897. 'exam_all'=>$exams['all'],
  898. 'exam_yestday_add'=>$exams['yest'],
  899. 'exam_add_percentage'=>$exams['percentage']."%",
  900. 'film_all'=>$exams['all'],
  901. 'film_yestday_add'=>$exams['yest'],
  902. 'film_add_percentage'=>$exams['percentage']."%",
  903. 'film_yest_look_all'=>$picNumber['yestAll'],
  904. 'film_yest_look_add'=>$picNumber['yest'],
  905. 'institution_all'=>$institutionInfo['all'],
  906. 'institution_add'=>$institutionInfo['yest'],
  907. ];
  908. $this->butt->insertDing($ding);
  909. return $result;
  910. }
  911. public function sendHosDing()
  912. {
  913. $time = time()* 1000;
  914. $secret = 'SECc2b5ad43721741fe16f6ac39ed423b047668fd691c01f9a051037bf4733a09e8';
  915. $m = $time."\n".$secret;
  916. $s = hash_hmac('sha256', $m, $secret, true);
  917. $a = base64_encode($s);
  918. $b = urlencode($a);
  919. $dingurl = Config::get('dingding_url');
  920. $url =$dingurl."/robot/send?access_token=2030ac71bf6811a7caad9a34899e686df9bef4e45d1c990b14339ba65c333776&timestamp=$time&sign=$b";
  921. $message = '';
  922. $institution_ids = $this->butt->getInsIds();
  923. $no_use = []; // 开通但是没有使用
  924. $use_his7 = []; //7天以上没有上传
  925. $use_his1 = []; //1天以上没有上传
  926. $exam7Out = []; //昨天上传了7天以外的数据
  927. foreach ($institution_ids as $k=>$v)
  928. {
  929. // $k 为医院id $v为名称
  930. // 获取检查最大时间
  931. $exam_time = $this->butt->getExamMaxTime($k);
  932. if(empty($exam_time[0]))
  933. {
  934. // 时间为空 代表医院未使用过数据
  935. $no_use[] = $v;
  936. }else {
  937. $diff = time() - strtotime($exam_time[0]);
  938. if ($diff > 86400*7){
  939. $array = [$v,$exam_time[0]];
  940. $use_his7[] = $array;
  941. }elseif($diff > 86400)
  942. {
  943. $array = [$v,$exam_time[0]];
  944. $use_his1[] = $array;
  945. }else{
  946. $examCount = $this->butt->get7OutExam($k);
  947. if($examCount > 0)
  948. {
  949. $exam7Out[] = [$v,$examCount];
  950. }
  951. }
  952. }
  953. }
  954. $count1 = count($no_use);
  955. $count2 = count($use_his7);
  956. $count3 = count($use_his1);
  957. $count4 = count($exam7Out);
  958. foreach ($no_use as $k=>$v)
  959. {
  960. if(empty($message))
  961. {
  962. $message = "已安装但是后续无使用记录医院共计".$count1."家,分别为:\n".($k+1).":".$v;
  963. }else{
  964. $message .= "\n".($k+1).":".$v;
  965. }
  966. }
  967. $data = array ('msgtype' => 'text','text' => array ('content' => $message));
  968. $data_string = json_encode($data);
  969. $result = $this->request_by_curl($url, $data_string);
  970. sleep(1);
  971. $message1 = '';
  972. foreach ($use_his7 as $k=>$v)
  973. {
  974. $create = explode(' ',$v[1]);
  975. if(empty($message1))
  976. {
  977. $message1 = "超过7天无使用记录的医院共计".$count2."家,分别为:\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
  978. }else{
  979. $message1 .= "\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
  980. }
  981. }
  982. $data1 = array ('msgtype' => 'text','text' => array ('content' => $message1));
  983. $data_string1 = json_encode($data1);
  984. $result1 = $this->request_by_curl($url, $data_string1);
  985. sleep(1);
  986. $message2 = '';
  987. foreach ($use_his1 as $k=>$v)
  988. {
  989. $create = explode(' ',$v[1]);
  990. if(empty($message2))
  991. {
  992. $message2 = "超过1天无使用记录的医院共计".$count3."家,分别为:\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
  993. }else{
  994. $message2 .= "\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
  995. }
  996. }
  997. $data2 = array ('msgtype' => 'text','text' => array ('content' => $message2));
  998. $data_string2 = json_encode($data2);
  999. $result2 = $this->request_by_curl($url, $data_string2);
  1000. sleep(1);
  1001. $all_message = "已安装但是后续无使用记录医院共计".$count1."家\n";
  1002. $all_message .= "超过7天无使用记录的医院共计".$count2."家\n";
  1003. $all_message .= "超过1天无使用记录的医院共计".$count3."家";
  1004. $data3 = array ('msgtype' => 'text','text' => array ('content' => $all_message));
  1005. $data_string3 = json_encode($data3);
  1006. $result3 = $this->request_by_curl($url, $data_string3);
  1007. sleep(1);
  1008. $at = 1;
  1009. if(!empty($exam7Out))
  1010. {
  1011. $message4 = '';
  1012. foreach ($exam7Out as $k=>$v)
  1013. {
  1014. if($v[1] > 100)
  1015. {
  1016. $at = 2;
  1017. }
  1018. if(empty($message4))
  1019. {
  1020. $message4 = "昨日上传了7天以上的数据的医院共计".$count4."家,分别为:\n".($k+1).":".$v[0].",上传数量为".$v[1];
  1021. }else{
  1022. $message4 .= "\n".($k+1).":".$v[0].",上传数量为".$v[1];
  1023. }
  1024. }
  1025. if($at == 1)
  1026. {
  1027. $data4 = array ('msgtype' => 'text','text' => array ('content' => $message4));
  1028. }else{
  1029. $data4 = array ('msgtype' => 'text','text' => array ('content' => $message4.' @18910065009'),'at'=>['atMobiles'=>['18910065009']]);
  1030. }
  1031. $data_string4 = json_encode($data4);
  1032. $result4 = $this->request_by_curl($url, $data_string4);
  1033. }
  1034. return $result;
  1035. }
  1036. public function getInsNum()
  1037. {
  1038. return 441;
  1039. $ins2 = $this->butt->get2Ins();
  1040. $ins3 = $this->butt->get3Ins();
  1041. $num = count($ins3);
  1042. $a = 1;
  1043. foreach ($ins2 as $k=>$v)
  1044. {
  1045. if(in_array($v['id'],$ins3)){
  1046. continue;
  1047. }else{
  1048. $num++;
  1049. }
  1050. }
  1051. return $num;
  1052. }
  1053. public function exam_search($params)
  1054. {
  1055. $study_id= $params['study_id'] ?? null;
  1056. if(!$study_id)
  1057. {
  1058. return [];
  1059. }
  1060. $institution = $this->butt->getInstitutionId($study_id);
  1061. $search = $this->getSearch($params['search'] ?? null);
  1062. if(empty($search))
  1063. {
  1064. return [];
  1065. }
  1066. $exam = $this->butt->getExamBySearch($search,$institution);
  1067. return $exam;
  1068. }
  1069. public function another_exam_search($params)
  1070. {
  1071. $study_id= $params['study_id'] ?? null;
  1072. if(!$study_id)
  1073. {
  1074. return [];
  1075. }
  1076. $institutionId = $this->butt->getInstitutionId($study_id);
  1077. $where = [];
  1078. if($institutionId == '16100017') {
  1079. $name = $this->butt->getPatientNameByStudyId($study_id);
  1080. if(empty($name))
  1081. {
  1082. return [];
  1083. }
  1084. $where['institution_id'] = $institutionId;
  1085. $where['name'] = $name;
  1086. } else {
  1087. $patient = $this->butt->getPatientByStudyId($study_id);
  1088. if(empty($patient))
  1089. {
  1090. return [];
  1091. }
  1092. $where['patient_id'] = $patient;
  1093. }
  1094. $exam = $this->butt->getExamByPatient($where);
  1095. return $exam;
  1096. }
  1097. public function getSearch($search)
  1098. {
  1099. $search_array = '';
  1100. if(empty($search))
  1101. {
  1102. return [];
  1103. }
  1104. $search_array = "name='$search' or patient_num='$search' or accession_num='$search'";
  1105. return $search_array;
  1106. }
  1107. public function save_video_url($params)
  1108. {
  1109. if(empty($params['video_url']))
  1110. {
  1111. $this->throwError('无效的url地址',0045);
  1112. }
  1113. $data = [
  1114. 'video_url'=>$params['video_url'],
  1115. 'doctor_id'=>$params['user_id'],
  1116. 'image_url'=>$params['image_url'] ?? '',
  1117. 'video_type'=>$params['video_type'] ?? '0',
  1118. ];
  1119. if(isset($params['exam_id']) && !empty($params['exam_id']))
  1120. {
  1121. //存在exam_id 则为上传并保存接口
  1122. $data['exam_id'] = $params['exam_id'];
  1123. $data['status'] = 1;
  1124. }
  1125. $info = $this->butt->save_video_url($data);
  1126. return $info;
  1127. }
  1128. public function getWorkList($params)
  1129. {
  1130. $info = $this->butt->getWorkList();
  1131. foreach ($info as $k=>$v)
  1132. {
  1133. $sex = $this->handle_sex($v['Sex']);
  1134. $info[$k]['Sex'] = $sex;
  1135. $info[$k]['DateOfBirth'] = $this->handleTime($v['DateOfBirth']);
  1136. $info[$k]['ExamDateAndTime'] = $this->handleTime($v['ExamDateAndTime']);
  1137. }
  1138. return $info;
  1139. }
  1140. public function handleTime($time)
  1141. {
  1142. $t = strtotime($time);
  1143. $r = date('Y-m-d H:i:s',$t);
  1144. return $r;
  1145. }
  1146. public function handle_sex($sex)
  1147. {
  1148. switch ($sex){
  1149. case 'M':
  1150. case '男':
  1151. return 'M';
  1152. break;
  1153. case 'F':
  1154. case '女':
  1155. return 'F';
  1156. break;
  1157. default:
  1158. return 'O';
  1159. break;
  1160. }
  1161. }
  1162. public function getNotInsReport($param)
  1163. {
  1164. $where_status[] = ['exam_status','in',explode(',',$param['report_status'])];
  1165. $where_institution = ['institution_id'=>$param['institution_id']];
  1166. $time = explode(',',$param['time']);
  1167. $where_time = [$time[0],$time[1]];
  1168. $field = [
  1169. 'e.name',
  1170. 'e.sex',
  1171. 'phone',
  1172. 'card_num',
  1173. 'hopitalized_no',
  1174. 'out_patient',
  1175. 'accession_num',
  1176. 'patient_num',
  1177. 'studyuid',
  1178. 'his_patient_id',
  1179. 'impression',
  1180. 'description',
  1181. 'report_datetime',
  1182. 'report_doctor_name',
  1183. 'review_doctor_name',
  1184. 'review_datetime',
  1185. 'r.report_result'
  1186. ];
  1187. $data = $this->butt->getNotInsReport($where_status,$where_institution,$where_time,$field);
  1188. return $data;
  1189. }
  1190. public function setNameCache($params)
  1191. {
  1192. foreach ($params as $k=>$v)
  1193. {
  1194. // $cache = $this->butt->saveCache($v['INPATIENTNO'],$v['NAME']);
  1195. $key = "worklist_".$v['INPATIENTNO'];
  1196. $cache = $this->butt->saveCache($key, json_encode($v));
  1197. Log::record('存储结果'.$cache.';存储key为'.$key.';存储内容为'.$this->butt->getCache($key));
  1198. }
  1199. return true;
  1200. }
  1201. public function getRisVersion()
  1202. {
  1203. $data = $this->butt->getRisVersion();
  1204. $return = [];
  1205. foreach ($data as $k=>$v)
  1206. {
  1207. $new = 1;
  1208. $time = time()-strtotime($v['time']);
  1209. if($time < 86400*30)
  1210. {
  1211. $new = 2;
  1212. }
  1213. $name = $this->butt->getProjectName($v['project']);
  1214. $info = ['project'=>$v['project'],'new'=>$new,'name'=>$name];
  1215. $return[] = $info;
  1216. }
  1217. return $return;
  1218. }
  1219. public function getVersionInfo($project)
  1220. {
  1221. $info = $this->butt->getVersionInfo($project);
  1222. return $info;
  1223. }
  1224. public function getBindInfo($param)
  1225. {
  1226. if(!($param['institution_id'] ?? null) || !($param['start'] ?? null) || !($param['finish'] ?? null) )
  1227. {
  1228. $this->throwError('医院id不能为空','0081');
  1229. }
  1230. $ins = ['institution_id'=>$param['institution_id']];
  1231. $start = $param['start'].' 00:00:00';
  1232. $finish = $param['finish'].' 23:59:59';
  1233. $visit = $this->butt->getBindInfo($ins,$start,$finish);
  1234. $ids = [];
  1235. $cTime = [];
  1236. $type = [];
  1237. foreach ($visit as $k=>$v)
  1238. {
  1239. $ids[] = $v['exam_id'];
  1240. $cTime[$v['exam_id']] = $v['createdAt'];
  1241. if($type[$v['exam_id']] ?? null)
  1242. {
  1243. $type[$v['exam_id']] = $type[$v['exam_id']].','.$v['source'];
  1244. }else{
  1245. $type[$v['exam_id']] = $v['source'];
  1246. }
  1247. }
  1248. $list= $this->butt->getExamByIds($ids);
  1249. $data = [];
  1250. foreach ($list as $k=>$v)
  1251. {
  1252. $list[$k]['createdAt'] = $cTime[$v['id']];
  1253. $source = '';
  1254. if($type[$v['id']] ?? null)
  1255. {
  1256. if(strpos($type[$v['id']],'1') !== false)
  1257. {
  1258. if(empty($source))
  1259. {
  1260. $source = '1';
  1261. }else{
  1262. $source .= ',1';
  1263. }
  1264. }
  1265. if(strpos($type[$v['id']],'2') !== false)
  1266. {
  1267. if(empty($source))
  1268. {
  1269. $source = '2';
  1270. }else{
  1271. $source .= ',2';
  1272. }
  1273. }
  1274. if(strpos($type[$v['id']],'3') !== false)
  1275. {
  1276. if(empty($source))
  1277. {
  1278. $source = '3';
  1279. }else{
  1280. $source .= ',3';
  1281. }
  1282. }
  1283. $list[$k]['source'] = $source;
  1284. }
  1285. if(!empty($source))
  1286. {
  1287. $data[] = $v;
  1288. }
  1289. }
  1290. return $list;
  1291. }
  1292. public function saveAnnex($params)
  1293. {
  1294. if(empty($params['url']))
  1295. {
  1296. $this->throwError('无效的url地址','9001');
  1297. }
  1298. $value = $params['code'];
  1299. $key = Config::get('report_save_type')[$params['type']] ?? null;
  1300. if(empty($key))
  1301. {
  1302. $this->throwError('无效的type类型','9002');
  1303. }
  1304. $field = ['e.id','r.id as report_id'];
  1305. if($key == 'id')
  1306. {
  1307. $key= 'e.id';
  1308. }
  1309. $where = [$key=>$value,'institution_id'=>$params['institution_id']];
  1310. $whereTime = [];
  1311. if($params['institution_id'] == '06300006')
  1312. {
  1313. if($params['type'] == 2)
  1314. {
  1315. $whereTime['exam_datetime'] = date('Ymd',time());
  1316. }
  1317. }
  1318. $exam = $this->butt->getExamReport($where,$field,$whereTime);
  1319. if(empty($exam))
  1320. {
  1321. $data = [
  1322. 'annex_class_code'=>$params['annex_class_code'] ?? '',
  1323. 'url'=>$params['url'],
  1324. 'name'=>$params['name'] ?? '',
  1325. 'report_id'=>'',
  1326. 'exam_id'=>'',
  1327. 'type'=>$params['type'],
  1328. 'code'=>$value,
  1329. 'exam_datetime'=>$params['exam_datetime'] ?? '',
  1330. 'institution_id'=>$params['institution_id']
  1331. ];
  1332. $whereAnnex = ['type'=>$params['type'],'code'=>$value,'url'=>$params['url']];
  1333. $info = $this->butt->checkAnnes($whereAnnex);
  1334. if($info)
  1335. {
  1336. $return = $this->butt->updateAnnex($data,$whereAnnex);
  1337. }else{
  1338. $return = $this->butt->saveAnnex($data);
  1339. }
  1340. return $return;
  1341. // $this->throwError('不存在的检查','9003');
  1342. }else{
  1343. $return = '';
  1344. foreach ($exam as $k=>$v)
  1345. {
  1346. $data = [
  1347. 'annex_class_code'=>$params['annex_class_code'] ?? '',
  1348. 'url'=>$params['url'],
  1349. 'name'=>$params['name'] ?? '',
  1350. 'report_id'=>$v['report_id'] ? $v['report_id'] : '',
  1351. 'exam_id'=>$v['id'],
  1352. 'type'=>$params['type'],
  1353. 'code'=>$value,
  1354. 'exam_datetime'=>$params['exam_datetime'] ?? '',
  1355. 'institution_id'=>$params['institution_id']
  1356. ];
  1357. $whereAnnex = ['exam_id'=>$v['id'],'url'=>$params['url']];
  1358. $info = $this->butt->checkAnnes($whereAnnex);
  1359. if($info)
  1360. {
  1361. $return = $this->butt->updateAnnex($data,$whereAnnex);
  1362. }else{
  1363. $return = $this->butt->saveAnnex($data);
  1364. }
  1365. }
  1366. return $return;
  1367. }
  1368. }
  1369. public function saveRegister($params)
  1370. {
  1371. if(empty($params['code']))
  1372. {
  1373. $this->throwError('无效的code码',0025);
  1374. }
  1375. $key = Config::get('ut')[$params['code']] ?? null;
  1376. if(empty($key))
  1377. {
  1378. $this->throwError('无效的code码',0025);
  1379. }
  1380. $where = [$key=>$params[$key]];
  1381. $examId = $this->butt->getRegisterExam($where);
  1382. // 添加 patient_infos 表数据
  1383. $patient_data = $this->makePatientData($params);
  1384. if(!is_null($examId)){
  1385. // 修改操作
  1386. unset($patient_data['id']);
  1387. $pat_id = $this->registerDao->getPatientId($examId);
  1388. $patient = $this->registerDao->updatePatient($patient_data,$pat_id);
  1389. } else {
  1390. // 添加操作
  1391. $pat_id = $patient_data['id'];
  1392. $patient = $this->registerDao->insertParent($patient_data);
  1393. }
  1394. // 添加 exam 表数据
  1395. $exam_data = $this->makeExamData($params);
  1396. $exam_data['patient_id'] = $pat_id;
  1397. if(!is_null($examId)){
  1398. // 修改操作
  1399. unset($exam_data['id']);
  1400. unset($exam_data['exam_status']);
  1401. $exam_res = $this->registerDao->updateExam($exam_data,$examId);
  1402. $exam_data['id'] = $examId;
  1403. } else {
  1404. $examId = $exam_data['id'];
  1405. $exam_res = $this->registerDao->insertExam($exam_data);
  1406. }
  1407. $register_data = $this->makeRegister($params);
  1408. $register_data['exam_id'] = $exam_data['id'];
  1409. $registerId = $this->registerDao->getRegisterId($exam_data['id']);
  1410. if(!is_null($registerId)){
  1411. // xiugai
  1412. $this->registerDao->updateRegister($register_data,$examId);
  1413. }else{
  1414. // xinzeng
  1415. $register_data['id'] = UUIDUtils::uuid();
  1416. $this->registerDao->insertRegister($register_data);
  1417. }
  1418. return $examId;
  1419. }
  1420. public function makePatientData($params)
  1421. {
  1422. try{
  1423. $sex_choose = $params['sex'] ?? '';
  1424. $sex = $this->getSex($sex_choose);
  1425. $data = [
  1426. 'id' => UUIDUtils::uuid(),
  1427. 'sex' => $sex,
  1428. 'name' => $params['name'] ?? '',
  1429. 'card_num' => $params['card_num'] ?? '',
  1430. 'phone' => $params['phone'] ?? '',
  1431. 'ctime' => date('Y-m-d H:i:s'),
  1432. 'birthday' => $params['birthday'] ?? '',
  1433. 'age' => $params['age'] ?? '',
  1434. 'card_type' => $params['card_type'] ?? '',
  1435. 'nationality' => $params['nationality'] ?? '',
  1436. 'nation' => $params['nation'] ?? '',
  1437. 'marry' => $params['marry'] ?? '',
  1438. 'professional' => $params['professional'] ?? '',
  1439. 'address' => $params['address'] ?? '',
  1440. 'status' => 1,
  1441. 'anamnesis' => $params['anamnesis'] ?? '',
  1442. 'family_ill' => $params['family_ill'] ?? '',
  1443. 'createdAt' => date('Y-m-d H:i:s'),
  1444. 'institution_id' => $params['institution_id'],
  1445. 'temp_patient_id' => $params['patient_num']
  1446. ];
  1447. return $data;
  1448. }catch (Exception $exception){
  1449. $this->throwError($exception->getMessage(),0001);
  1450. }
  1451. }
  1452. public function makeExamData($params)
  1453. {
  1454. try{
  1455. $sex_choose = $params['sex'] ?? '';
  1456. $sex = $this->getSex($sex_choose);
  1457. $data = [
  1458. 'id' => UUIDUtils::uuid(),
  1459. 'institution_id' => $params['institution_id'],
  1460. 'name' => $params['name'] ?? '',
  1461. 'phone' => $params['phone'] ?? '',
  1462. 'card_num' => $params['card_num'] ?? '',
  1463. 'patient_num' => $params['patient_num'] ?? '',
  1464. 'accession_num' => $params['accession_num'] ?? '', // 暂无
  1465. 'exam_project' => $params['exam_project'] ?? '',
  1466. 'exam_datetime' => $params['exam_datetime'] ?? '',
  1467. 'exam_status' => 1,
  1468. 'exam_sub_class' => $params['exam_sub_class'] ?? '',
  1469. 'body_part' =>$params['body_part'] ?? '',
  1470. 'device_name' => $params['device_name'] ?? '',
  1471. 'sex' => $sex,
  1472. 'age' =>$params['age'] ?? '',
  1473. 'birthday' => $params['birthday'] ?? '',
  1474. 'hopitalized_no' => $params['hopitalized_no'] ?? '',
  1475. 'bed_no' => $params['bed_no'] ?? '',
  1476. 'patient_area' => $params['patient_area'] ?? '',
  1477. 'application_department' => $params['application_department'] ?? '',
  1478. 'application_doctor' => $params['application_doctor'] ?? '',
  1479. 'out_patient' => $params['out_patient'] ?? '',
  1480. 'clin_symp' => $params['clin_symp'] ?? '',
  1481. 'clin_diag' => $params['clin_diag'] ?? '',
  1482. 'his_patient_id' => $params['his_patient_id'] ?? '',
  1483. 'exam_class' =>$params['exam_class'],
  1484. 'write_report' =>1
  1485. ];
  1486. return $data;
  1487. }catch (Exception $exception){
  1488. $this->throwError($exception->getMessage(),0001);
  1489. }
  1490. }
  1491. public function makeRegister($params)
  1492. {
  1493. $data = [
  1494. 'exam_sub_class' => $params['exam_sub_class'] ?? '',
  1495. 'body_part' =>$params['body_part'] ?? '',
  1496. 'device_name' => $params['device_name'] ?? null,
  1497. 'register_datetime' => date('Y-m-d H:i:s'),
  1498. 'illness_desc' => $params['illness_desc'] ?? '',
  1499. 'phys_sign' => $params['phys_sign'] ?? '',
  1500. 'clin_symp' => $params['clin_symp'] ?? '',
  1501. 'anamnesis' => $params['anamnesis'] ?? '',
  1502. 'family_ill' => $params['family_ill'] ?? '',
  1503. 'clin_diag' => $params['clin_diag'] ?? '',
  1504. 'application_department' => $params['application_department'] ?? '',
  1505. 'ext' => $params['remark'] ?? ''
  1506. ];
  1507. return $data;
  1508. }
  1509. public function getField($params)
  1510. {
  1511. $ins = $params['institution_id'];
  1512. $type = $this->butt->getField($ins);
  1513. return Config::get('report_save_type')[$type] ?? 'patient_num';
  1514. }
  1515. public function savePrintSync($params)
  1516. {
  1517. if(empty($params['type']))
  1518. {
  1519. $this->throwError('无效的type码',0025);
  1520. }
  1521. if(empty($params['code']))
  1522. {
  1523. $this->throwError('无效的code码',0025);
  1524. }
  1525. $key = Config::get('report_save_type')[$params['type']] ?? null;
  1526. if(empty($key))
  1527. {
  1528. $this->throwError('无效的type码',0025);
  1529. }
  1530. $where = [$key=>$params['code'],'institution_id'=>$params['institution_id']];
  1531. $exam = $this->butt->getExam($where,['name']);
  1532. if(empty($exam))
  1533. {
  1534. $this->throwError('无效的code,查不到匹配的检查',0027);
  1535. }
  1536. $where = ['code'=>$params['code'],'institution_id'=>$params['institution_id']];
  1537. // $today_print = $this->butt->checkPrint($where,"to_days(createdAt) = to_days(now())");
  1538. // if($today_print)
  1539. // {
  1540. // //检查次数+1
  1541. // $info = $this->butt->printZz($where);
  1542. // return '同步成功';
  1543. // }
  1544. $where['print_time'] = $params['print_time'] ?? null;
  1545. $data = [
  1546. 'institution_id'=>$params['institution_id'] ?? '',
  1547. 'type'=>$params['type'],
  1548. 'code'=>$params['code'],
  1549. 'print_time'=>$params['print_time'] ?? null,
  1550. 'name'=>$exam['name']
  1551. ];
  1552. $print = $this->butt->getPrint($where);
  1553. if($print)
  1554. {
  1555. $info = $this->butt->updatePrintSync($data,$where);
  1556. }else{
  1557. $info = $this->butt->savePrintSync($data);
  1558. }
  1559. return $info;
  1560. }
  1561. public function saveReportAnnex($url,$reportId)
  1562. {
  1563. $examId = $this->butt->getExamFromReport($reportId);
  1564. $data = [
  1565. 'annex_class_code'=>2,
  1566. 'url'=>$url,
  1567. 'name'=>'',
  1568. 'report_id'=>$reportId,
  1569. 'exam_id'=>$examId
  1570. ];
  1571. log::record('附件'.json_encode($data));
  1572. $this->butt->saveAnnex($data);
  1573. }
  1574. public function getPayExam($params)
  1575. {
  1576. $start = $params['start'];
  1577. $finish = $params['finish'];
  1578. $institution = $params['institution'];
  1579. $where = ['m.pay_type'=>1,'m.pay_way'=>1,'m.institution_id'=>$institution,'m.status'=>2,'m.type'=>2,'m.order_type'=>1,'m.is_sync'=>0];
  1580. $time = "m.createdAt between '$start' and '$finish'";
  1581. $water = $this->butt->getPayExam($where,$time);
  1582. // $examWhere[] = ['id','in',$water];
  1583. // $info = $this->butt->getPayExams($examWhere,['patient_num','accession_num','studyuid']);
  1584. return $water;
  1585. }
  1586. public function changeSyncStatus($params)
  1587. {
  1588. $id = $params['id'];
  1589. $info = $this->butt->changeSyncStatus($id);
  1590. return $info;
  1591. }
  1592. public function changePayStatus($params)
  1593. {
  1594. $patient_num = $params['patient_num'] ?? '';
  1595. if(empty($patient_num))
  1596. {
  1597. return '';
  1598. }
  1599. $ins = '03060002';
  1600. $info = $this->butt->changePayStatus($patient_num,$ins);
  1601. return $info;
  1602. }
  1603. public function getMiddle($params)
  1604. {
  1605. $num = $params['minute'];
  1606. $ins = $params['institution_id'];
  1607. //获取多少分钟内数据
  1608. $where = "m.createdAt > DATE_SUB(NOW(), INTERVAL $num MINUTE) and m.institution_id='$ins'";
  1609. $info = $this->butt->getMiddleInfo($where);
  1610. return $info;
  1611. }
  1612. public function changeMiddleStatus($params)
  1613. {
  1614. $where[] = ['id','in',explode(',',$params['ids'])];
  1615. $update = ['is_sync'=>1];
  1616. $info = $this->butt->changeMiddleStatus($where,$update);
  1617. return $info;
  1618. }
  1619. public function syncMiddle($params)
  1620. {
  1621. $where = ['studyuid'=>$params['studyuid']];
  1622. $field = ['id','institution_id'];
  1623. $exam = $this->butt->getExam($where,$field);
  1624. $examId = $exam['id'] ?? null;
  1625. if(empty($examId))
  1626. {
  1627. return '无效的studyuid';
  1628. }
  1629. $middleInfo = [
  1630. 'institution_id'=>$exam['institution_id'],
  1631. 'status'=>$params['status'],
  1632. 'doctor_id'=>$params['doctor_id'],
  1633. 'doctor_name'=>$params['doctor_name'],
  1634. 'exam_id'=>$examId,
  1635. 'is_sync'=>1
  1636. ];
  1637. $r = $this->butt->saveMiddle($middleInfo);
  1638. return $r;
  1639. }
  1640. public function goNoteUrl($param)
  1641. {
  1642. try{
  1643. if($param['id'] == 1)
  1644. {
  1645. return DebugModel::value('url');
  1646. }
  1647. $num = base64_decode($param['id']);
  1648. $id = base_convert(ltrim($num,0),36,10);
  1649. $url = $this->butt->getNoteUrl($id);
  1650. return $url;
  1651. }catch (Exception $e)
  1652. {
  1653. return '';
  1654. }
  1655. }
  1656. public function saveAiReport($param)
  1657. {
  1658. $this->reportDao->saveDcmReportData(json_encode($param),$param['exam_id'],5,$this->ts_time());
  1659. if($param['describe'] == 'gpu不可用,请1小时后再试')
  1660. {
  1661. return '';
  1662. }
  1663. $data = [
  1664. 'id'=>UUIDUtils::uuid(),
  1665. 'impression'=>$param['diagnosis'],
  1666. 'description'=>$param['describe'],
  1667. 'type'=>3,
  1668. 'exam_id'=>$param['exam_id'],
  1669. 'report_doctor_name'=>'ai报告医生',
  1670. 'review_doctor_name'=>'ai报告医生',
  1671. 'confirm_doctor_name'=>'ai报告医生',
  1672. 'report_datetime'=>date('Y-m-d H:i:s'),
  1673. 'review_datetime'=>date('Y-m-d H:i:s'),
  1674. 'confirm_datetime'=>date('Y-m-d H:i:s'),
  1675. 'detections'=>empty($param['detections']) ? '' : json_encode($param['detections'])
  1676. ];
  1677. $aiData = $this->reportDao->getReport($param['exam_id'],3);
  1678. if($aiData)
  1679. {
  1680. //修改ai报告
  1681. unset($data['id']);
  1682. $info = $this->reportDao->updateReport($param['exam_id'],3,$data);
  1683. }else{
  1684. $info = $this->butt->saveReport($data);
  1685. }
  1686. $arr = [
  1687. 'report_id'=>$data['exam_id'],
  1688. 'exam_id'=>$param['exam_id'],
  1689. 'diagnosis'=>$param['diagnosis'],
  1690. 'describe'=>$param['describe'],
  1691. 'detections'=>empty($param['detections']) ? '' : json_encode($param['detections'])
  1692. ];
  1693. $this->butt->saveAiReport($arr);
  1694. $this->reportDao->saveDcmReportData('',$param['exam_id'],6,$this->ts_time());
  1695. return $info;
  1696. }
  1697. public function getDmReport($param)
  1698. {
  1699. if($param['datetime'] ?? '')
  1700. {
  1701. $date = explode(',',$param['datetime']);
  1702. if(empty($date[0] ?? '') || empty($date['1'] ?? ''))
  1703. {
  1704. $this->throwError('参数传参错误','0058');
  1705. }
  1706. }else{
  1707. $this->throwError('缺少必要参数','0057');
  1708. }
  1709. $data = $this->reportDao->getDmReport($date[0],$date[1]);
  1710. return $data;
  1711. }
  1712. public function getInsReport($param)
  1713. {
  1714. if($param['datetime'] ?? '')
  1715. {
  1716. $date = explode(',',$param['datetime']);
  1717. if(empty($date[0] ?? '') || empty($date['1'] ?? ''))
  1718. {
  1719. $this->throwError('参数传参错误','0058');
  1720. }
  1721. }else{
  1722. $this->throwError('缺少必要参数','0057');
  1723. }
  1724. if(!($param['institution_id'] ?? ''))
  1725. {
  1726. $this->throwError('缺少必要参数','0057');
  1727. }
  1728. $data = $this->reportDao->getInsReport($date[0],$date[1],$param['institution_id'],$param['remote'] ?? '',$param['page'] ?? 1,$param['num'] ?? 10);
  1729. return $data;
  1730. }
  1731. public function getWechatData($openid)
  1732. {
  1733. if(empty($openid))
  1734. {
  1735. $this->throwError('错误的参数','0059');
  1736. }
  1737. $data = $this->reportDao->getWechatData($openid);
  1738. if(empty($data))
  1739. {
  1740. $this->throwError('未找到绑定信息','0060');
  1741. }
  1742. $wx_id = $data['wx_id'];
  1743. $patient = $data['patient'];
  1744. $exam = $data['exams'];
  1745. $arr = [
  1746. 'name'=>empty($patient['patient_name'] ?? '') ? ($exam['name'] ?? '') : $patient['patient_name'],
  1747. 'idCard' => empty($patient['idCard'] ?? '') ? ($exam['card_num'] ?? '') : $patient['idCard'],
  1748. 'phone'=>$patient['phone'] ?? '',
  1749. 'birthday'=>$exam['birthday'] ?? '',
  1750. 'sex'=>$exam['sex'] ?? '',
  1751. 'id'=>$wx_id
  1752. ];
  1753. $key = 'e386c7039aa49826664d576eb798da21';
  1754. $arr = openssl_encrypt((json_encode($arr)),'AES-128-ECB',$key,OPENSSL_RAW_DATA);
  1755. return base64_encode($arr);
  1756. }
  1757. public function getLwSyncExam($params)
  1758. {
  1759. $field = [
  1760. 'id',
  1761. 'name as PatName',
  1762. 'patient_id as PatID',
  1763. 'birthday as BirthDate',
  1764. 'sex as PatSex',
  1765. 'age as PatAge',
  1766. 'studyUid as StudyInstanceUID',
  1767. "'' as SeriesInstanceUID", // Series唯一标识符 Y
  1768. "'' as SOPInstanceUID", // SOP唯一标识符 Y
  1769. 'exam_datetime as StudyDate',
  1770. "'' as SeriesDate",
  1771. "'' as AcquistionTime",
  1772. 'accession_num as AccessionNumber',
  1773. 'exam_class as Modality',
  1774. 'patient_num as StudyID',
  1775. "'' as SeriesNumber",
  1776. "'' as AcquisitionNumber",
  1777. "'' as InstanceNumber",
  1778. "'' as FilePathName",
  1779. "'' as Manufacturer",
  1780. 'study_id as RelationField'
  1781. ];
  1782. $data = $this->reportDao->getLwSyncExam($params['institution_id'],$params['num'],$field);
  1783. $arr = [];
  1784. $url = 'https://query.pacsonline.cn/query/data_lw?RelationField=';
  1785. foreach ($data as $k=>$v)
  1786. {
  1787. $array = [];
  1788. $array = $v;
  1789. $urlImage = $url.$v['RelationField'];
  1790. $return = $this->curl_get($urlImage);
  1791. $return = json_decode($return,true);
  1792. foreach ($return as $value)
  1793. {
  1794. foreach ($value as $kk=>$vv)
  1795. {
  1796. if(empty($array[$kk]))
  1797. {
  1798. $array[$kk] = $vv;
  1799. }
  1800. }
  1801. }
  1802. $arr[] = $array;
  1803. }
  1804. return $arr;
  1805. }
  1806. public function changeLwSyncStatus($params)
  1807. {
  1808. $data = $this->reportDao->changeLwSyncStatus($params['id']);
  1809. return 'success';
  1810. }
  1811. public function changeLwSyncReportStatus($params)
  1812. {
  1813. $data = $this->reportDao->changeLwSyncReportStatus($params['id']);
  1814. return 'success';
  1815. }
  1816. public function getExamList($params)
  1817. {
  1818. $idCard = $params['sfzh'] ?? '';
  1819. $jgdm = $params['jgdm'] ?? '';
  1820. if(empty($jgdm) || empty($idCard))
  1821. {
  1822. $this->throwError('参数错误','9898');
  1823. }
  1824. $institution = $this->reportDao->getInstitutionData(['ins_jgdm'=>$jgdm],'id');
  1825. if(empty($institution))
  1826. {
  1827. $this->throwError('无效的参数','9899');
  1828. }
  1829. $data = $this->reportDao->getExamList(['institution_id'=>$institution['id'],'card_num'=>$idCard]);
  1830. return ['data'=>$data,'count'=>count($data)];
  1831. }
  1832. public function getInsToken($params)
  1833. {
  1834. $orgCode = $params['clientid']; //机构编码
  1835. $authID = $params['clientsecret']; //授权码
  1836. if(empty($orgCode) || empty($authID))
  1837. {
  1838. $this->throwError('','-1');
  1839. }
  1840. $where = ['id'=>$orgCode,'clientid'=>$authID];
  1841. $institution = $this->butt->getInstitution($where);
  1842. if(empty($institution))
  1843. {
  1844. return ['msg'=>'机构编码或授权码错误','data'=>[]];
  1845. }
  1846. $key = md5($orgCode.rand(0,99));
  1847. $expire = 3600;
  1848. // $aesKey = $this->generateRandomLetters();
  1849. // todo
  1850. $aesKey = 'zLxapoeqWYpoeqWY';
  1851. $token = base64_encode(md5($orgCode.$institution['id'].$aesKey));
  1852. $arr = ['token'=>$token,'key'=>$aesKey,'expire'=>$expire,'appId'=>$key,'orgCode'=>$orgCode];
  1853. $this->setCache($orgCode,[$orgCode=>$token],$expire);
  1854. $this->setCache($token,$arr,$expire);
  1855. return ['msg'=>'success','data'=>$arr];
  1856. }
  1857. public function getExamReport($params)
  1858. {
  1859. $id = $params['id'] ?? '';
  1860. $data = $this->reportDao->getExamReport(['e.id'=>$id]);
  1861. return $data;
  1862. }
  1863. public function saveLwExam()
  1864. {
  1865. $where = ['institution_id'=>'25500005','num'=>10];
  1866. $url = "localhost:806/butt/getLwSyncExam";
  1867. $list = $this->curlPost($url,$where);
  1868. $arr = json_decode($list,true);
  1869. $data = $arr['data'] ?? [];
  1870. if(!empty($data))
  1871. {
  1872. foreach ($data as $k=>$v)
  1873. {
  1874. var_dump($v);die;
  1875. }
  1876. }
  1877. var_dump($data);die;
  1878. return $data;
  1879. }
  1880. public function getLwSyncReport($params)
  1881. {
  1882. $field = [
  1883. 'e.id as exam_id',
  1884. 'medical_code as InsuCardNo',//医保卡号
  1885. 'accession_num as Accessionnumber',
  1886. 'patient_num as PatID',
  1887. 'name as PatCName',
  1888. 'name as PatEName',
  1889. 'sex as PatSex',
  1890. 'birthday as BirthDate',
  1891. 'age as PatAge',
  1892. "'' as Address",
  1893. 'card_num as ICCard',
  1894. 'phone as Phone',
  1895. "'未知' as Marriage",
  1896. "'' as PatSection",
  1897. "'' as Ward",
  1898. "'' as BedNumber",
  1899. 'application_department as ReqDept',
  1900. 'application_doctor as ReqDoctor',
  1901. "'' as ReqDate",
  1902. "'' as ReqDate",
  1903. 'body_part as ExamineBody',
  1904. 'exam_project as ExamineItem',
  1905. "'' as ExamineItemcode",
  1906. 'exam_class as Modality',
  1907. 'r.report_result as RequisitionNote', //0 阴性positive,1 阳性negative,-1 未知unkown
  1908. "'' as ExamineType",
  1909. 'patient_num as ClinicID',
  1910. 'patient_source as PatSource',
  1911. "'' as TreatItem",
  1912. "'' as ChiefComplain",
  1913. "'' as DocAdvice",
  1914. 'clin_diag as DocAdvice',
  1915. 'his_patient_id as HISID',
  1916. 'his_patient_id as HisExamineId',
  1917. "'' as ExamineDoctor",
  1918. 'exam_datetime as StudyDateTime',
  1919. 'report_doctor_name as ReportDoctor',
  1920. 'review_doctor_name as AuditDoctor',
  1921. 'report_datetime as ReportDateTime',
  1922. 'review_datetime as AuditDateTime',
  1923. 'description as Finding',
  1924. 'impression as Conclusion',
  1925. '0 as Tempreport',
  1926. '4 as ReportStatus',
  1927. 'r.id as ReportID',
  1928. 'r.updatedAt as UpDateTime',
  1929. 'study_id as StudyInstanceUID'
  1930. ];
  1931. if(empty($params['institution_id']))
  1932. {
  1933. return [];
  1934. }
  1935. $data = $this->butt->getExamLimitReport(['exam_status'=>9,'lw_report_sync_status'=>1],$field,['institution_id'=>$params['institution_id']],$params['num']);
  1936. foreach ($data as $k=>$v)
  1937. {
  1938. switch ($v['RequisitionNote'])
  1939. {
  1940. case 1 :
  1941. $result = 0;
  1942. break;
  1943. case 2 :
  1944. $result = 1;
  1945. break;
  1946. default:
  1947. $result = '-1';
  1948. }
  1949. $data[$k]['RequisitionNote'] = $result;
  1950. // //1:门诊:,2:住院,4:体检,5:急诊,6:住院急诊,7:职业病体检0:其他
  1951. switch ($v['PatSource'])
  1952. {
  1953. case 1:
  1954. $source = 5;
  1955. break;
  1956. case 2:
  1957. $source = 2;
  1958. break;
  1959. case 3:
  1960. $source = 1;
  1961. break;
  1962. case 4:
  1963. $source = 4;
  1964. break;
  1965. default:
  1966. $source = 0;
  1967. }
  1968. $data[$k]['PatSource'] = $source;
  1969. try{
  1970. $data[$k]['PatEName'] = PinyinChange::utf8_to($v['PatEName']);
  1971. }catch (Exception $e)
  1972. {
  1973. // todo
  1974. }
  1975. }
  1976. return $data;
  1977. }
  1978. public function saveAnalysiss()
  1979. {
  1980. $start = strtotime('yesterday');
  1981. $end = strtotime('yesterday');
  1982. $institution = $this->reportDao->getAllIns();
  1983. for ($t = $start; $t <= $end; $t = strtotime('+1 day', $t)) {
  1984. $date = date('Y-m-d', $t);
  1985. $this->saveAnalysis($date,$institution);
  1986. }
  1987. }
  1988. public function saveAnalysis($date, $institution)
  1989. {
  1990. // $institution = $this->reportDao->getAllIns();
  1991. // $date = date("Y-m-d",time()-86400);
  1992. $dateWhere = "createdAt between '$date 00:00:00' and '$date 23:59:59'";
  1993. $exam_date = date('Ymd',strtotime($date));
  1994. $examDateWhere = ['exam_datetime' => $exam_date];
  1995. foreach ($institution as $institution_id=>$institution_name) {
  1996. $institution[$institution_id] = [
  1997. 'institution_id'=>$institution_id,
  1998. 'institution_name'=>$institution_name,
  1999. 'date'=> $exam_date,
  2000. 'exam_all_num'=>0,
  2001. 'person_num'=>0,
  2002. 'exam_phone'=>0,
  2003. 'send_sms'=>0,
  2004. 'wechat_visit_pv'=>0,
  2005. 'wechat_visit_uv'=>0,
  2006. 'link_visit_pv' => 0,
  2007. 'link_visit_uv' => 0,
  2008. 'sms_visit_pv' => 0,
  2009. 'sms_visit_uv' => 0,
  2010. ];
  2011. }
  2012. $analysis = [];
  2013. $exams = $this->reportDao->getExamGroupByIns($dateWhere);
  2014. foreach ($exams as $exam)
  2015. {
  2016. if(!isset($institution[$exam['institution_id']]))
  2017. {
  2018. continue;
  2019. }
  2020. $institution[$exam['institution_id']]['exam_all_num'] = $exam['num'];
  2021. }
  2022. $phones = $this->reportDao->getExamGroupByIns($dateWhere, '', "phone is not null and phone <>''");
  2023. foreach ($phones as $phone)
  2024. {
  2025. if(!isset($institution[$phone['institution_id']]))
  2026. {
  2027. continue;
  2028. }
  2029. $institution[$phone['institution_id']]['exam_phone'] = $phone['num'];
  2030. }
  2031. $smss = $this->reportDao->getSmsNumGroupByIns($dateWhere);
  2032. foreach ($smss as $sms)
  2033. {
  2034. if(!isset($institution[$sms['institution_id']]))
  2035. {
  2036. continue;
  2037. }
  2038. $institution[$sms['institution_id']]['send_sms'] = $sms['num'];
  2039. }
  2040. $wechatPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 1]);
  2041. foreach ($wechatPvUvs as $wechatPvUv)
  2042. {
  2043. if(!isset($institution[$wechatPvUv['institution_id']]))
  2044. {
  2045. continue;
  2046. }
  2047. $institution[$wechatPvUv['institution_id']]['wechat_visit_pv'] = $wechatPvUv['pv'];
  2048. $institution[$wechatPvUv['institution_id']]['wechat_visit_uv'] = $wechatPvUv['uv'];
  2049. }
  2050. $linkPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 2]);
  2051. foreach ($linkPvUvs as $linkPvUv)
  2052. {
  2053. if(!isset($institution[$linkPvUv['institution_id']]))
  2054. {
  2055. continue;
  2056. }
  2057. $institution[$linkPvUv['institution_id']]['link_visit_pv'] = $linkPvUv['pv'];
  2058. $institution[$linkPvUv['institution_id']]['link_visit_uv'] = $linkPvUv['uv'];
  2059. }
  2060. $smsPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 3]);
  2061. foreach ($smsPvUvs as $smsPvUv)
  2062. {
  2063. if(!isset($institution[$smsPvUv['institution_id']]))
  2064. {
  2065. continue;
  2066. }
  2067. $institution[$smsPvUv['institution_id']]['sms_visit_pv'] = $smsPvUv['pv'];
  2068. $institution[$smsPvUv['institution_id']]['sms_visit_uv'] = $smsPvUv['uv'];
  2069. }
  2070. foreach ($institution as $k=>$v)
  2071. {
  2072. $analysis[] = $v;
  2073. }
  2074. // var_dump($analysis);die;
  2075. Db::connect('dbbi')->table('data_analysis')->insertAll($analysis);
  2076. }
  2077. public function makeWechatData($institution, $emails)
  2078. {
  2079. $email = explode(',',$emails);
  2080. $message = '';
  2081. $where = ['institution_id'=>$institution];
  2082. $institutionName = $this->reportDao->getInstitutionName($institution);
  2083. $yesterday = date('Y-m-d',strtotime('-1 day'));
  2084. $whereTime = "createdAt BETWEEN '$yesterday 00:00:00' and '$yesterday 23:59:59'";
  2085. $all = $this->reportDao->getAllExamCount($where,$whereTime);
  2086. $pvWechatVisit = $this->reportDao->getPvWechatVisit($where,$whereTime);
  2087. $uvWechatVisit = $this->reportDao->getUvWechatVisit($where,$whereTime);
  2088. $message = $institutionName.$yesterday.'的检查总数'.$all.' 访问pv是'.$pvWechatVisit.',访问uv是'.$uvWechatVisit;
  2089. foreach ($email as $k=>$v)
  2090. {
  2091. $this->sendWechatInfoEmail($message,$v);
  2092. }
  2093. }
  2094. public function sendWechatInfoEmail($message, $email)
  2095. {
  2096. set_time_limit(0);
  2097. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  2098. try {
  2099. //服务器配置
  2100. $mail->CharSet ="UTF-8"; //设定邮件编码
  2101. $mail->SMTPDebug = 0; // 调试模式输出
  2102. $mail->isSMTP(); // 使用SMTP
  2103. $mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
  2104. $mail->SMTPAuth = true; // 允许 SMTP 认证
  2105. $mail->Username = 'company@pacsonline.cn'; // SMTP 用户名 即邮箱的用户名
  2106. $mail->Password = 'Zskk1234'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  2107. $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
  2108. $mail->Port = 465;
  2109. $mail->SMTPOptions = array(
  2110. 'ssl' => array(
  2111. 'verify_peer' => false,
  2112. 'verify_peer_name' => false,
  2113. 'allow_self_signed' => true
  2114. )
  2115. );
  2116. // 服务器端口 25 或者465 具体要看邮箱服务器支持
  2117. $mail->setFrom('company@pacsonline.cn', '冠医云'); //发件人
  2118. $mail->addAddress($email, ''); // 收件人
  2119. $mail->addReplyTo('company@pacsonline.cn', '冠医云'); //回复的时候回复给哪个邮箱 建议和发件人一致
  2120. $mail->Subject = '数据汇总';
  2121. //$mail->addCC('cc@example.com'); //抄送
  2122. $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
  2123. $mail->Body = $message;
  2124. $mail->send();
  2125. return '邮件发送成功';
  2126. } catch (Exception $e) {
  2127. // return '邮件发送失败: ';
  2128. return '邮件发送失败: '.$mail->ErrorInfo;
  2129. }
  2130. }
  2131. public function saveDmExam($data)
  2132. {
  2133. $this->butt->insertDmLog(['data'=>json_encode($data),'type'=>1]);
  2134. $arr = $this->makeDmExamDatas($data);
  2135. $exam = [];
  2136. if(!empty($arr['studyuid']))
  2137. {
  2138. $where = ['studyuid'=>$arr['studyuid'],'institution_id'=>$arr['institution_id']];
  2139. $exam = $this->butt->getExam($where,'*');
  2140. if(empty($exam))
  2141. {
  2142. $exam = $this->butt->getExam(['accession_num'=>$arr['accession_num'],'institution_id'=>$arr['institution_id']],'*');
  2143. }
  2144. }
  2145. if(empty($exam))
  2146. {
  2147. if(!empty($arr['imagenumber']))
  2148. {
  2149. $info = $this->butt->getExam(['imagenumber'=>$arr['imagenumber'],'institution_id'=>$arr['institution_id']],'*');
  2150. }
  2151. if(empty($info))
  2152. {
  2153. $arr['id'] = UUIDUtils::uuid();
  2154. $this->butt->insertExam($arr);
  2155. $id = $arr['id'];
  2156. }else{
  2157. foreach ($arr as $k=>$v)
  2158. {
  2159. if(empty($v))
  2160. {
  2161. unset($arr[$k]);
  2162. }
  2163. }
  2164. $this->butt->updateExam($arr,$info['id']);
  2165. $id = $info['id'];
  2166. }
  2167. }else{
  2168. $this->butt->updateExam($arr,$exam['id']);
  2169. $id = $exam['id'];
  2170. }
  2171. $report = $this->butt->getReportData(['exam_id'=>null,'imagenumber'=>$arr['imagenumber']]);
  2172. if(!empty($report))
  2173. {
  2174. $this->butt->updateReport(['exam_id'=>$id],['id'=>$report['id']]);
  2175. $this->butt->updateExam(['exam_status'=>9],$id);
  2176. }
  2177. return $id;
  2178. }
  2179. public function makeDmExamDatas($data)
  2180. {
  2181. $sexArr = ['1'=>'M','2'=>'F'];
  2182. $arr = [];
  2183. $arr['name'] = $data['A']['AA'];
  2184. $arr['card_num'] = $data['A']['AC'];
  2185. $arr['sex'] = $sexArr[$data['A']['AD']] ?? 'O';
  2186. $arr['birthday'] = $data['A']['AE'];
  2187. $arr['phone'] = $data['A']['AF'];
  2188. $arr['patient_num'] = $data['B']['BB'];
  2189. $arr['imagenumber'] = $data['B']['BD'];
  2190. $arr['application_department'] = $data['B']['BF'];
  2191. $arr['application_doctor'] = $data['B']['BG'];
  2192. $arr['age'] = $data['B']['BJ'];
  2193. $arr['institution_id'] = $data['B']['BK'];
  2194. $arr['clin_diag'] = $data['B']['BM'];
  2195. $arr['exam_class'] = $data['C']['CC'];
  2196. $arr['exam_project'] = $data['C']['CD'];
  2197. $arr['body_part'] = $data['C']['CF'];
  2198. $arr['exam_datetime'] = date('Ymd',strtotime($data['C']['CI']));
  2199. $arr['studyuid'] = $data['C']['CM'];
  2200. $arr['accession_num'] = $data['C']['CN'];
  2201. $arr['exam_status'] = 3;
  2202. return $arr;
  2203. }
  2204. public function saveDmLog($params,$type)
  2205. {
  2206. $this->butt->insertDmLog(['data'=>json_encode($params['data'] ?? ''),'type'=>$type]);
  2207. }
  2208. public function saveDmReport($data)
  2209. {
  2210. $this->butt->insertDmLog(['data'=>json_encode($data),'type'=>2]);
  2211. $exam = [];
  2212. if(!empty($data['B']['BD']))
  2213. {
  2214. $where = ['imagenumber'=>$data['B']['BD'],'institution_id'=>$data['B']['BJ']];
  2215. $exam = $this->butt->getExam($where,'*');
  2216. }
  2217. $report = $this->makeReportData($data);
  2218. if(empty($exam))
  2219. {
  2220. $report['id'] = UUIDUtils::uuid();
  2221. $this->butt->insertReport($report);
  2222. return $report['id'];
  2223. }else{
  2224. $report['exam_id'] = $exam['id'];
  2225. $old = $this->butt->getReportData(['exam_id'=>$exam['id'],'type'=>1],'*');
  2226. if(empty($old))
  2227. {
  2228. //
  2229. $report['id'] = UUIDUtils::uuid();
  2230. $this->butt->insertReport($report);
  2231. }else{
  2232. $this->butt->updateReport($report,['id'=>$old['id']]);
  2233. $report['id'] = $old['id'];
  2234. }
  2235. $this->butt->updateExam(['exam_status'=>9],$exam['id']);
  2236. return $report['id'];
  2237. }
  2238. }
  2239. public function makeReportData($data)
  2240. {
  2241. $report = [];
  2242. $report['description'] = $data['C']['CD'];
  2243. $report['impression'] = $data['C']['CE'];
  2244. $report['report_result'] = ($data['C']['CF'] == 9) ? null : $data['C']['CF'];
  2245. $report['report_doctor_name'] = $data['C']['CH'];
  2246. $report['review_doctor_name'] = $data['C']['CI'];
  2247. $report['confirm_doctor_name'] = $data['C']['CI'];
  2248. $report['report_datetime'] = $data['C']['CJ'];
  2249. $report['review_datetime'] = $data['C']['CK'];
  2250. $report['confirm_datetime'] = $data['C']['CK'];
  2251. $report['imagenumber'] = $data['B']['BD'];
  2252. return $report;
  2253. }
  2254. /**
  2255. * AES-128-ECB 解密方法
  2256. * @param string $str 需要解密的 Base64 编码字符串
  2257. * @return string 解密后的原始数据
  2258. */
  2259. public function aesDecrypt($str)
  2260. {
  2261. $key = 'ghbfdmlyhxdxlyjl';
  2262. if($str) {
  2263. return openssl_decrypt(base64_decode($str), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  2264. }
  2265. return $str;
  2266. }
  2267. /*
  2268. * 获取检查报告
  2269. * @param $param
  2270. * type:查询类型
  2271. * code: 加密值
  2272. * institution_id: 机构id
  2273. */
  2274. public function getStudyUrl($param)
  2275. {
  2276. $acc = openssl_decrypt(base64_decode($param['code']), 'AES-128-ECB', 'ghbfdmlyhxdxlyjl', OPENSSL_RAW_DATA);
  2277. if(empty($acc))
  2278. {
  2279. return ['code'=>1,'msg'=>$param['code'].'密文无法解密,请联系管理员'];
  2280. }
  2281. if (empty($param['institution_id'])){
  2282. return ['code'=>1,'msg'=>'请选择机构'];
  2283. }
  2284. if (!in_array($param['type'],['1','2','3','4','5'])){
  2285. return ['code'=>1,'msg'=>'请选择查询类型'];
  2286. }
  2287. $where = [];
  2288. switch ($param['type']){
  2289. case '1':
  2290. //病历号
  2291. $where['PATIENT_NUM'] = $acc;
  2292. break;
  2293. case '2':
  2294. //检查号
  2295. $where['ACCESSION_NUM'] = $acc;
  2296. break;
  2297. case '3':
  2298. //住院号hopitalized_no
  2299. $where['HOPITALIZED_NO'] = $acc;
  2300. break;
  2301. case '4':
  2302. //身份证
  2303. $where['CARD_NUM'] = $acc;
  2304. break;
  2305. case '5':
  2306. //手机号
  2307. $where['PHONE'] = $acc;
  2308. break;
  2309. }
  2310. $where['INSTITUTION_ID'] = $param['institution_id'];
  2311. $study = $this->butt->getExam($where,['STUDY_ID']);
  2312. if(empty($study))
  2313. {
  2314. return ['code'=>1,'msg'=>$acc.'的检查未找到'];
  2315. }
  2316. if(empty($param['url']))
  2317. {
  2318. $domain = 'http://10.25.14.2:9603';
  2319. }else{
  2320. $domain = $param['url'];
  2321. }
  2322. $study_id = $study['study_id'];
  2323. $url = "http://10.25.14.2:9603/#/pc?studyurl=http://10.25.14.2:9603/query/?study_id=".$study_id;
  2324. return ['code'=>0,'url'=>$url];
  2325. }
  2326. }