/// <summary>Process the request.</summary>
        /// <param name="context">The context.</param>
        /// <returns>An asynchronous result that yields a HttpResponseMessage.</returns>
        internal static async Task <HttpResponseMessage> Process(HttpContext context)
        {
            string fhirServerUrl = ProcessorUtils.GetFhirServerUrlR4(context.Request);

            if (context.Request.Path.Value.Length > 4)
            {
                context.Request.Path = new PathString(context.Request.Path.Value.Substring(3));
            }

            // proxy this call
            ForwardContext proxiedContext = context.ForwardTo(fhirServerUrl);

            // send to server and await response
            HttpResponseMessage response = await proxiedContext.Send().ConfigureAwait(false);

            // get copies of data when we care
            switch (context.Request.Method.ToUpperInvariant())
            {
            case "GET":
                ProcessGet(ref context, ref response);

                break;

            default:

                // ignore
                break;
            }

            // return the originator response, plus any modifications we've done
            return(response);
        }
Exemple #2
0
        public void Forward(SoftmaxLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            float max = float.MinValue;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                max = Math.Max(max, src[oc]);
            }

            float sum = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                float value = (float)Math.Exp(src[oc] - max);
                sum     += value;
                dest[oc] = value;
            }

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                dest[oc] /= sum;
            }
        }
Exemple #3
0
        public void Forward(ResizeNearestNeighborLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            float heightScale = (float)argument.InputHeight / argument.OutputHeight;
            float widthScale  = (float)argument.InputWidth / argument.OutputWidth;

            int destIdx = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                var channelSrc = src.Slice((int)(argument.InputWidth * argument.InputHeight * oc));
                for (int oy = 0; oy < argument.OutputHeight; oy++)
                {
                    var inY     = (int)Math.Min(Math.Floor(oy * heightScale), argument.InputHeight - 1);
                    var yOrigin = channelSrc.Slice(inY * (int)argument.InputWidth);
                    for (int ox = 0; ox < argument.OutputWidth; ox++)
                    {
                        var inX = (int)Math.Min(Math.Floor(ox * widthScale), argument.InputWidth - 1);
                        dest[destIdx++] = yOrigin[inX];
                    }
                }
            }
        }
Exemple #4
0
        public void Forward(K210UploadLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = context.GetKpuRamAt((int)argument.KPUMemoryOutputAddress);

            K210Helper.KpuUpload(dest, src, (int)argument.Width, (int)argument.Height, (int)argument.Channels);
        }
Exemple #5
0
 public static ForwardContext ApplyCorrelationId(this ForwardContext forwardContext)
 {
     if (forwardContext.UpstreamRequest.Headers.Contains(XCorrelationId))
     {
         forwardContext.UpstreamRequest.Headers.Add(XCorrelationId, Guid.NewGuid().ToString());
     }
     return(forwardContext);
 }
Exemple #6
0
        public void Forward(K210RemovePaddingLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                dest[oc] = src[oc * 16];
            }
        }
Exemple #7
0
        public void Forward(RequantizeLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);

            for (int i = 0; i < argument.Count; i++)
            {
                dest[i] = argument.Table[src[i]];
            }
        }
Exemple #8
0
        public void Forward(LogisticLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                dest[oc] = 1f / (1f + (float)Math.Exp(-src[oc]));
            }
        }
Exemple #9
0
        public void Forward(DequantizeLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));
            var q    = argument.QuantParam;

            for (int i = 0; i < argument.Count; i++)
            {
                dest[i] = src[i] * q.Scale + q.Bias;
            }
        }
Exemple #10
0
        public void Forward(ConcatenationLayerArgument argument, ForwardContext context)
        {
            var dest = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);

            foreach (var input in argument.InputsMainMemory)
            {
                var src = context.GetMainRamAt((int)input.Start, (int)input.Size);
                src.CopyTo(dest);
                dest = dest.Slice((int)input.Size);
            }
        }
Exemple #11
0
        public void Forward(AddLayerArgument argument, ForwardContext context)
        {
            var srcA = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAAddress));
            var srcB = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputBAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            for (int oc = 0; oc < argument.Count; oc++)
            {
                dest[oc] = srcA[oc] + srcB[oc];
            }
        }
        /// <summary>Process the request.</summary>
        /// <param name="context">The context.</param>
        /// <returns>An asynchronous result that yields a HttpResponseMessage.</returns>
        internal static async Task <HttpResponseMessage> Process(HttpContext context)
        {
            string fhirServerUrl = ProcessorUtils.GetFhirServerUrlR4(context.Request);

            // determine if we need to ask the server for a current version of the resource
            switch (context.Request.Method)
            {
            case "PUT":
            case "POST":
            case "DELETE":

                // figure out if we need to ask the server about this
                break;

            default:
                // don't need to check for existing copy
                break;
            }

            if (context.Request.Path.Value.Length > 4)
            {
                context.Request.Path = new PathString(context.Request.Path.Value.Substring(3));
            }

            // proxy this call
            ForwardContext proxiedContext = context.ForwardTo(fhirServerUrl);

            // send to server and await response
            HttpResponseMessage response = await proxiedContext.Send().ConfigureAwait(false);

            //// get copies of data when we care
            //switch (context.Request.Method.ToUpperInvariant())
            //{
            //    case "PUT":
            //    case "POST":

            //        // grab the message body to look at
            //        string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            //        // run this Encounter through our Subscription Manager
            //        SubscriptionManager.ProcessEncounter(responseContent, response.Headers.Location);

            //        break;

            //    default:

            //        // just proxy
            //        break;
            //}

            // return the results of the proxied call
            return(response);
        }
Exemple #13
0
        public void Forward(QuantizeLayerArgument argument, ForwardContext context)
        {
            var   src   = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var   dest  = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);
            var   q     = argument.QuantParam;
            float scale = 1f / q.Scale;

            for (int i = 0; i < argument.Count; i++)
            {
                int value = (int)Math.Round((src[i] - q.Bias) * scale);
                dest[i] = (byte)FxExtensions.Clamp(value, 0, 0xFF);
            }
        }
        public static ForwardContext AddPreSharedKeyHeader(this ForwardContext forwardContext, string preSharedKey)
        {
            forwardContext
            .UpstreamRequest
            .Headers
            .Remove(SharedSettings.PreSharedKeyHeader);

            forwardContext
            .UpstreamRequest
            .Headers
            .TryAddWithoutValidation(SharedSettings.PreSharedKeyHeader, preSharedKey);

            return(forwardContext);
        }
Exemple #15
0
        public void Forward(FullyConnectedLayerArgument argument, ForwardContext context)
        {
            var src = MemoryMarshal.Cast<byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast<byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            for (int oc = 0; oc < argument.OutputChannels; oc++)
            {
                var weights = new ReadOnlySpan<float>(argument.Weights, (int)(oc * argument.InputChannels), (int)argument.InputChannels);
                float sum = 0;
                for (int ic = 0; ic < argument.InputChannels; ic++)
                    sum += src[ic] * weights[ic];
                dest[oc] = sum + argument.Bias[oc];
            }
        }
Exemple #16
0
        public void Forward(ChannelwiseDequantizeLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            int idx = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                var q = argument.QuantParams[oc];
                for (int i = 0; i < argument.ChannelSize; i++)
                {
                    dest[idx] = src[idx] * q.Scale + q.Bias;
                    idx++;
                }
            }
        }
Exemple #17
0
        public void Forward(GlobalAveragePool2dLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            int i = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                float sum = 0;
                for (int x = 0; x < argument.KernelSize; x++)
                {
                    sum += src[i++];
                }
                dest[oc] = sum / argument.KernelSize;
            }
        }
Exemple #18
0
        public void Forward(TensorflowFlattenLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            int i = 0;

            for (int oy = 0; oy < argument.Height; oy++)
            {
                for (int ox = 0; ox < argument.Width; ox++)
                {
                    for (int oc = 0; oc < argument.Channels; oc++)
                    {
                        dest[i++] = src[(int)((oc * argument.Height + oy) * argument.Width + ox)];
                    }
                }
            }
        }
Exemple #19
0
        /// <summary>Process the request.</summary>
        /// <param name="context">The context.</param>
        /// <returns>An asynchronous result that yields a HttpResponseMessage.</returns>
        internal static async Task <HttpResponseMessage> Process(HttpContext context)
        {
            string fhirServerUrl = ProcessorUtils.GetFhirServerUrlR4(context.Request);

            if (context.Request.Path.Value.Length > 4)
            {
                context.Request.Path = new PathString(context.Request.Path.Value.Substring(3));
            }

            // context.Request.Headers["Accept-Encoding"] = "";
            // proxy this call
            ForwardContext proxiedContext = context.ForwardTo(fhirServerUrl);

            // send to server and await response
            HttpResponseMessage response = await proxiedContext.Send().ConfigureAwait(false);

            // get copies of data when we care
            switch (context.Request.Method.ToUpperInvariant())
            {
            case "PUT":
            case "POST":

                // grab the message body to look at
                string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    // run this Encounter through our Subscription Manager
                    SubscriptionManagerR4.ProcessEncounter(
                        responseContent,
                        response.Headers.Location);
                }

                break;

            default:

                // ignore
                break;
            }

            // return the results of the proxied call
            return(response);
        }
Exemple #20
0
        public void Forward(AveragePool2dLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            int outIdx = 0;

            for (int oc = 0; oc < argument.OutputChannels; oc++)
            {
                var channelSrc = src.Slice((int)(argument.InputWidth * argument.InputHeight * oc));
                for (int oy = 0; oy < argument.OutputHeight; oy++)
                {
                    for (int ox = 0; ox < argument.OutputWidth; ox++)
                    {
                        int   inXOrigin    = (int)(ox * argument.StrideWidth) - (int)argument.PaddingWidth;
                        int   inYOrigin    = (int)(oy * argument.StrideHeight) - (int)argument.PaddingHeight;
                        int   kernelXStart = Math.Max(0, -inXOrigin);
                        int   kernelXEnd   = Math.Min((int)argument.KernelWidth, (int)argument.InputWidth - inXOrigin);
                        int   kernelYStart = Math.Max(0, -inYOrigin);
                        int   kernelYEnd   = Math.Min((int)argument.KernelHeight, (int)argument.InputHeight - inYOrigin);
                        float value        = 0;
                        float kernelCount  = 0;

                        for (int ky = kernelYStart; ky < kernelYEnd; ky++)
                        {
                            for (int kx = kernelXStart; kx < kernelXEnd; kx++)
                            {
                                int inX = inXOrigin + kx;
                                int inY = inYOrigin + ky;
                                value += channelSrc[inY * (int)argument.InputWidth + inX];
                                kernelCount++;
                            }
                        }

                        dest[outIdx++] = value / kernelCount;
                    }
                }
            }
        }
Exemple #21
0
        public void Forward(L2NormalizationLayerArgument argument, ForwardContext context)
        {
            var src  = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            float       sum     = 0;
            const float epsilon = 1e-10f;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                sum += src[oc] * src[oc];
            }
            if (sum < epsilon)
            {
                sum = epsilon;
            }
            sum = 1f / (float)Math.Sqrt(sum);

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                dest[oc] = src[oc] * sum;
            }
        }
Exemple #22
0
        public void Forward(K210AddPaddingLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = context.GetKpuRamAt((int)argument.KPUMemoryOutputAddress);

            var height = 4;

            (var groups, var rowLength, var rowPadding) = (4, 1, 16);
            int srcIdx = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                var channel_origin = oc / groups * rowLength * height * 64 + oc % groups * rowPadding;
                for (int y = 0; y < 1; y++)
                {
                    var y_origin = channel_origin + y * rowLength * 64;
                    for (int x = 0; x < 1; x++)
                    {
                        dest[y_origin + x] = src[srcIdx++];
                    }
                }
            }
        }
        /// <summary>Process the request.</summary>
        /// <param name="appInner">     The application inner.</param>
        /// <param name="fhirServerUrl">URL of the fhir server.</param>
        public static void ProcessRequest(IApplicationBuilder appInner, string fhirServerUrl)
        {
            // run the proxy for this request
            appInner.RunProxy(async context =>
            {
                // look for a FHIR server header
                if (context.Request.Headers.ContainsKey(Program._proxyHeaderKey) &&
                    (context.Request.Headers[Program._proxyHeaderKey].Count > 0))
                {
                    fhirServerUrl = context.Request.Headers[Program._proxyHeaderKey][0];
                }

                if (context.Request.Path.Value.Length > 4)
                {
                    context.Request.Path = new PathString(context.Request.Path.Value.Substring(3));
                }

                // proxy this call
                ForwardContext proxiedContext = context.ForwardTo(fhirServerUrl);

                // send to server and await response
                return(await proxiedContext.Send().ConfigureAwait(false));
            });
        }
Exemple #24
0
        public static ForwardContext Log(this ForwardContext forwardContext, ILogger logger)
        {
            logger.LogInformation($"upstream url: {forwardContext.UpstreamRequest.RequestUri}");

            return(forwardContext);
        }
        /// <summary>Process the request.</summary>
        /// <param name="appInner">     The application inner.</param>
        /// <param name="fhirServerUrl">URL of the fhir server.</param>
        public static void ProcessRequest(IApplicationBuilder appInner, string fhirServerUrl)
        {
            string serialized;

            // run the proxy for this request
            appInner.RunProxy(async context =>
            {
                // look for a FHIR server header
                if (context.Request.Headers.ContainsKey(Program._proxyHeaderKey) &&
                    (context.Request.Headers[Program._proxyHeaderKey].Count > 0))
                {
                    fhirServerUrl = context.Request.Headers[Program._proxyHeaderKey][0];
                }

                // create some response objects
                HttpResponseMessage response = new HttpResponseMessage();
                StringContent localResponse;
                r5s.FhirJsonSerializer serializer = new r5s.FhirJsonSerializer();

                // default to returning the representation if not specified
                string preferredResponse = "return=representation";

                // check for headers we are interested int
                foreach (KeyValuePair <string, StringValues> kvp in context.Request.Headers)
                {
                    if (kvp.Key.ToLowerInvariant() == "prefer")
                    {
                        preferredResponse = kvp.Value;
                    }
                }

                // act depending on request type
                switch (context.Request.Method.ToUpperInvariant())
                {
                case "GET":

                    // check for an ID
                    string requestUrl = context.Request.Path;
                    if (requestUrl.EndsWith('/'))
                    {
                        requestUrl = requestUrl.Substring(0, requestUrl.Length - 1);
                    }

                    string id = requestUrl.Substring(requestUrl.LastIndexOf('/') + 1);

                    // check for a subscription
                    if (SubscriptionManager.TryGetBasicSerialized(id, out serialized))
                    {
                        // build our response
                        response.Content = new StringContent(
                            serialized,
                            Encoding.UTF8,
                            "application/fhir+json");
                        response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/fhir+json");
                        response.StatusCode = System.Net.HttpStatusCode.OK;

                        // done
                        return(response);
                    }

                    // check for a topic
                    if (SubscriptionTopicManager.TryGetBasicSerialized(id, out serialized))
                    {
                        // build our response
                        response.Content = new StringContent(
                            serialized,
                            Encoding.UTF8,
                            "application/fhir+json");
                        response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/fhir+json");
                        response.StatusCode = System.Net.HttpStatusCode.OK;

                        // done
                        return(response);
                    }

                    // look for query parameters for a search we are interested in
                    if (context.Request.Query.ContainsKey("code"))
                    {
                        // check for topic
                        if (context.Request.Query["code"] == "R5SubscriptionTopic")
                        {
                            // serialize the bundle of topics
                            response.Content = new StringContent(
                                serializer.SerializeToString(SubscriptionTopicManager.GetTopicsBundle(true)));
                            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/fhir+json");
                            response.StatusCode = System.Net.HttpStatusCode.OK;

                            return(response);
                        }

                        // check for basic
                        if (context.Request.Query["code"] == "R5Subscription")
                        {
                            // serialize the bundle of subscriptions
                            response.Content = new StringContent(
                                serializer.SerializeToString(SubscriptionManager.GetSubscriptionsBundle(true)));
                            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/fhir+json");
                            response.StatusCode = System.Net.HttpStatusCode.OK;

                            return(response);
                        }
                    }

                    break;

                case "PUT":

                    // don't deal with PUT yet
                    response.StatusCode = System.Net.HttpStatusCode.NotImplemented;
                    return(response);

                case "POST":

                    try
                    {
                        // grab the message body to look at
                        System.IO.StreamReader requestReader = new System.IO.StreamReader(context.Request.Body);
                        string requestContent = requestReader.ReadToEndAsync().Result;

                        r5s.FhirJsonParser parser = new r5s.FhirJsonParser();
                        r5.Basic basic            = parser.Parse <r5.Basic>(requestContent);

                        // check to see if this is a something we are interested in
                        if ((basic.Code != null) &&
                            (basic.Code.Coding != null) &&
                            basic.Code.Coding.Any())
                        {
                            // look for codes we want
                            foreach (Coding coding in basic.Code.Coding)
                            {
                                if (coding.System.Equals("http://hl7.org/fhir/resource-types", StringComparison.Ordinal) &&
                                    coding.Code.Equals("R5SubscriptionTopic", StringComparison.Ordinal))
                                {
                                    // posting topics is not yet implemented
                                    response.StatusCode = HttpStatusCode.NotImplemented;
                                    return(response);
                                }

                                if (coding.System.Equals("http://hl7.org/fhir/resource-types", StringComparison.Ordinal) &&
                                    coding.Code.Equals("R5Subscription", StringComparison.Ordinal))
                                {
                                    // check for having the required resource
                                    if ((basic.Extension == null) ||
                                        (!basic.Extension.Any()) ||
                                        (!basic.Extension[0].Url.Equals("http://hl7.org/fhir/StructureDefinition/json-embedded-resource", StringComparison.Ordinal)))
                                    {
                                        response.StatusCode = System.Net.HttpStatusCode.BadRequest;
                                        return(response);
                                    }

                                    // check to see if the manager does anything with this text
                                    SubscriptionManager.HandlePost(
                                        basic.Extension[0].Value.ToString(),
                                        out r5.Subscription subscription,
                                        out HttpStatusCode statusCode,
                                        out string failureContent,
                                        true);

                                    // check for errors
                                    if (statusCode != HttpStatusCode.Created)
                                    {
                                        switch (preferredResponse)
                                        {
                                        case "return=minimal":
                                            localResponse = new StringContent(string.Empty, Encoding.UTF8, "text/plain");
                                            break;

                                        case "return=OperationOutcome":
                                            r5.OperationOutcome outcome = new r5.OperationOutcome()
                                            {
                                                Id    = Guid.NewGuid().ToString(),
                                                Issue = new List <r5.OperationOutcome.IssueComponent>()
                                                {
                                                    new r5.OperationOutcome.IssueComponent()
                                                    {
                                                        Severity    = r5.OperationOutcome.IssueSeverity.Error,
                                                        Code        = r5.OperationOutcome.IssueType.Unknown,
                                                        Diagnostics = failureContent,
                                                    },
                                                },
                                            };
                                            localResponse = new StringContent(
                                                serializer.SerializeToString(outcome),
                                                Encoding.UTF8,
                                                "application/fhir+json");

                                            break;

                                        default:
                                            localResponse = new StringContent(failureContent, Encoding.UTF8, "text/plain");
                                            break;
                                        }

                                        response.Content    = localResponse;
                                        response.StatusCode = statusCode;

                                        return(response);
                                    }

                                    // figure out our link to this resource
                                    string url = Program.UrlForResourceId("Basic", subscription.Id);

                                    switch (preferredResponse)
                                    {
                                    case "return=minimal":
                                        localResponse = new StringContent(string.Empty, Encoding.UTF8, "text/plain");
                                        break;

                                    case "return=OperationOutcome":
                                        r5.OperationOutcome outcome = new r5.OperationOutcome()
                                        {
                                            Id    = Guid.NewGuid().ToString(),
                                            Issue = new List <r5.OperationOutcome.IssueComponent>()
                                            {
                                                new r5.OperationOutcome.IssueComponent()
                                                {
                                                    Severity = r5.OperationOutcome.IssueSeverity.Information,
                                                    Code     = r5.OperationOutcome.IssueType.Value,
                                                },
                                            },
                                        };
                                        localResponse = new StringContent(
                                            serializer.SerializeToString(outcome),
                                            Encoding.UTF8,
                                            "application/fhir+json");

                                        break;

                                    default:
                                        localResponse = new StringContent(
                                            serializer.SerializeToString(SubscriptionManager.WrapInBasic(subscription)),
                                            Encoding.UTF8,
                                            "application/fhir+json");
                                        break;
                                    }

                                    response.Headers.Add("Location", url);
                                    response.Headers.Add("Access-Control-Expose-Headers", "Location,ETag");
                                    response.Content    = localResponse;
                                    response.StatusCode = HttpStatusCode.Created;

                                    return(response);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }

                    break;

                case "DELETE":

                    try
                    {
                        // check to see if this is a subscription
                        if (SubscriptionManager.HandleDelete(context.Request))
                        {
                            // deleted
                            response.StatusCode = System.Net.HttpStatusCode.NoContent;
                            return(response);
                        }

                        // fall through to proxy
                    }
                    catch (Exception)
                    {
                    }

                    break;
                }

                // if we're still here, proxy this call
                ForwardContext proxiedContext = context.ForwardTo(fhirServerUrl);

                // send to server and await response
                return(await proxiedContext.Send().ConfigureAwait(false));
            });
        }