Beispiel #1
0
        public async Task <Bundle> SearchByPost(string ResourceName)
        {
            System.Diagnostics.Debug.WriteLine("GET: " + this.Request.GetDisplayUrl());

            var parameters = Request.TupledParameters(true).ToList();

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            string sortby   = Request.GetParameter(FhirParameter.SORT);
            int    pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            var buri = this.CalculateBaseURI("{ResourceName}");

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

            // Also grab the application/x-www-form-urlencoded content body
            if (Request.HasFormContentType)
            {
                var requestData = Request.Form;
                foreach (var item in requestData)
                {
                    parameters.Add(new KeyValuePair <string, string>(item.Key, item.Value));
                }
            }

            Bundle result = await model.Search(parameters, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            // this.Request.SaveEntry(result);
            return(result);
        }
        public Bundle SearchByPost(string ResourceName)
        {
            System.Diagnostics.Trace.WriteLine("POST: " + this.ControllerContext.Request.RequestUri.OriginalString);

            var parameters = Request.TupledParameters(true).ToList();

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            string sortby   = Request.GetParameter(FhirParameter.SORT);
            int    pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            var buri = this.CalculateBaseURI("{ResourceName}");

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

            // Also grab the application/x-www-form-urlencoded content body
            if (Request.Content.IsFormData())
            {
                // This is Bad, talk to Andrew again to find out the library to assist with this.
                var requestData = Request.Content.ReadAsFormDataAsync().Result;
                foreach (var item in requestData.AllKeys)
                {
                    parameters.Add(new KeyValuePair <string, string>(item, requestData[item]));
                }
            }

            Bundle result = model.Search(parameters, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            this.ControllerContext.Request.SaveEntry(result);
            return(result);
        }
        public Bundle Search(string ResourceName)
        {
            try
            {
                System.Diagnostics.Trace.WriteLine("GET: " + this.ControllerContext.Request.RequestUri.OriginalString);

                var parameters = Request.TupledParameters(true);
                Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
                string sortby        = Request.GetParameter(FhirParameter.SORT);
                int    pagesize      = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;
                var    includeParams = Request.TupledParameters(false).Where(i => i.Key == "_include");

                var buri = this.CalculateBaseURI("{ResourceName}");
                parameters = parameters.Union(includeParams);

                IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

                Bundle result = model.Search(parameters, pagesize, summary);
                result.ResourceBase = new Uri(buri);

                this.ControllerContext.Request.SaveEntry(result);
                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                throw;
            }
        }
Beispiel #4
0
        public async Task <Hl7.Fhir.Model.CapabilityStatement> GetConformance()
        {
            var buri = this.CalculateBaseURI("metadata");

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            var Inputs = GetInputs(buri);
            var con    = await GetSystemModel(Inputs).GetConformance(Inputs, summary);

            con.ResourceBase = new Uri(buri, UriKind.RelativeOrAbsolute);
            con.SetAnnotation <SummaryType>(summary);
            return(con);
        }
        public HttpResponseMessage ProcessBatch(Bundle batch)
        {
            var buri   = this.CalculateBaseURI("metadata");
            var Inputs = GetInputs(buri);

            Bundle outcome = GetSystemModel(Inputs).ProcessBatch(Inputs, batch);

            outcome.ResourceBase = new Uri(buri);
            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            outcome.SetAnnotation <SummaryType>(summary);
            return(Request.ResourceResponse(outcome, HttpStatusCode.OK));
        }
Beispiel #6
0
        public async Task <IActionResult> PerformOperation(string ResourceName, string operation, [FromBody] Parameters operationParameters)
        {
            var buri = this.CalculateBaseURI("{ResourceName}");

            ExtractParametersFromUrl(ref operationParameters, Request.TupledParameters(false));
            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));
            var resource = await model.PerformOperation(operation, operationParameters, summary);

            return(PrepareOperationOutputMessage(buri, resource));
        }
Beispiel #7
0
        public async Task <IActionResult> PerformOperation(string operation, [FromBody] Parameters operationParameters)
        {
            var buri = this.CalculateBaseURI("${operation}");

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            ExtractParametersFromUrl(ref operationParameters, Request.TupledParameters(false));
            var inputs = GetInputs(buri);

            Resource resource = await GetSystemModel(inputs).PerformOperation(inputs, operation, operationParameters, summary);

            return(PrepareOperationOutputMessage(buri, resource));
        }
        public HttpResponseMessage PerformOperation(string ResourceName, string operation)
        {
            var buri = this.CalculateBaseURI("{ResourceName}");

            Parameters operationParameters = new Parameters();

            ExtractParametersFromUrl(ref operationParameters, Request.TupledParameters(false));
            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));
            var resource = model.PerformOperation(operation, operationParameters, summary);

            return(PrepareOperationOutputMessage(buri, resource));
        }
Beispiel #9
0
        public async Task <IActionResult> ProcessBatch(Bundle batch)
        {
            var buri   = this.CalculateBaseURI("metadata");
            var Inputs = GetInputs(buri);

            Bundle outcome = await GetSystemModel(Inputs).ProcessBatch(Inputs, batch);

            outcome.ResourceBase = new Uri(buri);
            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            outcome.SetAnnotation <SummaryType>(summary);
            return(new ObjectResult(outcome)
            {
                StatusCode = (int)HttpStatusCode.OK
            });
        }
Beispiel #10
0
 public Hl7.Fhir.Model.CapabilityStatement GetConformance()
 {
     try
     {
         var buri = this.CalculateBaseURI("metadata");
         Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
         var Inputs = GetInputs(buri);
         var con    = GetSystemModel(Inputs).GetConformance(Inputs, summary);
         con.ResourceBase = new Uri(buri, UriKind.RelativeOrAbsolute);
         con.SetAnnotation <SummaryType>(summary);
         return(con);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(ex.Message);
         return(null);
     }
 }
Beispiel #11
0
        public async Task <Bundle> WholeSystemHistory()
        {
            System.Diagnostics.Debug.WriteLine("GET: " + this.Request.GetDisplayUrl());
            var buri = this.CalculateBaseURI("_history");

            DateTimeOffset?since    = Request.GetDateParameter("_since");
            int            pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            var Inputs = GetInputs(buri);
            var model  = GetSystemModel(Inputs);

            Bundle result = await model.SystemHistory(Inputs, since, null, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            // this.Request.SaveEntry(result);
            return(result);
        }
Beispiel #12
0
        public Bundle WholeSystemHistory()
        {
            System.Diagnostics.Trace.WriteLine("GET: " + this.ControllerContext.Request.RequestUri.OriginalString);
            var buri = this.CalculateBaseURI("_history");

            DateTimeOffset?since    = Request.GetDateParameter("_since");
            int            pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            var Inputs = GetInputs(buri);
            var model  = GetSystemModel(Inputs);

            Bundle result = model.SystemHistory(Inputs, since, null, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            this.ControllerContext.Request.SaveEntry(result);
            return(result);
        }
Beispiel #13
0
        public async Task <Bundle> ResourceHistory(string ResourceName)
        {
            System.Diagnostics.Debug.WriteLine("GET: " + this.Request.GetDisplayUrl());

            DateTimeOffset?since    = Request.GetDateParameter("_since");
            int            pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            var buri = this.CalculateBaseURI("{ResourceName}");

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

            // TODO: Locate the till parameter in the history
            Bundle result = await model.TypeHistory(since, null, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            // this.Request.SaveEntry(result);
            return(result);
        }
Beispiel #14
0
        public async Task <Bundle> InstanceHistory(string ResourceName, string id)
        {
            System.Diagnostics.Debug.WriteLine("GET: " + this.Request.GetDisplayUrl());

            DateTimeOffset?since    = Request.GetDateParameter("_since");
            int            pagesize = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            string sortby = Request.GetParameter(FhirParameter.SORT);

            var buri = this.CalculateBaseURI("{ResourceName}");

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

            Bundle result = await model.InstanceHistory(id, since, null, pagesize, summary);

            result.ResourceBase = new Uri(buri);
            if (result.Total == 0)
            {
                try
                {
                    // Check to see if the item itself exists
                    if (model.Get(id, null, Hl7.Fhir.Rest.SummaryType.True) == null)
                    {
                        // this resource does not exist to have a history
                        throw new FhirServerException(HttpStatusCode.NotFound, "The resource was not found");
                    }
                }
                catch (FhirServerException ex)
                {
                    if (ex.StatusCode != HttpStatusCode.Gone)
                    {
                        throw ex;
                    }
                }
            }

            // this.Request.SaveEntry(result);
            return(result);
        }
Beispiel #15
0
        public async Task <Bundle> Search(string ResourceName)
        {
            System.Diagnostics.Debug.WriteLine("GET: " + this.Request.GetDisplayUrl());

            var parameters = Request.TupledParameters(true);

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);
            string sortby        = Request.GetParameter(FhirParameter.SORT);
            int    pagesize      = Request.GetIntParameter(FhirParameter.COUNT) ?? Const.DEFAULT_PAGE_SIZE;
            var    includeParams = Request.TupledParameters(false).Where(i => i.Key == "_include");

            var buri = this.CalculateBaseURI("{ResourceName}");

            parameters = parameters.Union(includeParams);

            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri));

            Bundle result = await model.Search(parameters, pagesize, summary);

            result.ResourceBase = new Uri(buri);

            // this.Request.SaveEntry(result);
            return(result);
        }
Beispiel #16
0
        public async Task <IActionResult> Get(string ResourceName, string id, string vid)
        {
            var buri = this.CalculateBaseURI("{ResourceName}");

            if (!Id.IsValidValue(id))
            {
                throw new FhirServerException(HttpStatusCode.BadRequest, "ID [" + id + "] is not a valid FHIR Resource ID");
            }

            var Inputs = GetInputs(buri);
            IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, Inputs);

            Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

            Resource resource = await model.Get(id, vid, summary);

            if (resource != null)
            {
                resource.ResourceBase = new Hl7.Fhir.Rest.ResourceIdentity(Request.RequestUri()).BaseUri;

                if (resource is DomainResource)
                {
                    DomainResource dr = resource as DomainResource;
                    switch (summary)
                    {
                    case Hl7.Fhir.Rest.SummaryType.False:
                        break;

                    case Hl7.Fhir.Rest.SummaryType.True:
                        // summary doesn't have the text in it.
                        dr.Text = null;
                        // there are no contained references in the summary form
                        dr.Contained = null;

                        // Add in the Meta Tag that indicates that this resource is only a partial
                        resource.Meta.Tag = new List <Coding>
                        {
                            new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED")
                        };
                        break;

                    case Hl7.Fhir.Rest.SummaryType.Text:
                        // what do we need to filter here
                        break;

                    case Hl7.Fhir.Rest.SummaryType.Data:
                        // summary doesn't have the text in it.
                        dr.Text = null;
                        // Add in the Meta Tag that indicates that this resource is only a partial
                        resource.Meta.Tag = new List <Coding>
                        {
                            new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED")
                        };
                        break;
                    }
                }

                if (ResourceName == "Binary")
                {
                    // We need to reset the accepts type so that the correct formatter is used on the way out.
                    string formatParam = this.Request.GetParameter("_format");
                    if (string.IsNullOrEmpty(formatParam))
                    {
                        this.Request.GetTypedHeaders().Accept.Clear();
                        this.Request.GetTypedHeaders().Accept.Add(new MediaTypeHeaderValue((resource as Binary).ContentType));
                    }
                }

                return(new ObjectResult(resource));
            }

            // this request is a "you wanted what?"
            return(new NotFoundResult());
        }
Beispiel #17
0
        public HttpResponseMessage Get(string ResourceName, string id, string vid)
        {
            try
            {
                var buri = this.CalculateBaseURI("{ResourceName}");

                if (!Id.IsValidValue(id))
                {
                    throw new FhirServerException(HttpStatusCode.BadRequest, "ID [" + id + "] is not a valid FHIR Resource ID");
                }

                var Inputs = GetInputs(buri);
                IFhirResourceServiceSTU3  model   = GetResourceModel(ResourceName, Inputs);
                Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request);

                Resource resource = model.Get(id, vid, summary);
                if (resource != null)
                {
                    var baseResource = new Hl7.Fhir.Rest.ResourceIdentity(Request.RequestUri);
                    resource.ResourceBase = new Uri(string.Format("http://{0}", baseResource.Authority));

                    if (resource is DomainResource)
                    {
                        DomainResource dr = resource as DomainResource;
                        switch (summary)
                        {
                        case Hl7.Fhir.Rest.SummaryType.False:
                            break;

                        case Hl7.Fhir.Rest.SummaryType.True:
                            // summary doesn't have the text in it.
                            dr.Text = null;
                            // there are no contained references in the summary form
                            dr.Contained = null;

                            // Add in the Meta Tag that indicates that this resource is only a partial
                            resource.Meta.Tag = new List <Coding>
                            {
                                new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED")
                            };
                            break;

                        case Hl7.Fhir.Rest.SummaryType.Text:
                            // what do we need to filter here
                            break;

                        case Hl7.Fhir.Rest.SummaryType.Data:
                            // summary doesn't have the text in it.
                            dr.Text = null;
                            // Add in the Meta Tag that indicates that this resource is only a partial
                            resource.Meta.Tag = new List <Coding>
                            {
                                new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED")
                            };
                            break;
                        }
                    }

                    if (ResourceName == "Binary")
                    {
                        // We need to reset the accepts type so that the correct formatter is used on the way out.
                        string formatParam = this.ControllerContext.Request.GetParameter("_format");
                        if (string.IsNullOrEmpty(formatParam))
                        {
                            this.ControllerContext.Request.Headers.Accept.Clear();
                            this.ControllerContext.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue((resource as Binary).ContentType));
                        }
                    }

                    var msg = Request.ResourceResponse(resource, HttpStatusCode.OK);
                    msg.Headers.Location = resource.ResourceIdentity().WithBase(resource.ResourceBase);
                    msg.Headers.Add("ETag", String.Format("\"{0}\"", resource.Meta.VersionId));

                    if (ResourceName == "Binary")
                    {
                        // We need to reset the accepts type so that the correct formatter is used on the way out.
                        string formatParam = this.ControllerContext.Request.GetParameter("_format");
                        if (string.IsNullOrEmpty(formatParam))
                        {
                            msg.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                            {
                                FileName = String.Format("fhir_binary_{0}_{1}.{2}",
                                                         resource.Id,
                                                         resource.Meta != null ? resource.Meta.VersionId : "0",
                                                         GetFileExtensionForMimeType((resource as Binary).ContentType))
                            };
                        }
                    }

                    return(msg);
                }

                // this request is a "you wanted what?"
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return(null);
            }
        }