Skip to content

Commit f4515e6

Browse files
authored
Merge pull request #89 from tranpl/update-import-records
Update import records
2 parents d0dd472 + 87dd51f commit f4515e6

12 files changed

+4579
-51
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: csharp
22
mono: none
3-
dotnet: 2.0.0
3+
dotnet: 2.1.810
44
script:
55
- dotnet restore
66
- dotnet build ./RedcapApi/

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,21 @@ __Install directly in Package Manager Console or Command Line Interface__
7373
```C#
7474
Package Manager
7575

76-
Install-Package RedcapAPI -Version 1.0.8
76+
Install-Package RedcapAPI -Version 1.0.9
7777

7878
```
7979

8080
```C#
8181
.NET CLI
8282

83-
dotnet add package RedcapAPI --version 1.0.8
83+
dotnet add package RedcapAPI --version 1.0.9
8484

8585
```
8686

8787
```C#
8888
Paket CLI
8989

90-
paket add RedcapAPI --version 1.0.8
90+
paket add RedcapAPI --version 1.0.9
9191

9292
```
9393

RedcapApi/Api/Redcap.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,7 @@ public async Task<string> ExportRecordAsync(string token, Content content, strin
28632863

28642864
/// <summary>
28652865
/// API Version 1.0.0+
2866+
/// Updated with version 10.3.0 improvements
28662867
/// Import Records
28672868
/// This method allows you to import a set of records for a project
28682869
/// </summary>
@@ -2880,16 +2881,19 @@ public async Task<string> ExportRecordAsync(string token, Content content, strin
28802881
/// <param name="overwriteBehavior">
28812882
/// normal - blank/empty values will be ignored [default]
28822883
/// overwrite - blank/empty values are valid and will overwrite data</param>
2883-
/// <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
2884+
/// <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).
2885+
/// 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.
2886+
/// 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
28842887
/// false (or 'false') - The record names provided in the request will be used. [default]
28852888
/// true (or 'true') - New record names will be automatically determined.</param>
28862889
/// <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.
28872890
/// 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>
28882891
/// <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>
2892+
/// <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>
28892893
/// <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>
28902894
/// <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>
28912895
/// <returns>the content specified by returnContent</returns>
2892-
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)
2896+
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)
28932897
{
28942898
try
28952899
{
@@ -2904,6 +2908,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, ReturnFormat forma
29042908
{ "type", redcapDataType.GetDisplayName() },
29052909
{ "overwriteBehavior", overwriteBehavior.ToString() },
29062910
{ "forceAutoNumber", forceAutoNumber.ToString() },
2911+
{ "csvDelimiter", csvDelimiter.ToString() },
29072912
{ "data", _serializedData },
29082913
{ "returnFormat", onErrorFormat.GetDisplayName() }
29092914
};
@@ -2930,6 +2935,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, ReturnFormat forma
29302935

29312936
/// <summary>
29322937
/// API Version 1.0.0+
2938+
/// Updated with version 10.3.0 improvements
29332939
/// Import Records
29342940
/// This method allows you to import a set of records for a project
29352941
/// </summary>
@@ -2954,16 +2960,15 @@ public async Task<string> ImportRecordsAsync<T>(string token, ReturnFormat forma
29542960
/// <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.
29552961
/// 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>
29562962
/// <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>
2963+
/// <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>
29572964
/// <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>
29582965
/// <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>
29592966
/// <returns>the content specified by returnContent</returns>
2960-
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)
2967+
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)
29612968
{
29622969
try
29632970
{
29642971
this.CheckToken(token);
2965-
2966-
29672972
var _serializedData = JsonConvert.SerializeObject(data);
29682973

29692974
var payload = new Dictionary<string, string>
@@ -2974,6 +2979,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, Content content, R
29742979
{ "type", redcapDataType.GetDisplayName() },
29752980
{ "overwriteBehavior", overwriteBehavior.ToString() },
29762981
{ "forceAutoNumber", forceAutoNumber.ToString() },
2982+
{ "csvDelimiter", csvDelimiter.ToString() },
29772983
{ "data", _serializedData },
29782984
{ "returnFormat", onErrorFormat.GetDisplayName() }
29792985
};

RedcapApi/Docs/Demographics_TestProject_DataDictionary.csv

-8
This file was deleted.

RedcapApi/Interfaces/IRedcap.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ public interface IRedcap
853853

854854
/// <summary>
855855
/// Import Records
856+
/// Updated with version 10.3.0 improvements
856857
/// This method allows you to import a set of records for a project
857858
/// </summary>
858859
/// <remarks>
@@ -876,12 +877,14 @@ public interface IRedcap
876877
/// <param name="data">The formatted data to be imported.
877878
/// 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>
878879
/// <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>
880+
/// <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>
879881
/// <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>
880882
/// <param name="returnFormat">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>
881883
/// <returns>the content specified by returnContent</returns>
882-
Task<string> ImportRecordsAsync<T>(string token, Content content, ReturnFormat inputFormat, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat, ReturnContent returnContent = ReturnContent.count, OnErrorFormat returnFormat = OnErrorFormat.json);
884+
Task<string> ImportRecordsAsync<T>(string token, Content content, ReturnFormat inputFormat, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, OnErrorFormat returnFormat = OnErrorFormat.json);
883885
/// <summary>
884886
/// Import Records
887+
/// Updated with version 10.3.0 improvements
885888
/// This method allows you to import a set of records for a project
886889
/// </summary>
887890
/// <remarks>
@@ -904,10 +907,11 @@ public interface IRedcap
904907
/// <param name="data">The formatted data to be imported.
905908
/// 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>
906909
/// <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>
910+
/// <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>
907911
/// <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>
908912
/// <param name="returnFormat">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>
909913
/// <returns>the content specified by returnContent</returns>
910-
Task<string> ImportRecordsAsync<T>(string token, ReturnFormat inputFormat, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat, ReturnContent returnContent = ReturnContent.count, OnErrorFormat returnFormat = OnErrorFormat.json);
914+
Task<string> ImportRecordsAsync<T>(string token, ReturnFormat inputFormat, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, OnErrorFormat returnFormat = OnErrorFormat.json);
911915

912916
/// <summary>
913917
/// Delete Records

RedcapApi/Models/CsvDelimiter.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace Redcap.Models
4+
{
5+
/// <summary>
6+
/// Csv Delimiter for the input data (redcap data type)
7+
/// </summary>
8+
public enum CsvDelimiter
9+
{
10+
/// <summary>
11+
/// , [default]
12+
/// </summary>
13+
[Display(Name = ",")]
14+
comma,
15+
/// <summary>
16+
/// tab
17+
/// </summary>
18+
///
19+
[Display(Name = "tab")]
20+
tab,
21+
/// <summary>
22+
/// ;
23+
/// </summary>
24+
///
25+
[Display(Name = ";")]
26+
semiColon,
27+
/// <summary>
28+
/// |
29+
/// </summary>
30+
///
31+
[Display(Name = "|")]
32+
pipe,
33+
/// <summary>
34+
/// ^
35+
/// </summary>
36+
///
37+
[Display(Name = "^")]
38+
caret
39+
}
40+
}

0 commit comments

Comments
 (0)