Skip to content

Commit

Permalink
Merge pull request #90 from tranpl/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
cctrbic authored Feb 5, 2021
2 parents a61bb09 + d62d219 commit f38f9b0
Show file tree
Hide file tree
Showing 25 changed files with 1,758 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: csharp
mono: none
dotnet: 2.1.810
dotnet: 5.0.2
script:
- dotnet restore
- dotnet build ./RedcapApi/
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ __Prerequisites__
5. Build the solution, then run the tests

__API METHODS SUPPORTED (Not all listed)__
* ExportLoggingAsync
* ExportDagsAsync
* ImportDagsAsync
* DeleteDagsAsync
* ExportArmsAsync
* ImportArmsAsync
* DeleteArmsAsync
Expand Down Expand Up @@ -54,7 +58,7 @@ namespace RedcapApiDemo
Console.WriteLine("Redcap Api Demo Started!");
// Use your own API Token here...
var apiToken = "3D57A7FA57C8A43F6C8803A84BB3957B";
var redcap_api = new RedcapApi("http://localhost/redcap/api/");
var redcap_api = new RedcapApi("https://localhost/redcap/api/");

Console.WriteLine("Exporting all records from project.");
var result = redcap_api.ExportRecordsAsync(apiToken).Result;
Expand All @@ -73,21 +77,21 @@ __Install directly in Package Manager Console or Command Line Interface__
```C#
Package Manager

Install-Package RedcapAPI -Version 1.0.9
Install-Package RedcapAPI -Version 1.1.0

```

```C#
.NET CLI

dotnet add package RedcapAPI --version 1.0.9
dotnet add package RedcapAPI --version 1.1.0

```

```C#
Paket CLI

paket add RedcapAPI --version 1.0.9
paket add RedcapAPI --version 1.1.0

```

Expand Down
338 changes: 324 additions & 14 deletions RedcapApi/Api/Redcap.cs

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions RedcapApi/Broker/ApiBroker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

using RestSharp;

using Serilog;

namespace Redcap.Broker
{
public partial class ApiBroker: IApiBroker
{
protected readonly HttpClient httpClient;
protected readonly IRestClient restClient;
public ApiBroker(HttpClient httpClient, IRestClient restClient)
{
this.httpClient = httpClient;
this.restClient = restClient;
}
public void LogException(Exception ex,
[CallerMemberName] string method = null,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = 0)
{
var errorMessage = $"Message: {ex.Message}. Method: {method} File: {filePath} LineNumber: {lineNumber}";
Log.Error($"Message: {ex.Message}. Method: {method} File: {filePath} LineNumber: {lineNumber}");
throw new Exception(errorMessage);
}
public async Task<T> PostAsync<T>(IRestRequest request, CancellationToken cancellationToken = default)
{
var response = await restClient.PostAsync<T>(request, cancellationToken);

return response;
}
public async Task<T> ExecuteAsync<T>(RestRequest request) where T : new()
{
var response = await restClient.ExecuteAsync<T>(request);
if(response.ErrorException != null)
{
LogException(response.ErrorException);
}
return response.Data;
}
}
}
16 changes: 16 additions & 0 deletions RedcapApi/Broker/IApiBroker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

using RestSharp;

namespace Redcap.Broker
{
public interface IApiBroker
{
Task<T> ExecuteAsync<T>(RestRequest request) where T : new();
void LogException(Exception ex, [CallerMemberName] string method = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = 0);
Task<T> PostAsync<T>(IRestRequest request, CancellationToken cancellationToken = default);
}
}
6 changes: 6 additions & 0 deletions RedcapApi/Interfaces/IRedcap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,5 +1484,11 @@ public interface IRedcap
/// <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>
/// <returns>Returns the content with format specified.</returns>
Task<string> SaveRecordsAsync(List<string> data, ReturnContent returnContent, OverwriteBehavior overwriteBehavior, ReturnFormat? inputFormat, RedcapDataType? redcapDataType, OnErrorFormat? returnFormat, string dateFormat = "MDY");
Task<string> ExportLoggingAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, LogType logType = LogType.All, string user = null, string record = null, string dag = null, string beginTime = null, string endTime = null, OnErrorFormat onErrorFormat = OnErrorFormat.json);
Task<string> ExportDagsAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json);
Task<string> ImportDagsAsync<T>(string token, Content content, RedcapAction action, ReturnFormat format, List<T> data, OnErrorFormat onErrorFormat = OnErrorFormat.json);
Task<string> DeleteDagsAsync(string token, Content content, RedcapAction action, string[] dags);
Task<string> ExportUserDagAssignmentAsync(string token, Content content, ReturnFormat format = ReturnFormat.json, OnErrorFormat onErrorFormat = OnErrorFormat.json);
Task<string> ImportUserDagAssignmentAsync<T>(string token, Content content, RedcapAction action, ReturnFormat format, List<T> data, OnErrorFormat onErrorFormat = OnErrorFormat.json);
}
}
2 changes: 1 addition & 1 deletion RedcapApi/Models/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Redcap.Models
{
/// <summary>
/// API Action
/// API Action => Export, Import, Delete
/// </summary>
public enum RedcapAction
{
Expand Down
15 changes: 15 additions & 0 deletions RedcapApi/Models/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ namespace Redcap.Models
/// </summary>
public enum Content
{
/// <summary>
/// Log
/// </summary>
[Display(Name ="log")]
Log,
/// <summary>
/// User-Mapping
/// </summary>
[Display(Name = "userDagMapping")]
UserDagMapping,
/// <summary>
/// Dag Content
/// </summary>
[Display(Name = "dag")]
Dag,
/// <summary>
/// Arm Content
/// </summary>
Expand Down
29 changes: 29 additions & 0 deletions RedcapApi/Models/Demographic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;

namespace Redcap.Models
{
/// <summary>
/// Simplified demographics instrument that we can test with.
/// </summary>
public class Demographic
{
/// <summary>
///
/// </summary>
[JsonRequired]
[JsonProperty("record_id")]
public string RecordId { get; set; }

/// <summary>
///
/// </summary>
[JsonProperty("first_name")]
public string FirstName { get; set; }

/// <summary>
///
/// </summary>
[JsonProperty("last_name")]
public string LastName { get; set; }
}
}
69 changes: 69 additions & 0 deletions RedcapApi/Models/LogType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.ComponentModel.DataAnnotations;

namespace Redcap.Models
{
/// <summary>
/// Logging type
/// </summary>
public enum LogType
{
/// <summary>
/// Data Export
/// </summary>
[Display(Name = "export")]
Export,

/// <summary>
/// Manage/Design
/// </summary>
[Display(Name = "manage")]
Manage,

/// <summary>
/// User or role created-updated-deleted
/// </summary>
[Display(Name = "user")]
User,

/// <summary>
/// Record created-updated-deleted
/// </summary>
[Display(Name = "record")]
Record,

/// <summary>
/// Record created (only)
/// </summary>
[Display(Name = "record_add")]
RecordAdd,

/// <summary>
/// Record updated (only)
/// </summary>
[Display(Name = "record_edit")]
RecordEdit,

/// <summary>
/// Record deleted (only)
/// </summary>
[Display(Name = "record_delete")]
RecordDelete,

/// <summary>
/// Record locking and e-signatures
/// </summary>
[Display(Name ="lock_record")]
LockRecord,
/// <summary>
/// Page views
/// </summary>
///
[Display(Name = "page_view")]
PageView,
/// <summary>
/// All event types (excluding page views)
/// </summary>
[Display(Name = "")]
All
}
}
32 changes: 32 additions & 0 deletions RedcapApi/Models/RedcapDag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

using Newtonsoft.Json;

namespace Redcap.Models
{
/// <summary>
/// Data Access Group
/// Example:
/// [{"data_access_group_name":"CA Site","unique_group_name":"ca_site"}
/// {"data_access_group_name":"FL Site","unique_group_name":"fl_site"},
/// { "data_access_group_name":"New Site","unique_group_name":""}]
/// </summary>
public class RedcapDag
{
/// <summary>
/// group name
/// </summary>
///
[JsonProperty("data_access_group_name")]
public string GroupName { get; set; }
/// <summary>
/// auto-generated unique group name
/// </summary>
///
[JsonProperty("unique_group_name")]

public string UniqueGroupName { get; set; }
}
}
40 changes: 23 additions & 17 deletions RedcapApi/Redcap.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>Michael Tran</Authors>
<Company>Virginia Commonwealth University</Company>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand All @@ -10,51 +10,57 @@
<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.0.9</Version>
<AssemblyVersion>1.0.9.0</AssemblyVersion>
<Version>1.1.0</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<PackageTags>redcap api library vcu</PackageTags>
<PackageReleaseNotes>- add improvements to 'ImportRecordsAsync'
Add ability to declare csv delimiter to match REDCap's API paramters
- minor update documentation
- Minor version bump
</PackageReleaseNotes>
<PackageReleaseNotes>New APIs have been added!
-ExportLoggingAsync
-ExportDagsAsync
-ImportDagsAsync
-DeleteDagsAsync
-ExportUserDagAssignmentAsync
-ImportUserDagAssignmentAsync
-Added models to support new APIs
Minor bugs fixes to existing APIs regarding optional parameters.</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
<NeutralLanguage>en</NeutralLanguage>
<FileVersion>1.0.9.0</FileVersion>
<FileVersion>1.1.0.0</FileVersion>
<license>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</license>
<Copyright>https://github.com/cctrbic/redcap-api/blob/master/LICENSE.md</Copyright>
<icon>https://vortex.cctr.vcu.edu/images/ram_crest_160.png</icon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>ram_crest_160.png</PackageIcon>
<PackageIcon>vcu.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>false</Optimize>
<DocumentationFile>bin\Debug\netcoreapp2.0\Redcap.xml</DocumentationFile>
<DocumentationFile></DocumentationFile>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>D:\Github\redcap-api\RedcapApi\Redcap.xml</DocumentationFile>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
<None Include="..\ram_crest_160.png">
<None Include="..\vcu.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.11.7" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<Content Include="Models\RedcapMetaData.cs" />
<Content Include="Models\RecordStatus.cs" />
</ItemGroup>
Expand Down
Loading

0 comments on commit f38f9b0

Please sign in to comment.