Esempio n. 1
0
def create_upload_demo_csv():
    """
        Generate csv file for demographic data

        :return: list of string to write in a csv string for XnatDemographic
    """
    csv_list = list()
    # Read the xlsx file:
    info_list = read_excel()

    # subject_l = list()
    for sess in XnatUtils.list_sessions(XNAT, 'prion'):
        found, subject_dict = find_subject_date(info_list, sess['subject_label'], sess['date'].replace('-',''), 'Hospital ID')
        if found:
            print sess['session_label']
            date = get_date(subject_dict['DOB'])
            if 'AOS' in subject_dict.keys():
                age = subject_dict['AOS']
            else:
                print subject_dict['Age']
                age = subject_dict['Age']
            csvstring = CSV_DEMOGRAPHIC.format(project="prion",
                                               subject=sess['subject_label'],
                                               session=sess['label'],
                                               gender=subject_dict['Gender'],
                                               yob=date[:4],
                                               education=subject_dict['Education'],
                                               genetic=subject_dict['Genetics'],
                                               codon129=subject_dict['Codon 129'],
                                               age=int(age),
                                               geneticstate=subject_dict['state'],
                                               MRC=subject_dict['MRC score'])
            csv_list.append(csvstring)
            """if 'Date of first symptoms' in subject_dict.keys() and sess['subject_label'] not in subject_l:
                print subject_dict['Date of first symptoms']
                da = get_date(subject_dict['Date of first symptoms'])
                csvstring = CSV_DEMOGRAPHIC2.format(project="prion",
                                                    subject=sess['subject_label'],
                                                    dos=da[:4]+'-'+da[4:6]+'-'+da[6:])
                csv_list.append(csvstring)
                subject_l.append(sess['subject_label'])"""

    return csv_list
Esempio n. 2
0
def missing_data():
    """
        Check data between XNAT and Excel

        :return: None
    """
    #Read the xlsx files
    info_list = read_excel()

    subject_done = list()
    for sess in XnatUtils.list_sessions(XNAT, 'prion'):
        found, subject_dict = find_subject_date(info_list, sess['subject_label'], sess['date'].replace('-',''), 'Hospital ID')
        if found and not sess['subject_label'] in subject_done:
            subject_done.append(sess['subject_label'])
            print "%s  ==  %s " % (sess['subject_label'], subject_dict['Subject ID'])

    for subject_dict in info_list:
        subject = subject_dict['Hospital ID']
        session = subject +'_'+ get_date(subject_dict['Date of scan'])
        sess_obj = XnatUtils.select_obj(XNAT, 'prion', subject, session)
        if not sess_obj.exists():
            print '%s not found on XNAT. (%s)' % (session, subject_dict['Subject ID'])
Esempio n. 3
0
    date = '{}-{}-{}'.format(date[:4], date[4:6], date[6:])
    print("%s - %s" % (session_info['label'], date))
    if session_info['date'] == date:
        print ' already set up.'
    else:
        session_obj = XnatUtils.get_full_object(xnat, session_info)
        session_obj.attrs.set('date', date)


if __name__ == '__main__':
    ARGS = parse_args()
    try:
        if ARGS.host:
            HOST = ARGS.host
        else:
            HOST = os.environ['XNAT_HOST']
        if ARGS.username:
            MSG = ("Please provide the password for user <%s> on xnat(%s):"
                   % (ARGS.username, HOST))
            PWD = getpass.getpass(prompt=MSG)
        else:
            PWD = None

        print 'INFO: connection to xnat <%s>:' % (HOST)
        XNAT = XnatUtils.get_interface(host=ARGS.host, user=ARGS.username,
                                       pwd=PWD)
        for session in XnatUtils.list_sessions(XNAT, ARGS.project):
            edit_session_date(XNAT, session)
    finally:
        XNAT.disconnect()
Esempio n. 4
0
                 print 'stop - wrong label'
                 continue
             if labels[1].isdigit():
                 print 'stop - already good label'
                 continue
             if '_' in labels[2]:
                 fin = '_'+'_'.join(labels[2].split('_')[1:])
                 labels[2] = labels[2].split('_')[0]
             else:
                 fin = ''
             new_labels = '%s-%s-%s%s' % (labels[0], labels[2],
                                          labels[1], fin)
             print subject['label'], new_labels
             subj_obj.attrs.set('label', new_labels)
 elif session_type:
     for session in XnatUtils.list_sessions(xnat, projectid='INNOVATE'):
         sess_obj = XnatUtils.get_full_object(xnat, session)
         if sess_obj.exists():
             labels = session['label'].split('-')
             if session['label'] == 'INN-DCO-036':
                 labels[2] = labels[2] + '_20160615'
             if session['label'].startswith('INN_'):
                 labels[0] = labels[0].replace('_', '-')
                 labels.append(labels[1])
                 labels[1] = labels[0].split('-')[1]
                 labels[0] = labels[0].split('-')[0]
             if labels[1].isdigit():
                 print 'stop - already good label'
                 continue
             if '_' in labels[2]:
                 fin = '_'+'_'.join(labels[2].split('_')[1:])
Esempio n. 5
0
def get_sessions_list():
    """Extract sessions list from XNAT to be deleted."""
    li_sessions = XnatUtils.list_sessions(XNAT, OPTIONS.project)
    li_sessions = XnatUtils.filter_list_dicts_regex(
                    li_sessions, 'session_label', OPTIONS.sessions.split(','))
    return li_sessions