orthancQR.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. return orthancDatabaseBrowser.extractJSON(response.data)
  23. def sendCFind(self,name,query):
  24. v={"Level":"Study","Query":query}
  25. apiURL='/'.join([self.net.getCoreURL(),'modalities',name,'query'])
  26. response=self.net.post(apiURL,json.dumps(v),'json')
  27. #pair of ID/Path json object
  28. return orthancDatabaseBrowser.extractJSON(response.data)
  29. def getCFindAnswers(self,queryId):
  30. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'answers'])
  31. response=self.net.get(apiURL)
  32. #list of answers
  33. return orthancDatabaseBrowser.extractJSON(response.data)
  34. def getCFindAnswerContent(self,queryId,answerId):
  35. apiURL='/'.join([self.net.getCoreURL(),'queries',queryId,'answers',answerId,'content'])
  36. response=self.net.get(apiURL)
  37. #content of answer, object with DICOM codes (IDs etc)
  38. return orthancDatabaseBrowser.extractJSON(response.data)