orthancQR.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import json
  2. import orthancInterface
  3. import orthancDatabaseBrowser
  4. import os
  5. import urllib3
  6. class orthancQR:
  7. def __init__(self,server):
  8. self.net=orthancInterface.orthancInterface()
  9. fconfig=os.path.join(os.path.expanduser('~'),'.labkey',f'{server}.json')
  10. self.net.init(fconfig)
  11. def addModality(self,name,v):
  12. #add modality with the name name and settings as shown below
  13. #v={"AET":aet,"Host":host,"Port":port}
  14. apiURL='/'.join([self.net.getCoreURL(),'modalities',name])
  15. response=self.net.put(apiURL,json.dumps(v),'json',timeout=urllib3.util.Timeout(read=0.5))
  16. def removeModality(self,name):
  17. apiURL='/'.join([self.net.getCoreURL(),'modalities',name])
  18. response=self.net.delete(apiURL,timeout=urllib3.util.Timeout(read=0.5))
  19. def cEcho(self,name):
  20. apiURL='/'.join([self.net.getCoreURL(),'modalities',name,'echo'])
  21. v={}
  22. response=self.net.post(apiURL,json.dumps(v),'json')
  23. #OK if empty,JSON if fail
  24. return orthancDatabaseBrowser.extractJSON(response.data)
  25. def sendCFind(self,name,par):
  26. v={"Level":par.get("Level","Study"),"Query":par["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)
  41. def startRetrievaJobForAll(self,queryId):
  42. #returns jobDescripton as JSON (ID,Path)
  43. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'retrieve'])
  44. v={"TargetAet":"NIXLJUOIL","RetrieveMethod":"C-MOVE","Synchronous":False}
  45. response=self.net.post(apiURL,json.dumps(v),'json')
  46. return orthancDatabaseBrowser.extractJSON(response.data)
  47. def startRetrieveJob(self,queryId,answerId):
  48. #returns jobDescripton as JSON (ID,Path)
  49. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'answers',answerId,'retrieve'])
  50. v={"TargetAet":"NIXLJUOIL","RetrieveMethod":"C-MOVE","Synchronous":False}
  51. response=self.net.post(apiURL,json.dumps(v),'json')
  52. return orthancDatabaseBrowser.extractJSON(response.data)