刘桂岩 5 năm trước cách đây
mục cha
commit
9130e155ec

+ 4 - 6
application/common/library/DicomPaser.php

@@ -13,26 +13,24 @@ namespace app\common\library;
 require dirname(__FILE__).'/nanodicom/Nanodicom.php';
 use Nanodicom;
 use app\common\library\DicomPaserTag;
-use think\Exception;
-
 class DicomPaser {
     public static function paser($filePath = '') { 
 
         if(empty($filePath)) {
-            return json_encode(['status'=>'fail','code'=>'2000','msg'=>"The filePath $filePath is empty or null"]);
+            throw new Error("The filePath $filePath is empty or null");
         }
 
         if(!file_exists($filePath)) {
-            return json_encode(['status'=>'fail','code'=>'2000','msg'=>"The filePath $filePath not exist"]);
+            throw new Error("The filePath $filePath not exist");
         }
 
         if(!is_file($filePath)) {
-            return json_encode(['status'=>'fail','code'=>'2000','msg'=>"The filePath $filePath not file"]);
+            throw new Error("The filePath $filePath not file");
         }
 
         $dicom = Nanodicom::factory($filePath);
         if(! $dicom->is_dicom()) {
-            return json_encode(['status'=>'fail','code'=>'2000','msg'=>"The filePath $filePath not dcm file"]);
+            throw new Error("The filePath $filePath not dcm file");
         }
 
         $a = $dicom->get(0x0010, 0x0010, 'N/A');

+ 5 - 5
application/inter/controller/Dcom.php

@@ -5,12 +5,13 @@ namespace app\inter\controller;
 use app\common\library\DicomPaser;
 use app\common\library\UUIDs;
 use think\Controller;
+use think\Exception;
 
 class Dcom extends Controller  //Base
 {
     public function upload_file()
     {
-//        try{
+        try{
             // 获取表单上传文件 例如上传了001.jpg
             $file = request()->file('file');
             // 移动到框架应用根目录/public/uploads/ 目录下
@@ -20,7 +21,6 @@ class Dcom extends Controller  //Base
                     // 成功上传后 获取上传信息
                     $path = 'public' . DS . 'uploads'.DS.$info->getSaveName();
                     $info = DicomPaser::paser(ROOT_PATH . $path);
-                    var_dump($info);die;
                     foreach($info as  $k=>$v){
                         $info[$k] = trim($v);
                     }
@@ -35,9 +35,9 @@ class Dcom extends Controller  //Base
             }else{
                 return json_encode(['status'=>'fail','code'=>'2000','msg'=>'不存在上传的文件']);
             }
-//        }catch(Exception $e){
-//            return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
-//        }
+        }catch(Exception $e){
+        return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
+    }
     }
 
     public function insertPatient($info)