12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import orthancInterface
- import json
- import chardet
- def extractJSON(data):
- encoding=chardet.detect(data)["encoding"]
- return json.loads(data.decode(encoding))
- class orthancDB:
- def __init__(self,net):
- self.net=net
- def getPatients(self):
- url=self.net.getCoreURL()
- url+='/patients'
- response=self.net.get(url)
- return extractJSON(response.data)
- def getPatientData(self, orthancId):
- return self.getData('patients',orthancId)
- def getStudyData(self, studyOrthancId):
- return self.getData('studies',studyOrthancId)
- def getSeriesData(self, seriesOrthancId):
- return self.getData('series',seriesOrthancId)
- def getData(self, level, orthancId):
- url=self.net.getCoreURL()
- url+='/'+level+'/'+orthancId
- response=self.net.get(url)
- return extractJSON(response.data)
- def selectRows(self, qfilter):
- obj={}
- obj["Level"]="Instance"
- obj["Query"]=qfilter
- jsonData=json.dumps(obj)
- url=self.net.getCoreURL()
- url+='/tools/find'
- response=self.net.post(url,'json',jsonData)
- encoding=chardet.detect(response.data)["encoding"]
- return json.loads(response.data.decode(encoding))
- def upload(self, f) :
- url=self.net.getCoreURL()
- url+='/instances'
- fobj=open (f, 'rb')
- response=self.net.post(url,'octet-stream',fobj.read())
- encoding=chardet.detect(response.data)["encoding"]
- return json.loads(response.data.decode(encoding))
|