|
@@ -2,10 +2,9 @@ import os
|
|
|
import unittest
|
|
|
from __main__ import vtk, qt, ctk, slicer
|
|
|
from slicer.ScriptedLoadableModule import *
|
|
|
-import slicerNetwork
|
|
|
-import loadDicom
|
|
|
import json
|
|
|
import datetime
|
|
|
+import sys
|
|
|
|
|
|
|
|
|
|
|
@@ -42,12 +41,41 @@ class iraemmBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
print("Setting up iraemmBrowserWidget")
|
|
|
ScriptedLoadableModuleWidget.setup(self)
|
|
|
|
|
|
- self.network=slicerNetwork.labkeyURIHandler()
|
|
|
+
|
|
|
+ fhome=os.path.expanduser('~')
|
|
|
+ fsetup=os.path.join(fhome,'.labkey','setup.json')
|
|
|
+ try:
|
|
|
+ with open(fsetup) as f:
|
|
|
+ self.setup=json.load(f)
|
|
|
+ except FileNotFoundError:
|
|
|
+ self.setup={}
|
|
|
+
|
|
|
+ try:
|
|
|
+ pt=self.setup['paths']
|
|
|
+ except KeyError:
|
|
|
+ self.setup['paths']={}
|
|
|
+
|
|
|
+ try:
|
|
|
+ sys.path.append(self.setup['paths']['labkeyInterface'])
|
|
|
+ except KeyError:
|
|
|
+ self.setup['paths']['labkeyInterface']=loadLibrary('labkeyInterface')
|
|
|
+ with open(fsetup,'w') as f:
|
|
|
+ json.dump(self.setup,f,indent='\t')
|
|
|
+
|
|
|
+ import labkeyInterface
|
|
|
+ import labkeyDatabaseBrowser
|
|
|
+ import labkeyFileBrowser
|
|
|
+
|
|
|
+
|
|
|
+ self.network=labkeyInterface.labkeyInterface()
|
|
|
|
|
|
fconfig=os.path.join(os.path.expanduser('~'),'.labkey','network.json')
|
|
|
- self.network.parseConfig(fconfig)
|
|
|
- self.network.initRemote()
|
|
|
+ self.network.init(fconfig)
|
|
|
+
|
|
|
+ self.db=labkeyDatabaseBrowser.labkeyDB(self.network)
|
|
|
+ self.fb=labkeyFileBrowser.labkeyFileBrowser(self.network)
|
|
|
self.project="iPNUMMretro/Study"
|
|
|
+ self.schema='study'
|
|
|
self.dataset="Imaging1"
|
|
|
self.reviewDataset="ImageReview"
|
|
|
self.aeDataset="PET"
|
|
@@ -55,7 +83,7 @@ class iraemmBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
|
|
|
|
|
|
- ds=self.network.filterDataset(self.project,self.dataset,[])
|
|
|
+ ds=self.db.selectRows(self.project,self.schema,self.dataset,[])
|
|
|
ids=[row['PatientId'] for row in ds['rows']]
|
|
|
ids=list(set(ids))
|
|
|
|
|
@@ -80,7 +108,10 @@ class iraemmBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
self.segmentationField=qt.QLabel("Segmentation")
|
|
|
setupFormLayout.addRow("Data field (Segmentation):",self.segmentationField)
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ self.idField=qt.QLabel(self.network.getUserId()['displayName'])
|
|
|
+ setupFormLayout.addRow("ID",self.idField)
|
|
|
self.logic=iraemmBrowserLogic(self)
|
|
|
|
|
|
|
|
@@ -194,7 +225,7 @@ class iraemmBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
def onPatientListChanged(self,i):
|
|
|
idFilter={'variable':'PatientId','value':self.patientList.currentText,'oper':'eq'}
|
|
|
- ds=self.network.filterDataset(self.project,self.dataset, [idFilter])
|
|
|
+ ds=self.db.selectRows(self.project,self.schema,self.dataset, [idFilter])
|
|
|
seq=[int(row['SequenceNum']) for row in ds['rows']]
|
|
|
self.visitList.clear()
|
|
|
|
|
@@ -211,7 +242,7 @@ class iraemmBrowserWidget(ScriptedLoadableModuleWidget):
|
|
|
idFilter={'variable':'PatientId',\
|
|
|
'value':self.patientList.currentText,'oper':'eq'}
|
|
|
sFilter={'variable':'SequenceNum','value':s,'oper':'eq'}
|
|
|
- ds=self.network.filterDataset(self.project,self.dataset,[idFilter,sFilter])
|
|
|
+ ds=self.db.selectRows(self.project,self.schema,self.dataset,[idFilter,sFilter])
|
|
|
if not len(ds['rows'])==1:
|
|
|
print("Found incorrect number {} of matches for [{}]/[{}]".\
|
|
|
format(len(ds['rows']),\
|
|
@@ -374,7 +405,10 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
self.parent=parent
|
|
|
self.net=parent.network
|
|
|
+ self.db=parent.db
|
|
|
+ self.fb=parent.fb
|
|
|
self.project=parent.project
|
|
|
+ self.schema=parent.schema
|
|
|
self.participantField=parent.participantField.text
|
|
|
self.segmentList=parent.segmentList
|
|
|
|
|
@@ -396,33 +430,44 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
def loadImage(self,row,keepCached):
|
|
|
|
|
|
+ tempDir=os.path.join(os.path.expanduser('~'),'temp')
|
|
|
+ if not os.path.isdir(tempDir):
|
|
|
+ os.mkdir(tempDir)
|
|
|
|
|
|
|
|
|
fields={"CT":self.parent.ctField.text,\
|
|
|
"PET":self.parent.petField.text,\
|
|
|
"Segmentation":self.parent.segmentationField.text}
|
|
|
|
|
|
- relativePaths={x:self.project+'/@files/preprocessedImages/'\
|
|
|
- +row['patientCode']+'/'+row['visitCode']+'/'+row[y]\
|
|
|
+ relativePaths={x:['preprocessedImages',row['patientCode'],row['visitCode'],row[y]]\
|
|
|
for (x,y) in fields.items()}
|
|
|
|
|
|
self.volumeNode={}
|
|
|
for f in relativePaths:
|
|
|
+
|
|
|
p=relativePaths[f]
|
|
|
- labkeyPath=self.net.GetLabkeyPathFromRelativePath(p)
|
|
|
- rp=self.net.head(labkeyPath)
|
|
|
- if not slicerNetwork.labkeyURIHandler.HTTPStatus(rp):
|
|
|
- print("Failed to get {}".format(labkeyPath))
|
|
|
- continue
|
|
|
+
|
|
|
+ localPath=os.path.join(tempDir,p[-1])
|
|
|
|
|
|
-
|
|
|
+ if not os.path.isfile(localPath):
|
|
|
+
|
|
|
+ remotePath=self.fb.formatPathURL(self.project,'/'.join(p))
|
|
|
+ if not self.fb.entryExists(remotePath):
|
|
|
+ print("Failed to get {}".format(remotePath))
|
|
|
+ continue
|
|
|
+
|
|
|
+ self.fb.readFileToFile(remotePath,localPath)
|
|
|
+
|
|
|
properties={}
|
|
|
|
|
|
if f=="Segmentation":
|
|
|
properties["labelmap"]=1
|
|
|
-
|
|
|
- self.volumeNode[f]=self.net.loadNode(p,'VolumeFile',\
|
|
|
- properties=properties,returnNode=True,keepCached=keepCached)
|
|
|
+
|
|
|
+
|
|
|
+ self.volumeNode[f]=slicer.util.loadNodeFromFile(localPath,filetype='VolumeFile',properties=properties)
|
|
|
+
|
|
|
+ if not keepCached:
|
|
|
+ os.remove(localPath)
|
|
|
|
|
|
|
|
|
self.volumeNode['CT'].GetScalarVolumeDisplayNode().\
|
|
@@ -535,14 +580,15 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
filters.append({'variable':f,'value':str(inputRow[f]),'oper':'eq'})
|
|
|
|
|
|
|
|
|
- ds=self.net.filterDataset(project,dataset,filters)
|
|
|
+ ds=self.db.selectRows(project,self.schema,dataset,filters)
|
|
|
return ds['rows']
|
|
|
|
|
|
def loadReview(self,currentRow):
|
|
|
|
|
|
|
|
|
+ currentRow['ModifiedBy']=self.net.getUserId()['id']
|
|
|
rows=self.getUniqueRows(self.parent.project,self.parent.reviewDataset,\
|
|
|
- [self.participantField,'visitCode','Segmentation'],currentRow)
|
|
|
+ [self.participantField,'visitCode','Segmentation','ModifiedBy'],currentRow)
|
|
|
|
|
|
if len(rows)==0:
|
|
|
return
|
|
@@ -559,7 +605,8 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
|
|
|
def submitReview(self,currentRow,comment):
|
|
|
- fields=[self.participantField,'visitCode','Segmentation']
|
|
|
+ currentRow['ModifiedBy']=self.net.getUserId()['id']
|
|
|
+ fields=[self.participantField,'visitCode','Segmentation','ModifiedBy']
|
|
|
rows=self.getUniqueRows(self.parent.project,self.parent.reviewDataset,\
|
|
|
fields,currentRow)
|
|
|
|
|
@@ -590,7 +637,7 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
row['reviewComment']=comment
|
|
|
row['Date']=datetime.datetime.now().ctime()
|
|
|
- self.net.modifyDataset(mode,self.parent.project,\
|
|
|
+ self.db.modifyRows(mode,self.parent.project,self.parent.schema,\
|
|
|
self.parent.reviewDataset,[row])
|
|
|
|
|
|
print("review submitted")
|
|
@@ -617,7 +664,8 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
|
|
|
def loadAE(self,currentRow):
|
|
|
- fields=[self.participantField,'petResampled']
|
|
|
+ currentRow['ModifiedBy']=self.net.getUserId()['id']
|
|
|
+ fields=[self.participantField,'petResampled','ModifiedBy']
|
|
|
rows=self.getUniqueRows(self.parent.project,self.parent.aeDataset,\
|
|
|
fields,currentRow)
|
|
|
|
|
@@ -626,7 +674,7 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
|
|
|
print("Found {} rows".format(len(rows)))
|
|
|
row=rows[0]
|
|
|
-
|
|
|
+
|
|
|
for seg in self.segmentList:
|
|
|
name=seg+'AE'
|
|
|
try:
|
|
@@ -637,7 +685,8 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
continue
|
|
|
|
|
|
def submitAE(self,currentRow):
|
|
|
- fields=[self.participantField,'petResampled']
|
|
|
+ currentRow['ModifiedBy']=self.net.getUserId()['id']
|
|
|
+ fields=[self.participantField,'petResampled','ModifiedBy']
|
|
|
rows=self.getUniqueRows(self.parent.project,self.parent.aeDataset,\
|
|
|
fields,currentRow)
|
|
|
|
|
@@ -648,7 +697,10 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
for f in fields:
|
|
|
row[f]=currentRow[f]
|
|
|
|
|
|
- row['SequenceNum']=currentRow['SequenceNum']
|
|
|
+ frows=self.getUniqueRows(self.parent.project,self.parent.aeDataset,\
|
|
|
+ [self.participantField,'visitCode'],currentRow)
|
|
|
+
|
|
|
+ row['SequenceNum']=currentRow['SequenceNum']+0.01*len(frows)
|
|
|
|
|
|
else:
|
|
|
mode='update'
|
|
@@ -658,7 +710,7 @@ class iraemmBrowserLogic(ScriptedLoadableModuleLogic):
|
|
|
row[seg+'AE']=self.getAEResult(seg)
|
|
|
|
|
|
row['Date']=datetime.datetime.now().ctime()
|
|
|
- resp=self.net.modifyDataset(mode,self.parent.project,\
|
|
|
+ resp=self.db.modifyRows(mode,self.parent.project,self.parent.schema,\
|
|
|
self.parent.aeDataset,[row])
|
|
|
print("Response {}".format(resp))
|
|
|
print("AE submitted")
|