private static XmlDocument Serialize(IGraphable graph)
        {
            using (var ms = new MemoryStream())
                using (var xmlWriter = XmlWriter.Create(ms, new XmlWriterSettings {
                    Indent = true
                }))
                    using (var xsw = new XmlStateWriter(xmlWriter))
                    {
                        var structureFormatter = CreateStructureFormater();
                        xsw.WriteStartElement("ClinicalDocument", "urn:hl7-org:v3");
                        xsw.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI);
                        xsw.WriteAttributeString("xmlns", null, null, "urn:hl7-org:v3");
                        xsw.WriteAttributeString("xmlns", "custom", null, CustomNamespace);
                        xsw.WriteAttributeString("xsi", "type", XmlIts1Formatter.NS_XSI, "custom:ClinicalDocument");

                        structureFormatter.Graph(xsw, graph);
                        xsw.Close();
                        ms.Seek(0, SeekOrigin.Begin);
                        Debug.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
                        using (var reader = new XmlTextReader(ms))
                        {
                            var result = new XmlDocument();
                            result.Load(reader);
                            return(result);
                        }
                    }
        }
        public void FormatPatient()
        {
            // Create a formatter with a graph aide
            XmlIts1Formatter fmtr = new XmlIts1Formatter();

            // Gets or sets a list of aide formatters
            // that assist in the formatting of this instance
            fmtr.GraphAides.Add(new DatatypeFormatter());

            // Format to a string
            StringWriter   sw    = new StringWriter();
            XmlStateWriter xmlSw = new XmlStateWriter(
                XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Indent = true
            })
                );

            // Call our method here...
            var patient = Utils.CreatePatient(
                Guid.NewGuid(),
                EN.CreateEN(EntityNameUse.Legal,
                            new ENXP("John", EntityNamePartType.Given),
                            new ENXP("Smith", EntityNamePartType.Family)
                            ),
                AD.CreateAD(PostalAddressUse.HomeAddress,
                            "123 Main Street West",
                            "Hamilton",
                            "Ontario",
                            "Canada"
                            ),
                "*****@*****.**"
                );

            // Format to the formatter.
            // Details results in a result code
            //  that indicates the outcome of the graph.
            var details = fmtr.Graph(xmlSw, patient);

            // Flush and close
            xmlSw.Close();

            // Output to console
            Console.WriteLine("XML: ");
            Console.WriteLine(sw.ToString());
            Console.WriteLine("Validation:");
            foreach (var dtl in details.Details)
            {
                Console.WriteLine("{0} : {1}", dtl.Type, dtl.Message);
            }
        }
Exemple #3
0
        public void IVLInclusiveFormattingTest()
        {
            IVL <INT> intIvl = new IVL <INT>(1, 4);

            intIvl.LowClosed  = true;
            intIvl.HighClosed = false;
            MemoryStream   ms     = new MemoryStream();
            XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(ms));

            writer.WriteStartElement("ivl", "urn:hl7-org:v3");
            MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter fmtr = new MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter();
            fmtr.Graph(writer, intIvl);
            writer.Close();
            ms.Seek(0, SeekOrigin.Begin);
            XmlDocument d = new XmlDocument();

            d.Load(ms);
            Tracer.Trace(d.OuterXml);
            Assert.IsTrue(d.OuterXml.Contains("inclusive"));
        }
        /// <summary>
        /// Serialize query
        /// </summary>
        internal static byte[] SerializeQuery(IGraphable queryByParameter)
        {
            using (XmlIts1Formatter fmtr = new XmlIts1Formatter()
            {
                ValidateConformance = false
            })
            {
                StringBuilder  sb     = new StringBuilder();
                XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(sb));

                // Write the start element
                writer.WriteStartElement("queryByParameter", "urn:hl7-org:v3");
                fmtr.GraphAides.Add(new DatatypeFormatter()
                {
                    CompatibilityMode = DatatypeFormatterCompatibilityMode.Universal, ValidateConformance = false
                });
                fmtr.Graph(writer, queryByParameter);
                writer.WriteEndElement();
                writer.Close();

                // Return the constructed result
                return(Encoding.ASCII.GetBytes(sb.ToString()));
            }
        }
        public void BuildPatientTest02()
        {
            // Flag used to verify if the graph result
            // contains details alongside its errors.
            bool noDetails = true;

            // Flag used to verify that the create instance is valid.
            bool valInstance = false;

            // Create a formatter with a graph aide
            XmlIts1Formatter fmtr = new XmlIts1Formatter();

            // Gets or sets a list of aide formatters
            // that assist in the formatting of this instance
            fmtr.GraphAides.Add(new DatatypeFormatter());

            // Format to a string
            StringWriter   sw    = new StringWriter();
            XmlStateWriter xmlSw = new XmlStateWriter(
                XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Indent = true
            })
                );

            // Call our method here with invalid instance identifier.
            var patient = Utils.CreatePatient(
                new II(),
                EN.CreateEN(EntityNameUse.Legal,
                            new ENXP("John", EntityNamePartType.Given),
                            new ENXP("Smith", EntityNamePartType.Family)
                            ),
                AD.CreateAD(PostalAddressUse.HomeAddress,
                            "123 Main Street West",
                            "Hamilton",
                            "Ontario",
                            "Canada"
                            ),
                "*****@*****.**"
                );

            // Format to the formatter
            var result = fmtr.Graph(xmlSw, patient);

            // Flush and close
            xmlSw.Close();

            // Output to console
            Console.WriteLine("XML:");
            Console.WriteLine(sw.ToString());

            // If we get errors, set error catching flag to false and
            // print the details of each error.
            if (result.Details.Count() > 0)
            {
                noDetails = false;
                Console.WriteLine("validation:");
                foreach (var dtl in result.Details)
                {
                    Console.WriteLine("{0} : {1}", dtl.Type, dtl.Message);
                }
            }
            else
            {
                valInstance = true;
            }

            // Assert:  Either there are no errors,
            //          or there are details in the 'details' collection.
            if (noDetails)
            {
                Assert.AreEqual(valInstance, true);
            }
            else if (!valInstance)
            {
                Assert.AreEqual(noDetails, false);
            }
            else
            {
                // Test fails
                Assert.Fail();
            }
        }