vubiostat / redcapAPI

R interface to REDCap (http://www.project-redcap.org/)
20 stars 26 forks source link

Export & Execute Data Quality Rules #408

Open rsh52 opened 1 month ago

rsh52 commented 1 month ago

Thank you for all of your work on redcapAPI, the new functionality and updated API are very impressive.

In using exportDataQuality() I had assumed it would reference the "Data Quality" rules in the named tool in REDCap, but I see it refers to queries under the "Data Resolution" workflow tool.

Is there a way to retrieve and execute the Data Quality rules themselves either in this package or that you might be aware of through the REDCap API? It would be great to be able to ingest those rules into an R environment and run them on projects for quality validation.

couthcommander commented 3 weeks ago

The short answer is no.

I'm a minor contributor, but have done some thinking about this. It is really confusing that there are "data quality" rules and a "data quality" module (which is actually hidden at our institution). Neither of these are supported through the REDCap API. The module (which is more "data resolution") can be accessed without the API, so we've provided a way to download this data. The REDCap team has not provided a way to download the rules, outside of the web interface. But that doesn't mean it can't be done.

Here's an example

pid <- rcon$projectInformation()$project_id
#####
# set these
u <- 'USERNAME'
p <- 'PASSWORD'
redcap_url <- 'https://redcap.vumc.org'
saved_file <- file.path('~', sprintf('dataQualityRules_%s.csv', pid))
#####
body <- list(username = u, password = p, submitted = '1', token = rcon$token)
resp <- redcapAPI:::.curlPost(redcap_url, body, rcon$config)
v <- rcon$version()
dq_url <- sprintf('%s/redcap_v%s/DataQuality/download_dq_rules.php?pid=%s', redcap_url, v, pid)
curl::curl_download(dq_url, saved_file, handle = resp$handle)

Given a valid username/password, a CSV file should be downloaded to [saved_file].

We could add the functionality to connect to redcap through username/password, as there may potentially be other uses (functions gained not accessible via API). I suspect the maintainer would reject this as out-of-scope (we support functionality the API supports).

The second part of your question is how to ingest rules and validate a data set. Parsing redcap logic is on our to-do list (#362), but it is a long way from being supported.