Example #1
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);
        }
Example #2
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());
        }
Example #3
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);
            }
        }