示例#1
0
def get_subjects(study_name):
    conn = ws.connect(settings.WEBSERVICE_URL, ws.SUBJ_WSDL)
    ws.authenticate(conn, (settings.OC_USER, settings.OC_PASS))
    subj_ids = sorted(ws.all_subjects(conn, study_name))

    for s in subj_ids:
        reg_status = None
        reg_info = None

        try:
            user = UserProfile.objects.get(subject_id=s, study_name=study_name)
            reg_status = 'registered'
            reg_info = user.user.username
        except UserProfile.DoesNotExist:
            pass

        try:
            pending_reg = PendingRegistration.objects.get(subj_id=s, study_name=study_name)
            reg_status = 'pending'
            reg_info = pending_reg.reg_code
        except PendingRegistration.DoesNotExist:
            pass

        yield {
            'id': s,
            'reg_status': reg_status,
            'reg_info': reg_info,
        }
示例#2
0
def get_subject_schedule(subject_id, study_id):
    conn = ws.connect(settings.WEBSERVICE_URL, ws.SUBJ_WSDL)
    ws.authenticate(conn, (settings.OC_USER, settings.OC_PASS))
    sched = ws.get_schedule(conn, subject_id, study_id)

    sd = sched.find('.//%s' % _('SubjectData'))
    subj_oid = sd.attrib['SubjectKey']

    def crfs():
        for sed in sd.findall(_('StudyEventData')):
            # ignore study event status for now
            event_oid = sed.attrib['StudyEventOID']
            ordinal = sed.attrib.get('StudyEventRepeatKey')
            if ordinal:
                ordinal = int(ordinal)

            # hack: treat this as a due date for demo purposes
            start_date = sed.attrib.get(_('StartDate', 'oc'))
            if start_date:
                due = datetime.strptime(start_date, '%Y-%m-%d').date()
            else:
                due = date.today() + timedelta(days=3)

            for fd in sed.findall(_('FormData')):
                form_oid = fd.attrib['FormOID']
                status = fd.attrib[_('Status', 'oc')]

                if status == 'not started':
                    yield {'form_oid': form_oid, 'event_oid': event_oid, 'ordinal': ordinal, 'due': due.strftime('%Y-%m-%d')}

    return {
        'subject_oid': subj_oid,
        'upcoming': sorted(list(crfs()), key=lambda c: c['due']),
    }
示例#3
0
    def _func(self, f, wsdl, auth):
        conn = self.wsdl[wsdl]
        ws.authenticate(conn, auth)

        def _exec(*args, **kwargs):
            try:
                return f(self.wsdl[wsdl], *args, **kwargs)
            except Exception, e:
                msg = str(e).lower()
                if 'authentication' in msg and 'failed' in msg: #ghetto
                    raise AuthenticationFailed()
                else:
                    raise
示例#4
0
def get_studies():
    conn = ws.connect(settings.WEBSERVICE_URL, ws.STUDY_WSDL)
    ws.authenticate(conn, (settings.OC_USER, settings.OC_PASS))
    studies = ws.list_studies(conn)

    for study in studies:
        try:
            existing = Study.objects.get(oid=study['oid'])
            # TODO: update info here if changed
        except Study.DoesNotExist:
            new_study = Study(**study)
            new_study.save()

    return studies
示例#5
0
def study_export(study_name):
    conn = ws.connect(settings.WEBSERVICE_URL, ws.STUDY_WSDL)
    ws.authenticate(conn, (settings.OC_USER, settings.OC_PASS))
    return ws.study_export(conn, study_name)