def importVisitData(server, events, clinic, ranges, request, action): for range in ranges: # loop the server communication to avoid being held up by errors while True: try: print clinic.te_id records = server.patients_data(request, 0, range['start'], range['end'], 3, clinic.te_id) break except socket.error, e: if not e[0] == errno.ECONNRESET: raise e for record in records: event = ImportEvent() try: event = action(event, clinic, record) except ImportError, e: event.append(str(e), 'error') events.append(event)
records = server.patients_data(request, 0, range['start'], range['end'], 3, clinic.te_id) break except socket.error, err: logger.error(err) if not (err[0] in (errno.ETIMEDOUT, errno.ECONNRESET, 8)): raise err except ProtocolError, err: logger.error("A protocol error occurred") logger.error("URL: %s" % err.url) logger.error("HTTP/HTTPS headers: %s" % err.headers) logger.error("Error code: %d" % err.errcode) logger.error("Error message: %s" % err.errmsg) raise err for record in records: event = ImportEvent() try: logger.debug("Calling '%s' with args '%s'" % (action, (event, clinic, record))) event = action(event, clinic, record) except ImportError, e: logger.error(e) event.append(str(e), 'error') events.append(event) return events def importPatient(event, clinic, record): te_id = validateField(event, record, PATIENT_ID_RE, 'te_id', 'Patient ID') age = validateField(event, record, PATIENT_AGE_RE, 'age', 'Age') sex = validateField(event, record, PATIENT_SEX_RE, 'sex', 'Sex') msisdns = validateField(event, record, MSISDNS_RE, 'celphone', 'Mobile Number')