@@ -28,6 +28,10 @@ def __init__(self, proj_code, stormdblogin='~/.stormdblogin', username=None, ver
2828 print 'ERROR: Bad project code?'
2929 sysexit (- 1 )
3030
31+ self .proj_code = proj_code
32+ self ._server = 'http://hyades00.pet.auh.dk/modules/StormDb/extract/'
33+ self ._wget_cmd = 'wget -qO - test ' + self ._server
34+
3135 try :
3236 with open (os .path .expanduser (stormdblogin )):
3337 if verbose :
@@ -56,10 +60,6 @@ def __init__(self, proj_code, stormdblogin='~/.stormdblogin', username=None, ver
5660 fout .close ()
5761 os .chmod (os .path .expanduser (stormdblogin ), 0400 )
5862
59- self .proj_code = proj_code
60- self ._server = 'http://hyades00.pet.auh.dk/modules/StormDb/extract/'
61- self ._wget_cmd = 'wget -qO - test ' + self ._server
62-
6363 @staticmethod
6464 def _wget_error_handling (stdout ):
6565 if 'error' in stdout :
@@ -120,32 +120,40 @@ def get_studies(self, subj_id, modality=None, unique=True, verbose=False):
120120 stud_list = [x for x in stud_list if x ]
121121
122122 if modality :
123- for study in stud_list :
123+ for ii , study in enumerate ( stud_list ) :
124124 url = 'modalities?' + self ._login_code + '\\ &projectCode=' + self .proj_code + '\\ &subjectNo=' + \
125125 subj_id + '\\ &study=' + study
126126 output = self ._wget_system_call (url ).split ('\n ' )
127127 #print output, '==', modality
128128
129- for entry in output :
130- if entry == modality :
131- if unique :
132- return study
133- ### NB!! This only matches first hit! If subject contains several studies
134- ### with this modality,
135- ### only first one is returned... Fix me!
136- else :
137- # must re-write code a bit to accommodate the existence of
138- # several studies containing the desired modality...
139- print "Error: non-unique modalities not implemented yet!"
140- sysexit (- 1 )
129+ if modality in output :
130+ if unique :
131+ return study # NB: returns string! Should change to [study] to return list...
132+ else :
133+ stud_list [ii ] = None
134+
135+ stud_list = filter (None , stud_list )
136+ # for entry in output:
137+ # if entry == modality:
138+ # if unique:
139+ # return study
140+ # ### NB!! This only matches first hit! If subject contains several studies
141+ # ### with this modality,
142+ # ### only first one is returned... Fix me!
143+ # else:
144+ # stud_list = [x for x in stud_list if x
145+ # else:
146+ # # must re-write code a bit to accommodate the existence of
147+ # # several studies containing the desired modality...
148+ # print "Error: non-unique modalities not implemented yet!"
149+ # sysexit(-1)
141150
142151 # If we get this far, no studies found with the desired modality
143152 if verbose :
144153 print "No studies found with the desired modality"
145- return None
154+ return None
146155
147- else :
148- return stud_list
156+ return stud_list
149157
150158 def get_series (self , subj_id , study , modality , verbose = False ):
151159
0 commit comments