//public static HttpResponseMessage HttpResponse(this HttpRequestMessage request, HttpStatusCode code, Entry entry)
        //{
        //    request.SaveEntry(entry);

        //    HttpResponseMessage msg;
        //    msg = request.CreateResponse<Resource>(code, entry.Resource);
            
        //    // DSTU2: tags
        //    //msg.Headers.SetFhirTags(entry.Tags);
        //    return msg;
        //}

       

        public static void AcquireHeaders(this HttpResponseMessage response, FhirResponse fhirResponse)
        {
            // http.StatusCode = fhir.StatusCode;
            if (fhirResponse.Key != null)
            {
                response.Headers.ETag = ETag.Create(fhirResponse.Key.VersionId);

                Uri location = fhirResponse.Key.ToUri();

                if (response.Content != null)
                {
                    response.Content.Headers.ContentLocation = location;

                    if (fhirResponse.Resource != null && fhirResponse.Resource.Meta != null)
                    {
                        response.Content.Headers.LastModified = fhirResponse.Resource.Meta.LastUpdated;
                    }
                }
                else
                {
                    response.Headers.Location = location;
                }
            }
        }
        private static HttpResponseMessage CreateBareFhirResponse(this HttpRequestMessage request, FhirResponse fhir)
        {
            bool includebody = request.PreferRepresentation();

            if (fhir.Resource != null)
            {
                if (includebody)
                {
                    return request.CreateResponse(fhir.StatusCode, fhir.Resource);
                }
                else
                {
                    return request.CreateResponse(fhir.StatusCode);
                }
            }
            else
            {
                return request.CreateResponse(fhir.StatusCode);
            }
        }
 public static HttpResponseMessage CreateResponse(this HttpRequestMessage request, FhirResponse fhir)
 {
     HttpResponseMessage message = request.CreateBareFhirResponse(fhir);
     message.AcquireHeaders(fhir);
     return message;
 }