12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745 |
- <?php
- namespace app\api\servies\butt;
- 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 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'];
- $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']);
- 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']));
- // }
- // }
- // 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->butt->insertSpecialLog($time,'butt/saveReport');
- return $id;
- // } catch (\Exception $exception){
- // DB::rollback();
- // $this->throwError($exception->getMessage(),0001);
- // }
- }
- 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 sendSms($phone,$examId,$studyId,$institution,$source,$exam_class='')
- {
- $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://wc.pacsonline.cn/#/jump?id='.$id
- ];
- $noteId = $this->reportDao->insertNote($note);
- $nid = base64_encode(str_pad(base_convert($noteId,10,36),6,'0',STR_PAD_LEFT));
- 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;
- }
- $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);
- }
- }
- 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'];
- $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);
- 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);
- }
- }
|