orthancDatabaseBrowser.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import orthancInterface
  2. import json
  3. import chardet
  4. def extractJSON(data):
  5. encoding=chardet.detect(data)["encoding"]
  6. return json.loads(data.decode(encoding))
  7. class orthancDB:
  8. def __init__(self,net):
  9. self.net=net
  10. def getPatients(self):
  11. url=self.net.getCoreURL()
  12. url+='/patients'
  13. response=self.net.get(url)
  14. return extractJSON(response.data)
  15. def getPatientData(self, orthancId):
  16. return self.getData('patients',orthancId)
  17. def getStudyData(self, studyOrthancId):
  18. return self.getData('studies',studyOrthancId)
  19. def getSeriesData(self, seriesOrthancId):
  20. return self.getData('series',seriesOrthancId)
  21. def getData(self, level, orthancId):
  22. url=self.net.getCoreURL()
  23. url+='/'+level+'/'+orthancId
  24. response=self.net.get(url)
  25. return extractJSON(response.data)
  26. def selectRows(self, qfilter):
  27. obj={}
  28. obj["Level"]="Instance"
  29. obj["Query"]=qfilter
  30. jsonData=json.dumps(obj)
  31. url=self.net.getCoreURL()
  32. url+='/tools/find'
  33. response=self.net.post(url,'json',jsonData)
  34. encoding=chardet.detect(response.data)["encoding"]
  35. return json.loads(response.data.decode(encoding))
  36. def upload(self, f) :
  37. url=self.net.getCoreURL()
  38. url+='/instances'
  39. fobj=open (f, 'rb')
  40. response=self.net.post(url,'octet-stream',fobj.read())
  41. encoding=chardet.detect(response.data)["encoding"]
  42. return json.loads(response.data.decode(encoding))