Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to pull survey invitation log? #230

Closed
amysheep opened this issue Jul 18, 2018 · 7 comments
Closed

Function to pull survey invitation log? #230

amysheep opened this issue Jul 18, 2018 · 7 comments
Assignees

Comments

@amysheep
Copy link

Is there a function to download the survey invitation log to get information on what time the survey is sent to a participant?

@wibeasley wibeasley self-assigned this Aug 11, 2018
@wibeasley
Copy link
Member

Hi @amysheep, are you asking for a REDCapR function that calls REDCap's participantList API function? If so, using the private-ish REDCapR:::kernel_api() will retrieve the information.

config_options <- NULL
uri            <- "https://bbmc.ouhsc.edu/redcap/api/"
token          <- "78BB15EFC7DB9CF4E0BAB0A510887A70"
post_body      <- list(
  token      = token,
  content    = 'participantList',
  instrument = 'participant_info_survey',
  event      = '',
  format     = 'csv'
)
kernel <- REDCapR:::kernel_api(uri, post_body, config_options)

# Consume the results in a few different ways.
kernel$result
read.csv(text=kernel$raw_text, stringsAsFactors=FALSE)
as.list(read.csv(text=kernel$raw_text, stringsAsFactors=FALSE))

I see you're based in Chicago. Any chance you'll be at REDCapCon there in a week? If so, I'll be a moderator in the "REDCap & R Reporting" session. Come talk to me there or some other time.

@amysheep
Copy link
Author

Hi @wibeasley ,

Thanks. I will check it out.
Do you have experience on exporting the history information such as when a field is modified by whom at what time etc?
I didn't know there is a REDCapCon in Chicago. The REDCap & R Reporting session sounds very relevant to part of my autoreporting work. Not sure if I can just walk in without registration but I'm always open for coffee/drink if you want to take a break between sessions/ after the conference.

@wibeasley
Copy link
Member

wibeasley commented Sep 14, 2018

@amysheep, I forgot about this until now. Did the 'participantList' do what you needed?

Do you have experience on exporting the history information such as when a field is modified by whom at what time etc?

I just skimmed the API functions again and don't see anything new about these record modification history. If you have access to the underlying database, you could always query the tables using ODBC. We've had to do that with a few projects that needed more scheduling details.

edit: Reopen the issue if you'd like, @amysheep.

@beib
Copy link

beib commented Mar 3, 2020

@wibeasley I managed to pull status of survey invitation log, but cannot find a way to pull timestamps of these invitations. In REDCap there is a page on "Survey Invitation Log" with timestamps. How do I fetch those information? Thanks!

@wibeasley
Copy link
Member

Hi @beib, do you mind starting a dedicated issue for this? Do you know if REDCap exposes this function already? If not, is there any discussion on the forums about it?

@joey-levy
Copy link

A very useful package in Python "PyCap" for interacting with the REDCap API makes it pretty straightforward to export a project's participant list including participant email address, record id, invitation sent status, invitation send time (includes future scheduled times), response status, survey access code, survey link expiration time, survey link, and survey queue link.

I am also more comfortable in R, so I use R's reticulate package to run these few lines of Python in R to export the participant list.

api_token <- 'xxxxxxxxxxxxxx'

library(reticulate)

py_install("PyCap", pip = TRUE) #(only needs to be done once)

py_run_string("from redcap import Project")
py_run_string("api_url = 'https://redcap.xxxxxxx.edu/api/'")

python_api_string = paste("api_key = '", api_token, "'", sep = "")
py_run_string(python_api_string)

py_run_string("project = Project(api_url, api_key)")

# a function for exporting participant lists from redcap (setup code in lines above must be run first)
get_usable_participant_list <- function(export_instrument_name, export_event_name){
  
  #creates string that can be read by Python for exporting participant list
  python_export_string = paste("parts_list = project.export_survey_participant_list(instrument = '",export_instrument_name,"', event='", export_event_name, "', format='csv')", sep = "")
  
  #executes the above string in Python, exporting the participant list as a Python variable named parts_list
  py_run_string(python_export_string)
  
  #this saves the Python variable as an R variable
  Rparts_list = py$parts_list
  
  #The participant list is exported as a list of two objects
  #The first object has all the participant data.
 
  #This saves a new variable of just that first object
  usable_Rparts_list = Rparts_list[1]
  
  #This changes the format of that list into a string
  writeable_parts_list = paste(unlist(usable_Rparts_list), collapse='')
  
  #This creates a .csv file from this string
  filename = "temp_pts_list.csv"
  write(writeable_parts_list, filename)
  
  #this now reads in the .csv file as a data frame
  parts_list_data <- read.csv(filename)
}

@felix515
Copy link

The REDCap API for exporting the participant list does not export PAST invitation send times. From the documentation:

'invitation_send_time' is the date/time in which the next invitation will be sent, and is blank if there is no invitation that is scheduled to be sent. '

The survey invitation log has these past send times but is not accessible in the API. TI has an Excel export button from the user interface. The email logging user interface also shows the invitations that have been sent but is even less accessible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants