123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202 |
- <?php
- namespace app\api\servies\butt;
- use app\api\change\PinyinChange;
- use app\api\dao\applets\AppletsDao;
- use app\api\dao\report\ReportDao;
- use app\api\dao\register\RegisterDao;
- use app\api\model\debug\DebugModel;
- use app\api\servies\application\ApplicationService;
- use app\api\servies\report\ReportService;
- use app\api\servies\ZskkDefaultService;
- use app\api\dao\butt\ButtDao;
- use app\api\utils\UUIDUtils;
- use app\common\library\Gm;
- use app\common\library\PublicPhone;
- use app\common\library\send_message;
- use PHPMailer\PHPMailer\PHPMailer;
- use think\Db;
- use think\Exception;
- use think\facade\Config;
- use think\facade\Log;
- use think\exception\DbException;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class ButtService extends ZskkDefaultService {
- protected $logName = "ButtService";
- private $butt = null;
- private $applets = null;
- private $application = null;
- private $reportDao = null;
- private $registerDao = null;
- public function __construct(ButtDao $buttDao,AppletsDao $appletsDao,ApplicationService $application,ReportDao $reportDao,RegisterDao $registerDao) {
- parent::__construct();
- $this->butt = $buttDao;
- $this->applets = $appletsDao;
- $this->application = $application;
- $this->reportDao = $reportDao;
- $this->registerDao = $registerDao;
- }
- public function save_report($params)
- {
- // try{
- $time1 = time();
- Log::record('当前传参为'.json_encode($params));
- // Db::startTrans();
- if(isset($params['type']) && !empty($params['type']))
- {
- if(empty(Config::get('report_save_type')[$params['type']]))
- {
- $this->throwError('非规则内的type值',0002);
- }
- if(empty($params['code']) || empty($params['institution_id']))
- {
- $this->throwError('参数错误',0003);
- }
- $search = [Config::get('report_save_type')[$params['type']]=>$params['code']];
- $exams = $this->butt->getExamBySearch($search,$params['institution_id']);
- // if(count($exams) !== 1)
- // {
- // $this->throwError('存在复数的检查,请联系管理员',0004);
- // }
- // $exam = $exams[0];
- }else{
- $exam = $this->butt->getExamById($params['exam_id']);
- $exams[] = $exam;
- }
- if(empty($exams))
- {
- $this->throwError('找不到检查',0004);
- }
- $id = '';
- foreach ($exams as $exam)
- {
- // if($exam['exam_status'] != '3'){
- // $this->throwError('报告重复','0999');
- // }
- $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
- $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
- $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
- $report = [
- 'id'=>UUIDUtils::uuid(),
- 'exam_id'=>$exam['id'],
- 'report_doctor_id'=>$reportDoctor,
- 'report_doctor_name'=>$params['report_doctor_name'],
- 'report_datetime'=>$params['report_datetime'],
- 'review_doctor_id'=>$reviewDoctor,
- 'review_doctor_name'=>$params['review_doctor_name'],
- 'review_datetime'=>$params['review_datetime'],
- 'confirm_doctor_id'=>$confirmDoctor,
- 'confirm_doctor_name'=>$params['confirm_doctor_name'],
- 'confirm_datetime'=>$params['confirm_datetime'],
- 'description'=>$params['description'],
- 'impression'=>$params['impression'],
- 'report_result'=>$params['report_result'],
- 'type'=>1
- ];
- $id = $report['id'];
- $report_id = $this->butt->checkReport($exam['id']);
- if(!empty($report_id)){
- unset($report['id']);
- $id = $report_id;
- $this->butt->saveReport($report,$report_id);
- $report['id'] = $report_id;
- }else{
- $this->butt->saveReport($report);
- }
- $url = 'https://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
- // exec("nohup /bin/curl '$url' > /dev/null &");
- // $this->curl_get($url);
- $examData = [
- 'exam_status'=>9,
- 'application_department'=>$params['application_department'] ?? null,
- 'application_doctor'=>$params['application_doctor'] ?? null,
- 'clin_diag'=>$params['clin_diag'] ?? null,
- 'clin_symp'=>$params['clin_symp'] ?? null,
- 'name'=>$params['name'],
- 'report_result'=>$params['report_result'] ?? ''
- ];
- if(isset($params['patient_source']) && !empty($params['patient_source']))
- {
- $examData['patient_source'] = $params['patient_source'];
- }
- if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
- {
- $examData['hopitalized_no'] = $params['hopitalized_no'];
- }
- if(isset($params['out_patient']) && !empty($params['out_patient']))
- {
- $examData['out_patient'] = $params['out_patient'];
- }
- if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
- {
- $examData['his_patient_id'] = $params['his_patient_id'];
- }
- $patient = [];
- if(isset($params['exam_class']) && !empty($params['exam_class']))
- {
- $examData['exam_class'] = $params['exam_class'];
- if($params['institution_id'] == '16100014')
- {
- if($examData['exam_class' == 'RF'])
- {
- $examData['exam_class'] = 'DX';
- }
- }
- }
- if(isset($params['phone']) && !empty($params['phone']))
- {
- $examData['phone'] = $params['phone'];
- $patient['phone'] = $params['phone'];
- }
- if(isset($params['card_num']) && !empty($params['card_num']))
- {
- $examData['card_num'] = $params['card_num'];
- $patient['card_num'] = $params['card_num'];
- }
- if(isset($params['exam_project']) && !empty($params['exam_project']))
- {
- $examData['exam_project'] = $params['exam_project'];
- if(empty($exam['body_part_text'] ?? ''))
- {
- $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
- }
- }
- if(isset($params['exam_method']) && !empty($params['exam_method']))
- {
- $examData['exam_method'] = $params['exam_method'];
- }
- //medical_code 国家医保信息平台人员管理码
- //body_part_code 检查部位代码
- //device_code 医保医用设备代码
- $examData['medical_code'] = $params['medical_code'] ?? str_pad(0, 26, "0", STR_PAD_LEFT);
- $examData['body_part_code'] = $params['body_part_code'] ?? str_pad(0, 9, "0", STR_PAD_LEFT);
- $examData['device_code'] = $params['device_code'] ?? str_pad(0, 13, "0", STR_PAD_LEFT);
- $study = $this->butt->getStudyByExamId($exam['id']);
- if(!empty($study['studytime'] ?? ''))
- {
- $studyDate = $study['studytime'];
- $examData['exam_datetime_code'] = $exam['exam_datetime'].substr($studyDate, 0, 4);
- }
- $this->butt->updateExam($examData,$exam['id']);
- PublicPhone::savePublicSearch($params['phone'] ?? '',$exam['id'] ?? '');
- $patientId = $exam['patient_id'];
- $patient['name'] = $params['name'];
- $this->butt->updatePatient($patient,$patientId);
- $institution = $this->butt->getIns($exam['institution_id']);
- if($institution['keyword_switch'] == 1)
- {
- $wechat = [
- 'type'=>7,
- 'id'=>$exam['id'],
- 'report_id'=>$id,
- ];
- $wechat = json_encode($wechat);
- $wechatUrl = 'https://ws4.pacsonline.cn/sendWechatMsg?params='.$wechat;
- $this->curl_get($wechatUrl);
- }
- Log::record('当前医院是否发送短信'.$institution['patient_sms']);
- if($institution['patient_sms'] == 1)
- {
- log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
- $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
- if(empty($telSend))
- {
- log::record('手机号'.($params['phone'] ?? $exam['phone']),'没有发送过短信');
- // 为空 没有发送过短信
- $this->sendSms(($params['phone'] ?? $exam['phone']),$exam['id'],$exam['study_id'],$exam['institution_id'],3,($params['exam_class'] ?? $exam['exam_class']),$exam['exam_datetime']);
- }
- }
- if(in_array($exam['institution_id'],['13000003','04500002']))
- {
- $newExam = $this->butt->getExamById($exam['id']);
- $this->saveHrData($newExam,$report,$institution);
- }
- }
- // DB::commit();
- $time2 = time();
- $time = $time2-$time1;
- $this->saveMonitorReport($params,$institution);
- //$this->butt->insertSpecialLog($time,'butt/saveReport');
- return $id;
- // } catch (\Exception $exception){
- // DB::rollback();
- // $this->throwError($exception->getMessage(),0001);
- // }
- }
- public function saveMonitorReport($params,$institution)
- {
- $arr = [];
- $arr['institution_id'] = $institution['id'];
- $arr['institution_name'] = $institution['name'];
- $arr['name'] = $params['name'];
- $this->butt->saveMonitorReport($arr);
- }
- public function saveHrData($exam, $report,$institution)
- {
- $hrItems = $this->butt->getHrItems($exam['exam_project']);
- if(empty($hrItems))
- {
- return '';
- }
- if($this->getCache('hrToken'))
- {
- // 已获取过登陆 todo
- $return = $this->getCache('hrToken');
- }else{
- $return = $this->getHrToken();
- if($return == 'error')
- {
- // 错误 todo
- return 'error';
- }
- }
- $header = array ("Content-Type: application/json;charset=utf-8","Authorization: Bearer $return");
- $arr = $this->makeHrData($exam,$report,$institution,$hrItems);
- $hrInfo = $this->request_by_curl("https://8001.pacsonline.cn/zskk/api/postExamReport",json_encode($arr),$header);
- }
- public function makeHrData($exam, $report,$institution,$hrItems)
- {
- switch ($exam['sex'])
- {
- case 'M':
- $sex = '1';
- break;
- case 'F':
- $sex = '2';
- break;
- case 'O':
- $sex = '9';
- break;
- default:
- $sex = '0';
- break;
- }
- $arrA = [
- 'AA'=>$exam['name'], // 姓名
- 'AB'=>'01', // 证件类型编码
- 'AC'=>$exam['card_num'], // 证件号码
- 'AD'=>$sex, // 性别编码
- 'AE'=>$exam['birthday'], // 出生日期
- ];
- switch ($exam['patient_source'])
- {
- case '1':
- $source = '2';
- break;
- case '2':
- $source = '3';
- break;
- case '3':
- $source = '1';
- break;
- case '4':
- $source = '4';
- break;
- default:
- $source = '';
- break;
- }
- $arrB = [
- 'BA'=>$source, //就诊类型编码 1 门诊 2 急诊 3 住院 4 体检 9 其他
- 'BB'=>$exam['patient_num'], //就诊卡号
- 'BC'=>$exam['patient_num'], //就诊号
- 'BD'=>$exam['institution_id'], //医院主索引
- 'BE'=>$exam['exam_datetime'], //就诊时间 todo
- 'BF'=>$exam['application_department'], //就诊科室名称
- 'BG'=>$exam['clin_symp'], //主诉 使用症状
- 'BH'=>$exam['age'], //年龄
- 'BI'=>$exam['institution_id'], //机构编码
- 'BJ'=>$institution['name'], //机构名称
- 'BK'=>'', //诊断编码
- 'BL'=>'', //DIAGNOSENAME
- 'BM'=>$exam['application_doctor'], //DOCTORNAME
- 'BN'=>$exam['application_doctor'], //DOCTORCODE
- ];
- switch ($report['report_result'])
- {
- case '1':
- $result = '1';
- break;
- case '2':
- $result = '2';
- break;
- default:
- $result = '9';
- break;
- }
- $arrC = [
- 'CA'=>$exam['study_id'], //申请单编号/医嘱编号
- 'CB'=>$report['id'], //报告单编号
- 'CC'=>$exam['exam_class'], //检查类型
- 'CD'=>$exam['exam_project'], //检查项目名称 todo
- 'CE'=>$hrItems['code'], //检查项目编码
- 'CF'=>$exam['body_part_text'], //检查部位
- 'CG'=>$report['description'], //检查所见/影像所见
- 'CH'=>$report['impression'], //影像诊断/意见
- 'CI'=>$result, //检查结果类别
- 'CJ'=>'', //互认范围
- 'CK'=>$hrItems['code'], //互认项目编码
- 'CL'=>$institution['name'], //报告机构
- 'CM'=>$exam['institution_id'], //报告机构编码
- 'CN'=>'影像科', //报告科室名称
- 'CO'=>$report['report_doctor_name'], //报告医生姓名
- 'CP'=>$report['review_doctor_name'], //审核医师姓名
- 'CQ'=>$report['report_datetime'], //报告时间
- 'CR'=>$exam['exam_datetime'], //检查时间
- 'CS'=>'', //报告单内容
- 'CT'=>$hrItems['name'], //互认项目
- ];
- $arr = [
- 'A'=>$arrA,
- 'B'=>$arrB,
- 'C'=>[$arrC]
- ];
- $key = 'zLxapoeqWYpoeqWY';
- $json = base64_encode(json_encode($arr));
- $jm = Gm::encrypt($key,$json);
- return ['data'=>$jm];
- }
- public function getHrToken()
- {
- $clientid = '12371600494581158K';
- $clientsecret = '837ffb03803b72cd99a941770fb6b2be';
- $arr = ['request_time'=>time(),'request_no'=>time(),'data'=>['clientid'=>$clientid,'clientsecret'=>$clientsecret]];
- $return = $this->request_by_curl("https://8001.pacsonline.cn/zskk/api/getToken",json_encode($arr));
- $return = json_decode($return,true);
- if($return['code'] == 1)
- {
- // 请求成功
- $this->setCache('hrToken',$return['data']['token'],3500);
- return $return['data']['token'];
- }else{
- return 'error';
- }
- }
- public function sendS($phone,$datetime,$insName,$exam_class,$id)
- {
- $appid = '111345'; //appid参数
- $appkey = 'ccf6327cf227f5f54292dd1bf9479852'; //appkey参数
- $to = $phone; //收信人 手机号码
- // $project_id = 'CzMP41'; //模板ID
- // $project_id = '9AafR2'; //模板ID
- $project_id = '1Wzd84'; //模板ID
- $vars = json_encode(array( //模板对应变量
- 'val1'=>$datetime,'val2'=>$insName,'val3'=>$exam_class,'val4'=>$id
- )); //收信人 手机号码
- // $project_id = '3mPW44'; //模板ID
- // $vars = json_encode(array( //模板对应变量
- // 'var1'=>$insName,'var2'=>$exam_class,'var3'=>$id //模板对应变量
- //// 'val1'=>$datetime,'val2'=>$insName,'val3'=>$exam_class,'val4'=>$id
- // ));
- $post_data = array(
- "appid" => $appid,
- "signature" => $appkey,
- "to" => $to,
- "project" => $project_id,
- "vars" => $vars
- );
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => 'https://api-v4.mysubmail.com/sms/xsend.json',
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_POST => 0,
- CURLOPT_POSTFIELDS => $post_data,
- CURLOPT_HEADER => 0,
- CURLOPT_SSL_VERIFYHOST=>false,
- CURLOPT_SSL_VERIFYPEER=>false,
- ));
- $output = curl_exec($ch);
- $data = json_decode($output,true);
- return $data;
- }
- public function sendSms($phone,$examId,$studyId,$institution,$source,$exam_class='',$exam_datetime='')
- {
- $data = $this->butt->getInsById($institution);
- $name = $data['name'];
- if(!empty($data['filter']))
- {
- $filter = json_decode($data['filter'],true);
- if(!empty($filter) && !empty($filter['exam_class'] ?? ''))
- {
- $class = explode(',',$filter['exam_class']);
- if(in_array($exam_class,$class))
- {
- return '';
- }
- }
- }
- $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
- $id = UUIDUtils::uuid();
- if(empty($phone)){
- $send_message = 0;
- }else{
- //发送短信
- // $send = send_message::sendExam2Patient($phone,$code,$name,$id);
- $note = [
- // 'long_url'=>'https://wc4.pacsonline.cn/#/jump?id='.$id
- 'long_url'=>'https://wc4.pacsonline.cn/#/reportInfo/report?id='.$id.'&short=1&is_dcm=1&isAnonymous=0&isEncrypt=0'
- ];
- $noteId = $this->reportDao->insertNote($note);
- $nid = base64_encode(str_pad(base_convert($noteId,10,36),6,'0',STR_PAD_LEFT));
- $return = $this->sendS($phone,$exam_datetime,$name,$exam_class,$nid);
- // if($institution == '43600001')
- // {
- // if($exam_class == 'US'){
- // return '';
- // }
- // $send = send_message::sendEZShortMessage($phone,$code,$nid);
- // }elseif($institution == '03060002'){
- // $send = send_message::sendReportShortMessage($phone,$name);
- // }else{
- // $send = send_message::sendExam2ShortPatient($phone,$code,$name,$nid);
- // }
- // $data = json_decode(json_encode($send),true);
- // if($data['Code'] == 'OK'){
- // $send_message = 1;
- // }else{
- // $send_message = 0;
- // }
- // $data = json_decode($return,true);
- if($return['status'] == 'success'){
- $send_message = 1;
- }else{
- $send_message = 0;
- }
- $share = [
- 'id'=>$id,
- 'examId'=>$examId,
- 'status'=>1,
- 'overdueTime'=>5475,
- 'code'=>$code,
- 'short_url'=>'',
- 'phone'=>$phone,
- 'report_isset'=>1,
- 'study_id'=>$studyId,
- 'source'=>$source,
- 'send_message'=>$send_message,
- ];
- $this->reportDao->insertShare($share);
- $smsLog = [
- 'exam_id'=>$examId,
- 'institution_id'=>$institution,
- 'send_message'=>$send_message,
- 'phone'=>$phone,
- 'status'=>$send_message
- ];
- $this->reportDao->insertSMSLog($smsLog);
- }
- }
- public function save_exam($params)
- {
- try{
- $exam = $this->butt->getExamById($params['exam_id']);
- if($exam['exam_status'] != '3'){
- $this->throwError('报告重复','0999');
- }
- // $reportDoctor = $this->getReportDoctor($params['report_doctor_name'],$exam['institution_id']);
- // $reviewDoctor = $this->getReportDoctor($params['review_doctor_name'],$exam['institution_id']);
- // $confirmDoctor = $this->getReportDoctor($params['confirm_doctor_name'],$exam['institution_id']);
- // $report = [
- // 'id'=>UUIDUtils::uuid(),
- // 'exam_id'=>$params['exam_id'],
- // 'report_doctor_id'=>$this->butt->getDcotorId($params['report_doctor_name'],$exam['institution_id']),
- // 'report_doctor_name'=>$params['report_doctor_name'],
- // 'report_datetime'=>$params['report_datetime'],
- // 'review_doctor_id'=>$this->butt->getDcotorId($params['review_doctor_name'],$exam['institution_id']),
- // 'review_doctor_name'=>$params['review_doctor_name'],
- // 'review_datetime'=>$params['review_datetime'],
- // 'confirm_doctor_id'=>$this->butt->getDcotorId($params['confirm_doctor_name'],$exam['institution_id']),
- // 'confirm_doctor_name'=>$params['confirm_doctor_name'],
- // 'confirm_datetime'=>$params['confirm_datetime'],
- // 'description'=>$params['description'],
- // 'impression'=>$params['impression'],
- // 'report_result'=>$params['report_result'],
- // 'type'=>1
- // ];
- // $id = $report['id'];
- // $report_id = $this->butt->checkReport($params['exam_id']);
- // if(!empty($report_id)){
- // unset($report['id']);
- // $this->butt->saveReport($report,$report_id);
- // }else{
- // $this->butt->saveReport($report);
- // }
- // $url = 'http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId='.$id.'&version=3';
- // $this->curl_get($url);
- $params['phone'] = trim($params['phone']);
- $examData = [
- 'application_department'=>$params['application_department'] ?? null,
- 'application_doctor'=>$params['application_doctor'] ?? null,
- 'clin_diag'=>$params['clin_diag'] ?? null,
- 'clin_symp'=>$params['clin_symp'] ?? null,
- 'name'=>$params['name'],
- 'phone'=>$params['phone'],
- 'card_num'=>$params['card_num'] ?? null,
- 'patient_source'=>$params['patient_source'] ?? null
- ];
- if(isset($params['exam_project']) && !empty($params['exam_project'])){
- $examData['exam_project'] = $params['exam_project'];
- if(empty($exam['body_part_text'] ?? ''))
- {
- $examData['body_part_text'] = $this->butt->getBodyByProject($params['exam_project']);
- }
- }
- if(isset($params['device_name']) && !empty($params['device_name'])){
- $examData['device_name'] = $params['device_name'];
- }
- if(isset($params['exam_class']) && !empty($params['exam_class']))
- {
- $examData['exam_class'] = $params['exam_class'];
- }
- if(isset($params['hopitalized_no']) && !empty($params['hopitalized_no']))
- {
- $examData['hopitalized_no'] = $params['hopitalized_no'];
- }
- if(isset($params['out_patient']) && !empty($params['out_patient']))
- {
- $examData['out_patient'] = $params['out_patient'];
- }
- if(isset($params['his_patient_id']) && !empty($params['his_patient_id']))
- {
- $examData['his_patient_id'] = $params['his_patient_id'];
- }
- if(isset($params['exam_method']) && !empty($params['exam_method']))
- {
- $examData['exam_method'] = $params['exam_method'];
- }
- $examData['sync_exam'] = 1;
- $this->butt->updateExam($examData,$params['exam_id']);
- $institution = $this->butt->getIns($exam['institution_id']);
- Log::record('当前医院是否发送短信'.$institution['patient_sms']);
- if($institution['patient_sms'] == 1)
- {
- // log::record('可以发送短信,查看检查id'.$exam['id'].'查看study是'.$exam['study_id']);
- // $telSend = $this->butt->getHistorySend($exam['id'],$exam['study_id']);
- // if(empty($telSend))
- // {
- // log::record('手机号'.$params['phone'],'没有发送过短信');
- // // 为空 没有发送过短信
- // $this->sendSms($params['phone'],$exam['id'],$exam['study_id'],$exam['institution_id'],2);
- // }
- }
- $patientId = $exam['patient_id'];
- $patient = [
- 'name'=>$params['name'],
- 'phone'=>$params['phone'],
- 'card_num'=>$params['card_num'] ?? null
- ];
- $this->butt->updatePatient($patient,$patientId);
- $this->saveMonitorExam($params,$institution);
- return $params['exam_id'];
- } catch (DbException $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function save_register($params)
- {
- try{
- $field = [
- 'application_department',
- 'application_doctor',
- 'clin_diag',
- 'clin_symp',
- 'name',
- 'phone',
- 'card_num',
- 'patient_source',
- 'exam_project',
- 'exam_class',
- 'hopitalized_no',
- 'out_patient',
- 'his_patient_id',
- 'exam_method',
- 'studyuid',
- 'accession_num',
- 'patient_num',
- 'institution_id',
- 'age',
- 'exam_datetime'
- ];
- $examData = $this->makeRegisterExamData($params,$field);
- $examData['id'] = UUIDUtils::uuid();
- $examData['patient_id'] = UUIDUtils::uuid();
- if(isset($params['is_dcm']) && $params['is_dcm'] == 2)
- {
- $examData['is_dcm'] = 2;
- }
- $this->butt->insertExam($examData);
- $patient = [
- 'id'=>$examData['patient_id'],
- 'name'=>$params['name'],
- 'phone'=>$params['phone'] ?? null,
- 'card_num'=>$params['card_num'] ?? null,
- 'temp_patient_id'=>$params['patient_num'] ?? null,
- 'institution_id'=>$params['institution_id'],
- 'age'=>$params['age'] ?? null
- ];
- $this->butt->insertPatient($patient);
- return $examData['id'];
- } catch (DbException $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function saveFiles($params)
- {
- $fileData = [];
- if(isset($params['data']) && !empty($params['data']))
- {
- $data = [
- 'exam_id'=>$params['id']
- ];
- $url = json_decode($params['data'],true);
- foreach ($url as $v)
- {
- $data['type']=$v['type'];
- $data['url']=$v['url'];
- $fileData[] = $data;
- }
- }
- if(empty($fileData))
- {
- return '';
- }
- $return = $this->butt->saveFileData($fileData);
- $this->butt->updateExam(['exam_status'=>3],$params['id']);
- return $return;
- }
- public function makeRegisterExamData($data,$field)
- {
- $examData = [];
- foreach ($field as $v)
- {
- if(isset($data[$v]) && !empty($data[$v]))
- {
- $examData[$v] = $data[$v];
- }
- }
- return $examData;
- }
- public function getReportDoctor($name,$institution)
- {
- if($name == ''){
- return '';
- }
- $id = $this->butt->getDcotorId($name,$institution);
- if(empty($id)){
- $doctor = [
- 'id'=>UUIDUtils::uuid(),
- 'realname'=>$name,
- 'institution_id'=>$institution,
- 'password'=>md5('zskk1234'),
- 'username'=>'none'
- ];
- $this->butt->makeDcotor($doctor);
- return $doctor['id'];
- }
- return $id;
- }
- public function getExam($params)
- {
- $timeWhere = '';
- if(isset($params['createdAt']) && !empty($params['createdAt']))
- {
- $time = explode(',',$params['createdAt']);
- $timeWhere = "createdAt between '$time[0]' and '$time[1]'";
- }
- if(isset($params['exam_status']) && !empty($params['exam_status']))
- {
- $status = explode(',',$params['exam_status']);
- }else{
- $status = [3];
- }
- $where = [];
- if(isset($params['is_sync']) && $params['is_sync'] == '0')
- {
- $where = ['sync_exam'=>'0'];
- }
- $data = $this->butt->getExams($params['institution_id'],$params['num'],$where,$timeWhere,$status);
- return $data;
- }
- public function getReports($params)
- {
- $timeWhere = '';
- if(isset($params['date']) && !empty($params['date']))
- {
- $time = explode(',',$params['date']);
- $timeWhere = "confirm_datetime between '$time[0]' and '$time[1]'";
- }
- $data = $this->butt->getReports($params['institution_id'],$params['page'],$params['num'],$timeWhere);
- foreach ($data as $k=>$v)
- {
- $data[$k]['impression'] = strip_tags($v['impression']);
- $data[$k]['description'] = strip_tags($v['description']);
- }
- return $data;
- }
- public function getConfirmExams($params)
- {
- $data = $this->butt->getConfirmExams($params['institution_id'],$params['num']);
- return $data;
- }
- public function sendDingDing()
- {
- $time = time()* 1000;
- $secret = 'SECc2b5ad43721741fe16f6ac39ed423b047668fd691c01f9a051037bf4733a09e8';
- $m = $time."\n".$secret;
- $s = hash_hmac('sha256', $m, $secret, true);
- $a = base64_encode($s);
- $b = urlencode($a);
- $dingurl = Config::get('dingding_url');
- $url =$dingurl."/robot/send?access_token=2030ac71bf6811a7caad9a34899e686df9bef4e45d1c990b14339ba65c333776×tamp=$time&sign=$b";
- $message = '';
- $user_wechat = $this->butt->getUserWechat();
- $message .= "累计公众号关注人数:".$user_wechat['all'];
- $yestWechat = $this->butt->getYestNumber(); //获取昨日的已关注数量
- if((int)$user_wechat['now'] >= (int)$yestWechat){
- $user_different = "增加".((int)$user_wechat['now']-(int)$yestWechat).'人';
- }else{
- $user_different = "减少".((int)$yestWechat-(int)$user_wechat['now']).'人';
- }
- $message .= "\n公众号实时关注总人数为".$user_wechat['now'].'人';
- $message .= "\n公众号实时关注人数较昨日".$user_different;
- $exams = $this->butt->getExamData();
- $message .= "\n昨日新增数字胶片量:".$exams['yest']."张";
- // $message .= "\n昨日财务流水:".($exams['yest']*20);
- $message .= "\n累计数字胶片量:".$exams['all']."张";
- $message .= "\n胶片增长率:".$exams['percentage']."%";
- $picNumber = $this->butt->getPicNumber();
- $message .= "\n昨日查阅数字胶片量:".$picNumber['yestAll']."次(昨日患者共计查阅胶片次数)";
- $message .= "\n昨日新增查阅数字胶片量:".$picNumber['yest']."次(去重查阅)";
- $institutionInfo = $this->butt->getInsInfo();
- $message .= "\n新增医院数:".$institutionInfo['yest']."家 ";
- // 新增医院名称
- if($institutionInfo['yest'] > 0){
- foreach ($institutionInfo['name'] as $k=>$v){
- $message .= $v['name'].' ';
- }
- }
- $message .= "\n累计医院数:".$institutionInfo['all']."家";
- $ins_all_info = $this->butt->getAllInsInfo();
- $b = $ins_all_info['patient_num'];
- $d = $ins_all_info['accession_num'];
- $e = $ins_all_info['phone'];
- $f= $ins_all_info['card_num'];
- $g = $ins_all_info['hopitalized_no'];
- $c = [];
- foreach ($b as $k=>$v)
- {
- if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
- {
- $c[$v['institution_id']]['num']++;
- }else{
- $c[$v['institution_id']]['num'] = 1;
- $c[$v['institution_id']]['name'] = $v['name'];
- $c[$v['institution_id']]['code'] = $v['patient_num'];
- }
- }
- foreach ($d as $k=>$v)
- {
- if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['accession_num']){
- continue;
- }
- if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
- {
- $c[$v['institution_id']]['num']++;
- }else{
- $c[$v['institution_id']]['num'] = 1;
- $c[$v['institution_id']]['name'] = $v['name'];
- $c[$v['institution_id']]['code'] = $v['accession_num'];
- }
- }
- foreach ($e as $k=>$v)
- {
- if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['phone']){
- continue;
- }
- if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
- {
- $c[$v['institution_id']]['num']++;
- }else{
- $c[$v['institution_id']]['num'] = 1;
- $c[$v['institution_id']]['name'] = $v['name'];
- $c[$v['institution_id']]['code'] = $v['phone'];
- }
- }
- foreach ($f as $k=>$v)
- {
- if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['card_num']){
- continue;
- }
- if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
- {
- $c[$v['institution_id']]['num']++;
- }else{
- $c[$v['institution_id']]['num'] = 1;
- $c[$v['institution_id']]['name'] = $v['name'];
- $c[$v['institution_id']]['code'] = $v['card_num'];
- }
- }
- foreach ($g as $k=>$v)
- {
- if(isset($c[$v['institution_id']]['code']) && $c[$v['institution_id']]['code'] == $v['hopitalized_no']){
- continue;
- }
- if(isset($c[$v['institution_id']]['num']) && !empty($c[$v['institution_id']]['num']))
- {
- $c[$v['institution_id']]['num']++;
- }else{
- $c[$v['institution_id']]['num'] = 1;
- $c[$v['institution_id']]['name'] = $v['name'];
- $c[$v['institution_id']]['code'] = $v['hopitalized_no'];
- }
- }
- $message .= "\n新增医院名称与每日每家新增量:";
- $i = 1;
- foreach ($c as $key => $row)
- {
- $volume[$key] = $row['num'];
- }
- array_multisort($volume, SORT_DESC, $c);
- foreach ($c as $k=>$v){
- if($i > 49)
- {
- continue;
- }
- $ins_name = $v['name'];
- $ins_num = $v['num'];
- if($i < 10)
- {
- $a = $i." ";
- }else{
- $a = $i;
- }
- $message .= "\n $a:$ins_name \n \t\t 新增胶片查阅量:$ins_num";
- $i++;
- }
- $data = array ('msgtype' => 'text','text' => array ('content' => $message));
- $data_string = json_encode($data);
- $result = $this->request_by_curl($url, $data_string);
- Log::record('钉钉返回'.$result);
- $message0 = '医院昨日检查/报告/报告率统计:';
- $allIns = $this->butt->getAllIns();
- $yestExams = $this->butt->getYestExams();
- $YestCompleteExams = $this->butt->getYestCompleteExams();
- foreach ($yestExams as $v)
- {
- $message0 .= "\n ".($allIns[$v['institution_id']] ?? '').':'.$v['c'].'/'.($YestCompleteExams[$v['institution_id']] ?? 0).'/'.(number_format(($YestCompleteExams[$v['institution_id']] ?? 0)/$v['c'],2)*100).'%';
- }
- $data0 = array ('msgtype' => 'text','text' => array ('content' => $message0));
- $data_string0 = json_encode($data0);
- $result = $this->request_by_curl($url, $data_string0);
- $ding = [
- 'wechat_bind_all'=>$user_wechat['all'],
- 'wechat_yestday_focus'=>$user_wechat['now'],
- 'exam_all'=>$exams['all'],
- 'exam_yestday_add'=>$exams['yest'],
- 'exam_add_percentage'=>$exams['percentage']."%",
- 'film_all'=>$exams['all'],
- 'film_yestday_add'=>$exams['yest'],
- 'film_add_percentage'=>$exams['percentage']."%",
- 'film_yest_look_all'=>$picNumber['yestAll'],
- 'film_yest_look_add'=>$picNumber['yest'],
- 'institution_all'=>$institutionInfo['all'],
- 'institution_add'=>$institutionInfo['yest'],
- ];
- $this->butt->insertDing($ding);
- return $result;
- }
- public function sendHosDing()
- {
- $time = time()* 1000;
- $secret = 'SECc2b5ad43721741fe16f6ac39ed423b047668fd691c01f9a051037bf4733a09e8';
- $m = $time."\n".$secret;
- $s = hash_hmac('sha256', $m, $secret, true);
- $a = base64_encode($s);
- $b = urlencode($a);
- $dingurl = Config::get('dingding_url');
- $url =$dingurl."/robot/send?access_token=2030ac71bf6811a7caad9a34899e686df9bef4e45d1c990b14339ba65c333776×tamp=$time&sign=$b";
- $message = '';
- $institution_ids = $this->butt->getInsIds();
- $no_use = []; // 开通但是没有使用
- $use_his7 = []; //7天以上没有上传
- $use_his1 = []; //1天以上没有上传
- $exam7Out = []; //昨天上传了7天以外的数据
- foreach ($institution_ids as $k=>$v)
- {
- // $k 为医院id $v为名称
- // 获取检查最大时间
- $exam_time = $this->butt->getExamMaxTime($k);
- if(empty($exam_time[0]))
- {
- // 时间为空 代表医院未使用过数据
- $no_use[] = $v;
- }else {
- $diff = time() - strtotime($exam_time[0]);
- if ($diff > 86400*7){
- $array = [$v,$exam_time[0]];
- $use_his7[] = $array;
- }elseif($diff > 86400)
- {
- $array = [$v,$exam_time[0]];
- $use_his1[] = $array;
- }else{
- $examCount = $this->butt->get7OutExam($k);
- if($examCount > 0)
- {
- $exam7Out[] = [$v,$examCount];
- }
- }
- }
- }
- $count1 = count($no_use);
- $count2 = count($use_his7);
- $count3 = count($use_his1);
- $count4 = count($exam7Out);
- foreach ($no_use as $k=>$v)
- {
- if(empty($message))
- {
- $message = "已安装但是后续无使用记录医院共计".$count1."家,分别为:\n".($k+1).":".$v;
- }else{
- $message .= "\n".($k+1).":".$v;
- }
- }
- $data = array ('msgtype' => 'text','text' => array ('content' => $message));
- $data_string = json_encode($data);
- $result = $this->request_by_curl($url, $data_string);
- sleep(1);
- $message1 = '';
- foreach ($use_his7 as $k=>$v)
- {
- $create = explode(' ',$v[1]);
- if(empty($message1))
- {
- $message1 = "超过7天无使用记录的医院共计".$count2."家,分别为:\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
- }else{
- $message1 .= "\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
- }
- }
- $data1 = array ('msgtype' => 'text','text' => array ('content' => $message1));
- $data_string1 = json_encode($data1);
- $result1 = $this->request_by_curl($url, $data_string1);
- sleep(1);
- $message2 = '';
- foreach ($use_his1 as $k=>$v)
- {
- $create = explode(' ',$v[1]);
- if(empty($message2))
- {
- $message2 = "超过1天无使用记录的医院共计".$count3."家,分别为:\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
- }else{
- $message2 .= "\n".($k+1).":".$v[0].",最后上传时间为".$create[0];
- }
- }
- $data2 = array ('msgtype' => 'text','text' => array ('content' => $message2));
- $data_string2 = json_encode($data2);
- $result2 = $this->request_by_curl($url, $data_string2);
- sleep(1);
- $all_message = "已安装但是后续无使用记录医院共计".$count1."家\n";
- $all_message .= "超过7天无使用记录的医院共计".$count2."家\n";
- $all_message .= "超过1天无使用记录的医院共计".$count3."家";
- $data3 = array ('msgtype' => 'text','text' => array ('content' => $all_message));
- $data_string3 = json_encode($data3);
- $result3 = $this->request_by_curl($url, $data_string3);
- sleep(1);
- $at = 1;
- if(!empty($exam7Out))
- {
- $message4 = '';
- foreach ($exam7Out as $k=>$v)
- {
- if($v[1] > 100)
- {
- $at = 2;
- }
- if(empty($message4))
- {
- $message4 = "昨日上传了7天以上的数据的医院共计".$count4."家,分别为:\n".($k+1).":".$v[0].",上传数量为".$v[1];
- }else{
- $message4 .= "\n".($k+1).":".$v[0].",上传数量为".$v[1];
- }
- }
- if($at == 1)
- {
- $data4 = array ('msgtype' => 'text','text' => array ('content' => $message4));
- }else{
- $data4 = array ('msgtype' => 'text','text' => array ('content' => $message4.' @18910065009'),'at'=>['atMobiles'=>['18910065009']]);
- }
- $data_string4 = json_encode($data4);
- $result4 = $this->request_by_curl($url, $data_string4);
- }
- return $result;
- }
- public function getInsNum()
- {
- return 441;
- $ins2 = $this->butt->get2Ins();
- $ins3 = $this->butt->get3Ins();
- $num = count($ins3);
- $a = 1;
- foreach ($ins2 as $k=>$v)
- {
- if(in_array($v['id'],$ins3)){
- continue;
- }else{
- $num++;
- }
- }
- return $num;
- }
- public function exam_search($params)
- {
- $study_id= $params['study_id'] ?? null;
- if(!$study_id)
- {
- return [];
- }
- $institution = $this->butt->getInstitutionId($study_id);
- $search = $this->getSearch($params['search'] ?? null);
- if(empty($search))
- {
- return [];
- }
- $exam = $this->butt->getExamBySearch($search,$institution);
- return $exam;
- }
- public function another_exam_search($params)
- {
- $study_id= $params['study_id'] ?? null;
- if(!$study_id)
- {
- return [];
- }
- $institutionId = $this->butt->getInstitutionId($study_id);
- $where = [];
- if($institutionId == '16100017') {
- $name = $this->butt->getPatientNameByStudyId($study_id);
- if(empty($name))
- {
- return [];
- }
- $where['institution_id'] = $institutionId;
- $where['name'] = $name;
- } else {
- $patient = $this->butt->getPatientByStudyId($study_id);
- if(empty($patient))
- {
- return [];
- }
- $where['patient_id'] = $patient;
- }
- $exam = $this->butt->getExamByPatient($where);
- return $exam;
- }
- public function getSearch($search)
- {
- $search_array = '';
- if(empty($search))
- {
- return [];
- }
- $search_array = "name='$search' or patient_num='$search' or accession_num='$search'";
- return $search_array;
- }
- public function save_video_url($params)
- {
- if(empty($params['video_url']))
- {
- $this->throwError('无效的url地址',0045);
- }
- $data = [
- 'video_url'=>$params['video_url'],
- 'doctor_id'=>$params['user_id'],
- 'image_url'=>$params['image_url'] ?? '',
- 'video_type'=>$params['video_type'] ?? '0',
- ];
- if(isset($params['exam_id']) && !empty($params['exam_id']))
- {
- //存在exam_id 则为上传并保存接口
- $data['exam_id'] = $params['exam_id'];
- $data['status'] = 1;
- }
- $info = $this->butt->save_video_url($data);
- return $info;
- }
- public function getWorkList($params)
- {
- $info = $this->butt->getWorkList();
- foreach ($info as $k=>$v)
- {
- $sex = $this->handle_sex($v['Sex']);
- $info[$k]['Sex'] = $sex;
- $info[$k]['DateOfBirth'] = $this->handleTime($v['DateOfBirth']);
- $info[$k]['ExamDateAndTime'] = $this->handleTime($v['ExamDateAndTime']);
- }
- return $info;
- }
- public function handleTime($time)
- {
- $t = strtotime($time);
- $r = date('Y-m-d H:i:s',$t);
- return $r;
- }
- public function handle_sex($sex)
- {
- switch ($sex){
- case 'M':
- case '男':
- return 'M';
- break;
- case 'F':
- case '女':
- return 'F';
- break;
- default:
- return 'O';
- break;
- }
- }
- public function getNotInsReport($param)
- {
- $where_status[] = ['exam_status','in',explode(',',$param['report_status'])];
- $where_institution = ['institution_id'=>$param['institution_id']];
- $time = explode(',',$param['time']);
- $where_time = [$time[0],$time[1]];
- $field = [
- 'e.name',
- 'e.sex',
- 'phone',
- 'card_num',
- 'hopitalized_no',
- 'out_patient',
- 'accession_num',
- 'patient_num',
- 'studyuid',
- 'his_patient_id',
- 'impression',
- 'description',
- 'report_datetime',
- 'report_doctor_name',
- 'review_doctor_name',
- 'review_datetime',
- 'r.report_result'
- ];
- $data = $this->butt->getNotInsReport($where_status,$where_institution,$where_time,$field);
- return $data;
- }
- public function setNameCache($params)
- {
- foreach ($params as $k=>$v)
- {
- // $cache = $this->butt->saveCache($v['INPATIENTNO'],$v['NAME']);
- $key = "worklist_".$v['INPATIENTNO'];
- $cache = $this->butt->saveCache($key, json_encode($v));
- Log::record('存储结果'.$cache.';存储key为'.$key.';存储内容为'.$this->butt->getCache($key));
- }
- return true;
- }
- public function getRisVersion()
- {
- $data = $this->butt->getRisVersion();
- $return = [];
- foreach ($data as $k=>$v)
- {
- $new = 1;
- $time = time()-strtotime($v['time']);
- if($time < 86400*30)
- {
- $new = 2;
- }
- $name = $this->butt->getProjectName($v['project']);
- $info = ['project'=>$v['project'],'new'=>$new,'name'=>$name];
- $return[] = $info;
- }
- return $return;
- }
- public function getVersionInfo($project)
- {
- $info = $this->butt->getVersionInfo($project);
- return $info;
- }
- public function getBindInfo($param)
- {
- if(!($param['institution_id'] ?? null) || !($param['start'] ?? null) || !($param['finish'] ?? null) )
- {
- $this->throwError('医院id不能为空','0081');
- }
- $ins = ['institution_id'=>$param['institution_id']];
- $start = $param['start'].' 00:00:00';
- $finish = $param['finish'].' 23:59:59';
- $visit = $this->butt->getBindInfo($ins,$start,$finish);
- $ids = [];
- $cTime = [];
- $type = [];
- foreach ($visit as $k=>$v)
- {
- $ids[] = $v['exam_id'];
- $cTime[$v['exam_id']] = $v['createdAt'];
- if($type[$v['exam_id']] ?? null)
- {
- $type[$v['exam_id']] = $type[$v['exam_id']].','.$v['source'];
- }else{
- $type[$v['exam_id']] = $v['source'];
- }
- }
- $list= $this->butt->getExamByIds($ids);
- $data = [];
- foreach ($list as $k=>$v)
- {
- $list[$k]['createdAt'] = $cTime[$v['id']];
- $source = '';
- if($type[$v['id']] ?? null)
- {
- if(strpos($type[$v['id']],'1') !== false)
- {
- if(empty($source))
- {
- $source = '1';
- }else{
- $source .= ',1';
- }
- }
- if(strpos($type[$v['id']],'2') !== false)
- {
- if(empty($source))
- {
- $source = '2';
- }else{
- $source .= ',2';
- }
- }
- if(strpos($type[$v['id']],'3') !== false)
- {
- if(empty($source))
- {
- $source = '3';
- }else{
- $source .= ',3';
- }
- }
- $list[$k]['source'] = $source;
- }
- if(!empty($source))
- {
- $data[] = $v;
- }
- }
- return $list;
- }
- public function saveAnnex($params)
- {
- if(empty($params['url']))
- {
- $this->throwError('无效的url地址','9001');
- }
- $value = $params['code'];
- $key = Config::get('report_save_type')[$params['type']] ?? null;
- if(empty($key))
- {
- $this->throwError('无效的type类型','9002');
- }
- $field = ['e.id','r.id as report_id'];
- if($key == 'id')
- {
- $key= 'e.id';
- }
- $where = [$key=>$value,'institution_id'=>$params['institution_id']];
- $whereTime = [];
- if($params['institution_id'] == '06300006')
- {
- if($params['type'] == 2)
- {
- $whereTime['exam_datetime'] = date('Ymd',time());
- }
- }
- $exam = $this->butt->getExamReport($where,$field,$whereTime);
- if(empty($exam))
- {
- $data = [
- 'annex_class_code'=>$params['annex_class_code'] ?? '',
- 'url'=>$params['url'],
- 'name'=>$params['name'] ?? '',
- 'report_id'=>'',
- 'exam_id'=>'',
- 'type'=>$params['type'],
- 'code'=>$value,
- 'exam_datetime'=>$params['exam_datetime'] ?? '',
- 'institution_id'=>$params['institution_id']
- ];
- $whereAnnex = ['type'=>$params['type'],'code'=>$value,'url'=>$params['url']];
- $info = $this->butt->checkAnnes($whereAnnex);
- if($info)
- {
- $return = $this->butt->updateAnnex($data,$whereAnnex);
- }else{
- $return = $this->butt->saveAnnex($data);
- }
- return $return;
- // $this->throwError('不存在的检查','9003');
- }else{
- $return = '';
- foreach ($exam as $k=>$v)
- {
- $data = [
- 'annex_class_code'=>$params['annex_class_code'] ?? '',
- 'url'=>$params['url'],
- 'name'=>$params['name'] ?? '',
- 'report_id'=>$v['report_id'] ? $v['report_id'] : '',
- 'exam_id'=>$v['id'],
- 'type'=>$params['type'],
- 'code'=>$value,
- 'exam_datetime'=>$params['exam_datetime'] ?? '',
- 'institution_id'=>$params['institution_id']
- ];
- $whereAnnex = ['exam_id'=>$v['id'],'url'=>$params['url']];
- $info = $this->butt->checkAnnes($whereAnnex);
- if($info)
- {
- $return = $this->butt->updateAnnex($data,$whereAnnex);
- }else{
- $return = $this->butt->saveAnnex($data);
- }
- }
- return $return;
- }
- }
- public function saveRegister($params)
- {
- if(empty($params['code']))
- {
- $this->throwError('无效的code码',0025);
- }
- $key = Config::get('ut')[$params['code']] ?? null;
- if(empty($key))
- {
- $this->throwError('无效的code码',0025);
- }
- $where = [$key=>$params[$key]];
- $examId = $this->butt->getRegisterExam($where);
- // 添加 patient_infos 表数据
- $patient_data = $this->makePatientData($params);
- if(!is_null($examId)){
- // 修改操作
- unset($patient_data['id']);
- $pat_id = $this->registerDao->getPatientId($examId);
- $patient = $this->registerDao->updatePatient($patient_data,$pat_id);
- } else {
- // 添加操作
- $pat_id = $patient_data['id'];
- $patient = $this->registerDao->insertParent($patient_data);
- }
- // 添加 exam 表数据
- $exam_data = $this->makeExamData($params);
- $exam_data['patient_id'] = $pat_id;
- if(!is_null($examId)){
- // 修改操作
- unset($exam_data['id']);
- unset($exam_data['exam_status']);
- $exam_res = $this->registerDao->updateExam($exam_data,$examId);
- $exam_data['id'] = $examId;
- } else {
- $examId = $exam_data['id'];
- $exam_res = $this->registerDao->insertExam($exam_data);
- }
- $register_data = $this->makeRegister($params);
- $register_data['exam_id'] = $exam_data['id'];
- $registerId = $this->registerDao->getRegisterId($exam_data['id']);
- if(!is_null($registerId)){
- // xiugai
- $this->registerDao->updateRegister($register_data,$examId);
- }else{
- // xinzeng
- $register_data['id'] = UUIDUtils::uuid();
- $this->registerDao->insertRegister($register_data);
- }
- return $examId;
- }
- public function makePatientData($params)
- {
- try{
- $sex_choose = $params['sex'] ?? '';
- $sex = $this->getSex($sex_choose);
- $data = [
- 'id' => UUIDUtils::uuid(),
- 'sex' => $sex,
- 'name' => $params['name'] ?? '',
- 'card_num' => $params['card_num'] ?? '',
- 'phone' => $params['phone'] ?? '',
- 'ctime' => date('Y-m-d H:i:s'),
- 'birthday' => $params['birthday'] ?? '',
- 'age' => $params['age'] ?? '',
- 'card_type' => $params['card_type'] ?? '',
- 'nationality' => $params['nationality'] ?? '',
- 'nation' => $params['nation'] ?? '',
- 'marry' => $params['marry'] ?? '',
- 'professional' => $params['professional'] ?? '',
- 'address' => $params['address'] ?? '',
- 'status' => 1,
- 'anamnesis' => $params['anamnesis'] ?? '',
- 'family_ill' => $params['family_ill'] ?? '',
- 'createdAt' => date('Y-m-d H:i:s'),
- 'institution_id' => $params['institution_id'],
- 'temp_patient_id' => $params['patient_num']
- ];
- return $data;
- }catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function makeExamData($params)
- {
- try{
- $sex_choose = $params['sex'] ?? '';
- $sex = $this->getSex($sex_choose);
- $data = [
- 'id' => UUIDUtils::uuid(),
- 'institution_id' => $params['institution_id'],
- 'name' => $params['name'] ?? '',
- 'phone' => $params['phone'] ?? '',
- 'card_num' => $params['card_num'] ?? '',
- 'patient_num' => $params['patient_num'] ?? '',
- 'accession_num' => $params['accession_num'] ?? '', // 暂无
- 'exam_project' => $params['exam_project'] ?? '',
- 'exam_datetime' => $params['exam_datetime'] ?? '',
- 'exam_status' => 1,
- 'exam_sub_class' => $params['exam_sub_class'] ?? '',
- 'body_part' =>$params['body_part'] ?? '',
- 'device_name' => $params['device_name'] ?? '',
- 'sex' => $sex,
- 'age' =>$params['age'] ?? '',
- 'birthday' => $params['birthday'] ?? '',
- 'hopitalized_no' => $params['hopitalized_no'] ?? '',
- 'bed_no' => $params['bed_no'] ?? '',
- 'patient_area' => $params['patient_area'] ?? '',
- 'application_department' => $params['application_department'] ?? '',
- 'application_doctor' => $params['application_doctor'] ?? '',
- 'out_patient' => $params['out_patient'] ?? '',
- 'clin_symp' => $params['clin_symp'] ?? '',
- 'clin_diag' => $params['clin_diag'] ?? '',
- 'his_patient_id' => $params['his_patient_id'] ?? '',
- 'exam_class' =>$params['exam_class'],
- 'write_report' =>1
- ];
- return $data;
- }catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function makeRegister($params)
- {
- $data = [
- 'exam_sub_class' => $params['exam_sub_class'] ?? '',
- 'body_part' =>$params['body_part'] ?? '',
- 'device_name' => $params['device_name'] ?? null,
- 'register_datetime' => date('Y-m-d H:i:s'),
- 'illness_desc' => $params['illness_desc'] ?? '',
- 'phys_sign' => $params['phys_sign'] ?? '',
- 'clin_symp' => $params['clin_symp'] ?? '',
- 'anamnesis' => $params['anamnesis'] ?? '',
- 'family_ill' => $params['family_ill'] ?? '',
- 'clin_diag' => $params['clin_diag'] ?? '',
- 'application_department' => $params['application_department'] ?? '',
- 'ext' => $params['remark'] ?? ''
- ];
- return $data;
- }
- public function getField($params)
- {
- $ins = $params['institution_id'];
- $type = $this->butt->getField($ins);
- return Config::get('report_save_type')[$type] ?? 'patient_num';
- }
- public function savePrintSync($params)
- {
- if(empty($params['type']))
- {
- $this->throwError('无效的type码',0025);
- }
- if(empty($params['code']))
- {
- $this->throwError('无效的code码',0025);
- }
- $key = Config::get('report_save_type')[$params['type']] ?? null;
- if(empty($key))
- {
- $this->throwError('无效的type码',0025);
- }
- $where = [$key=>$params['code'],'institution_id'=>$params['institution_id']];
- $exam = $this->butt->getExam($where,['name']);
- if(empty($exam))
- {
- $this->throwError('无效的code,查不到匹配的检查',0027);
- }
- $where = ['code'=>$params['code'],'institution_id'=>$params['institution_id']];
- // $today_print = $this->butt->checkPrint($where,"to_days(createdAt) = to_days(now())");
- // if($today_print)
- // {
- // //检查次数+1
- // $info = $this->butt->printZz($where);
- // return '同步成功';
- // }
- $where['print_time'] = $params['print_time'] ?? null;
- $data = [
- 'institution_id'=>$params['institution_id'] ?? '',
- 'type'=>$params['type'],
- 'code'=>$params['code'],
- 'print_time'=>$params['print_time'] ?? null,
- 'name'=>$exam['name']
- ];
- $print = $this->butt->getPrint($where);
- if($print)
- {
- $info = $this->butt->updatePrintSync($data,$where);
- }else{
- $info = $this->butt->savePrintSync($data);
- }
- return $info;
- }
- public function saveReportAnnex($url,$reportId)
- {
- $examId = $this->butt->getExamFromReport($reportId);
- $data = [
- 'annex_class_code'=>2,
- 'url'=>$url,
- 'name'=>'',
- 'report_id'=>$reportId,
- 'exam_id'=>$examId
- ];
- log::record('附件'.json_encode($data));
- $this->butt->saveAnnex($data);
- }
- public function getPayExam($params)
- {
- $start = $params['start'];
- $finish = $params['finish'];
- $institution = $params['institution'];
- $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];
- $time = "m.createdAt between '$start' and '$finish'";
- $water = $this->butt->getPayExam($where,$time);
- // $examWhere[] = ['id','in',$water];
- // $info = $this->butt->getPayExams($examWhere,['patient_num','accession_num','studyuid']);
- return $water;
- }
- public function changeSyncStatus($params)
- {
- $id = $params['id'];
- $info = $this->butt->changeSyncStatus($id);
- return $info;
- }
- public function changePayStatus($params)
- {
- $patient_num = $params['patient_num'] ?? '';
- if(empty($patient_num))
- {
- return '';
- }
- $ins = '03060002';
- $info = $this->butt->changePayStatus($patient_num,$ins);
- return $info;
- }
- public function getMiddle($params)
- {
- $num = $params['minute'];
- $ins = $params['institution_id'];
- //获取多少分钟内数据
- $where = "m.createdAt > DATE_SUB(NOW(), INTERVAL $num MINUTE) and m.institution_id='$ins'";
- $info = $this->butt->getMiddleInfo($where);
- return $info;
- }
- public function changeMiddleStatus($params)
- {
- $where[] = ['id','in',explode(',',$params['ids'])];
- $update = ['is_sync'=>1];
- $info = $this->butt->changeMiddleStatus($where,$update);
- return $info;
- }
- public function syncMiddle($params)
- {
- $where = ['studyuid'=>$params['studyuid']];
- $field = ['id','institution_id'];
- $exam = $this->butt->getExam($where,$field);
- $examId = $exam['id'] ?? null;
- if(empty($examId))
- {
- return '无效的studyuid';
- }
- $middleInfo = [
- 'institution_id'=>$exam['institution_id'],
- 'status'=>$params['status'],
- 'doctor_id'=>$params['doctor_id'],
- 'doctor_name'=>$params['doctor_name'],
- 'exam_id'=>$examId,
- 'is_sync'=>1
- ];
- $r = $this->butt->saveMiddle($middleInfo);
- return $r;
- }
- public function goNoteUrl($param)
- {
- try{
- if($param['id'] == 1)
- {
- return DebugModel::value('url');
- }
- $num = base64_decode($param['id']);
- $id = base_convert(ltrim($num,0),36,10);
- $url = $this->butt->getNoteUrl($id);
- return $url;
- }catch (Exception $e)
- {
- return '';
- }
- }
- public function saveAiReport($param)
- {
- $this->reportDao->saveDcmReportData(json_encode($param),$param['exam_id'],5,$this->ts_time());
- if($param['describe'] == 'gpu不可用,请1小时后再试')
- {
- return '';
- }
- $data = [
- 'id'=>UUIDUtils::uuid(),
- 'impression'=>$param['diagnosis'],
- 'description'=>$param['describe'],
- 'type'=>3,
- 'exam_id'=>$param['exam_id'],
- 'report_doctor_name'=>'ai报告医生',
- 'review_doctor_name'=>'ai报告医生',
- 'confirm_doctor_name'=>'ai报告医生',
- 'report_datetime'=>date('Y-m-d H:i:s'),
- 'review_datetime'=>date('Y-m-d H:i:s'),
- 'confirm_datetime'=>date('Y-m-d H:i:s'),
- 'detections'=>empty($param['detections']) ? '' : json_encode($param['detections'])
- ];
- $aiData = $this->reportDao->getReport($param['exam_id'],3);
- if($aiData)
- {
- //修改ai报告
- unset($data['id']);
- $info = $this->reportDao->updateReport($param['exam_id'],3,$data);
- }else{
- $info = $this->butt->saveReport($data);
- }
- $arr = [
- 'report_id'=>$data['exam_id'],
- 'exam_id'=>$param['exam_id'],
- 'diagnosis'=>$param['diagnosis'],
- 'describe'=>$param['describe'],
- 'detections'=>empty($param['detections']) ? '' : json_encode($param['detections'])
- ];
- $this->butt->saveAiReport($arr);
- $this->reportDao->saveDcmReportData('',$param['exam_id'],6,$this->ts_time());
- return $info;
- }
- public function getDmReport($param)
- {
- if($param['datetime'] ?? '')
- {
- $date = explode(',',$param['datetime']);
- if(empty($date[0] ?? '') || empty($date['1'] ?? ''))
- {
- $this->throwError('参数传参错误','0058');
- }
- }else{
- $this->throwError('缺少必要参数','0057');
- }
- $data = $this->reportDao->getDmReport($date[0],$date[1]);
- return $data;
- }
- public function getInsReport($param)
- {
- if($param['datetime'] ?? '')
- {
- $date = explode(',',$param['datetime']);
- if(empty($date[0] ?? '') || empty($date['1'] ?? ''))
- {
- $this->throwError('参数传参错误','0058');
- }
- }else{
- $this->throwError('缺少必要参数','0057');
- }
- if(!($param['institution_id'] ?? ''))
- {
- $this->throwError('缺少必要参数','0057');
- }
- $data = $this->reportDao->getInsReport($date[0],$date[1],$param['institution_id'],$param['remote'] ?? '',$param['page'] ?? 1,$param['num'] ?? 10);
- return $data;
- }
- public function getWechatData($openid)
- {
- if(empty($openid))
- {
- $this->throwError('错误的参数','0059');
- }
- $data = $this->reportDao->getWechatData($openid);
- if(empty($data))
- {
- $this->throwError('未找到绑定信息','0060');
- }
- $wx_id = $data['wx_id'];
- $patient = $data['patient'];
- $exam = $data['exams'];
- $arr = [
- 'name'=>empty($patient['patient_name'] ?? '') ? ($exam['name'] ?? '') : $patient['patient_name'],
- 'idCard' => empty($patient['idCard'] ?? '') ? ($exam['card_num'] ?? '') : $patient['idCard'],
- 'phone'=>$patient['phone'] ?? '',
- 'birthday'=>$exam['birthday'] ?? '',
- 'sex'=>$exam['sex'] ?? '',
- 'id'=>$wx_id
- ];
- $key = 'e386c7039aa49826664d576eb798da21';
- $arr = openssl_encrypt((json_encode($arr)),'AES-128-ECB',$key,OPENSSL_RAW_DATA);
- return base64_encode($arr);
- }
- public function getLwSyncExam($params)
- {
- $field = [
- 'id',
- 'name as PatName',
- 'patient_id as PatID',
- 'birthday as BirthDate',
- 'sex as PatSex',
- 'age as PatAge',
- 'studyUid as StudyInstanceUID',
- "'' as SeriesInstanceUID", // Series唯一标识符 Y
- "'' as SOPInstanceUID", // SOP唯一标识符 Y
- 'exam_datetime as StudyDate',
- "'' as SeriesDate",
- "'' as AcquistionTime",
- 'accession_num as AccessionNumber',
- 'exam_class as Modality',
- 'patient_num as StudyID',
- "'' as SeriesNumber",
- "'' as AcquisitionNumber",
- "'' as InstanceNumber",
- "'' as FilePathName",
- "'' as Manufacturer",
- 'study_id as RelationField'
- ];
- $data = $this->reportDao->getLwSyncExam($params['institution_id'],$params['num'],$field);
- $arr = [];
- $url = 'https://query.pacsonline.cn/query/data_lw?RelationField=';
- foreach ($data as $k=>$v)
- {
- $array = [];
- $array = $v;
- $urlImage = $url.$v['RelationField'];
- $return = $this->curl_get($urlImage);
- $return = json_decode($return,true);
- foreach ($return as $value)
- {
- foreach ($value as $kk=>$vv)
- {
- if(empty($array[$kk]))
- {
- $array[$kk] = $vv;
- }
- }
- }
- $arr[] = $array;
- }
- return $arr;
- }
- public function changeLwSyncStatus($params)
- {
- $data = $this->reportDao->changeLwSyncStatus($params['id']);
- return 'success';
- }
- public function changeLwSyncReportStatus($params)
- {
- $data = $this->reportDao->changeLwSyncReportStatus($params['id']);
- return 'success';
- }
- public function getExamList($params)
- {
- $idCard = $params['sfzh'] ?? '';
- $jgdm = $params['jgdm'] ?? '';
- if(empty($jgdm) || empty($idCard))
- {
- $this->throwError('参数错误','9898');
- }
- $institution = $this->reportDao->getInstitutionData(['ins_jgdm'=>$jgdm],'id');
- if(empty($institution))
- {
- $this->throwError('无效的参数','9899');
- }
- $data = $this->reportDao->getExamList(['institution_id'=>$institution['id'],'card_num'=>$idCard]);
- return ['data'=>$data,'count'=>count($data)];
- }
- public function getExamReport($params)
- {
- $id = $params['id'] ?? '';
- $data = $this->reportDao->getExamReport(['e.id'=>$id]);
- return $data;
- }
- public function saveLwExam()
- {
- $where = ['institution_id'=>'25500005','num'=>10];
- $url = "localhost:806/butt/getLwSyncExam";
- $list = $this->curlPost($url,$where);
- $arr = json_decode($list,true);
- $data = $arr['data'] ?? [];
- if(!empty($data))
- {
- foreach ($data as $k=>$v)
- {
- var_dump($v);die;
- }
- }
- var_dump($data);die;
- return $data;
- }
- public function getLwSyncReport($params)
- {
- $field = [
- 'e.id as exam_id',
- 'medical_code as InsuCardNo',//医保卡号
- 'accession_num as Accessionnumber',
- 'patient_num as PatID',
- 'name as PatCName',
- 'name as PatEName',
- 'sex as PatSex',
- 'birthday as BirthDate',
- 'age as PatAge',
- "'' as Address",
- 'card_num as ICCard',
- 'phone as Phone',
- "'未知' as Marriage",
- "'' as PatSection",
- "'' as Ward",
- "'' as BedNumber",
- 'application_department as ReqDept',
- 'application_doctor as ReqDoctor',
- "'' as ReqDate",
- "'' as ReqDate",
- 'body_part as ExamineBody',
- 'exam_project as ExamineItem',
- "'' as ExamineItemcode",
- 'exam_class as Modality',
- 'r.report_result as RequisitionNote', //0 阴性positive,1 阳性negative,-1 未知unkown
- "'' as ExamineType",
- 'patient_num as ClinicID',
- 'patient_source as PatSource',
- "'' as TreatItem",
- "'' as ChiefComplain",
- "'' as DocAdvice",
- 'clin_diag as DocAdvice',
- 'his_patient_id as HISID',
- 'his_patient_id as HisExamineId',
- "'' as ExamineDoctor",
- 'exam_datetime as StudyDateTime',
- 'report_doctor_name as ReportDoctor',
- 'review_doctor_name as AuditDoctor',
- 'report_datetime as ReportDateTime',
- 'review_datetime as AuditDateTime',
- 'description as Finding',
- 'impression as Conclusion',
- '0 as Tempreport',
- '4 as ReportStatus',
- 'r.id as ReportID',
- 'r.updatedAt as UpDateTime',
- 'study_id as StudyInstanceUID'
- ];
- if(empty($params['institution_id']))
- {
- return [];
- }
- $data = $this->butt->getExamLimitReport(['exam_status'=>9,'lw_report_sync_status'=>1],$field,['institution_id'=>$params['institution_id']],$params['num']);
- foreach ($data as $k=>$v)
- {
- switch ($v['RequisitionNote'])
- {
- case 1 :
- $result = 0;
- break;
- case 2 :
- $result = 1;
- break;
- default:
- $result = '-1';
- }
- $data[$k]['RequisitionNote'] = $result;
- // //1:门诊:,2:住院,4:体检,5:急诊,6:住院急诊,7:职业病体检0:其他
- switch ($v['PatSource'])
- {
- case 1:
- $source = 5;
- break;
- case 2:
- $source = 2;
- break;
- case 3:
- $source = 1;
- break;
- case 4:
- $source = 4;
- break;
- default:
- $source = 0;
- }
- $data[$k]['PatSource'] = $source;
- try{
- $data[$k]['PatEName'] = PinyinChange::utf8_to($v['PatEName']);
- }catch (Exception $e)
- {
- // todo
- }
- }
- return $data;
- }
- public function saveAnalysiss()
- {
- $start = strtotime('yesterday');
- $end = strtotime('yesterday');
- $institution = $this->reportDao->getAllIns();
- for ($t = $start; $t <= $end; $t = strtotime('+1 day', $t)) {
- $date = date('Y-m-d', $t);
- $this->saveAnalysis($date,$institution);
- }
- }
- public function saveAnalysis($date, $institution)
- {
- // $institution = $this->reportDao->getAllIns();
- // $date = date("Y-m-d",time()-86400);
- $dateWhere = "createdAt between '$date 00:00:00' and '$date 23:59:59'";
- $exam_date = date('Ymd',strtotime($date));
- $examDateWhere = ['exam_datetime' => $exam_date];
- foreach ($institution as $institution_id=>$institution_name) {
- $institution[$institution_id] = [
- 'institution_id'=>$institution_id,
- 'institution_name'=>$institution_name,
- 'date'=> $exam_date,
- 'exam_all_num'=>0,
- 'person_num'=>0,
- 'exam_phone'=>0,
- 'send_sms'=>0,
- 'wechat_visit_pv'=>0,
- 'wechat_visit_uv'=>0,
- 'link_visit_pv' => 0,
- 'link_visit_uv' => 0,
- 'sms_visit_pv' => 0,
- 'sms_visit_uv' => 0,
- ];
- }
-
- $analysis = [];
-
- $exams = $this->reportDao->getExamGroupByIns($dateWhere);
- foreach ($exams as $exam)
- {
- if(!isset($institution[$exam['institution_id']]))
- {
- continue;
- }
- $institution[$exam['institution_id']]['exam_all_num'] = $exam['num'];
- }
- $phones = $this->reportDao->getExamGroupByIns($dateWhere, '', "phone is not null and phone <>''");
- foreach ($phones as $phone)
- {
- if(!isset($institution[$phone['institution_id']]))
- {
- continue;
- }
- $institution[$phone['institution_id']]['exam_phone'] = $phone['num'];
- }
- $smss = $this->reportDao->getSmsNumGroupByIns($dateWhere);
- foreach ($smss as $sms)
- {
- if(!isset($institution[$sms['institution_id']]))
- {
- continue;
- }
- $institution[$sms['institution_id']]['send_sms'] = $sms['num'];
- }
- $wechatPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 1]);
- foreach ($wechatPvUvs as $wechatPvUv)
- {
- if(!isset($institution[$wechatPvUv['institution_id']]))
- {
- continue;
- }
- $institution[$wechatPvUv['institution_id']]['wechat_visit_pv'] = $wechatPvUv['pv'];
- $institution[$wechatPvUv['institution_id']]['wechat_visit_uv'] = $wechatPvUv['uv'];
- }
- $linkPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 2]);
- foreach ($linkPvUvs as $linkPvUv)
- {
- if(!isset($institution[$linkPvUv['institution_id']]))
- {
- continue;
- }
- $institution[$linkPvUv['institution_id']]['link_visit_pv'] = $linkPvUv['pv'];
- $institution[$linkPvUv['institution_id']]['link_visit_uv'] = $linkPvUv['uv'];
- }
- $smsPvUvs = $this->reportDao->getPvUvWechatVisitGroupByIns($dateWhere, $examDateWhere, ['source' => 3]);
- foreach ($smsPvUvs as $smsPvUv)
- {
- if(!isset($institution[$smsPvUv['institution_id']]))
- {
- continue;
- }
- $institution[$smsPvUv['institution_id']]['sms_visit_pv'] = $smsPvUv['pv'];
- $institution[$smsPvUv['institution_id']]['sms_visit_uv'] = $smsPvUv['uv'];
- }
- foreach ($institution as $k=>$v)
- {
- $analysis[] = $v;
- }
- // var_dump($analysis);die;
- Db::connect('dbbi')->table('data_analysis')->insertAll($analysis);
- }
- public function makeWechatData($institution, $emails)
- {
- $email = explode(',',$emails);
- $message = '';
- $where = ['institution_id'=>$institution];
- $institutionName = $this->reportDao->getInstitutionName($institution);
- $yesterday = date('Y-m-d',strtotime('-1 day'));
- $whereTime = "createdAt BETWEEN '$yesterday 00:00:00' and '$yesterday 23:59:59'";
- $all = $this->reportDao->getAllExamCount($where,$whereTime);
- $pvWechatVisit = $this->reportDao->getPvWechatVisit($where,$whereTime);
- $uvWechatVisit = $this->reportDao->getUvWechatVisit($where,$whereTime);
- $message = $institutionName.$yesterday.'的检查总数'.$all.' 访问pv是'.$pvWechatVisit.',访问uv是'.$uvWechatVisit;
- foreach ($email as $k=>$v)
- {
- $this->sendWechatInfoEmail($message,$v);
- }
- }
- public function sendWechatInfoEmail($message, $email)
- {
- set_time_limit(0);
- $mail = new PHPMailer(true); // Passing `true` enables exceptions
- try {
- //服务器配置
- $mail->CharSet ="UTF-8"; //设定邮件编码
- $mail->SMTPDebug = 0; // 调试模式输出
- $mail->isSMTP(); // 使用SMTP
- $mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
- $mail->SMTPAuth = true; // 允许 SMTP 认证
- $mail->Username = 'company@pacsonline.cn'; // SMTP 用户名 即邮箱的用户名
- $mail->Password = 'Zskk1234'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
- $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
- $mail->Port = 465;
- $mail->SMTPOptions = array(
- 'ssl' => array(
- 'verify_peer' => false,
- 'verify_peer_name' => false,
- 'allow_self_signed' => true
- )
- );
- // 服务器端口 25 或者465 具体要看邮箱服务器支持
- $mail->setFrom('company@pacsonline.cn', '冠医云'); //发件人
- $mail->addAddress($email, ''); // 收件人
- $mail->addReplyTo('company@pacsonline.cn', '冠医云'); //回复的时候回复给哪个邮箱 建议和发件人一致
- $mail->Subject = '数据汇总';
- //$mail->addCC('cc@example.com'); //抄送
- $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
- $mail->Body = $message;
- $mail->send();
- return '邮件发送成功';
- } catch (Exception $e) {
- // return '邮件发送失败: ';
- return '邮件发送失败: '.$mail->ErrorInfo;
- }
- }
- }
|