コード例 #1
0
        public static ITypedElement GetResourceNavigatorR4(string text, out string parseErrors)
        {
            f4.Resource resource = null;
            try
            {
                if (text.StartsWith("{"))
                {
                    resource = new r4.Hl7.Fhir.Serialization.FhirJsonParser(new r4.Hl7.Fhir.Serialization.ParserSettings()
                    {
                    }).Parse <f4.Resource>(text);
                }
                else
                {
                    resource = new r4.Hl7.Fhir.Serialization.FhirXmlParser(new r4.Hl7.Fhir.Serialization.ParserSettings()
                    {
                    }).Parse <f4.Resource>(text);
                }
            }
            catch (Exception ex)
            {
                parseErrors = "R4 Resource read error:\r\n" + ex.Message;
                return(null);
            }
            parseErrors = null;
            var inputNav = r4.Hl7.Fhir.ElementModel.PocoNavigatorExtensions.ToTypedElement(resource);

            return(inputNav);
        }
コード例 #2
0
        public static void PretifyJson(string text, Action <string> setText)
        {
            // prettify the Json (and convert to Json if it wasn't already)
            f3.Resource resource = null;
            string      contentAsJson;

            try
            {
                if (text.StartsWith("{"))
                {
                    contentAsJson = text;
                }
                else
                {
                    resource      = new stu3.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f3.Resource>(text);
                    contentAsJson = new stu3.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource);
                }
                var sr     = new System.IO.StringReader(contentAsJson);
                var reader = new JsonTextReader(sr);
                var doc    = JObject.Load(reader);
                setText(doc.ToString(Formatting.Indented));
            }
            catch (Exception)
            {
                f2.Resource resource2 = null;
                try
                {
                    if (text.StartsWith("{"))
                    {
                        contentAsJson = text;
                    }
                    else
                    {
                        resource2     = new dstu2.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f2.Resource>(text);
                        contentAsJson = new dstu2.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource2);
                    }
                    var sr     = new System.IO.StringReader(contentAsJson);
                    var reader = new JsonTextReader(sr);
                    var doc    = JObject.Load(reader);
                    setText(doc.ToString(Formatting.Indented));
                }
                catch (Exception)
                {
                    f4.Resource resource4 = null;
                    try
                    {
                        if (text.StartsWith("{"))
                        {
                            contentAsJson = text;
                        }
                        else
                        {
                            resource4     = new r4.Hl7.Fhir.Serialization.FhirXmlParser().Parse <f4.Resource>(text);
                            contentAsJson = new r4.Hl7.Fhir.Serialization.FhirJsonSerializer().SerializeToString(resource4);
                        }
                        var sr     = new System.IO.StringReader(contentAsJson);
                        var reader = new JsonTextReader(sr);
                        var doc    = JObject.Load(reader);
                        setText(doc.ToString(Formatting.Indented));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }