Reputation: 3
I would like to know if it's possible to create a filter regarding dates. For example, I would like to have the state of the database at a specific date. So, any modifications to the data that occurred afterward should not be taken into account. Currently, I've tried using dateRangeEnd, but it keeps the individuals that were included before that date. However, if any of their information has been modified after my date, I'll get the modified value instead of the original value.
Upvotes: 0
Views: 745
Reputation: 737
Thanks for clarifying! I'm not familiar with Stata, as my primary programming language is R, so though the syntax will differ, the process will likely be very similar. You can request the logs instead of records using the REDCap API by changing the raw parameter content
to content=log
instead of content=record
. This opens up new parameters for logtype
(all events except page views, data exports, manage/design, record created-updated-deleted, page views, etc.), beginTime
, and endTime
. Those last two function quite similar to the dateRangeEnd
parameter because they allow you to filter the log using date-times (has to be in YYYY-MM-DD HH:MM:SS format). The response returns action
and details
keys which contain your data of interest (e.g., the state of a given record at a given time). Action
s relevant to you would probably be record creation, record updates, and record deletion. details
contain the former and new values and you can perform additional data manipulation as you see fit. So in R, it might look something like this:
token <- "my_api_token"
url <- "my_redcap_uri"
formData <- list("token"=token,
content='log', # query the logs rather than current records
logtype='record', # filter to record create-update-delete only
user='', # if blank, this means all users
record='', # if blank, this means all records
beginTime='2023-03-31 09:39',
endTime='',
format='json',
returnFormat='json'
)
response <- httr::POST(url, body = formData, encode = "form")
result <- httr::content(response)
head(result)
Which then might print out something like the following (example modeled off of REDCapR package):
#> # A tibble: 6 × 5
#> timestamp username action details record
#> <dttm> <chr> <chr> <chr> <chr>
#> 1 2023-03-31 09:39:00 john_doe Update Response 004 my_variable = … 004
#> 2 2023-03-31 09:49:35 john_doe Update Response 004 my_other_varia… 004
#> 3 2023-03-31 10:25:14 john_doe Update Response 005 my_other_varia… 005
#> 4 2023-03-31 11:12:56 john_doe Create Record 006 first_name = A… 006
#> 5 2023-03-31 11:39:47 john_doe Update Response 006 my_variable = … 006
#> 6 2023-03-31 12:49:33 john_doe Update Response 006 my_other_varia… 006
Upvotes: 0