Skip to content

Commit

Permalink
feature: Add GET interaction support for transaction bundles
Browse files Browse the repository at this point in the history
This adds support for GET interaction in batch/transaction bundles.

Fixes #305
  • Loading branch information
kennethmyhra committed Sep 5, 2021
1 parent 7a3cd05 commit 85fb8cf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Spark.Engine/Core/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public static Entry Create(Bundle.HTTPVerb method, Resource resource)
return new Entry(method, null, null, resource);
}

public static Entry Create(Bundle.HTTPVerb method, IKey key)
{
return new Entry(method, key, null, null);
}

public static Entry Create(Bundle.HTTPVerb method, IKey key, Resource resource)
{
return new Entry(method, key, null, resource);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Spark.Engine.Core;
using System;
using System.Collections.Generic;

namespace Spark.Engine.Service.FhirServiceExtensions
{
public class GetManipulationOperation : ResourceManipulationOperation
{
public GetManipulationOperation(Resource resource, IKey operationKey, SearchResults searchResults, SearchParams searchCommand = null)
: base(resource, operationKey, searchResults, searchCommand)
{
}

public static Uri ReadSearchUri(Bundle.EntryComponent entry)
{
return entry.Request != null
? new Uri(entry.Request.Url, UriKind.RelativeOrAbsolute)
: null;
}

protected override IEnumerable<Entry> ComputeEntries()
{
if (SearchResults != null)
{
foreach (string localKeyLiteral in SearchResults)
{
yield return Entry.Create(Bundle.HTTPVerb.GET, Key.ParseOperationPath(localKeyLiteral));
}
}
else
{
yield return Entry.Create(Bundle.HTTPVerb.GET, OperationKey);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ static ResourceManipulationOperationFactory()
{
{ Bundle.HTTPVerb.POST, CreatePost },
{ Bundle.HTTPVerb.PUT, CreatePut },
{ Bundle.HTTPVerb.DELETE, CreateDelete }
{ Bundle.HTTPVerb.DELETE, CreateDelete },
{ Bundle.HTTPVerb.GET, CreateGet },
};

_asyncBuilders = new Dictionary<Bundle.HTTPVerb, Func<Resource, IKey, ISearchService, SearchParams, Task<ResourceManipulationOperation>>>
{
{ Bundle.HTTPVerb.POST, CreatePostAsync },
{ Bundle.HTTPVerb.PUT, CreatePutAsync },
{ Bundle.HTTPVerb.DELETE, CreateDeleteAsync }
{ Bundle.HTTPVerb.DELETE, CreateDeleteAsync },
{ Bundle.HTTPVerb.GET, CreateGetAsync },
};
}

Expand Down Expand Up @@ -91,6 +93,16 @@ private static async Task<ResourceManipulationOperation> CreateDeleteAsync(Resou
return new DeleteManipulationOperation(null, key, await GetSearchResultAsync(key, searchService, searchParams).ConfigureAwait(false), searchParams);
}

private static ResourceManipulationOperation CreateGet(Resource resource, IKey key, ISearchService searchService, SearchParams searchParams)
{
return new GetManipulationOperation(resource, key, GetSearchResult(key, searchService, searchParams), searchParams);
}

private static async Task<ResourceManipulationOperation> CreateGetAsync(Resource resource, IKey key, ISearchService searchService, SearchParams searchParams)
{
return new GetManipulationOperation(resource, key, await GetSearchResultAsync(key, searchService, searchParams), searchParams);
}

public static ResourceManipulationOperation GetManipulationOperation(Bundle.EntryComponent entryComponent, ILocalhost localhost, ISearchService searchService = null)
{
Bundle.HTTPVerb method = localhost.ExtrapolateMethod(entryComponent, null);
Expand Down Expand Up @@ -127,6 +139,10 @@ private static Uri GetSearchUri(Bundle.EntryComponent entryComponent, Bundle.HTT
{
searchUri = DeleteManipulationOperation.ReadSearchUri(entryComponent);
}
else if (method == Bundle.HTTPVerb.GET)
{
searchUri = FhirServiceExtensions.GetManipulationOperation.ReadSearchUri(entryComponent);
}
return searchUri;
}

Expand Down

0 comments on commit 85fb8cf

Please sign in to comment.