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']), }
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')}