Beispiel #1
0
        public void SXPRSTMixedComponentsFormatting()
        {
            SXPR <RTO <INT, INT> > test = SXPR <RTO <INT, INT> > .CreateSXPR(new IVL <RTO <INT, INT> >(new RTO <INT, INT>(1, 3), new RTO <INT, INT>(2, 3)),
                                                                             new PIVL <RTO <INT, INT> >(
                                                                                 new IVL <RTO <INT, INT> >(new RTO <INT, INT>(2, 3), new RTO <INT, INT>(5, 6)),
                                                                                 new PQ((decimal)1.0, "y")
                                                                                 )
                                                                             //new SXCM<RTO<INT,INT>>(new RTO<INT,INT>(1,2)) { Operator = SetOperator.A },
                                                                             //new IVL<RTO<INT,INT>>(new RTO<INT,INT>(1,2)) { Operator = SetOperator.Intersect
                                                                             );

            StringWriter      sw   = new StringWriter();
            DatatypeFormatter fmtr = new DatatypeFormatter();
            XmlStateWriter    xw   = new XmlStateWriter(XmlWriter.Create(sw));

            xw.WriteStartElement("sxpr");
            fmtr.Graph(xw, test);
            xw.WriteEndElement(); // comp
            xw.Flush();
            Tracer.Trace(sw.ToString());
            StringReader   sr  = new StringReader(sw.ToString());
            XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));

            rdr.Read(); rdr.Read();
            var parse = fmtr.Parse(rdr, typeof(SXPR <RTO <INT, INT> >)).Structure as SXPR <RTO <INT, INT> >;

            Assert.AreEqual(parse.Count, test.Count);
            for (int i = 0; i < parse.Count; i++)
            {
                Assert.AreEqual(parse[i].GetType(), test[i].GetType());
            }
        }
Beispiel #2
0
        public void EV_1089SETParseTest()
        {
            PRPA_IN201305UV02 test = new PRPA_IN201305UV02();

            test.Sender           = new RMIM.UV.NE2010.MCCI_MT100200UV01.Sender();
            test.Sender.Device    = new RMIM.UV.NE2010.MCCI_MT100200UV01.Device();
            test.Sender.Device.Id = new SET <II>()
            {
                NullFlavor = NullFlavor.NoInformation
            };

            XmlIts1Formatter fmtr = new XmlIts1Formatter();

            fmtr.GraphAides.Add(new DatatypeFormatter());

            var            sw     = new StringWriter();
            XmlStateWriter writer = new XmlStateWriter(XmlWriter.Create(sw));

            fmtr.Graph(writer, test);
            writer.Flush();
            String xmlString = sw.ToString();

            StringReader   sr     = new StringReader(xmlString);
            XmlStateReader rdr    = new XmlStateReader(XmlReader.Create(sr));
            var            result = fmtr.Parse(rdr);

            Assert.IsNotNull(result.Structure as PRPA_IN201305UV02);
            Assert.IsNotNull((result.Structure as PRPA_IN201305UV02).Sender.Device.Id);
            //Assert.AreEqual(test, result.Structure);
        }
        /// <summary>
        /// Parse a string
        /// </summary>
        /// <param name="actualXml"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        internal static object ParseString(string xmlString, Type type)
        {
            StringReader        sr   = new StringReader(xmlString);
            DatatypeR2Formatter fmtr = new DatatypeR2Formatter();
            XmlStateReader      rdr  = new XmlStateReader(XmlReader.Create(sr));

            while (rdr.NodeType != XmlNodeType.Element)
            {
                rdr.Read();
            }
            var result = fmtr.Parse(rdr, type);

            Assert.AreEqual(ResultCode.Accepted, result.Code);
            return(result.Structure);
        }
Beispiel #4
0
        public void EV_1089SampleParseTest()
        {
            try
            {
                var instance = ParseFromStreamTest.FindResource("REPC_IN002120UV01.xml");
                // Parse
                XmlIts1Formatter fmtr = new XmlIts1Formatter()
                {
                    GraphAides = new List <Connectors.IStructureFormatter>()
                    {
                        new DatatypeFormatter()
                    }
                };

                XmlStateReader reader = new XmlStateReader(XmlReader.Create(ParseFromStreamTest.GetResourceStream(instance)));
                var            result = fmtr.Parse(reader, typeof(PRPA_IN201301UV02).Assembly);
                Assert.IsNotNull(((((result.Structure as REPC_IN002120UV01).controlActProcess.Subject[0].act.PertinentInformation3[3].CareStatement as RMIM.UV.NE2010.REPC_MT000100UV01.Observation).TargetOf[1].CareEntry as MARC.Everest.RMIM.UV.NE2010.REPC_MT000100UV01.SubstanceAdministration).Consumable.ConsumableChoice as RMIM.UV.NE2010.COCT_MT230100UV.Medication).AdministerableMedicine.Name);
            }
            catch { }
        }
Beispiel #5
0
        public void IVLInclusiveParsingTest()
        {
            StringReader   sr  = new StringReader("<ivl xmlns=\"urn:hl7-org:v3\"><low inclusive=\"true\" value=\"1\" /><high inclusive=\"false\" value=\"4\" /></ivl>");
            XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));

            // Read to first node
            while (rdr.NodeType != XmlNodeType.Element)
            {
                rdr.Read();
            }

            // Parse
            MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter fmtr = new MARC.Everest.Formatters.XML.Datatypes.R1.DatatypeFormatter();
            IVL <INT> retVal = fmtr.Parse(rdr, typeof(IVL <INT>)).Structure as IVL <INT>;

            Assert.IsTrue(retVal.HighClosed.HasValue);
            Assert.IsTrue(retVal.LowClosed.HasValue);
            Assert.IsFalse(retVal.HighClosed.Value);
            Assert.IsTrue(retVal.LowClosed.Value);
        }
Beispiel #6
0
        public void EV_1089ENXPParseTest()
        {
            EN myEn = EN.FromFamilyGiven(EntityNameUse.License, "Toet", "J");

            myEn.Part[0].Qualifier = new SET <CS <EntityNamePartQualifier> >();
            myEn.Part[1].Qualifier = new SET <CS <EntityNamePartQualifier> >();
            myEn.Part[0].Qualifier.Add(EntityNamePartQualifier.Birth);
            myEn.Part[1].Qualifier.Add(EntityNamePartQualifier.Initial);
            String xmlString = R1SerializationHelper.SerializeAsString(myEn);

            StringReader      sr   = new StringReader(xmlString);
            DatatypeFormatter fmtr = new DatatypeFormatter();
            XmlStateReader    rdr  = new XmlStateReader(XmlReader.Create(sr));

            while (rdr.NodeType != XmlNodeType.Element)
            {
                rdr.Read();
            }
            var result = fmtr.Parse(rdr, typeof(EN));

            Assert.AreEqual(0, result.Details.Count(o => o.Type == Connectors.ResultDetailType.Error));
        }
Beispiel #7
0
        public void WI1086_VerifyBugReflectTest()
        {
            // Load the XmlInstance into a string reader
            StringReader   sr = new StringReader(this.m_xmlInstance);
            XmlStateReader xr = new XmlStateReader(XmlReader.Create(sr));

            XmlIts1Formatter formatter = new XmlIts1Formatter();

            formatter.ValidateConformance = false;
            formatter.Settings            = SettingsType.DefaultUniprocessor;
            formatter.GraphAides.Add(new DatatypeFormatter()
            {
                CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian
            });

            try
            {
                MCCI_IN000002CA instance = formatter.Parse(xr, typeof(MCCI_IN000002CA)).Structure as MCCI_IN000002CA;
                if (instance == null)
                {
                    throw new InvalidOperationException("Invalid test data");
                }

                // Test 1, /receiver should be null (xsi:nil = true)
                Assert.IsNull(instance.Receiver, "Receiver");

                // Test 2, /sender should also be null (xsi:nil = true)
                Assert.IsNull(instance.Sender, "Sender");

                // Test 3, /acknowledgement should not be null and should have a null flavor (a notification should be notified though)
                Assert.IsNotNull(instance.Acknowledgement);
                Assert.AreEqual((NullFlavor)instance.Acknowledgement.NullFlavor.Code, NullFlavor.Unavailable);
            }
            finally
            {
                formatter.Dispose();
            }
        }
Beispiel #8
0
        public void SXPRTSMixedComponentsFormatting()
        {
            SXPR <TS> test = SXPR <TS> .CreateSXPR(new IVL <TS>(DateTime.Now, DateTime.Now.AddDays(1)),
                                                   new PIVL <TS>(
                                                       new IVL <TS>(DateTime.Now, DateTime.Now.AddDays(1)),
                                                       new PQ((decimal)1.0, "y")
                                                       ),
                                                   //new SXCM<TS>(DateTime.Now) { Operator = SetOperator.A },
                                                   new IVL <TS>(DateTime.Now) { Operator = SetOperator.Intersect },
                                                   new EIVL <TS>(DomainTimingEventType.BeforeLunch,
                                                                 new IVL <PQ>(
                                                                     new PQ((decimal)1.0, "d")
                                                                     )
                                                                 ) { Operator = SetOperator.Inclusive });

            StringWriter      sw   = new StringWriter();
            DatatypeFormatter fmtr = new DatatypeFormatter();
            XmlStateWriter    xw   = new XmlStateWriter(XmlWriter.Create(sw));

            xw.WriteStartElement("sxpr");
            fmtr.Graph(xw, test);
            xw.WriteEndElement(); // comp
            xw.Flush();
            Tracer.Trace(sw.ToString());
            StringReader   sr  = new StringReader(sw.ToString());
            XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));

            rdr.Read(); rdr.Read();
            var parse = fmtr.Parse(rdr, typeof(SXPR <TS>)).Structure as SXPR <TS>;

            Assert.AreEqual(parse.Count, test.Count);
            for (int i = 0; i < parse.Count; i++)
            {
                Assert.AreEqual(parse[i].GetType(), test[i].GetType());
            }
        }
        /// <summary>
        /// Validate the MIF file
        /// </summary>
        public void ValidateMifFile(Stream fileStream, string fileName)
        {
            string mifDirectory = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "schemas"), "mif2.1.4");

            // First, validate the schema directory exists
            if (context.Mode != Pipeline.OperationModeType.Strict)
            {
                Trace.Write("Not operating in strict mode, not applying MIF validation", "warn1");
                return;
            }
            if (!Directory.Exists(mifDirectory))
            {
                throw new InvalidOperationException("Cannot find the MIF schemas, ensure that the Schemas\\mif2.1.4 directory exists");
            }

            // Load the schemas
            if (m_schemas == null)
            {
                m_schemas = new XmlSchemaSet();
                m_schemas.ValidationEventHandler += new ValidationEventHandler(m_schemas_ValidationEventHandler);
                foreach (var file in Directory.GetFiles(mifDirectory, "*.xsd"))
                {
                    XmlReader schemaReader = XmlReader.Create(file, new XmlReaderSettings()
                    {
                        ProhibitDtd = false
                    });
                    try
                    {
                        m_schemas.Add("urn:hl7-org:v3/mif2", schemaReader);
                    }
                    finally
                    {
                        schemaReader.Close();
                    }
                }
                m_schemas.Compile();
            }

            // Sanity check
            if (!m_schemas.IsCompiled)
            {
                throw new InvalidOperationException("The schema set must compile successfully for execution to continue");
            }

            // Reader
            XmlStateReader xr = null;

            try
            {
                // Create settings
                var settings = new XmlReaderSettings()
                {
                    ProhibitDtd    = false,
                    ValidationType = ValidationType.Schema,
                    Schemas        = m_schemas
                };


                // Is the object valid
                bool isValid = true;
                settings.ValidationEventHandler += new ValidationEventHandler(
                    delegate(object sender, ValidationEventArgs e)
                {
                    Trace.WriteLine(String.Format("{0} : {1}", Path.GetFileName(fileName), e.Message), e.Severity == XmlSeverityType.Error ? "error" : "warn");
                    isValid &= e.Severity == XmlSeverityType.Warning;
                }
                    );

                // Create the reader
                xr = new XmlStateReader(XmlReader.Create(fileStream, settings));

                // Read
                while (xr.Read())
                {
                    ;
                }

                if (!isValid)
                {
                    throw new XmlSchemaValidationException("File failed basic schema check");
                }
            }
            finally
            {
                if (xr != null)
                {
                    xr.Close();
                }
            }
        }