Skip to content

SQL Generators for REDCap

Aditya Chinchure edited this page Aug 29, 2020 · 3 revisions

Any site administrator who has access to REDCap databases can choose to write custom SQL generators that can generate queries for REDCap data. These functions can be customized to the needs and access privileges of the project, or can be used to optimize results sent over the API.

In site_algo, you may add functions to rc_sql_gen.py which look like this:

def gen_X(options):

   # Returns the SQL query
   def generate():
       … generate an SQL query for X using options
       return query
  
   # Validates options
   def validate():
       return {
          "valid": False, 
          "error": "a field is missing in sql-options"
       }
       [OR]
       return {"valid": True}

   ret = {
       "generate": generate,
       "validate": validate
   }
   return ret
  • The generate() function is called by site algo to produce the SQL statement
  • The validate() function is run at the coordinator level to validate the selector’s “sql-options” field. See Selector Verification API