redi.utils package¶
Submodules¶
redi.utils.GetEmrData module¶
This module is used to connect to an sftp server and retrieve the raw EMR file to be used as input for RED-I.
-
class
redi.utils.GetEmrData.
EmrFileAccessDetails
(emr_sftp_project_name, emr_download_list, emr_host, emr_username, emr_password, emr_port, emr_private_key, emr_private_key_pass)[source]¶ Bases:
object
Encapsulate the settings used to retrieve the EMR source file using an SFTP connection @see redi#_run()
redi.utils.SimpleConfigParser module¶
SimpleConfigParser
Simple configuration file parser: Python module to parse configuration files without sections. Based on ConfigParser from the standard library.
Author: Philippe Lagadec
Project website: http://www.decalage.info/python/configparser
Inspired from an idea posted by Fredrik Lundh: http://mail.python.org/pipermail/python-dev/2002-November/029987.html
Usage: see end of source code and http://docs.python.org/library/configparser.html
-
class
redi.utils.SimpleConfigParser.
SimpleConfigParser
(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False)[source]¶ Bases:
ConfigParser.RawConfigParser
Simple configuration file parser: based on ConfigParser from the standard library, slightly modified to parse configuration files without sections.
Inspired from an idea posted by Fredrik Lundh: http://mail.python.org/pipermail/python-dev/2002-November/029987.html
redi.utils.rawxml module¶
redi.utils.redcapClient module¶
-
class
redi.utils.redcapClient.
RedcapClient
(redcap_uri, token, verify_ssl=True)[source]¶ Bases:
object
Client for a REDCap server.
Parameters: - redcap_uri – URI for to REDCap server’s API
- token – API Token for a REDCap project.
- verify_ssl – verify the SSL certificate? (default: True)
Raises: - RedcapError – if we failed to get the project’s metadata
- RequestException – if some other network-related failure occurs
-
get_data_from_redcap
(records_to_fetch=None, events_to_fetch=None, fields_to_fetch=None, forms_to_fetch=None, return_format='xml')[source]¶ Exports REDCap records.
Parameters: - records_to_fetch (list or None) – if specified, only includes records in this list. Otherwise, includes all records.
- events_to_fetch (list or None) – if specified, only includes events in this list. Otherwise, includes all events.
- fields_to_fetch (list or None) – if specified, only includes fields in this list. Otherwise, includes all fields
- forms_to_fetch (list or None) – if specified, only includes forms in this list. Otherwise, includes all forms.
- return_format – specifies the format of the REDCap response (default: xml)
Returns: response
-
send_data_to_redcap
(data, max_retry_count, overwrite=False, retry_count=0)[source]¶ Sends records to REDCap.
Parameters: - of dict objects data (list) – records to send.
- overwrite (bool) – treat blank values as intentional? (default: False) When sending a record, if a field is blank, by default REDCap will not overwrite any existing value with a blank.
Returns: response
Raises: RedcapError – if failed to send records for any reason.
- :If MaxRetryError is caught, the function will try resending the same
- data for a maximum of max_retry_count times before exitting. For each attempt the wait time before sending is (the_attempt_no * 6)
redi.utils.redi_email module¶
-
redi.utils.redi_email.
add_attachment
(msg, body)[source]¶ Add the html report as attachment
- msg : MIMEMultipart
- The object to which we attach the body content
- body : string
- The html content to be attached
-
redi.utils.redi_email.
send_email
(host, port, sender, to_addr_list, cc_addr_list, subject, msg_body)[source]¶ The email deliverer. Return True if the email was sent
- to_addr_list : list
- The recipients of the email
-
redi.utils.redi_email.
send_email_data_import_completed
(email_settings, body='')[source]¶ Email the html report after redi completed the data transfer Returns a dictionary, with one entry for each recipient that was refused
- email_settings : dict
- Email params produced by redi.get_email_settings()
- body : string
- The html content produced by transforming the xsl generated by redi.create_summary_report()
-
redi.utils.redi_email.
send_email_input_data_unchanged
(email_settings, raw_xml)[source]¶ Send a warning email to the redcap_support_receiver_email if the input file did not change for more than batch_warning_days Return True if the email was sent
- email_settings : dictionary
- The email delivery parameters
- raw_xml : RawXml instance
- The object storing details about the input file
-
redi.utils.redi_email.
send_email_redcap_connection_error
(email_settings, subject='', msg='')[source]¶ Return True if the email was sent. Notify the designated REDCap support person about problems with reaching REDCap
- email_settings : dict
- The dictionary with smtp server parameters
- subject : str
- The email subject
- msg : str
- The content to be emailed
redi.utils.throttle module¶
Utility module for throttling calls to a function
-
class
redi.utils.throttle.
Throttle
(function, max_calls, interval_in_seconds=60)[source]¶ Bases:
object
Limits the number of calls to a function to a given rate.
The rate limit is equal to the max_calls over the interval_in_seconds.
Parameters: - function – function to call after throttling
- max_calls – maximum number of calls allowed
- interval_in_seconds – size of the sliding window