-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path7_Build_String.do
75 lines (61 loc) · 1.66 KB
/
7_Build_String.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
Using the REDCap API with Stata
Luke Stevens, Murdoch Childrens Research Institute
20-Jun-2017
7. Build_Command_String.do
An example of building the curl command programmatically.
- Timestamp in downloaded file name
- Iterate a supplied list of fields
- Iterate a supplied list of evnts
- Iterate a supplied list of instruments
*/
version 12
set more off
clear
local token="<insert your token here>"
local content="record"
local format="csv"
local type="flat"
local data "token=`token'&content=`content'&format=`format'&type=`type'"
local curlpath="c:\curl\curl.exe"
local apiurl="https://redcap.mcri.edu.au/api/"
local dttm : display %td_CY-N-D date("$S_DATE", "DMY") "_$S_TIME"
local outfile = "redcap_api_export_"+trim(subinstr(subinstr("`dttm'","-","",.),":","",.))+".csv"
// Request selected fields
local param "fields"
local i 0
foreach listentry in ///
record_id /// // include record id field if you're not downloading the first form
dob ///
gender ///
{
local data "`data'&`param'[`i']=`listentry'"
local i=`i'+1
}
// Request selected events
local param "events"
local i=0
foreach listentry in ///
enrolment_arm_1 ///
randomisation_arm_1 ///
3month_questionnai_arm_1 ///
6month_visit_arm_1 ///
9month_questionnai_arm_1 ///
12month_visit_arm_1 ///
{
local data "`data'&`param'[`i']=`listentry'"
local i=`i'+1
}
// Request selected instruments
local param "forms"
local i=0
foreach listentry in ///
visit ///
questionnaire ///
{
local data "`data'&`param'[`i']=`listentry'"
local i=`i'+1
}
shell curl --output "`outfile'" --data "`data'" "`apiurl'"
import delimited using `outfile', varnames(1) clear
br