ButtService.php 83 KB

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