12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import orthancInterface
- import orthancDatabaseBrowser
- import json
- def getJobId(jobDescription):
- return jobDescription['ID']
- def getStatus(jobStatus):
- return jobStatus['State']
-
- def isComplete(jobStatus):
- return getStatus(jobStatus)=='Success'
- class orthancPeers:
- def __init__(self,net):
- self.net=net
- def addPeer(self,name,url,username,password):
- v={"Url":url,"Username":username,"Password":password}
- jsonData=json.dumps(v)
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/peers/{name}'
- response=self.net.put(apiUrl,jsonData,'json')
- #empty response
- def deletePeer(self,name):
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/peers/{name}'
- response=self.net.delete(apiUrl)
- #empty response
- def sendResource(self,name,orthancId):
- #returns jobDescription as JSON (ID,Path)
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/peers/{name}/store'
- #response=self.net.post(apiUrl,orthancId,'text')
- v={"Resources":[f'{orthancId}'],"Synchronous":False}
- jsonData=json.dumps(v)
- response=self.net.post(apiUrl,jsonData,'json')
- return orthancDatabaseBrowser.extractJSON(response.data)
- def checkJobStatus(self,name,jobId):
- #returns jobStatus as JSON (ErrorCode, ErrorDescription, ErrorDetails, Progress, State)
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/jobs/{jobId}'
- response=self.net.get(apiUrl)
- return orthancDatabaseBrowser.extractJSON(response.data)
- def test(self,name):
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/peers/{name}/system'
- response=self.net.get(apiUrl)
- return orthancDatabaseBrowser.extractJSON(response.data)
- def list(self):
- apiUrl=self.net.getCoreURL()
- apiUrl+=f'/peers?expand'
- response=self.net.get(apiUrl)
- return orthancDatabaseBrowser.extractJSON(response.data)
|