刘桂岩 4 months ago
parent
commit
1dc0a306c3
1 changed files with 84 additions and 12 deletions
  1. 84 12
      data/code/w7/w7_bgui_dicom/application/dicom/controller/Dicom.php

+ 84 - 12
data/code/w7/w7_bgui_dicom/application/dicom/controller/Dicom.php

@@ -146,7 +146,7 @@ class Dicom extends Controller
                     ->where('ID', $study_id)
                     ->value('EXAM_ID');
                 if(!$exam){
-                    $res = Http::post('127.0.0.1:9600/xz/create',$exam_data);
+                    $res = Http::post('127.0.0.1:8088/xz/create',$exam_data);
                     if($res && json_decode($res,true)['code'] == 0){
                         Db::table('PACSDB.STUDIES')
                             ->where('ID', $study_id)
@@ -291,6 +291,7 @@ class Dicom extends Controller
 				];
 				$res = Http::post('127.0.0.1:9600/xz/create',$exam_data);
 				if($res && json_decode($res,true)['code'] == 0){
+                    log::record($res);
 				    $this->data_update('STUDIES',['ID'=>$study_id],['EXAM_ID' =>  json_decode($res,true)['data']]);
 				}
 		//	}
@@ -305,14 +306,81 @@ class Dicom extends Controller
                		  Cache::set('taskList',$task);
 			  };
             // todo push his
+            $cache = Cache::get($study_id.$dicom_data['accessionNumber']);
+            if(empty($cache))
+            {
+                // 只有第一次才会推送
+                Cache::set($study_id.$dicom_data['accessionNumber'],1,600);
+                $this->pushDcmUrl($dicom_data['accessionNumber'],$study_id);
+            }
 //            $this->pushHis($dicom_data['studyUid'],$study_id);
 			// 成功
+//            $this->pushW7($dicom_data['studyUid'],$study_id);
 			return ServerResponse::getSuccess(['success'=>true],'success');
 		} catch ( Exception $exception){
 			ServerResponse::throwError($exception->getMessage());
 		}
 	}
 
+    public function pushDcmUrl($accession,$study)
+    {
+        $a = ROOT_PATH.'/public/data.xml';
+        $xml_object = simplexml_load_file($a);
+        $xml_json = json_encode($xml_object);//转换为json数据
+        $xml_array = json_decode($xml_json,true);//转换成数组
+        $serverIp = $xml_array['server_ip'];
+        $clientIp = $xml_array['client_ip'];
+        $url = $clientIp."/#/pc?studyurl=".$serverIp."/dicom/dicom/getData?address=".$clientIp."&study_id=".$study;
+        $arr =  ['url'=>$url,'status'=>'complete','applicationFormNo'=>$accession];
+        $this->curlPost($url,$arr);
+    }
+    public function push()
+    {
+        $params = $this->request->get();
+        $uid = $params['study_uid'] ?? null;
+        if(empty($uid))
+        {
+            return 'studyUid is empty';
+        }
+        $studyId = $this->data_value('EXAMS',['STUDYUID'=>$uid],'STUDY_ID');
+        $data = $this->pushW7($uid,$studyId);
+        return $data;
+    }
+    public function pushW7($studyUid,$study_id)
+    {
+        if(empty($studyUid))
+        {
+            return 'studyUid is empty';
+        }
+        $zip = ROOT_PATH . 'public' . DS.'cs.zip';
+        $check_code = $this->data_value('WJ_WORKLIST',['STUDY_INSTANCE_UID'=>$studyUid],'EXAM_NO');
+        $data = [
+            'jcxxbh' => $check_code,
+            'studyid' => $study_id,
+            'zip'	=> new \CURLFile(realpath($zip))
+        ];
+        $a = '/data/code/w7/server_ris/server/public/data.xml';
+        $xml_object = simplexml_load_file($a);
+        $xml_json = json_encode($xml_object);//转换为json数据
+        $xml_array = json_decode($xml_json,true);//转换成数组
+        $ip = $xml_array['w7CallBackIp'];
+        $url = 'http://'.$ip.'/web/pacs/pacsResult';
+
+        $this->curlPost($url,$data);
+	}
+
+    public function curlPost($url, $data)
+    {
+        $ch = curl_init();
+        curl_setopt($ch,CURLOPT_URL,$url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch,CURLOPT_POST,1);
+        curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type:multipart/form-data;charset=utf-8'));
+        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
+        $res = curl_exec($ch);
+        curl_close($ch);
+        return $res;
+    }
 	// 走定时任务
     public function timingTask()
     {
@@ -407,15 +475,7 @@ class Dicom extends Controller
                 $xml_array = json_decode($xml_json,true);//转换成数组
                 $ip = $xml_array['w7CallBackIp'];
                 $url = 'http://'.$ip.'/web/pacs/pacsResult';
-
-                $ch = curl_init();
-                curl_setopt($ch,CURLOPT_URL,$url);
-                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-                curl_setopt($ch,CURLOPT_POST,1);
-                curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type:multipart/form-data;charset=utf-8'));
-                curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
-                $res = curl_exec($ch);
-                curl_close($ch);
+                $res = $this->curlPost($url,$data);
 
                 if($res && json_decode($res,true)['statusCode'] == '200'){
                     $this->data_update('WJ_WORKLIST',['STUDY_INSTANCE_UID'=>$studyUid],[
@@ -570,6 +630,8 @@ class Dicom extends Controller
             $save['ID'] = $id;
             $save['STUDYUID'] = $info['studyUid'];
             $save['PATIENT_ID'] = $patient_id;
+            $save['IS_BIND'] = 0;
+            $save['IS_W7'] = 0;
             $res = $this->data_insert('STUDIES',$save);
         }
 
@@ -689,8 +751,8 @@ class Dicom extends Controller
 	public function convertEncoding($arr)
 	{
 		foreach ($arr as &$v){
-			$encode = mb_detect_encoding($v, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
-			$v = mb_convert_encoding($v, 'UTF-8', $encode);
+//			$encode = mb_detect_encoding($v, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
+//			$v = mb_convert_encoding($v, 'UTF-8', $encode);
 			$v = trim($v);
 		}
 		unset($v);
@@ -877,5 +939,15 @@ class Dicom extends Controller
     }
 
 
+    public function getDicomZip()
+    {
+        $params = $this->request->get();
+        $patientId = $params['patientId']; // PATIENT_NUM
+        $studyUid = $params['studyUid'];
+        $zip = $this->makeZip($this->storagePath.$patientId.'/',$studyUid,ROOT_PATH . 'public' . DS.'zip'.'/'.$studyUid.'.zip');
+        $data = new \CURLFile(realpath($zip));
+        return $data;
+    }
+
 }