Skip to content

Commit 50be847

Browse files
authored
Merge pull request #77 from tranpl/master
implement new api methods and bug fixes
2 parents 431cdc5 + 50fc6ab commit 50be847

13 files changed

+711
-416
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Travis](https://img.shields.io/travis/cctrbic/redcap-api.svg?style=for-the-badge)](https://travis-ci.org/cctrbic/redcap-api) [![NuGet](https://img.shields.io/nuget/dt/RedcapApi.svg?style=for-the-badge)](https://www.nuget.org/packages/RedcapAPI/1.0.1-beta) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md)
2-
2+
[![Build status](https://dev.azure.com/cctrbic/redcap-api-library/_apis/build/status/redcap-api-library-ASP.NET%20Core-CI)](https://dev.azure.com/cctrbic/redcap-api-library/_build/latest?definitionId=15)
33

44
Project Feedback, using REDCap of course: https://redcap.vcu.edu/surveys/?s=KJLHWRTJYA
55

RedcapApi/Api/Redcap.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public async Task<string> ExportArmsAsync(string token, ReturnFormat returnForma
133133
}
134134

135135
}
136-
137136
/// <summary>
138137
/// API Version 1.0.0+ **
139138
/// Export Arms
@@ -146,7 +145,7 @@ public async Task<string> ExportArmsAsync(string token, ReturnFormat returnForma
146145
/// <param name="token">The API token specific to your REDCap project and username (each token is unique to each user for each project). See the section on the left-hand menu for obtaining a token for a given project.</param>
147146
/// <param name="content">arm</param>
148147
/// <param name="returnFormat">csv, json [default], xml</param>
149-
/// <param name="arms">an array of arm numbers that you wish to pull events for (by default, all events are pulled)</param>
148+
/// <param name="arms">e.g. ["1","2"] an array of arm numbers that you wish to pull events for (by default, all events are pulled)</param>
150149
/// <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>
151150
/// <returns>Arms for the project in the format specified(only ones with Events available)</returns>
152151
public async Task<string> ExportArmsAsync(string token, Content content, ReturnFormat returnFormat = ReturnFormat.json, string[] arms = null, OnErrorFormat onErrorFormat = OnErrorFormat.json)
@@ -3173,6 +3172,50 @@ public async Task<string> ExportRepeatingInstrumentsAndEvents(string token, Cont
31733172
return Ex.Message;
31743173
}
31753174
}
3175+
/// <summary>
3176+
/// API Version 1.0.0+
3177+
/// From Redcap Version 8.10.0
3178+
///
3179+
/// Import Repeating Instruments and Events
3180+
/// This method allows you to import a list of the repeated instruments and repeating events for a project. This includes their unique instrument name as seen in the second column of the Data Dictionary, as well as each repeating instrument's corresponding custom repeating instrument label. For longitudinal projects, the unique event name is also needed for each repeating instrument. Additionally, repeating events must be submitted as separate items, in which the instrument name will be blank/null to indicate that it is a repeating event (rather than a repeating instrument).
3181+
/// </summary>
3182+
/// <param name="token">The API token specific to your REDCap project and username (each token is unique to each user for each project). See the section on the left-hand menu for obtaining a token for a given project.</param>
3183+
/// <param name="data">Note: Super API Tokens can also be utilized for this method instead of a project-level API token. Users can only be granted a super token by a REDCap administrator (using the API Tokens page in the REDCap Control Center).</param>
3184+
/// <param name="content">repeatingFormsEvents</param>
3185+
/// <param name="format">csv, json [default], xml</param>
3186+
/// <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>
3187+
/// <returns>Repeated instruments and events for the project in the format specified and will be ordered according to their order in the project.</returns>
3188+
public async Task<string> ImportRepeatingInstrumentsAndEvents<T>(string token, List<T> data, Content content = Content.RepeatingFormsEvents, ReturnFormat format = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json)
3189+
{
3190+
try
3191+
{
3192+
/*
3193+
* Check the required parameters for empty or null
3194+
*/
3195+
this.CheckToken(token);
3196+
3197+
var _serializedData = JsonConvert.SerializeObject(data);
3198+
3199+
var payload = new Dictionary<string, string>
3200+
{
3201+
{ "token", token },
3202+
{ "content", content.GetDisplayName() },
3203+
{ "format", format.GetDisplayName() },
3204+
{ "returnFormat", onErrorFormat.GetDisplayName() },
3205+
{ "data", _serializedData }
3206+
};
3207+
return await this.SendPostRequestAsync(payload, _uri);
3208+
}
3209+
catch (Exception Ex)
3210+
{
3211+
/*
3212+
* We'll just log the error and return the error message.
3213+
*/
3214+
Log.Error($"{Ex.Message}");
3215+
return Ex.Message;
3216+
}
3217+
}
3218+
31763219
#endregion Repeating Instruments and Events
31773220
#region Reports
31783221
/// <summary>
@@ -3476,7 +3519,7 @@ public async Task<string> ExportSurveyLinkAsync(string token, Content content, s
34763519
return Ex.Message;
34773520
}
34783521
}
3479-
3522+
34803523
/// <summary>
34813524
/// API Version 1.0.0+
34823525
/// Export a Survey Participant List
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"Variable / Field Name","Form Name","Section Header","Field Type","Field Label","Choices, Calculations, OR Slider Labels","Field Note","Text Validation Type OR Show Slider Number","Text Validation Min","Text Validation Max",Identifier?,"Branching Logic (Show field only if...)","Required Field?","Custom Alignment","Question Number (surveys only)","Matrix Group Name","Matrix Ranking?","Field Annotation"
2+
record_id,demographics,,text,"Study Id",,,,,,,,,,,,,
3+
first_name,demographics,"Contact Information",text,"First Name",,,,,,y,,,,,,,
4+
last_name,demographics,,text,"Last Name",,,,,,y,,,,,,,
5+
address,demographics,,notes,"Street, City, State, ZIP",,,,,,y,,,,,,,
6+
email,demographics,,text,E-mail,,,email,,,y,,,,,,,
7+
dob,demographics,,text,"Date of Birth",,,date_ymd,,,y,,,,,,,
8+
file_upload,demographics,,file,"File Upload",,,,,,,,,,,,,

RedcapApi/Interfaces/IRedcap.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ public interface IRedcap
943943
Task<string> DeleteRecordsAsync(string token, string[] records, int? arm);
944944

945945
/// <summary>
946-
/// API Version 1.0.0
946+
/// API Version 1.0.0+
947947
/// From Redcap Version 8.2.0
948948
///
949949
/// Export Repeating Instruments and Events
@@ -956,7 +956,7 @@ public interface IRedcap
956956
/// <returns>Repeated instruments and events for the project in the format specified and will be ordered according to their order in the project.</returns>
957957
Task<string> ExportRepeatingInstrumentsAndEvents(string token, Content content = Content.RepeatingFormsEvents, ReturnFormat format = ReturnFormat.json);
958958
/// <summary>
959-
/// API Version 1.0.0
959+
/// API Version 1.0.0+
960960
/// From Redcap Version 8.2.0
961961
///
962962
/// Export Repeating Instruments and Events
@@ -967,7 +967,20 @@ public interface IRedcap
967967
/// <param name="format">csv, json [default], xml odm ('odm' refers to CDISC ODM XML format, specifically ODM version 1.3.1)</param>
968968
/// <returns>Repeated instruments and events for the project in the format specified and will be ordered according to their order in the project.</returns>
969969
Task<string> ExportRepeatingInstrumentsAndEvents(string token, ReturnFormat format = ReturnFormat.json);
970-
970+
/// <summary>
971+
/// API Version 1.0.0+
972+
/// From Redcap Version 8.10.0
973+
///
974+
/// Import Repeating Instruments and Events
975+
/// This method allows you to import a list of the repeated instruments and repeating events for a project. This includes their unique instrument name as seen in the second column of the Data Dictionary, as well as each repeating instrument's corresponding custom repeating instrument label. For longitudinal projects, the unique event name is also needed for each repeating instrument. Additionally, repeating events must be submitted as separate items, in which the instrument name will be blank/null to indicate that it is a repeating event (rather than a repeating instrument).
976+
/// </summary>
977+
/// <param name="token">The API token specific to your REDCap project and username (each token is unique to each user for each project). See the section on the left-hand menu for obtaining a token for a given project.</param>
978+
/// <param name="data">Note: Super API Tokens can also be utilized for this method instead of a project-level API token. Users can only be granted a super token by a REDCap administrator (using the API Tokens page in the REDCap Control Center).</param>
979+
/// <param name="content">repeatingFormsEvents</param>
980+
/// <param name="returnFormat">csv, json [default], xml</param>
981+
/// <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>
982+
/// <returns></returns>
983+
Task<string> ImportRepeatingInstrumentsAndEvents<T>(string token, List<T> data, Content content = Content.RepeatingFormsEvents, ReturnFormat returnFormat = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json);
971984
/// <summary>
972985
/// Export Reports
973986
/// This method allows you to export the data set of a report created on a project's 'Data Exports, Reports, and Stats' page.

RedcapApi/Models/RedcapArm.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Redcap.Models
1+
using Newtonsoft.Json;
2+
3+
namespace Redcap.Models
24
{
35
/// <summary>
46
/// Arms are only available for longitudinal projects.
@@ -8,10 +10,14 @@ public class RedcapArm
810
/// <summary>
911
/// Number associated with the event, e.g "1"
1012
/// </summary>
11-
public string arm_num { get; set; }
13+
///
14+
[JsonProperty("arm_num")]
15+
public string ArmNumber { get; set; }
1216
/// <summary>
1317
/// Name of the event. e.g "event1_arm_1"
1418
/// </summary>
15-
public string name { get; set; }
19+
///
20+
[JsonProperty("name")]
21+
public string Name { get; set; }
1622
}
1723
}

RedcapApi/Models/RedcapEvent.cs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
1-
namespace Redcap.Models
1+
using Newtonsoft.Json;
2+
3+
namespace Redcap.Models
24
{
35
/// <summary>
4-
/// Event for redcap longitudinal projects.
6+
/// Event for redcap longitudinal projects and repeating instruments/forms.
57
/// </summary>
68
public class RedcapEvent
79
{
10+
/// Name of the Event
11+
/// This is required.
12+
/// The unique name of the redcap event, usually appended with arm_1 after event name.
13+
/// e.g "event_1_arm_1"
14+
[JsonProperty("event_name")]
15+
[JsonRequired]
16+
public string EventName { get; set; }
817
/// <summary>
9-
/// Name of the event
10-
/// </summary>
11-
public string event_name { get; set; }
12-
/// <summary>
13-
/// Arm the event belongs to
18+
/// Arm the event belongs to, if any
1419
/// </summary>
15-
public string arm_num { get; set; }
20+
///
21+
[JsonProperty("arm_num")]
22+
public string ArmNumber { get; set; }
1623
/// <summary>
17-
/// Days of offset
24+
/// Days of offset, if any
1825
/// </summary>
19-
public string day_offset { get; set; }
26+
///
27+
[JsonProperty("day_offset")]
28+
public string DayOffset { get; set; }
2029
/// <summary>
21-
/// Minimum(floor) of offset
30+
/// Minimum(floor) of offset, if any
2231
/// </summary>
23-
public string offset_min { get; set; }
32+
///
33+
[JsonProperty("offset_min")]
34+
public string MinimumOffset { get; set; }
2435
/// <summary>
25-
/// Max(ceiling) of offset
36+
/// Max(ceiling) of offset, if any
2637
/// </summary>
27-
public string offset_max { get; set; }
38+
///
39+
[JsonProperty("offset_max")]
40+
public string MaximumOffset { get; set; }
2841
/// <summary>
29-
/// Unique event name used to identify this event
42+
/// Unique event name used to identify this event, if any
3043
/// </summary>
31-
public string unique_event_name { get; set; }
44+
///
45+
[JsonProperty("unique_event_name")]
46+
public string UniqueEventName { get; set; }
3247
/// <summary>
33-
/// Label displayed for this event
48+
/// Label displayed for this event, if any
3449
/// </summary>
35-
public object custom_event_label { get; set; }
50+
///
51+
[JsonProperty("custom_event_label")]
52+
public object CustomEventLabel { get; set; }
3653
}
3754

3855
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Redcap.Models
7+
{
8+
/// <summary>
9+
/// A single repeat instance in redcap
10+
/// </summary>
11+
public class RedcapRepeatInstance
12+
{
13+
/// <summary>
14+
/// The instance number that the instrument is repeated, e.g 3, repeated on the 3rd instance
15+
/// </summary>
16+
[JsonProperty("redcap_repeat_instance")]
17+
public int RepeatInstance { get; set; }
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Redcap.Models
4+
{
5+
/// <summary>
6+
/// Redcap Repeat Instrument
7+
/// The instrument that is repeated in a project that has repeating instruments enabled.
8+
/// This can support "repeat entire event" or "repeat instruments" mode.
9+
/// </summary>
10+
public class RedcapRepeatInstrument: RedcapEvent
11+
{
12+
13+
/// <summary>
14+
/// The unique instrument/form name that is repeated for the specific event.
15+
/// e.g demographics
16+
/// </summary>
17+
[JsonProperty("form_name")]
18+
public string FormName { get; set; }
19+
20+
/// <summary>
21+
/// The custom form/instrument label for this repeating instrument or event.
22+
/// </summary>
23+
[JsonProperty("custom_form_label")]
24+
public string CustomFormLabel { get; set; }
25+
}
26+
}

RedcapApi/Redcap.csproj

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk">
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Authors>Michael Tran</Authors>
6-
<Company>Virginia Commonwealth University</Company>
7-
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8-
<RepositoryUrl>https://github.com/cctrbic/redcap-api</RepositoryUrl>
9-
<PackageProjectUrl>https://github.com/cctrbic/redcap-api</PackageProjectUrl>
10-
<Description>This library allows applications on the .NET platform to make http calls to REDCap instances.</Description>
11-
<Product>Redcap Api Library</Product>
12-
<PackageId>RedcapAPI</PackageId>
13-
<Version>1.0.6</Version>
14-
<AssemblyVersion>1.0.6.0</AssemblyVersion>
15-
<PackageTags>redcap api library</PackageTags>
16-
<PackageReleaseNotes>quality of life changes for methods
17-
updated documents
18-
bug fixes</PackageReleaseNotes>
19-
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
20-
<ApplicationIcon />
21-
<OutputType>Library</OutputType>
22-
<StartupObject />
23-
<NeutralLanguage>en</NeutralLanguage>
24-
</PropertyGroup>
25-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
26-
<Optimize>false</Optimize>
27-
<DocumentationFile>bin\Debug\netcoreapp2.0\Redcap.xml</DocumentationFile>
28-
<DebugType>portable</DebugType>
29-
<DebugSymbols>true</DebugSymbols>
30-
<PlatformTarget>AnyCPU</PlatformTarget>
31-
</PropertyGroup>
32-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
33-
<DocumentationFile>bin\Release\netcoreapp1.1\Redcap.xml</DocumentationFile>
34-
</PropertyGroup>
35-
<ItemGroup>
36-
<Compile Remove="bin\**" />
37-
<EmbeddedResource Remove="bin\**" />
38-
<None Remove="bin\**" />
39-
</ItemGroup>
40-
<ItemGroup>
41-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
42-
<PackageReference Include="Serilog" Version="2.7.1" />
43-
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
44-
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
45-
<PackageReference Include="xunit.extensibility.core" Version="2.4.0" />
46-
<Content Include="Models\RedcapMetaData.cs" />
47-
<Content Include="Models\RecordStatus.cs" />
48-
</ItemGroup>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Authors>Michael Tran</Authors>
6+
<Company>Virginia Commonwealth University</Company>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<RepositoryUrl>https://github.com/cctrbic/redcap-api</RepositoryUrl>
9+
<PackageProjectUrl>https://github.com/cctrbic/redcap-api</PackageProjectUrl>
10+
<Description>This library allows applications on the .NET platform to make http calls to REDCap instances.</Description>
11+
<Product>Redcap Api Library</Product>
12+
<PackageId>RedcapAPI</PackageId>
13+
<Version>1.0.7</Version>
14+
<AssemblyVersion>1.0.7.0</AssemblyVersion>
15+
<PackageTags>redcap api library</PackageTags>
16+
<PackageReleaseNotes>Additional tests for latest release.
17+
Additional methods include: ImportRepeatingInstrumentsAndEvents
18+
Older APIs have been deprecated(you can still use them but they'll generate warnings).
19+
Bug fixes</PackageReleaseNotes>
20+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21+
<ApplicationIcon />
22+
<OutputType>Library</OutputType>
23+
<StartupObject />
24+
<NeutralLanguage>en</NeutralLanguage>
25+
<FileVersion>1.0.7.0</FileVersion>
26+
<PackageLicenseUrl>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</PackageLicenseUrl>
27+
<Copyright>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</Copyright>
28+
</PropertyGroup>
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
30+
<Optimize>false</Optimize>
31+
<DocumentationFile>bin\Debug\netcoreapp2.0\Redcap.xml</DocumentationFile>
32+
<DebugType>portable</DebugType>
33+
<DebugSymbols>true</DebugSymbols>
34+
<PlatformTarget>AnyCPU</PlatformTarget>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
37+
<DocumentationFile>bin\Release\netcoreapp1.1\Redcap.xml</DocumentationFile>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Compile Remove="bin\**" />
41+
<EmbeddedResource Remove="bin\**" />
42+
<None Remove="bin\**" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
46+
<PackageReference Include="Serilog" Version="2.7.1" />
47+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
48+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
49+
<PackageReference Include="xunit.extensibility.core" Version="2.4.0" />
50+
<Content Include="Models\RedcapMetaData.cs" />
51+
<Content Include="Models\RecordStatus.cs" />
52+
</ItemGroup>
4953
</Project>

0 commit comments

Comments
 (0)