123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- <?php
- namespace app\api\servies\xz;
- use app\api\model\studies\StudiesModel;
- use app\api\servies\ZskkDefaultService;
- // use app\api\validate\xz\XzValidate;
- use app\api\dao\xz\XzDao;
- use app\api\servies\common\CommonService;
- use app\api\utils\UUIDUtils;
- use app\common\library\send_message;
- use think\Db;
- use think\Exception;
- use think\facade\Config;
- use think\facade\Log;
- use app\api\change\PinyinChange;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class XzService extends ZskkDefaultService {
- protected $logName = "XzService";
- private $xz = null;
- public function __construct(XzDao $xzDao) {
- parent::__construct();
- $this->xz = $xzDao;
- }
- public function savePacs($params)
- {
- try{
- $xz = $params;
- // 数据存储
- $xz['id'] = UUIDUtils::uuid();
- $xz['phonetic'] = PinyinChange::utf8_to($xz['patientName'],1);
- $xz['descriptionPhonetic'] = PinyinChange::utf8_to($xz['contentDescription'],1);
- $where = [
- 'applicationFormNo'=>$params['applicationFormNo'],
- 'clinicId'=>$params['clinicId']
- ];
- $xzInfo = $this->xz->checkXz($where);
- if(empty($xzInfo)){
- $data = $this->xz->insertXz($xz);
- }else{
- return json_encode(['code'=>'0']);
- }
- // 存储患者信息
- $patientData = [
- 'id'=>UUIDUtils::uuid(),
- 'name'=>$params['patientName'],
- 'sex'=>$params['patientSex'],
- 'birthday'=>$params['patientBirthDate'] ?? '',
- 'age'=>$params['patientAge'],
- 'institution_id'=>$params['clinicId'],
- 'createdAt'=>date('Y-m-d H:i:s',time()),
- 'temp_patient_id'=>$params['patientId']
- ];
- $patient = $this->xz->insertPatient($patientData);
- // 存储studies
- $studiesData = [
- 'id'=>UUIDUtils::uuid(),
- 'studyuid'=>'1.3.6.1.4.1.30071.8.'.time().$params['clinicId'].$params['patientId'].$params['applicationFormNo'],
- 'patient_id'=>$patientData['id'],
- 'studydate'=>$params['startDate'],
- 'modality'=> $params['modality'] == 1? 'US' : 'OP',
- 'accession_num'=>$params['applicationFormNo'],
- 'status'=>1,
- 'patient_age'=>$params['patientAge'],
- 'studyDescribe'=>$params['contentDescription'] ?? '',
- 'institution_id'=>$params['clinicId'],
- 'createdAt' => date('Y-m-d H:i:s',time()),
- 'weight'=>$params['patientWeight'] ?? ''
- ];
- $studies = $this->xz->insertStudies($studiesData);
- // 存储exams 信息
- $examData = [
- 'id'=>UUIDUtils::uuid(),
- 'patient_num'=>$params['patientId'],
- 'accession_num'=>$params['applicationFormNo'],
- 'patient_id'=>$patientData['id'],
- 'exam_datetime'=>$params['startDate'],
- 'exam_class' => $params['modality'] == 1? 'US' : 'OP',
- 'clin_dept_id'=>$params['department'] ?? '',
- 'institution_id'=>$params['clinicId'],
- 'illness_desc'=>$params['symptom'] ?? '',
- 'clin_doctors'=>$params['clinicalDoctor'] ?? '',
- 'study_uid'=>$studiesData['studyuid'],
- 'exam_status'=>'1',
- 'study_id'=>$studiesData['id']
- ];
- if($params['clinicalDoctor'] ?? ''){
- $doctorId = $this->xz->checkDoctor($params['clinicalDoctor']);
- if(!empty($doctorId)){
- $examData['register'] = $doctorId;
- }else{
- $doctorData = [
- 'id'=>UUIDUtils::uuid(),
- 'realname'=>$params['clinicalDoctor'],
- 'password'=>md5('123456'),
- 'username'=>UUIDUtils::uuid(),
- 'institution_id'=>$params['clinicId']
- ];
- $examData['register'] = $doctorData['id'];
- }
- }
- $exam = $this->xz->insertExam($examData);
- $this->xz->updateStudies($studiesData['id'],$examData['id']);
- $updateXz = ['exam_id'=>$examData['id'],'studyUid'=>$studiesData['studyuid']];
- $this->xz->updateXz($where,$updateXz);
- $status = $this->xz->updateStatus($where,1);
- return json_encode(['code'=>'0']);
- }catch(\Exception $e){
- return json_encode(['code'=>'1','message'=>$e->getMessage()]);
- }
- }
- public function cancel($params)
- {
- try{
- $where = [
- 'applicationFormNo'=>$params['applicationFormNo'],
- 'clinicId'=>$params['clinicId']
- ];
- $xzInfo = $this->xz->checkXz($where);
- if(empty($xzInfo)){
- return json_encode(['code'=>'1','message'=>'该检查不存在']);
- }
- if($xzInfo['exam_status'] == '1' || $xzInfo['exam_status'] == '0'){
- $status = $this->xz->updateStatus($where,0);
- $update = ['exam_status'=>-99];
- $a = $this->xz->updateExam($xzInfo['exam_id'],$update);
- return json_encode(['code'=>'0']);
- }else{
- return json_encode(['code'=>'1','message'=>'非检查完成状态的检查不可撤回']);
- }
- }catch(\Exception $e){
- return json_encode(['code'=>'1','message'=>$e->getMessage()]);
- }
- }
- // 3 推送检查消息
- public function pushExam($params,$url)
- {
- try{
- $data = $params;
- $info = $this->curlJsonPost($url,$data);
- $xz = json_decode($info,true);
- $return = [];
- if($xz['code'] == '0'){
- return '1';
- }else{
- return $xz;
- }
- // 是否要修改xz表中的状态
- // return $info;
- }catch(\Exception $e){
- return json_encode(['code'=>'0001','message'=>$e->getMessage()]);
- }
- }
- public function getData($params)
- {
- $info = $this->xz->getXzData($params['id']);
- if($info['exam_status'] != 1){
- $this->throwError('非正常的流程操作,无法开始检查','0001');
- }
- $data = [
- 'applicationFormNo'=>$info['applicationFormNo'],
- 'clinicId'=>$info['clinicId']
- ];
- return $data;
- }
- public function change($params,$status)
- {
- $where = [
- 'exam_id'=>$params['id']
- ];
- $this->xz->updateStatus($where,$status);
- $this->xz->updateExam($params['id'],['exam_status'=>$status]);
- }
- public function getInfo($params)
- {
- $info = $this->xz->getXzData($params['id']);
- $data = [
- 'applicationFormNo'=>$info['applicationFormNo'],
- 'clinicId'=>$info['clinicId'],
- 'urlParm'=>$params['id']
- ];
- return $data;
- }
- public function getExamData($id)
- {
- $xzData = $this->xz->getExamData($id);
- return $xzData;
- }
- public function getExamPush($id)
- {
- try{
- $xzData = $this->xz->getXzData($id);
- $report = $this->xz->getReport($id);
- $reportName = $this->xz->getDoctorName($report['report_doctor_id']);
- $reviewName = $this->xz->getDoctorName($report['review_doctor_id']);
- $studyUid = $this->xz->getUid($id);
- $accessionNum = $this->xz->getAccession($id);
- $info = [
- 'report'=>[
- 'department'=>$xzData['department'],
- 'clinicalDoctor'=>$xzData['clinicalDoctor'],
- 'symptom'=>$xzData['symptom'],
- 'reportDate'=>$report['report_datetime'],
- 'description'=>$report['description'],
- 'impression'=>$report['impression'],
- 'reportDoctor'=>$reportName,
- 'reviewDoctor'=>$reviewName,
- 'studyInstanceUId'=>$studyUid,
- 'modality'=>$xzData['modality'],
- 'accessionNumber'=>$accessionNum
- ],
- 'applicationFormNo'=>$xzData['applicationFormNo'],
- 'clinicId'=>$xzData['clinicId'],
- ];
- $data = json_encode($info);
- $url = 'http://wjw.yidab.cn:801/pacs/pushExamReport.do';
- // $url = 'http://wjw.yidab.cn:801/wjw-test/pacs/pushExamReport.do';
- $return = $this->curlJsonPost($url,$data);
- return $return;
- }catch(\Exception $e){
- return json_encode(['code'=>'1','message'=>$e->getMessage()]);
- }
- }
- public function saveExam($params)
- {
- /*if(isset($params['institution_id']) && $params['institution_id'] == '730900006')
- {
- log::record('存在730900006');
- // $db = Db::connect('db2');
- $e = Db::connect('db2')->table('exams')->where('study_id',$params['study_id'])->value('id');
- if(!empty($e)){
- log::record('存在检查');
- log::record('检查id%'.$e.'%');
- return true;
- }
- log::record('不存在检查');
- $exam2 = [
- 'id'=>UUIDUtils::uuid(),
- 'patient_id'=>$params['patient_id'] ?? null,
- 'patient_num'=>$params['patient_num'] ?? null,
- 'accession_num'=>$params['accession_num'] ?? null,
- 'exam_datetime'=>$params['exam_datetime'] ?? null,
- 'exam_class'=>$params['exam_class'] ?? null,
- 'institution_id'=>$params['institution_id'],
- 'study_id'=>$params['study_id'] ?? null,
- 'id_card' => $params['card_num'] ?? null,
- 'study_uid'=>StudiesModel::where('id',$params['study_id'])->value('studyuid'),
- 'exam_status'=>3,
- 'createdAt'=>date('Y-m-d H:i:s',time()),
- 'phone'=>$params['phone'] ?? null,
- ];
- log::record('存储的检查数据'.json_encode($exam2));
- $e2 = Db::connect('db2')->table('exams')->insert($exam2);
- log::record('存储是否成功'.$e2);
- log::record('当前患者id为'.$params['patient_id'].'患者id存在');
- if(!empty($params['patient_id'])){
- log::record('存在患者id');
- $patient = [
- 'id'=>$params['patient_id'],
- 'name'=>$params['name'] ?? null,
- 'sex'=>$params['sex'] ?? null,
- 'card_num'=>$params['card_num'] ?? null,
- 'phone'=>$params['phone'] ?? null,
- 'age'=>$params['age'] ?? null,
- 'temp_patient_id'=>$params['patient_num'] ?? null,
- 'institution_id'=>$params['institution_id']
- ];
- log::record('存储的患者数据'.json_encode($patient));
- $p = Db::connect('db2')->table('patient_infos')->insert($patient);
- log::record('患者存储成功'.$p);
- }
- return true;
- }*/
- $time1 = time();
- if($params['institution_id'] == '43600001')
- {
- $exam = $this->xz->checkIsSet($params['study_id'],$params['studyuid'],$params['institution_id']);
- }else{
- $exam = $this->xz->checkIsSet($params['study_id']);
- }
- if($params['institution_id'] == '71900004')
- {
- $params['name'] = str_replace('=','',$params['name']);
- }
- if($params['institution_id'] == '16100014')
- {
- if($params['exam_class'] == 'RF')
- {
- $params['exam_class'] = 'DX';
- }
- }
- if($params['institution_id'] == '71900007' || $params['institution_id'] == '71900008')
- {
- if($params['exam_class'] == 'CR')
- {
- $params['exam_class'] = 'DR';
- }
- }
- if($exam){
- //存在则修改
- $id = $exam['id'];
- $water_log = $this->xz->getWaterLog($id,$params['institution_id']);
- $update = [];
- if(empty($water_log)){
- $film = $this->xz->getInsFilmInfo($params['institution_id']);
- if(!empty($film))
- {
- if($film['charge_mode'] == Config::get('order_type')['hospitalPay']){
- //创建检查 必须为医院托管模式 才允许创建胶片记录
- $this->save_ins_film_water($id,$film['charge_mode'],$film['film_price'],$params['institution_id']);
- $update['pay_status'] = 1;
- }
- }
- }
- $update['updatedAt'] = date('Y-m-d H:i:s',time());
- if(isset($params['node_type']) && !empty($params['node_type']))
- {
- $update['node_type'] = $params['node_type'];
- }
- if(isset($params['exam_class']) && !empty($params['exam_class']))
- {
- if($exam['exam_class'] !== $params['exam_class'])
- {
- $update['exam_class'] = $params['exam_class'];
- }
- }
- $update['status'] = 1;
- if($params['institution_id'] == '27400005') {
- $cache = $this->xz->getCache("worklist_".$params['patient_num']);
- if(!empty($cache))
- {
- $key = "worklist_".$params['patient_num'];
- $d = json_decode($cache, true);
- Log::record('东民二院;存储key为'.$key.';存储内容为'.$cache);
- $update["name"] = $d['NAME'];
- $update["hopitalized_no"] = $d['zyh'];
- $update["bed_no"] = $d['cwh'];
- $update["exam_project"] = $d['PARTOFCHECK'];
- }
- }
- // foreach ($params as $k=>$v){
- // if(!empty($v) && $k !== 'exam_class'){
- // $update[$k] = $v;
- // if($k == 'name' && $params['institution_id'] == '27400005'){
- // //东明二院
- // $cache = $this->xz->getCache("worklist_".$params['patient_num']);
- // if(!empty($cache))
- // {
- // // $d = json_decode($cache, true);
- // $update[$k] = $cache;
- // }
- // }
- // }
- // }
- if($exam['exam_status'] == -1){
- $update['exam_status'] = '9';
- $this->xz->updateExam($id,$update);
- }elseif($exam['exam_status']<3){
- $update['exam_status'] = '3';
-
- //进行分派
- $did = $this->handle_queue($params['institution_id']);
- $update['doctor_sign'] = $did;
- $this->xz->updateExam($id,$update);
- }else{
- $this->xz->updateExam($id,$update);
- }
- }
- else{
- $name = $params['name'] ?? null;
- $hopitalized_no = null;
- $bed_no = null;
- $exam_project = null;
- if($params['institution_id'] == '27400005') {
- $cache = $this->xz->getCache("worklist_".$params['patient_num']);
- if(!empty($cache))
- {
- $key = "worklist_".$params['patient_num'];
- $d = json_decode($cache, true);
- Log::record('东民二院;存储key为'.$key.';存储内容为'.$cache);
- $name = $d['NAME'];
- $hopitalized_no = $d['zyh'];
- $bed_no = $d['cwh'];
- $exam_project = $d['PARTOFCHECK'];
- }
- }
- $uid = $this->xz->getStudyUid($params['study_id']);
- if(empty($uid))
- {
- $uid = $params['studyuid'] ?? null;
- }
- $body_part_text = '';
- if(!empty($params['body_part'] ?? null))
- {
- $body_part_text = $this->xz->getBodyText($params['body_part']);
- }
- $data = [
- 'id'=>UUIDUtils::uuid(),
- 'patient_id'=>$params['patient_id'],
- 'study_id'=>$params['study_id'],
- 'patient_num'=>$params['patient_num'],
- 'accession_num'=>$params['accession_num'] ?? null,
- 'exam_datetime'=>$params['exam_datetime'] ?? null,
- 'exam_class'=>$params['exam_class'] ?? null,
- 'institution_id'=>$params['institution_id'] ?? null,
- 'device_name'=>$params['device_name'] ?? null,
- 'body_part'=>$params['body_part'] ?? null,
- 'body_part_text'=>$body_part_text,
- 'createdAt'=>date('Y-m-d H:i:s',time()),
- 'exam_status'=>'3',
- 'name'=>$name,
- 'phone'=>$params['phone'] ?? null,
- 'card_num' => $params['card_num'] ?? null,
- 'studyid'=>$params['studyid'] ?? null,
- 'studyuid'=>$uid,
- 'sex' =>$params['sex'] ?? null,
- 'age' => $params['age'] ?? null,
- 'hopitalized_no' => $hopitalized_no,
- 'bed_no' => $bed_no,
- 'exam_project' => $exam_project,
- 'node_type'=>$params['node_type'] ?? 1
- ];
- // 队列处理并分配
- $did = $this->handle_queue($params['institution_id']);
- $exam['doctor_sign'] = $did;
- $this->xz->insertExam($data);
- $id = $data['id'];
- $exam = $data;
- unset($exam['id']);
- $exam['exam_id'] = $data['id'];
- $film = $this->xz->getInsFilmInfo($params['institution_id']);
- if(!empty($film))
- {
- if($film['charge_mode'] == Config::get('order_type')['hospitalPay']){
- //创建检查 必须为医院托管模式 才允许创建胶片记录
- $this->save_ins_film_water($id,$film['charge_mode'],$film['film_price'],$params['institution_id']);
- $this->xz->updateExam($id,['pay_status'=>1]);
- }
- }
- log::record('当前医院id'.$params['institution_id']);
- $phone = $params['phone'] ?? '';
- $value = 'patient_sms';
- $sms = $this->xz->getInsValue($params['institution_id'],$value);
- log::record('当前医院发送短信'.$sms);
- if($sms == 1)
- {
- // log::record('手机号为'.$phone);
- // if(!empty($phone))
- // {
- // $institution = $this->xz->getInstitutionName($params['institution_id']);
- // $code = rand(1000,9999);
- // $share = [
- // 'id'=>UUIDUtils::uuid(),
- // 'examId'=>$id,
- // 'code'=>$code,
- // 'overdueTime'=>'5475', //有效期15年
- // 'phone'=>$phone,
- // 'study_id'=>$params['study_id'],
- // 'send_message'=>1,
- // 'source'=>1 //1 为影像同步
- // ];
- // $send = send_message::sendExam2Patient($phone,$code,$institution,$share['id']);
- // $data = json_decode(json_encode($send),true);
- // if($data['Code'] == 'OK'){
- // $share['send_message'] = 1;
- // }else{
- // $share['send_message'] = 0;
- // }
- // $this->xz->saveSms($share);
- // }
- }
- // if($params['institution_id'] ?? null){
- // log::record('开始回调');
- // $method = $this->xz->getApiAction($params['institution_id'],Config::get('api_action')['create']);
- // $action = $method.'Action';
- // log::record($action);
- // if(method_exists($this,$action)){
- // $r = $this->$action($params,$exam,Config::get('api_action')['create']);
- //// return $r;
- // }else{
- // log::record('没有找到对应的action');
- // }
- //
- // }else{
- // log::record('没有这个医院id'.$params['institution_id'] ?? null);
- // }
- }
- $time2 = time();
- $time = $time2-$time1;
- $this->xz->insertSpecialLog($time,'xz/create');
- return $id;
- }
- //医院胶片流水
- public function save_ins_film_water($exam_id,$order_type,$money,$institution)
- {
- $money_water = [
- 'money'=>$money,
- 'order_type'=>$order_type,
- 'type'=>'2', //电子胶片
- 'exam_id'=>$exam_id,
- 'institution_id'=>$institution,
- 'pay_way'=>'2', //医院支付
- 'status'=>'0', //未支付
- 'pay_type'=>'1' //支入
- ];
- $this->xz->saveMoneyWater($money_water);
- return true;
- }
- public function test($params,$exam)
- {
- $method = $this->xz->getApiAction($params['institution_id'],Config::get('api_action')['create']);
- $action = $method.'Action';
- if(method_exists($this,$action)){
- $r = $this->$action($params,$exam,Config::get('api_action')['create']);
- return $r;
- }
- }
- public function jsdAction($params,$data,$action,$times = 1)
- {
- try{
- $this->jsdLog('进入金盛达区间');
- log::record('进入金盛达区间');
- $this->jsdLog('当前次数----'.$times);
- log::record('当前次数----'.$times);
- $jsd_token = $this->xz->getCache('jsd_token');
- $this->jsdLog('第一次请求的token----'.$jsd_token);
- $this->jsdLog('请求的examid----'.$data['exam_id']);
- log::record('第一次请求的token----'.$jsd_token);
- if(!$jsd_token){
- $jsd_token = $this->getJsdToken($params['institution_id'],$data['exam_id']);
- }
- $this->jsdLog("token为:".$jsd_token) ;
- log::record("token为:".$jsd_token) ;
- $this->jsdLog('医院id'.$params['institution_id']);
- log::record('医院id'.$params['institution_id']);
- $this->jsdLog('动作'.$action);
- log::record('动作'.$action);
- $apis = $this->xz->getApis($params['institution_id'],$action);
- $method = $apis['action'].'_'.$apis['method'];
- $this->jsdLog('调用方法'.$method);
- log::record('调用方法'.$method);
- // $apis['key'] = 'a093e7998f0f4c80a5a7f66f31bdb483';
- // $apis['url'] = 'http://pacs.hnjsd.com.cn:8080/pacs/api/pacs/pacsOrganRegister.json';
- // $method = 'jsdcreate_jsd';
- $this->jsdLog("密钥为 :".$apis['key']) ;
- log::record("密钥为 :".$apis['key']) ;
- $jsdInfo = $this->makeJsdInfo($params,$data,$jsd_token,$apis['key']);
- if(method_exists($this,$method)){
- $this->jsdLog('存在方法,进入区间');
- log::record('存在方法,进入区间');
- $return = $this->$method($apis['url'],$jsdInfo);
- $this->jsdLog('金盛达回调返回数据'.$return);
- log::record('金盛达回调返回数据'.$return);
- $r = json_decode($return,true);
- $this->jsdLog('返回码是:'.$r['resultCode']);
- log::record('返回码是:'.$r['resultCode']);
- $update = ['push_api'=>$r['resultCode'],'api_message'=>$r['message'] ?? null];
- $this->xz->updateExam($jsdInfo['exam_id'],$update);
- if($r['resultCode'] != 1){
- $this->sendDing('金盛达请求失败,失败原因:'.($r['message'] ?? '无').'失败返回码:'.$r['resultCode'].',登陆请求token为'.$jsd_token,$data['exam_id']);
- $this->jsdLog('当前次数----'.$times);
- log::record('当前次数----'.$times);
- $del = $this->xz->delCache('jsd_token');
- $this->jsdLog('缓存删除'.($del ? '成功' : '失败'));
- log::record('缓存删除'.($del ? '成功' : '失败'));
- if($times == 3){
- $this->throwError($r['message'],$r['resultCode']);
- }
- $time = $times+1;
- return $this->jsdAction($params,$data,$action,$time);
- }
- $success = '金盛达请求成功,唯一检查id:'.$data['exam_id'].',登陆token为'.$jsd_token;
- $this->sendDing($success);
- return $r;
- }else{
- $this->jsdLog('方法不存在');
- log::record('方法不存在');
- $this->throwError('不存在方法'.$method,'3030');
- }
- }catch (\Exception $e)
- {
- $this->sendDing('金盛达异常,原因:'.$e->getMessage(),$data['exam_id']);
- $this->jsdLog('金盛达异常,原因:'.$e->getMessage().' 检查id:'.$data['exam_id']);
- log::record('金盛达异常,原因:'.$e->getMessage());
- $this->throwError('金盛达异常,原因:'.$e->getMessage(),'3031');
- }
- }
- public function sendDing($message,$examId=null)
- {
- $time = time()* 1000;
- $secret = 'SEC7eb73155768e08feeb0cb1bb84b2effe7ce6a75b69634a339a900dcc2cf5dd4e';
- $m = $time."\n".$secret;
- $s = hash_hmac('sha256', $m, $secret, true);
- $a = base64_encode($s);
- $b = urlencode($a);
- if(!empty($examId)){
- $message .= " 继续请求地址为:https://risdevserver3.pacsonline.cn/xz/test?id=".$examId;
- }
- $dingding = Config::get('dingding_url');
- $url =$dingding."/robot/send?access_token=a7994ade98986725955c4a6f583ba4b5d6e500ad15f16173c96cc76518b67ae4×tamp=$time&sign=$b";
- $data = array ('msgtype' => 'text','text' => array ('content' => $message));
- $data_string = json_encode($data);
- $result = $this->request_by_curl($url, $data_string);
- }
- public function makeJsdInfo($params,$data,$token,$key)
- {
- $info = [
- 'sysCode'=>'0015',
- 'patient_id'=>$data['patient_id'],
- 'patient_name'=>$data['name'],
- 'patient_sex'=>$data['sex'],
- 'card_num'=>$data['card_num'],
- 'phone'=>$data['phone'],
- 'birthday'=>$data['birthday'] ?? null,
- 'patient_age'=>$data['age'],
- 'hospital_id'=>$params['institution_id'],
- 'hospital_name'=>$this->xz->getInstitutionName($params['institution_id']),
- 'dcm_patient_id'=>$data['patient_num'],
- 'study_id'=>$data['study_id'],
- 'studyuid'=>$data['studyuid'],
- 'studyid'=>$data['studyid'],
- 'accession_num'=>$data['accession_num'],
- 'studydate'=>$data['exam_datetime'],
- 'modality'=>$data['exam_class'],
- 'status'=>'1',
- 'exam_id'=>$data['exam_id'],
- 'exam_status'=>(string)$data['exam_status'],
- 'timestamp'=>(string)$this->msectime(),
- ];
- ksort($info);
- $string = '';
- foreach ($info as $k=>$v){
- if(!empty($v)){
- if($string == ''){
- $string = $k.'='.$v;
- }else{
- $string .= "&".$k.'='.$v;
- }
- }
- }
- $string .= '&key='.$key;
- $this->jsdLog( "加密前字符串 :".$string);
- $this->jsdLog( "加密后sign ".md5($string));;
- $info['sign'] = strtoupper(md5($string));
- $info['token'] = $token;
- // var_dump(json_encode($info));
- $this->jsdLog( "转换为json的数据:".json_encode($info));
- return $info;
- }
- public function getJsdToken($institution,$exam_id)
- {
- $username = 'pacsonline';
- $password = 'zskk_200408';
- $sysCode = '0015';
- $data = [
- 'userName'=>$username,
- 'password'=>$password,
- 'sysCode'=>$sysCode
- ];
- $url = 'http://pacs.hnjsd.com.cn:9080/pacs/api/pacs/getToken.json';
- $return = $this->curlPost($url,$data);
- $this->jsdLog($exam_id.'登陆请求的返回值'.$return);
- log::record($exam_id.'登陆请求的返回值'.$return);
- $info = json_decode($return,true);
- if($info['resultCode'] == '1')
- {
- $token = $info['uniqueCode'];
- $this->xz->setCache('jsd_token',$token,6000);
- return $token;
- }else{
- $this->sendDing('金盛达登陆异常,原因:'.$info['message'] ?? '',$exam_id);
- $this->throwError($info['message'] ?? '金盛达登陆异常',$info['resultCode'] ?? 10000);
- }
- }
- public function create_jsd($url,$info)
- {
- $data = $this->curlPost($url,$info);
- $this->jsdLog('金盛达创建请求数据为'.json_encode($info));
- $this->jsdLog('金盛达创建请求结果为'.$data);
- log::record('金盛达创建请求数据为'.json_encode($info));
- log::record('金盛达创建请求结果为'.$data);
- return $data;
- }
- public function yjkAction($params,$data,$action)
- {
- $apis = $this->xz->getApis($params['institution_id'],$action);
- $data = json_encode($data);
- $method = $apis['action'].'_'.$apis['method'];
- $number = rand(10000000,99999999);
- $time = time();
- $key = $apis['key'];
- $str = $data.$number.$time;
- $info = [
- 'timestamp'=>$time,
- 'random'=>$number,
- 'signature'=>base64_encode(hash_hmac("sha1", $str, $key, true)),
- 'data'=>$data
- ];
- if(method_exists($this,$method)){
- $this->$method($apis['url'],$info);
- }
- }
- public function yjkcreate_jyk($url,$info)
- {
- $data = $this->curlPost($url,$info);
- Log::record('医健康创建请求数据为'.$info);
- Log::record('医健康创建请求结果为'.$data);
- }
- public function filmCallback($params)
- {
- $key = Config::get('ins_type')[$params['ins_type']];
- $exam = $this->xz->getExam($key,$params[$key],$params['institution_id']);
- $examId = $exam['id'];
- if(!empty($examId)){
- $film = $this->xz->getInsFilmInfo($params['institution_id']);
- if($film['charge_mode'] == Config::get('order_type')['patientToHospital']){
- $water_log = $this->xz->getWaterLog($examId,$params['institution_id']);
- //胶片回调 必须为医院代收模式才允许创建胶片流水
- if(empty($water_log)){
- $this->save_ins_film_water($examId,$film['charge_mode'],$film['film_price'],$params['institution_id']);
- }
- }
- log::record('zskkccs存在回调');
- if(!empty($exam['id'])){
- if($exam['pay_status'] !== '1')
- {
- log::record('支付状态为'.$exam['pay_status']);
- Log::record('zskkccs胶片回调key值'.$params[$key]);
- $data = $this->xz->getPushInfo($exam['id']);
- $pushType = 5;
- $cont = [
- 'name'=>$exam['name'],
- 'modality'=>$exam['exam_class'],
- 'examDate'=>$exam['exam_datetime'],
- 'study_id'=>$exam['study_id']
- ];
- $content = json_encode($cont,true);
- $openids = $this->xz->getOpenId($data);
- foreach ($openids as $k=>$v){
- $this->new_wechat_push($v,$pushType,$content);
- }
- }
- }
- $this->xz->updateExam($examId,['pay_status'=>1]);
- return true;
- }else{
- $this->throwError('检查不存在','0231');
- }
- }
- public function jsdLog($info)
- {
- $file = ROOT_PATH . 'public' . DS . 'runtime/jsd';
- if(!file_exists($file)){
- mkdir($file,0777,true);
- }
- $date = date('Ymd',time());
- $value = date('Y-m-d H:i:s',time()).$info;
- //创建ini文件
- $gao_file = fopen($file.'/'.$date.".txt","a+");
- //替换
- $string = iconv("utf-8", "GB2312", $value);
- //附加分号和换行专
- $string = $string . ";" . "\r\n";
- //将内容写入文件
- fwrite($gao_file, $string);
- //关闭文件
- fclose($gao_file);
- }
- public function getDcmUrlInfo($id)
- {
- $exam = $this->xz->getExamDataById($id);
- $study = $exam['study_id'];
- $image= $this->xz->getImageInfo($study);
- $data = [];
- $i = 0;
- foreach ($image as $k=>$v)
- {
- $info = [];
- $adress = ''; //前端传值
- $url = $this->makeUrl($v['url'],$adress);
- $info = ['id'=>$v['id'],'url'=>str_replace('dicomweb','http',$url),'exam_id'=>$id,'study_id'=>$v['study_id'],'series_id'=>$v['series_id'],'sop_uid'=>$v['sopUid']];
- $data[] = $info;
- }
- // var_dump($data);die;
- // var_dump(json_encode($data,JSON_UNESCAPED_SLASHES));
- $this->curlJsonYbPost('http://192.168.1.51:5000/get_dcm_batch_flask/',json_encode($data,JSON_UNESCAPED_SLASHES));
- return true;
- }
- public function makeUrl($url,$adress)
- {
- if(!$url)
- {
- return '';
- }
- if(preg_match('/^dicomweb:\/\//',$url)){
- return $this->generateAliossURL($url,$adress);
- }
- if(preg_match('/^group/',$url)){
- return $this->generateFastdfsURL($url,$adress);
- }
- return $this->generateLcossURL($url,$adress);
- }
- public function generateAliossURL($url,$address)
- {
- if ($address) {
- return str_replace('zskk-dcm.oss-cn-beijing.aliyuncs.com',$address.'/oss',$url);
- }
- return $url;
- }
- public function generateFastdfsURL($url,$adress)
- {
- if($adress)
- {
- return "dicomweb://$adress/$url";
- }
- return "dicomweb://dcm.pacsonline.cn/$url";
- }
- public function wechatFix($str)
- {
- if(!$str) {
- return $str;
- }
- return str_replace('=','%3D',$str);
- }
- public function generateLcossURL($key,$adress)
- {
- $uCloudPublicKey = 'TOKEN_109bb131-db96-46cf-b693-745f37129bee';
- $uCloudPrivateKey = '515bec45-1709-41e9-862e-f05705ba47b3';
- $hTTPVerb = "GET";
- $expires = '';
- $canonicalizedUCloudHeaders = '';
- $bucket = 'zskkdcm';
- $canonicalizedResource = '/'.$bucket.'/'.$key;
- $stringToSign = $hTTPVerb."\n" .
- "\n" .
- "\n" .
- $expires . "\n" .
- $canonicalizedUCloudHeaders .
- $canonicalizedResource;
- $signature = base64_encode(hash_hmac("sha1", $stringToSign, $uCloudPrivateKey, true));
- $domain = 'dicomweb://'.$bucket.'.infile.inspurcloud.cn';
- if($adress)
- {
- $domain = 'dicomweb://'.$adress.'/lcoss';
- }
- $uCloudPublicKey = $this->wechatFix($uCloudPublicKey);
- $signature = $this->wechatFix($signature);
- $url = $domain.'/'.$key.'?UCloudPublicKey='.$uCloudPublicKey.'&Signature='.$signature.'&Expires='.$expires;
- return $url;
- // $uCloudRootPublicKey = '0cCMBBXqiuFdJrb3jy0csUwXHDEAzjPT4I8ZDvcnKlpd6RGdQ7vStHO0z1M=';
- // $uCloudRootPrivateKey = '8JYvmvzBIaM7W15bVqmdriR9pFohACpBMDz/w/c/XSqTjX+aL0YN8yFb9EQ2SUP1';
- }
- // public function getlsoss()
- //{
- // $data['UCloudPublicKey'] = 'TOKEN_109bb131-db96-46cf-b693-745f37129bee';
- // $data['UCloudPrivateKey'] = '515bec45-1709-41e9-862e-f05705ba47b3';
- // $data['bucket'] = 'zskkdcm';
- // $data['UCloudRootPublicKey'] = '0cCMBBXqiuFdJrb3jy0csUwXHDEAzjPT4I8ZDvcnKlpd6RGdQ7vStHO0z1M=';
- // $data['UCloudRootPrivateKey'] = '8JYvmvzBIaM7W15bVqmdriR9pFohACpBMDz/w/c/XSqTjX+aL0YN8yFb9EQ2SUP1';
- // return $data;
- //}
- public function saveImageNode($params)
- {
- if(empty($params))
- {
- return false;
- }
- $data = json_decode($params,true);
- $info = [];
- $num = 0;
- foreach ($data as $k=>$v)
- {
- if($k == ($num+1)*500 && $k != 0)
- {
- $num++;
- }
- if($num*500 <= $k && $k < ($num+1) * 500)
- {
- //500一组 防止一次性过多存储
- $info[$num][] = ['image_id'=>$v['id'],'image_node'=>json_encode($v['node']),'exam_id'=>$v['exam_id'],'study_id'=>$v['study_id'],'series_id'=>$v['series_id'],'sop_uid'=>$v['sop_uid']];
- }
- }
- foreach ($info as $v)
- {
- $this->xz->saveImageNode($v);
- }
- return true;
- }
- public function getImageNode($code,$type)
- {
- $where = [Config::get('dcm_type')[$type]=>$code];
- $nodeInfo = $this->xz->getImageNode($where);
- $array = [];
- foreach ($nodeInfo as $k=>$v)
- {
- $array[$k]['instanceUID'] = $v['sop_uid'];
- $nodeArray = json_decode($v['image_node']);
- $coords = [];
- foreach ($nodeArray as $key=>$value)
- {
- $coords['coords'][$key]['x'] = $value[0];
- $coords['coords'][$key]['y'] = $value[1];
- $coords['color'] = 'red';
- }
- $array[$k]['data'] = [$coords];
- }
- return json_encode($array);
- }
- public function getWjwData()
- {
- $data = $this->xz->getWjwData();
- return $data;
- }
- public function getRemoteCount()
- {
- $data = $this->xz->getRemoteCount();
- return $data;
- }
- public function getYjRemote($page,$num)
- {
- $data = $this->xz->getYjRemote($page,$num);
- return $data;
- }
- public function getYjDoctor()
- {
- $data = $this->xz->getYjDoctor();
- return $data;
- }
- }
|