12 changed files
RedcapApi | ||
Api | ||
Redcap.cs | ||
Docs | ||
Demographics_TestProject_DataDictionary.csv | ||
Interfaces | ||
IRedcap.cs | ||
Models | ||
CsvDelimiter.cs + | ||
Utilities | ||
Utils.cs | ||
Redcap.csproj | ||
Redcap.xml + | ||
RedcapApiDemo | ||
Program.cs | ||
Tests | ||
RedcapApiTests.cs | ||
.travis.yml | ||
ram_crest_160.png + | ||
README.md | ||
Add comment 2863
Add comment 2864 /// <summary>
Add comment 2865 /// API Version 1.0.0+
Add comment 2866 Plus /// Updated with version 10.3.0 improvements
Add comment 2866 2867 /// Import Records
Add comment 2867 2868 /// This method allows you to import a set of records for a project
Add comment 2868 2869 /// </summary>
Add comment 2880 2881 /// <param name="overwriteBehavior">
Add comment 2881 2882 /// normal - blank/empty values will be ignored [default]
Add comment 2882 2883 /// overwrite - blank/empty values are valid and will overwrite data</param>
Add comment 2883 Minus /// <param name="forceAutoNumber">If record auto-numbering has been enabled in the project, it may be desirable to import records where each record's record name is automatically determined by REDCap (just as it does in the user interface). If this parameter is set to 'true', the record names provided in the request will not be used (although they are still required in order to associate multiple rows of data to an individual record in the request), but instead those records in the request will receive new record names during the import process. NOTE: To see how the provided record names get translated into new auto record names, the returnContent parameter should be set to 'auto_ids', which will return a record list similar to 'ids' value, but it will have the new record name followed by the provided record name in the request, in which the two are comma-delimited. For example, if
Add comment 2884 Plus /// <param name="forceAutoNumber">If record auto-numbering has been enabled in the project, it may be desirable to import records where each record's record name is automatically determined by REDCap (just as it does in the user interface).
Add comment 2885 Plus /// If this parameter is set to 'true', the record names provided in the request will not be used (although they are still required in order to associate multiple rows of data to an individual record in the request), but instead those records in the request will receive new record names during the import process.
Add comment 2886 Plus /// NOTE: To see how the provided record names get translated into new auto record names, the returnContent parameter should be set to 'auto_ids', which will return a record list similar to 'ids' value, but it will have the new record name followed by the provided record name in the request, in which the two are comma-delimited. For example, if
Add comment 2884 2887 /// false (or 'false') - The record names provided in the request will be used. [default]
Add comment 2885 2888 /// true (or 'true') - New record names will be automatically determined.</param>
Add comment 2886 2889 /// <param name="data">The formatted data to be imported. The data should be a List of Dictionary(string,string) or object that contains the fields and values.
Add comment 2887 2890 /// NOTE: When importing data in EAV type format, please be aware that checkbox fields must have their field_name listed as variable+'___'+optionCode and its value as either '0' or '1' (unchecked or checked, respectively). For example, for a checkbox field with variable name 'icecream', it would be imported as EAV with the field_name as 'icecream___4' having a value of '1' in order to set the option coded with '4' (which might be 'Chocolate') as 'checked'.</param>
Add comment 2888 2891 /// <param name="dateFormat">MDY, DMY, YMD [default] - the format of values being imported for dates or datetime fields (understood with M representing 'month', D as 'day', and Y as 'year') - NOTE: The default format is Y-M-D (with dashes), while MDY and DMY values should always be formatted as M/D/Y or D/M/Y (with slashes), respectively.</param>
Add comment 2892 Plus /// <param name="csvDelimiter">Set the delimiter used to separate values in the CSV data file (for CSV format only). Options include: comma ',' (default), 'tab', semi-colon ';', pipe '|', or caret '^'. Simply provide the value in quotes for this parameter.</param>
Add comment 2889 2893 /// <param name="returnContent">count [default] - the number of records imported, ids - a list of all record IDs that were imported, auto_ids = (used only when forceAutoNumber=true) a list of pairs of all record IDs that were imported, includes the new ID created and the ID value that was sent in the API request (e.g., 323,10). </param>
Add comment 2890 2894 /// <param name="onErrorFormat">csv, json, xml - specifies the format of error messages. If you do not pass in this flag, it will select the default format for you passed based on the 'format' flag you passed in or if no format flag was passed in, it will default to 'json'.</param>
Add comment 2891 2895 /// <returns>the content specified by returnContent</returns>
Add comment 2892 Minus public async Task<string> ImportRecordsAsync<T>(string token, ReturnFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat, ReturnContent returnContent = ReturnContent.count, OnErrorFormat onErrorFormat = OnErrorFormat.json)
Add comment 2896 Plus public async Task<string> ImportRecordsAsync<T>(string token, ReturnFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, OnErrorFormat onErrorFormat = OnErrorFormat.json)
Add comment 2893 2897 {
Add comment 2894 2898 try
Add comment 2895 2899 {
Add comment 2904 2908 { "type", redcapDataType.GetDisplayName() },
Add comment 2905 2909 { "overwriteBehavior", overwriteBehavior.ToString() },
Add comment 2906 2910 { "forceAutoNumber", forceAutoNumber.ToString() },
Add comment 2911 Plus { "csvDelimiter", csvDelimiter.ToString() },
Add comment 2907 2912 { "data", _serializedData },
Add comment 2908 2913 { "returnFormat", onErrorFormat.GetDisplayName() }
Add comment 2909 2914 };
Add comment 2930 2935
Add comment 2931 2936 /// <summary>
Add comment 2932 2937 /// API Version 1.0.0+
Add comment 2938 Plus /// Updated with version 10.3.0 improvements
Add comment 2933 2939 /// Import Records
Add comment 2934 2940 /// This method allows you to import a set of records for a project
Add comment 2935 2941 /// </summary>
Add comment 2954 2960 /// <param name="data">The formatted data to be imported. The data should be a List of Dictionary(string,string) or object that contains the fields and values.
Add comment 2955 2961 /// NOTE: When importing data in EAV type format, please be aware that checkbox fields must have their field_name listed as variable+'___'+optionCode and its value as either '0' or '1' (unchecked or checked, respectively). For example, for a checkbox field with variable name 'icecream', it would be imported as EAV with the field_name as 'icecream___4' having a value of '1' in order to set the option coded with '4' (which might be 'Chocolate') as 'checked'.</param>
Add comment 2956 2962 /// <param name="dateFormat">MDY, DMY, YMD [default] - the format of values being imported for dates or datetime fields (understood with M representing 'month', D as 'day', and Y as 'year') - NOTE: The default format is Y-M-D (with dashes), while MDY and DMY values should always be formatted as M/D/Y or D/M/Y (with slashes), respectively.</param>
Add comment 2963 Plus /// <param name="csvDelimiter">Set the delimiter used to separate values in the CSV data file (for CSV format only). Options include: comma ',' (default), 'tab', semi-colon ';', pipe '|', or caret '^'. Simply provide the value in quotes for this parameter.</param>
Add comment 2957 2964 /// <param name="returnContent">count [default] - the number of records imported, ids - a list of all record IDs that were imported, auto_ids = (used only when forceAutoNumber=true) a list of pairs of all record IDs that were imported, includes the new ID created and the ID value that was sent in the API request (e.g., 323,10). </param>
Add comment 2958 2965 /// <param name="onErrorFormat">csv, json, xml - specifies the format of error messages. If you do not pass in this flag, it will select the default format for you passed based on the 'format' flag you passed in or if no format flag was passed in, it will default to 'json'.</param>
Add comment 2959 2966 /// <returns>the content specified by returnContent</returns>
Add comment 2960 Minus public async Task<string> ImportRecordsAsync<T>(string token, Content content, ReturnFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat, ReturnContent returnContent = ReturnContent.count, OnErrorFormat onErrorFormat = OnErrorFormat.json)
Add comment 2967 Plus public async Task<string> ImportRecordsAsync<T>(string token, Content content, ReturnFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, OnErrorFormat onErrorFormat = OnErrorFormat.json)
Add comment 2961 2968 {
Add comment 2962 2969 try
Add comment 2963 2970 {
Add comment 2964 2971 this.CheckToken(token);
Add comment 2965 Minus
Add comment 2966 Minus
Add comment 2967 2972 var _serializedData = JsonConvert.SerializeObject(data);
Add comment 2968 2973
Add comment 2969 2974 var payload = new Dictionary<string, string>
Add comment 2974 2979 { "type", redcapDataType.GetDisplayName() },
Add comment 2975 2980 { "overwriteBehavior", overwriteBehavior.ToString() },
Add comment 2976 2981 { "forceAutoNumber", forceAutoNumber.ToString() },
Add comment 2982 Plus { "csvDelimiter", csvDelimiter.ToString() },
Add comment 2977 2983 { "data", _serializedData },
Add comment 2978 2984 { "returnFormat", onErrorFormat.GetDisplayName() }
Add comment 2979 2985 };
Demographics_TestProject_DataDictionary.csv
/RedcapApi/Docs/Demographics_TestProject_DataDictionary.csv/RedcapApi/Docs/Demographics_TestProject_DataDictionary.csv