Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background import process #129

Merged
merged 10 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add the updated flag
this update was in redcap 14.4.0
tranpl committed Jul 9, 2024
commit c9ed50a3ada9a724f62e213c58366d2977ef8997
10 changes: 8 additions & 2 deletions RedcapApi/Api/RedcapApi.cs
Original file line number Diff line number Diff line change
@@ -3384,6 +3384,7 @@ public async Task<string> ExportRecordAsync(string token, Content content, strin
/// 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
/// false (or 'false') - The record names provided in the request will be used. [default]
/// true (or 'true') - New record names will be automatically determined.</param>
/// <param name="backgroundProcess">Specifies whether to do the import as background process.0 or 'false' for no. [default] 1 or 'true' for yes.</param>
/// <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.
/// 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>
/// <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>
@@ -3393,13 +3394,14 @@ public async Task<string> ExportRecordAsync(string token, Content content, strin
/// <param name="cancellationToken"></param>
/// <param name="timeOutSeconds">Number of seconds before the http request tiems out.</param>
/// <returns>the content specified by returnContent</returns>
public async Task<string> ImportRecordsAsync<T>(string token, RedcapFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = default, CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, RedcapReturnFormat returnFormat = RedcapReturnFormat.json, CancellationToken cancellationToken = default, long timeOutSeconds = 100)
public async Task<string> ImportRecordsAsync<T>(string token, RedcapFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, bool backgroundProcess, List<T> data, string dateFormat = default, CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, RedcapReturnFormat returnFormat = RedcapReturnFormat.json, CancellationToken cancellationToken = default, long timeOutSeconds = 100)
{
try
{
this.CheckToken(token);

var _serializedData = JsonConvert.SerializeObject(data);
var _backgroundProcess = backgroundProcess ? "1" : "0";
var payload = new Dictionary<string, string>
{
{ "token", token },
@@ -3408,6 +3410,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, RedcapFormat forma
{ "type", redcapDataType.GetDisplayName() },
{ "overwriteBehavior", overwriteBehavior.ToString() },
{ "forceAutoNumber", forceAutoNumber.ToString() },
{ "backgroundProcess", _backgroundProcess },
{ "csvDelimiter", csvDelimiter.ToString() },
{ "data", _serializedData },
{ "returnFormat", returnFormat.GetDisplayName() }
@@ -3453,6 +3456,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, RedcapFormat forma
/// <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
/// false (or 'false') - The record names provided in the request will be used. [default]
/// true (or 'true') - New record names will be automatically determined.</param>
/// <param name="backgroundProcess">Specifies whether to do the import as background process.0 or 'false' for no. [default] 1 or 'true' for yes.</param>
/// <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.
/// 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>
/// <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>
@@ -3462,14 +3466,15 @@ public async Task<string> ImportRecordsAsync<T>(string token, RedcapFormat forma
/// <param name="cancellationToken"></param>
/// <param name="timeOutSeconds">Number of seconds before the http request tiems out.</param>
/// <returns>the content specified by returnContent</returns>
public async Task<string> ImportRecordsAsync<T>(string token, Content content, RedcapFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, RedcapReturnFormat returnFormat = RedcapReturnFormat.json, CancellationToken cancellationToken = default, long timeOutSeconds = 100)
public async Task<string> ImportRecordsAsync<T>(string token, Content content, RedcapFormat format, RedcapDataType redcapDataType, OverwriteBehavior overwriteBehavior, bool forceAutoNumber, bool backgroundProcess, List<T> data, string dateFormat = "", CsvDelimiter csvDelimiter = CsvDelimiter.tab, ReturnContent returnContent = ReturnContent.count, RedcapReturnFormat returnFormat = RedcapReturnFormat.json, CancellationToken cancellationToken = default, long timeOutSeconds = 100)
{
var importRecordsResults = string.Empty;
try
{
this.CheckToken(token);

var _serializedData = JsonConvert.SerializeObject(data);
var _backgroundProcess = backgroundProcess ? "1" : "0";
var payload = new Dictionary<string, string>
{
{ "token", token },
@@ -3478,6 +3483,7 @@ public async Task<string> ImportRecordsAsync<T>(string token, Content content, R
{ "type", redcapDataType.GetDisplayName() },
{ "overwriteBehavior", overwriteBehavior.ToString() },
{ "forceAutoNumber", forceAutoNumber.ToString() },
{ "backgroundProcess", _backgroundProcess },
{ "csvDelimiter", csvDelimiter.ToString() },
{ "data", _serializedData },
{ "returnFormat", returnFormat.GetDisplayName() }
6 changes: 3 additions & 3 deletions RedcapApi/Redcap.csproj
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@
<Description>This library allows applications on the .NET platform to make http calls to REDCap instances.</Description>
<Product>Redcap Api Library</Product>
<PackageId>RedcapAPI</PackageId>
<Version>1.3.5</Version>
<AssemblyVersion>1.3.5</AssemblyVersion>
<Version>1.3.6</Version>
<AssemblyVersion>1.3.6</AssemblyVersion>
<PackageTags>redcap api library vcu</PackageTags>
<ApplicationIcon />
<OutputType>Library</OutputType>
<NeutralLanguage>en</NeutralLanguage>
<FileVersion>1.3.5</FileVersion>
<FileVersion>1.3.6</FileVersion>
<Copyright>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</Copyright>
<icon>https://vortex.cctr.vcu.edu/images/ram_crest_160.png</icon>
<PackageIcon>vcu.png</PackageIcon>