orthancQR.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import json
  2. import orthancInterface
  3. import orthancDatabaseBrowser
  4. import os
  5. class orthancQR:
  6. def __init__(self,server):
  7. self.net=orthancInterface.orthancInterface()
  8. fconfig=os.path.join(os.path.expanduser('~'),'.labkey',f'{server}.json')
  9. self.net.init(fconfig)
  10. def addModality(self,name,aet,host,port):
  11. apiURL='/'.join([self.net.getCoreURL(),'modalities',name])
  12. v={"AET":aet,"Host":host,"Port":port}
  13. response=self.net.put(apiURL,json.dumps(v),'json')
  14. def removeModality(self,name):
  15. apiURL='/'.join([self.net.getCoreURL(),'modalities',name])
  16. response=self.net.delete(apiURL)
  17. def cEcho(self,name):
  18. apiURL='/'.join([self.net.getCoreURL(),'modalities',name,'echo'])
  19. v={}
  20. response=self.net.get(apiURL)
  21. #OK if empty,JSON if fail
  22. if len(response.data)==0:
  23. return {}
  24. return orthancDatabaseBrowser.extractJSON(response.data)
  25. def sendCFind(self,name,query):
  26. v={"Level":"Study","Query":query}
  27. apiURL='/'.join([self.net.getCoreURL(),'modalities',name,'query'])
  28. response=self.net.post(apiURL,json.dumps(v),'json')
  29. #pair of ID/Path json object
  30. return orthancDatabaseBrowser.extractJSON(response.data)
  31. def getCFindAnswers(self,queryId):
  32. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'answers'])
  33. response=self.net.get(apiURL)
  34. #list of answers
  35. return orthancDatabaseBrowser.extractJSON(response.data)
  36. def getCFindAnswerContent(self,queryId,answerId):
  37. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'answers',answerId,'content'])
  38. response=self.net.get(apiURL)
  39. #content of answer, object with DICOM codes (IDs etc)
  40. return orthancDatabaseBrowser.extractJSON(response.data)