Bläddra i källkod

Merge to head

NIX User 4 år sedan
förälder
incheckning
d5bfe8c323
4 ändrade filer med 49 tillägg och 0 borttagningar
  1. 3 0
      Readme.md
  2. 5 0
      network-config-sample.json
  3. 8 0
      orthancFileBrowser.py
  4. 33 0
      pythonScripts/testUpload.py

+ 3 - 0
Readme.md

@@ -23,5 +23,8 @@ ofb=orthancFileBrowser.orthancFileBrowser(onet)
 ...
 #download seriesId to fname
 ofb.getZip('series',seriesId,fname)
+
+#upload dicom file
+ofb.upload('/path/to/file.dcm')
 ```
 

+ 5 - 0
network-config-sample.json

@@ -11,5 +11,10 @@
   { "user" : "andrej.studen@ijs.si",
     "password" : "labkeyPassword"
   }
+  "orthanc":
+  { "user" : "userName",
+    "password": "orthancPassword",
+    "server":"https://orthanc.fmf.uni-lj.si",
+    "notUsedSSL":"change to SSL to use SSL, provide user crt, key and ca"
 }
 

+ 8 - 0
orthancFileBrowser.py

@@ -10,9 +10,17 @@ class orthancFileBrowser:
     def getZip(self,retrieveLevel, dataId, path):
         url=self.net.getCoreURL()
         url+="/"+retrieveLevel+"/"+dataId+"/archive";
+        print("Using: {}".format(url))
         response=self.net.get(url,binary=True);
         with open(path,'wb') as out_file:
             shutil.copyfileobj(response,out_file)
         response.release_conn()
         #response.data is a byte array -> is the same as file
 
+    def upload(self,path):
+        url=self.net.getCoreURL()
+        url+="/instances"
+        with open(path,'rb') as f:
+            response=self.net.post(url,"octet-stream", f.read())
+        print(response.data)
+

+ 33 - 0
pythonScripts/testUpload.py

@@ -0,0 +1,33 @@
+import os
+import json
+import re
+import subprocess
+#import nibabel
+import shutil
+import sys
+import pydicom
+
+shome=os.path.expanduser('~studen')
+
+sys.path.insert(1,shome+'/software/src/orthancInterface')
+import orthancInterface
+import orthancFileBrowser
+
+fhome=os.path.expanduser('~')
+fconfig=os.path.join(fhome,'.labkey','network.json')
+
+onet=orthancInterface.orthancInterface()
+onet.init(fconfig)
+ofb=orthancFileBrowser.orthancFileBrowser(onet)
+
+uploadDir=os.path.join(fhome,'temp','testFiles')
+
+files=os.listdir(uploadDir)
+
+for f in files:
+    fg=os.path.join(uploadDir,f)
+    print(fg)
+    ofb.upload(fg)
+
+print("Done")
+