public Stu3Model.Bundle Load()
        {
            string            ZipFileName       = "search-parameters.json";
            ZipFileJsonLoader ZipFileJsonLoader = new ZipFileJsonLoader();
            JsonReader        JsonReader        = ZipFileJsonLoader.Load(Bug.CodeGeneration.ProjectResource.definitions_3_0_2_json, ZipFileName);

            try
            {
                Stu3Model.Resource Resource = ParseJson(JsonReader);
                if (Resource is Stu3Model.Bundle Bundle)
                {
                    return(Bundle);
                }
                else
                {
                    throw new Exception($"Exception thrown when casting the json resource to a Bundle from the Stu3 FHIR specification {ZipFileName} file.");
                }
            }
            catch (Exception Exec)
            {
                throw new Exception($"Exception thrown when de-serializing FHIR resource bundle from the Stu3 FHIR specification {ZipFileName} file. See inner exception for more info.", Exec);
            }
        }
Example #2
0
        public override System.Threading.Tasks.Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (selectedEncoding == null)
            {
                throw new ArgumentNullException(nameof(selectedEncoding));
            }

            using (StreamWriter writer = new StreamWriter(context.HttpContext.Response.Body))
            {
                // netcore default is for async only
                var syncIOFeature = context.HttpContext.Features.Get <IHttpBodyControlFeature>();
                if (syncIOFeature != null)
                {
                    syncIOFeature.AllowSynchronousIO = true;
                }

                JsonTextWriter jsonwriter = (JsonTextWriter)SerializationUtil.CreateJsonTextWriter(writer); // This will use the BetterJsonWriter which handles precision correctly
                using (jsonwriter)
                {
                    jsonwriter.ArrayPool  = _charPool;
                    jsonwriter.Formatting = Formatting.Indented; // lets make it pretty

                    R4Rest.SummaryType   R4SummaryType   = R4Rest.SummaryType.False;
                    Stu3Rest.SummaryType Stu3SummaryType = Stu3Rest.SummaryType.False;
                    if (context.ObjectType == typeof(Stu3Model.OperationOutcome))
                    {
                        // We will only honor the summary type during serialization of the outcome
                        // if the resource wasn't a stored OpOutcome we are returning
                        Stu3Model.OperationOutcome resource = (Stu3Model.OperationOutcome)context.Object;
                        if (string.IsNullOrEmpty(resource.Id) && resource.HasAnnotation <Stu3Rest.SummaryType>())
                        {
                            Stu3SummaryType = resource.Annotation <Stu3Rest.SummaryType>();
                        }
                        new Stu3Serialization.FhirJsonSerializer().Serialize(resource, jsonwriter, Stu3SummaryType);
                    }
                    else if (typeof(Stu3Model.Resource).IsAssignableFrom(context.ObjectType))
                    {
                        if (context.Object != null)
                        {
                            Stu3Model.Resource r = (Stu3Model.Resource)context.Object;
                            if (r.HasAnnotation <Stu3Rest.SummaryType>())
                            {
                                Stu3SummaryType = r.Annotation <Stu3Rest.SummaryType>();
                            }
                            new Stu3Serialization.FhirJsonSerializer().Serialize(r, jsonwriter, Stu3SummaryType);
                        }
                    }
                    else if (context.ObjectType == typeof(R4Model.OperationOutcome))
                    {
                        // We will only honor the summary type during serialization of the outcome
                        // if the resource wasn't a stored OpOutcome we are returning
                        R4Model.OperationOutcome resource = (R4Model.OperationOutcome)context.Object;
                        if (string.IsNullOrEmpty(resource.Id) && resource.HasAnnotation <R4Rest.SummaryType>())
                        {
                            R4SummaryType = resource.Annotation <R4Rest.SummaryType>();
                        }
                        new R4Serialization.FhirJsonSerializer().Serialize(resource, jsonwriter, R4SummaryType);
                    }
                    else if (typeof(R4Model.Resource).IsAssignableFrom(context.ObjectType))
                    {
                        if (context.Object != null)
                        {
                            R4Model.Resource r = (R4Model.Resource)context.Object;
                            if (r.HasAnnotation <R4Rest.SummaryType>())
                            {
                                R4SummaryType = r.Annotation <R4Rest.SummaryType>();
                            }
                            new R4Serialization.FhirJsonSerializer().Serialize(r, jsonwriter, R4SummaryType);
                        }
                    }
                    return(writer.FlushAsync());
                }
            }
        }
        public async Task <ActionResult <Stu3Model.Resource> > Put(string resourceName, string resourceId, [FromBody] Stu3Model.Resource resource)
        {
            if (resource == null)
            {
                return(BadRequest());
            }

            var command = new UpdateQuery(
                HttpVerb.PUT,
                _ControllerFhirVersion,
                this.Request.GetUrl(),
                QueryHelpers.ParseQuery(this.Request.QueryString.ToString()),
                new Dictionary <string, StringValues>(this.Request.Headers),
                resourceName,
                resourceId,
                new Common.FhirTools.FhirResource(_ControllerFhirVersion)
            {
                Stu3 = resource
            }
                );

            var           UpdateCommandHandler = this.IFhirApiQueryHandlerFactory.GetUpdateCommand();
            FhirApiResult Result = await UpdateCommandHandler.Handle(command);

            return(Result.PrepareResponse <Stu3Model.Resource>(this));
        }
Example #4
0
        public override System.Threading.Tasks.Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (selectedEncoding == null)
            {
                throw new ArgumentNullException(nameof(selectedEncoding));
            }

            XmlWriterSettings settings = new XmlWriterSettings
            {
                Encoding           = new UTF8Encoding(false),
                OmitXmlDeclaration = true,
                Async           = true,
                CloseOutput     = true,
                Indent          = true,
                NewLineHandling = NewLineHandling.Entitize,
                IndentChars     = "  "
            };

            using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Body, settings))
            {
                R4Rest.SummaryType   R4SummaryType   = R4Rest.SummaryType.False;
                Stu3Rest.SummaryType Stu3SummaryType = Stu3Rest.SummaryType.False;
                if (context.ObjectType == typeof(R4Model.OperationOutcome))
                {
                    // We will only honor the summary type during serialization of the outcome
                    // if the resource wasn't a stored OpOutcome we are returning
                    R4Model.OperationOutcome resource = (R4Model.OperationOutcome)context.Object;
                    if (string.IsNullOrEmpty(resource.Id) && resource.HasAnnotation <R4Rest.SummaryType>())
                    {
                        R4SummaryType = resource.Annotation <R4Rest.SummaryType>();
                    }
                    new R4Serialization.FhirXmlSerializer().Serialize(resource, writer, R4SummaryType);
                }
                else if (context.ObjectType == typeof(Stu3Model.OperationOutcome))
                {
                    // We will only honor the summary type during serialization of the outcome
                    // if the resource wasn't a stored OpOutcome we are returning
                    Stu3Model.OperationOutcome resource = (Stu3Model.OperationOutcome)context.Object;
                    if (string.IsNullOrEmpty(resource.Id) && resource.HasAnnotation <Stu3Rest.SummaryType>())
                    {
                        Stu3SummaryType = resource.Annotation <Stu3Rest.SummaryType>();
                    }
                    new Stu3Serialization.FhirXmlSerializer().Serialize(resource, writer, Stu3SummaryType);
                }
                else if (typeof(R4Model.Resource).IsAssignableFrom(context.ObjectType))
                {
                    if (context.Object != null)
                    {
                        R4Model.Resource r = (R4Model.Resource)context.Object;
                        if (r.HasAnnotation <R4Rest.SummaryType>())
                        {
                            R4SummaryType = r.Annotation <R4Rest.SummaryType>();
                        }

                        new R4Serialization.FhirXmlSerializer().Serialize(r, writer, R4SummaryType);
                    }
                }
                else if (typeof(Stu3Model.Resource).IsAssignableFrom(context.ObjectType))
                {
                    if (context.Object != null)
                    {
                        Stu3Model.Resource r = (Stu3Model.Resource)context.Object;
                        if (r.HasAnnotation <Stu3Rest.SummaryType>())
                        {
                            Stu3SummaryType = r.Annotation <Stu3Rest.SummaryType>();
                        }
                        new Stu3Serialization.FhirXmlSerializer().Serialize(r, writer, Stu3SummaryType);
                    }
                }
                return(writer.FlushAsync());
            }
        }
        public async Task <ActionResult <Stu3Model.Resource> > Post(string resourceName, [FromBody] Stu3Model.Resource resource)
        {
            if (resource == null)
            {
                return(BadRequest());
            }
            if (string.IsNullOrWhiteSpace(resourceName))
            {
                return(BadRequest());
            }

            var Query = new Logic.Query.FhirApi.Create.CreateQuery(
                HttpVerb.POST,
                _ControllerFhirVersion,
                this.Request.GetUrl(),
                QueryHelpers.ParseQuery(this.Request.QueryString.ToString()),
                new Dictionary <string, StringValues>(this.Request.Headers),
                resourceName,
                new Common.FhirTools.FhirResource(_ControllerFhirVersion)
            {
                Stu3 = resource
            }
                );

            var           CreateQueryHandler = this.IFhirApiQueryHandlerFactory.GetCreateCommand();
            FhirApiResult Result             = await CreateQueryHandler.Handle(Query);

            return(Result.PrepareResponse <Stu3Model.Resource>(this));
        }