Reputation: 11
I recently encountered an issue while working with REDCap and would appreciate your expertise in finding a streamlined solution. Here's a brief overview:
Inadvertently, I imported data into the wrong record_id for 999 repetitions of a form in REDCap. To rectify this, I imported the same CSV with empty data (retaining "record_id," "redcap_repeat_instrument," and "redcap_repeat_instance") and opted to overwrite the data with blank values. Consequently, I now have 999 empty repetitions in that specific record_id.
I've explored the API but couldn't find a direct way to delete a redcap_repeat_instance. While manually deleting repetitions one by one is an option, it's time-consuming. I'm curious if anyone has encountered a similar situation and found a more efficient method, perhaps through importing a CSV with specific information to facilitate bulk deletion?
Your insights and suggestions on this matter would be immensely valuable.
Upvotes: 0
Views: 718
Reputation: 17279
redcapAPI
had an update after I had given this answer, and some arguments were added to make this a bit easier. The new call would be
deleteRecords(rcon,
records = 11, # one record at a time
instrument = 'procedimientos'
repeat_instance = 2)
There are also arguments for event
and arm
, should they be needed.
If you have access to the API and the R software, you can use the redcapAPI
package to delete a record
library(redcapAPI)
rcon <- redcapConnection(url = [your api url],
token = [your api token])
deleteRecord(rcon,
records = [record ids to delete],
arm = [arm number in which records are found. this is length 1],
api_param = list(event = [unique event name, length 1],
repeat_instance = [repeat instance number, length 1]))
you'll need a separate call for each arm/event/repeat_instance combination.
Without access to the API, you'll have the most success talking to your REDCap Administrator.
Upvotes: 0
Reputation: 11
I found the solution!! using API:
token <- "xxx"
url <- "yyy"
# Formulate the data for deletion
formData <- list(
token = token,
action = 'delete',
content = 'record',
'records[0]'='11',
'repeat_instance'=2,
instrument = 'procedimientos',
returnFormat = 'json'
)
# Send the POST request
response <- POST(url, body = formData, encode = "form")
# Handling the response based on the expected JSON format
result <- content(response, "parsed", type = "application/json")
# Print the result to understand what's returned
print(result)
Upvotes: 1
Reputation: 86
With API: as @Benjamin indicates, the "Delete Record" API method permits optional event/instrument/repeat_instance parameters to be supplied with the call that will restrict the delete to just the specified event/instrument/repeat_instance rather than the entire record.
If the API feels like overkill for a one-off process, you could do what you need via a process along these lines:
Upvotes: 0