def get_database_xml_from_path(server,token,pathname) : # is it a valid dicom directory? # is it a braink parameters.txt file? # is it an unknown file? # if it is a directory, assume it is a dicom directory # if it is a file, check if it is a brainK parameters.txt file # otherwise, for now assume it is a raw file if not os.path.exists(pathname) : object_xml=None if os.path.isdir(pathname) : if do.isvaliddicom(pathname) : df=do.getfirstdicomfile(pathname) object_xml=do.checkdicomexistence(server,token,df.SeriesInstanceUID) if os.path.isfile(pathname) : if pathname.endswith('.Parameters.txt') : bkstub=pathname.replace('.Parameters.txt','') bkhash=bko.brainkhash(bkstub) object_xml=bko.checkbrainkexistence(server,token,bkhash) else : # 'raw' file case rawhash=rawfilehash(pathname) object_xml=checkrawfileexistence(server,token,rawhash) #raise Exception('raw file case not implemented yet') return object_xml
def upload_nii_with_dicom_reference(server,token,nii_path,reference_dicom_path) : """ Extract subject from dicom, upload nii file using this subject. Use with care! This routine cannot verify that the nii and dicom actually correspond""" if not dicomobject.isvaliddicom(reference_dicom_path) : raise Exception('Invalid dicom path ' +reference_dicom_path+' given') subject=dicomobject.DicomSubject(dicomobject.getfirstdicomfile(reference_dicom_path)) # this will add subject to database, if it isn't there already subject_parsed_xml=dicomobject.uploadsubject(server,token,subject) subject_id=common.get_id_from_parsed_xml(subject_parsed_xml) nii_parsed_xml=uploadnii(server,token,nii_path,subject_id) return nii_parsed_xml