Skip to content

Commit 35659f0

Browse files
authored
Merge pull request #23 from tranpl/net-core-1.x
implemented apis
2 parents cc38b51 + 2a5535e commit 35659f0

File tree

11 files changed

+759
-245
lines changed

11 files changed

+759
-245
lines changed

RedcapApi.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.10
4+
VisualStudioVersion = 15.0.26730.15
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Redcap", "RedcapApi\Redcap.csproj", "{E34E88C8-D30F-4924-8108-8E84D14C2E9A}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RedcapApiDemo", "RedcapApiDemo\RedcapApiDemo.csproj", "{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedcapApiTests", "RedcapApiTests\RedcapApiTests.csproj", "{F7B44B5F-7559-4507-AC25-2B2D08C1E078}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{CBAF5212-0D5F-44F1-A7C5-F1B0ED7AF43E}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{F7B44B5F-7559-4507-AC25-2B2D08C1E078}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

RedcapApi/Api/Redcap.cs

Lines changed: 536 additions & 197 deletions
Large diffs are not rendered by default.

RedcapApi/Interfaces/IRedcap.cs

Lines changed: 38 additions & 37 deletions
Large diffs are not rendered by default.

RedcapApi/Models/Record.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Redcap.Models
6+
{
7+
public class Record
8+
{
9+
public KeyValuePair<string, string> Value { get; set; }
10+
}
11+
}

RedcapApi/Models/RedcapDataType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Redcap.Models
22
{
33
/// <summary>
4-
/// The format which is provided when requesting a import through Redcap API
4+
/// The data format which the Redcap API endpoint should receive.
55
/// RedcapDataType, 0 = flat
66
/// RedcapDataType, 1 = eav
77
/// RedcapDataType, 2 = nonlogitudinal

RedcapApi/Models/RedcapFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// RedcapFormat, 1 = CSV
77
/// RedcapFormat, 2 = XML
88
/// </summary>
9-
public enum RedcapFormat
9+
public enum InputFormat
1010
{
1111
json = 0,
1212
csv = 1,

RedcapApi/Redcap.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<Description>This library allows external applications to connect to REDCap remotely and is used to programmatically retrieve or modify data or settings within REDCap, e.g Import/Export records into Redcap</Description>
1111
<Product>Redcap Api Library</Product>
1212
<PackageId>RedcapAPI</PackageId>
13-
<Version>0.2.6-alpha-release</Version>
14-
<AssemblyVersion>0.2.6.0</AssemblyVersion>
13+
<Version>0.2.8-alpha</Version>
14+
<AssemblyVersion>0.2.8.0</AssemblyVersion>
1515
<PackageTags>redcap</PackageTags>
1616
<PackageReleaseNotes>alpha release</PackageReleaseNotes>
1717
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1818
<ApplicationIcon />
19-
<OutputType>WinExe</OutputType>
19+
<OutputType>Library</OutputType>
2020
<StartupObject />
2121
</PropertyGroup>
2222

RedcapApiDemo/Program.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using Newtonsoft.Json;
43
using Redcap;
54
using Redcap.Models;
@@ -14,9 +13,38 @@ static void Main(string[] args)
1413

1514
var redcap_api = new RedcapApi("3D57A7FA57C8A43F6C8803A84BB3957B", "http://localhost/redcap/api/");
1615

17-
var result = redcap_api.GetRecordAsync("1",RedcapFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result;
18-
var data = JsonConvert.DeserializeObject(result);
19-
Console.WriteLine(data);
16+
Console.WriteLine("Calling GetRecordAsync() . . .");
17+
var GetRecordAsync = redcap_api.GetRecordAsync("1", InputFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result;
18+
var GetRecordAsyncData = JsonConvert.DeserializeObject(GetRecordAsync);
19+
Console.WriteLine($"GetRecordAsync Result: {GetRecordAsyncData}");
20+
21+
Console.WriteLine("Calling ExportEventsAsync() . . .");
22+
var exportEvents = redcap_api.ExportEventsAsync(InputFormat.json, ReturnFormat.json).Result;
23+
var exportEventsAsync = JsonConvert.DeserializeObject(exportEvents);
24+
Console.WriteLine($"ExportEventsAsync Result: {exportEventsAsync}");
25+
26+
Console.WriteLine("Calling GetRecordsAsync() . . .");
27+
var GetRecordsAsync = redcap_api.GetRecordsAsync(InputFormat.json, ReturnFormat.json, RedcapDataType.flat).Result;
28+
var GetRecordsAsyncData = JsonConvert.DeserializeObject(GetRecordsAsync);
29+
Console.WriteLine($"GetRecordsAsync Result: {GetRecordsAsyncData}");
30+
31+
Console.WriteLine("Calling GetRedcapVersionAsync() . . .");
32+
var GetRedcapVersionAsync = redcap_api.GetRedcapVersionAsync(InputFormat.json, RedcapDataType.flat).Result;
33+
Console.WriteLine($"GetRedcapVersionAsync Result: {GetRedcapVersionAsync}");
34+
35+
36+
var saveRecordsAsyncObject = new {
37+
record_id = "1",
38+
redcap_event_name = "event_1_arm_1",
39+
first_name = "John",
40+
last_name = "Doe"
41+
};
42+
43+
Console.WriteLine("Calling SaveRecordsAsync() . . .");
44+
var SaveRecordsAsync = redcap_api.SaveRecordsAsync(saveRecordsAsyncObject, ReturnContent.ids,OverwriteBehavior.overwrite, InputFormat.json, RedcapDataType.flat, ReturnFormat.json).Result;
45+
var SaveRecordsAsyncData = JsonConvert.DeserializeObject(SaveRecordsAsync);
46+
Console.WriteLine($"SaveRecordsAsync Result: {SaveRecordsAsyncData}");
47+
2048
Console.ReadLine();
2149

2250
}

RedcapApiDemo/RedcapApiDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<ItemGroup>
1818
<Reference Include="Redcap">
19-
<HintPath>..\RedcapApi\bin\Debug\netcoreapp1.1\Redcap.dll</HintPath>
19+
<HintPath>..\RedcapApi\bin\Release\netcoreapp1.1\Redcap.dll</HintPath>
2020
</Reference>
2121
</ItemGroup>
2222

RedcapApiTests/ApiMethodTests.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Newtonsoft.Json;
2+
using Redcap;
3+
using Redcap.Models;
4+
using NUnit.Framework;
5+
6+
namespace RedcapApiTests
7+
{
8+
[TestFixture]
9+
public class ApiMethodTests
10+
{
11+
private string _apiKey = "3D57A7FA57C8A43F6C8803A84BB3957B";
12+
private string _apiEndpoint = "http://localhost/redcap/api/";
13+
[TestCase]
14+
public void CanExportAsync_SingleRecord_ShouldContain_1()
15+
{
16+
// Arrange
17+
var apiKey = _apiKey;
18+
var apiEndpoint = _apiEndpoint;
19+
20+
// Act
21+
var redcap_api = new RedcapApi(apiKey, apiEndpoint);
22+
var result = redcap_api.GetRecordAsync("1", InputFormat.json, RedcapDataType.flat, ReturnFormat.json, null, null, null, null).Result;
23+
var data = JsonConvert.DeserializeObject(result).ToString();
24+
25+
// Assert
26+
StringAssert.Contains("1", data);
27+
}
28+
[TestCase]
29+
public void CanExportAsync_AllEvents_ShouldContain_event_name()
30+
{
31+
// Arrange
32+
var apiKey = _apiKey;
33+
var apiEndpoint = _apiEndpoint;
34+
35+
// Act
36+
var redcap_api = new RedcapApi(apiKey, apiEndpoint);
37+
var result = redcap_api.ExportEventsAsync(InputFormat.json, ReturnFormat.json).Result;
38+
var data = JsonConvert.DeserializeObject(result).ToString();
39+
40+
// Assert
41+
StringAssert.Contains("event_name", data);
42+
43+
}
44+
[TestCase]
45+
public void CanGetRecordsAsync_AllRecords_ShouldContain_record_id()
46+
{
47+
// Arrange
48+
var apiKey = _apiKey;
49+
var apiEndpoint = _apiEndpoint;
50+
51+
// Act
52+
var redcap_api = new RedcapApi(apiKey, apiEndpoint);
53+
var result = redcap_api.GetRecordsAsync(InputFormat.json, ReturnFormat.json, RedcapDataType.flat).Result;
54+
var data = JsonConvert.DeserializeObject(result).ToString();
55+
56+
// Assert
57+
StringAssert.Contains("record_id", data);
58+
59+
}
60+
[TestCase]
61+
public void CanGetRedcapVersion_VersionNumber_Shouldontain_Number()
62+
{
63+
// Arrange
64+
// Assume current redcap version is 7.4.9
65+
var currentRedcapVersion = "7.4.9";
66+
var apiKey = _apiKey;
67+
var apiEndpoint = _apiEndpoint;
68+
69+
// Act
70+
var redcap_api = new RedcapApi(apiKey, apiEndpoint);
71+
var result = redcap_api.GetRedcapVersionAsync(InputFormat.json, RedcapDataType.flat).Result;
72+
var data = result;
73+
74+
// Assert
75+
Assert.AreEqual(currentRedcapVersion, data);
76+
77+
}
78+
[TestCase]
79+
public void CanSaveRecord_SingleRecord_ShouldReturn_Ids()
80+
{
81+
// Arrange
82+
var apiKey = _apiKey;
83+
var apiEndpoint = _apiEndpoint;
84+
85+
var record = new
86+
{
87+
record_id = "1",
88+
redcap_event_name = "event_1_arm_1",
89+
first_name = "John",
90+
last_name = "Doe"
91+
};
92+
// Act
93+
var redcap_api = new RedcapApi(apiKey, apiEndpoint);
94+
var result = redcap_api.SaveRecordsAsync(record, ReturnContent.ids, OverwriteBehavior.overwrite, InputFormat.json, RedcapDataType.flat, ReturnFormat.json).Result;
95+
var data = JsonConvert.DeserializeObject(result).ToString();
96+
97+
// Assert
98+
StringAssert.Contains("1", data);
99+
100+
}
101+
102+
}
103+
}

0 commit comments

Comments
 (0)