Skip to content

Commit

Permalink
Merge branch 'develop' into feature/VONK-5093-IScopedNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutkramer authored Dec 11, 2023
2 parents 305b033 + 44a02c8 commit 063f8e1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions src/Hl7.Fhir.Base/Rest/BaseFhirClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,21 @@ public virtual void Delete(string resourceType, SearchParams condition)
return OperationAsync(operation, parameters, useGet).WaitResult();
}

public virtual Task<Bundle?> ProcessMessageAsync(Bundle bundle, bool async = false, string? responseUrl = null, CancellationToken? ct = null)
{
if (bundle == null) throw new ArgumentNullException(nameof(bundle));

var tx = new TransactionBuilder(Endpoint).ProcessMessage(bundle, async, responseUrl).ToBundle();

return executeAsync<Bundle>(tx, new [] {HttpStatusCode.OK, HttpStatusCode.Accepted, HttpStatusCode.NoContent}, ct);
}

[Obsolete("Synchronous use of the FhirClient is strongly discouraged, use the asynchronous call instead.")]
public virtual Resource? ProcessMessage(Bundle messageBundle, bool async = false, string? responseUrl = null)
{
return ProcessMessageAsync(messageBundle, async, responseUrl).WaitResult();
}

private Task<Resource?> internalOperationAsync(string operationName, string? type = null, string? id = null, string? vid = null,
Parameters? parameters = null, bool useGet = false, CancellationToken? ct = null)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Hl7.Fhir.Base/Rest/TransactionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ public TransactionBuilder ResourceOperation(string resourceType, string id, stri
return EndpointOperation(path, parameters, useGet, bundleEntryFullUrl);
}

public TransactionBuilder ProcessMessage(Bundle messageBundle, bool async = false, string? responseUrl = null, string? bundleEntryFullUrl = null)
{
var entry = newEntry(Bundle.HTTPVerb.POST, InteractionType.Operation, bundleEntryFullUrl);
var path = newRestUrl().AddPath(OPERATIONPREFIX + "process-message");
if (async) path.AddParam("async", "true");
if (responseUrl != null) path.AddParam("response-url", responseUrl);
entry.Resource = messageBundle;
addEntry(entry, path);

return this;
}

/// <summary>
/// Add a "search" entry to the transaction/batch
/// </summary>
Expand Down
16 changes: 11 additions & 5 deletions src/Hl7.Fhir.Conformance/Specification/Source/SnapshotSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Hl7.Fhir.Utility;
using System;
using System.Diagnostics;
using T=System.Threading.Tasks;
using T = System.Threading.Tasks;

namespace Hl7.Fhir.Specification.Source
{
Expand Down Expand Up @@ -34,7 +34,9 @@ public SnapshotSource(SnapshotGenerator generator)
/// <summary>Creates a new instance of the <see cref="SnapshotSource"/> for the specified internal resolver.</summary>
/// <param name="source">An internal <see cref="IResourceResolver"/> instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory.</param>
/// <param name="settings">Configuration settings for the snapshot generator.</param>
public SnapshotSource(IResourceResolver source, SnapshotGeneratorSettings settings)
#pragma warning disable CS0618 // Type or member is obsolete
public SnapshotSource(ISyncOrAsyncResourceResolver source, SnapshotGeneratorSettings settings)
#pragma warning restore CS0618 // Type or member is obsolete
{
// SnapshotGenerator ctor will throw if source or settings are null
Generator = new SnapshotGenerator(source, settings);
Expand All @@ -43,11 +45,13 @@ public SnapshotSource(IResourceResolver source, SnapshotGeneratorSettings settin
/// <summary>Creates a new instance of the <see cref="SnapshotSource"/> for the specified internal resolver.</summary>
/// <param name="source">An internal <see cref="IResourceResolver"/> instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory.</param>
/// <param name="regenerate">Determines if the source should always discard any existing snapshot components provided by the internal source and force re-generation.</param>
public SnapshotSource(IResourceResolver source, bool regenerate)
#pragma warning disable CS0618 // Type or member is obsolete
public SnapshotSource(ISyncOrAsyncResourceResolver source, bool regenerate)
#pragma warning restore CS0618 // Type or member is obsolete
: this(source, createSettings(regenerate)) { }

// Create default SnapshotGeneratorSettings, apply the specified regenerate flag
static SnapshotGeneratorSettings createSettings(bool regenerate)
private static SnapshotGeneratorSettings createSettings(bool regenerate)
{
var settings = SnapshotGeneratorSettings.CreateDefault();
settings.ForceRegenerateSnapshots = regenerate;
Expand All @@ -56,7 +60,9 @@ static SnapshotGeneratorSettings createSettings(bool regenerate)

/// <summary>Creates a new instance of the <see cref="SnapshotSource"/> for the specified internal resolver.</summary>
/// <param name="source">An internal <see cref="IResourceResolver"/> instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory.</param>
public SnapshotSource(IResourceResolver source)
#pragma warning disable CS0618 // Type or member is obsolete
public SnapshotSource(ISyncOrAsyncResourceResolver source)
#pragma warning restore CS0618 // Type or member is obsolete
: this(source, SnapshotGeneratorSettings.CreateDefault()) { }

/// <summary>Returns the internal <see cref="SnapshotGenerator"/> instance used by the source.</summary>
Expand Down
42 changes: 42 additions & 0 deletions src/Hl7.Fhir.Support.Poco.Tests/Rest/FhirClientMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,48 @@ public async T.Task TestOperationWithEmptyBody()
parameters!.Parameter.FirstOrDefault()!.Value.Should().BeOfType<FhirString>().Which.Value.Should().Be("connected");
}

[TestMethod]
public async T.Task TestProcessMessage()
{
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(@"{""resourceType"": ""Bundle"" }", Encoding.UTF8, "application/json"),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$process-message")
};

using var client = new MoqBuilder()
.Send(response, h => h.RequestUri == new Uri("http://example.com/$process-message"))
.AsClient();

var message = new TransactionBuilder("http://example.com/", Bundle.BundleType.Message).ToBundle();

var bundle = await client.ProcessMessageAsync(message);

bundle.Should().NotBeNull();
}

[TestMethod]
public async T.Task TestProcessMessageParameters()
{
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(@"{""resourceType"": ""Bundle"" }", Encoding.UTF8, "application/json"),
RequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$process-message")
};

using var client = new MoqBuilder()
.Send(response, h => h.RequestUri == new Uri("http://example.com/$process-message?async=true&response-url=http%3A%2F%2Fresponseurl.com"))
.AsClient();

var message = new TransactionBuilder("http://example.com/", Bundle.BundleType.Message).ToBundle();

var bundle = await client.ProcessMessageAsync(message, true, "http://responseurl.com");

bundle.Should().NotBeNull();
}

[TestMethod]
public async Task WillFetchFullRepresentation()
{
Expand Down

0 comments on commit 063f8e1

Please sign in to comment.