Exemple #1
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));

        }
 public void UVPEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>(), bValue = null;
     aValue.Probability = (decimal)0.0f;
     aValue.Value = new MARC.Everest.DataTypes.INT(0);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.UVP<MARC.Everest.DataTypes.INT>)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #3
0
        public void EV_1089SampleReflectParseTest()
        {
            try
            {
                var instance = ParseFromStreamTest.FindResource("REPC_IN002120UV01.xml");
                // Parse 
                XmlIts1Formatter fmtr = new XmlIts1Formatter()
                {
                    GraphAides = new List<Connectors.IStructureFormatter>() { 
                    new DatatypeFormatter()
                },
                    Settings = SettingsType.DefaultUniprocessor
                };

                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 { }
        }
 public void IVLEqualsSerializationLowTest()
 {
     MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>(), bValue = null;
     aValue.Low = new MARC.Everest.DataTypes.INT(0);
     aValue.LowClosed = false;
     //aValue.High = new MARC.Everest.DataTypes.INT(0);
     //aValue.HighIncluded = false;
     //aValue.Width = new MARC.Everest.DataTypes.PQ(0, "0");
     aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
 public void EDEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.ED aValue = new MARC.Everest.DataTypes.ED(), bValue = null;
     aValue.Data = new System.Byte[] { 0 };
     aValue.Compression = new System.Nullable<MARC.Everest.DataTypes.Interfaces.EncapsulatedDataCompression>(MARC.Everest.DataTypes.Interfaces.EncapsulatedDataCompression.DF);
     aValue.Representation = MARC.Everest.DataTypes.Interfaces.EncapsulatedDataRepresentation.TXT;
     aValue.Language = "0";
     aValue.MediaType = "0";
     aValue.IntegrityCheck = new System.Byte[] { 0 };
     aValue.IntegrityCheckAlgorithm = new System.Nullable<MARC.Everest.DataTypes.Interfaces.EncapsulatedDataIntegrityAlgorithm>(MARC.Everest.DataTypes.Interfaces.EncapsulatedDataIntegrityAlgorithm.SHA1);
     aValue.Thumbnail = new MARC.Everest.DataTypes.ED(new System.Byte[] { 0 }, "0");
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.ED>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.ED)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
 public void IIEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.II aValue = new MARC.Everest.DataTypes.II(), bValue = null;
     aValue.Root = "0";
     aValue.Extension = "0";
     aValue.Displayable = false;
     aValue.Use = new System.Nullable<MARC.Everest.DataTypes.IdentifierUse>(MARC.Everest.DataTypes.IdentifierUse.Business);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.II>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.II)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #7
0
        /// <summary>
        /// Parse an object from <see cref="T:System.Xml.XmlReader"/> <paramref name="r"/> using the type
        /// hint <param name="t"/>
        /// </summary>
        /// <param name="r">The <see cref="T:System.Xml.XmlReader"/> to parse an object from</param>
        /// <param name="t">The type hint to parse the object</param>
        /// <returns>A <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterParseResult"/> containing the formatted instance</returns>
        /// <remarks>
        /// <para>
        /// This particular overload of the Graph method can be used to graph objects into a <see cref="T:System.Xml.XmlWriter"/> and can provide
        /// an opportunity to use Everest as an assistant (or XmlSerializerSurrogate) for more complex systems like WCF.
        /// </para>
        /// <example>
        /// <code lang="cs" title="Using Everest as a Serializer Assistant">
        /// <![CDATA[
        /// StringWriter sw = new StringWriter("<hello><MCCI_IN000002CA xmlns=\"urn:hl7-org:v3\"/></hello>");
        /// XmlReader reader = XmlReader.Create(sw);
        /// reader.Read(); // Read <hello>
        /// 
        /// Formatter f = new Formatter();
        /// f.GraphAides.Add(typeof(MARC.Everest.Formatters.XML.DataTypes.R1.Formatter));
        /// f.ValidateConformance = false;
        /// var result = f.Parse(reader, typeof(MCCI_IN000002CA));
        /// 
        /// reader.Read();
        /// reader.Close();
        /// Console.WriteLine(result.Code); 
        /// 
        /// ]]>
        /// </code>
        /// </example>
        /// <para>
        /// When using this method, it is recommended that you pass a <see cref="T:MARC.Everest.Xml.XmlStateReader"/> as it 
        /// will allow the formatter to give additional location information when reporting issues.
        /// </para>
        /// </remarks>
        public IFormatterParseResult Parse(XmlReader r, Type t)
        {
            if (!(r is XmlStateReader))
                r = new XmlStateReader(r);

            // Initial state
            if (r.ReadState == ReadState.Initial)
                while (r.NodeType != XmlNodeType.Element)
                    r.Read();

            // Detect if we can parse this...
            if (r.NamespaceURI != "urn:hl7-org:v3")
                throw new XmlException(string.Format("Can't parse '{0}' in namespace '{1}'. The data does not appear to be an HL7v3 instance", r.LocalName, r.NamespaceURI), null);

            var resultContext = new XmlIts1FormatterParseResult(ResultCode.Accepted, null);
            resultContext.Structure = ParseObject(r, t, null, resultContext);
            return resultContext;
        }
 public void ADEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.AD aValue = new MARC.Everest.DataTypes.AD(), bValue = null;
     aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.PostalAddressUse>>(0) { new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.PostalAddressUse>(MARC.Everest.DataTypes.PostalAddressUse.HomeAddress) };
     aValue.IsNotOrdered = false;
     aValue.Part.Add(new MARC.Everest.DataTypes.ADXP("123 Main Street West", MARC.Everest.DataTypes.AddressPartType.AddressLine));
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test", "urn:hl7-org:v3");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.AD>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.AD)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
 public void EIVLEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>(), bValue = null;
     aValue.Event = new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.DomainTimingEventType>(MARC.Everest.DataTypes.DomainTimingEventType.BeforeMeal);
     aValue.Offset = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.PQ>(new MARC.Everest.DataTypes.PQ((decimal)0, "0"));
     aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.EIVL<MARC.Everest.DataTypes.INT>)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
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();
            }

        }
Exemple #13
0
                /// <summary>
        /// Parses an object from <paramref name="r"/> using <paramref name="a"/> to locate
        /// a suitable class definition to populate.
        /// </summary>
        /// <param name="r">The <see cref="T:System.Xml.XmlReader"/> from which to parse the object</param>
        /// <param name="a"><paramref name="s"/> in object form</param>
        /// <returns>A <see cref="MARC.Everest.Formatters.XML.ITS1.Its1FormatterParseResult"/> containing the results of the parse</returns>
        /// <remarks>
        /// <para>This method differs from the <seealso cref="F:Parse(System.Xml.XmlReader)"/> method in that it
        /// will only look within the specified assembly for a suitable class to populate.</para>
        /// <para>
        /// This method will not check the current learned type repository for a class to serialize (ie: it will always 
        /// check the assembly regardless of what has been formatted prior)
        /// </para>
        /// </remarks>
        public IFormatterParseResult Parse(XmlReader r, Assembly a)
        {
            ThrowIfDisposed();

            var resultContext = new XmlIts1FormatterParseResult(ResultCode.Accepted, null);

            if (!(r is XmlStateReader))
                r = new XmlStateReader(r);

            // Initial state
            if (r.ReadState == ReadState.Initial)
                while (r.NodeType != XmlNodeType.Element)
                    r.Read();

            // Detect if we can parse this...
            //if (r.NamespaceURI != "urn:hl7-org:v3")
            //    throw new XmlException(string.Format("Can't parse '{0}' in namespace '{1}'. The data does not appear to be an HL7v3 instance", r.LocalName, r.NamespaceURI), null);

            // Predicate will find the mapped type for us
            Predicate<Type> typeComparator = delegate(Type t)
            {
                object[] structureAttribute = t.GetCustomAttributes(typeof(StructureAttribute), true);
                if (structureAttribute.Length > 0 && ((structureAttribute[0] as StructureAttribute).StructureType == StructureAttribute.StructureAttributeType.Interaction || (structureAttribute[0] as StructureAttribute).IsEntryPoint)
                    && (structureAttribute[0] as StructureAttribute).Name == r.LocalName && (structureAttribute[0] as StructureAttribute).NamespaceUri == r.NamespaceURI)
                    return true;
                return false;
            };

            // Try to find the value if it doesn't succeed, try to build it and try to find it again
#if WINDOWS_PHONE
            Type fType = a.GetTypes().Find(typeComparator);
#else
            Type fType = Array.Find<Type>(a.GetTypes(), typeComparator);
#endif

            // Found the type
            if (fType != null)
                resultContext.Structure = this.ParseObject(r, fType, fType, resultContext);
            else
                resultContext.AddResultDetail(
                        new ResultDetail(ResultDetailType.Error, String.Format("Could not find a type to de-serialize '{0}' into", r.Name), r.ToString(), null)
                    );

            // Set the acceptance code
            resultContext.Code = CalculateResultCode(resultContext.Details);
            return resultContext;
        }
Exemple #14
0
 /// <summary>
 /// Parse an object from <paramref name="s"/>
 /// </summary>
 /// <param name="s">The stream from which to parse an object</param>
 /// <returns>An <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterParseResult"/> structure containing the parsed information</returns>
 /// <remarks>
 /// <para>
 /// The parse method will attempt to search any of the already known types (ie: types already learned) for a serialization start point. If
 /// one is not found, the method will search the current AppDomain to find <see cref="T:MARC.Everest.Interfaces.IGraphable"/> classes
 /// which can be used to interpret the data within the stream. For this, the root element is used to find 
 /// which of the types can start serialization.
 /// </para>
 /// <para>
 /// While this method will work fine when dealing with one RMIM assembly, it is recommended that you use the 
 /// <seealso cref="F:Graph(System.IO.Stream,System.Reflection.Assembly)"/> method when more than one RMIM assembly
 /// is loaded in memory.
 /// </para>
 /// </remarks>
 public IFormatterParseResult Parse(Stream s)
 {
     XmlReader rdr = new XmlStateReader(XmlReader.Create(s));
     try
     {
         return Parse(rdr); // Parse the object using the XML Reader
     }
     finally
     {
         rdr.Close();
     }
 }
Exemple #15
0
 public void COEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.CO aValue = new MARC.Everest.DataTypes.CO(), bValue = null;
     aValue.OriginalText = new MARC.Everest.DataTypes.ED(new System.Byte[] { 0 }, "0");
     aValue.Code = new MARC.Everest.DataTypes.CD<System.String>("0");
     aValue.Code.CodeSystem = "0";
     aValue.Code.CodeSystemName = "0";
     aValue.Code.CodeSystemVersion = "0";
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.CO>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.CO)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #16
0
        public void ENEqualsSerializationTest()
        {
            MARC.Everest.DataTypes.EN aValue = new MARC.Everest.DataTypes.EN(), bValue = null;
            aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.EntityNameUse>>(MARC.Everest.DataTypes.EntityNameUse.Legal);
            aValue.Flavor = "0";
            aValue.Part.Add(new MARC.Everest.DataTypes.ENXP("Bob", MARC.Everest.DataTypes.EntityNamePartType.Given));
            aValue.Part.Add(new MARC.Everest.DataTypes.ENXP("Dole", MARC.Everest.DataTypes.EntityNamePartType.Family));

            StringWriter sw = new StringWriter();
            DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
            XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
            xw.WriteStartElement("test");
            fmtr.Graph(xw, aValue);
            xw.WriteEndElement(); // comp
            xw.Flush();
            StringReader sr = new StringReader(sw.ToString());
            XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
            rdr.Read(); rdr.Read();
            bValue = Util.Convert<MARC.Everest.DataTypes.EN>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.EN)).Structure);
            Assert.AreEqual(aValue, bValue);
        }
        /// <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();
            }

            
        }
Exemple #18
0
 public void ADXPEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.ADXP aValue = new MARC.Everest.DataTypes.ADXP(), bValue = null;
     aValue.Value = "0";
     aValue.Code = "0";
     aValue.Type = new System.Nullable<MARC.Everest.DataTypes.AddressPartType>(MARC.Everest.DataTypes.AddressPartType.AddressLine);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.ADXP>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.ADXP)).Structure);
     bValue.Type = MARC.Everest.DataTypes.AddressPartType.AddressLine;
     Assert.AreEqual(aValue, bValue);
 }
Exemple #19
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());

        }
Exemple #20
0
 public void TELEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.TEL aValue = new MARC.Everest.DataTypes.TEL(), bValue = null;
     aValue.Use = new MARC.Everest.DataTypes.SET<MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse>>(0) { new MARC.Everest.DataTypes.CS<MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse>(MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.Home) };
     aValue.UseablePeriod = new MARC.Everest.DataTypes.GTS(new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.TS>(new MARC.Everest.DataTypes.TS(DateTime.Parse("2011-1-10"))));
     aValue.Value = "0";
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.TEL>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.TEL)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #21
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());

        }
Exemple #22
0
 public void PIVLEqualsSerializationTest()
 {
     MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT> aValue = new MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>(), bValue = null;
     aValue.Phase = new MARC.Everest.DataTypes.IVL<MARC.Everest.DataTypes.INT>(new MARC.Everest.DataTypes.INT(0));
     aValue.Period = new MARC.Everest.DataTypes.PQ((decimal)0, "0");
     aValue.Alignment = new System.Nullable<MARC.Everest.DataTypes.CalendarCycle>(MARC.Everest.DataTypes.CalendarCycle.Year);
     aValue.InstitutionSpecified = false;
     aValue.Operator = new System.Nullable<MARC.Everest.DataTypes.SetOperator>(MARC.Everest.DataTypes.SetOperator.Hull);
     aValue.Flavor = "0";
     StringWriter sw = new StringWriter();
     DatatypeFormatter fmtr = new DatatypeFormatter() { CompatibilityMode = DatatypeFormatterCompatibilityMode.Canadian };
     XmlStateWriter xw = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings() { Encoding = System.Text.Encoding.UTF8 }));
     xw.WriteStartElement("test");
     fmtr.Graph(xw, aValue);
     xw.WriteEndElement(); // comp
     xw.Flush();
     StringReader sr = new StringReader(sw.ToString());
     XmlStateReader rdr = new XmlStateReader(XmlReader.Create(sr));
     rdr.Read(); rdr.Read();
     bValue = Util.Convert<MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>>(fmtr.Parse(rdr, typeof(MARC.Everest.DataTypes.PIVL<MARC.Everest.DataTypes.INT>)).Structure);
     Assert.AreEqual(aValue, bValue);
 }
Exemple #23
0
        /// <summary>
        /// Parse an object from <see cref="T:System.Xml.XmlReader"/> <paramref name="r"/>
        /// </summary>
        /// <param name="r">The <see cref="T:System.Xml.XmlReader"/> to parse an object from</param>
        /// <returns>A <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterParseResult"/> containing the formatted instance</returns>
        /// <remarks>
        /// <para>
        /// This particular overload of the Graph method can be used to graph objects into a <see cref="T:System.Xml.XmlWriter"/> and can provide
        /// an opportunity to use Everest as an assistant (or XmlSerializerSurrogate) for more complex systems like WCF.
        /// </para>
        /// <example>
        /// <code lang="cs" title="Using Everest as a Serializer Assistant">
        /// <![CDATA[
        /// StringWriter sw = new StringWriter("<hello><MCCI_IN000002CA xmlns=\"urn:hl7-org:v3\"/></hello>");
        /// XmlReader reader = XmlReader.Create(sw);
        /// reader.Read(); // Read <hello>
        /// 
        /// Formatter f = new Formatter();
        /// f.GraphAides.Add(typeof(MARC.Everest.Formatters.XML.DataTypes.R1.Formatter));
        /// f.ValidateConformance = false;
        /// var result = f.Parse(reader);
        /// 
        /// reader.Read();
        /// reader.Close();
        /// Console.WriteLine(result.Code); 
        /// 
        /// ]]>
        /// </code>
        /// </example>
        /// <para>
        /// When using this method, it is recommended that you pass a <see cref="T:MARC.Everest.Xml.XmlStateReader"/> as it 
        /// will allow the formatter to give additional location information when reporting issues.
        /// </para>
        /// </remarks>
        public IFormatterParseResult Parse(XmlReader r)
        {
            ThrowIfDisposed();

            // Clear existing results
            XmlIts1FormatterParseResult resultContext = new XmlIts1FormatterParseResult(ResultCode.Accepted, null);

            if (!(r is XmlStateReader))
                r = new XmlStateReader(r);

            // Initial state
            if (r.ReadState == ReadState.Initial)
                while (r.NodeType != XmlNodeType.Element)
                    r.Read();

            // Detect if we can parse this...
            //if (r.NamespaceURI != "urn:hl7-org:v3")
            //    throw new XmlException(string.Format("Can't parse '{0}' in namespace '{1}'. The data does not appear to be an HL7v3 instance", r.LocalName, r.NamespaceURI), null);

            // Do we have a formatter for the object
            Type mappedType;

            // Predicate will find the mapped type for us
            Predicate<Type> typeComparator = delegate(Type t)
            {
                object[] structureAttribute = t.GetCustomAttributes(typeof(StructureAttribute), true);
                if (structureAttribute.Length > 0 && ((structureAttribute[0] as StructureAttribute).StructureType == StructureAttribute.StructureAttributeType.Interaction || (structureAttribute[0] as StructureAttribute).IsEntryPoint)
                    && (structureAttribute[0] as StructureAttribute).Name == r.LocalName && (structureAttribute[0] as StructureAttribute).NamespaceUri == r.NamespaceURI)
                    return true;
                return false;
            };

            // Try to find the value if it doesn't succeed, try to build it and try to find it again
            for (int i = 0; i < 2 && resultContext.Structure == null; i++)
            {
                if (s_rootNameMaps.TryGetValue(r.LocalName, out mappedType)) // Try to get a root name map
                {
                    resultContext.Structure = ParseObject(r, mappedType, mappedType, resultContext);
                    resultContext.Code = CalculateResultCode(resultContext.Details);
                    return resultContext;
                }
                else if (i == 0) // Try to build the cache for this root name
                {
                    // Last attempt, try to find a type in the app domain that we can scan!
                    Predicate<Assembly> asmPredicate = delegate(Assembly a)
                    {
                        try
                        {
#if WINDOWS_PHONE
                            return a.GetTypes().Exists(typeComparator);
#else
                            return Array.Find<Type>(a.GetTypes(), typeComparator) != null;
#endif
                        }
                        catch
                        {
                            return false;
                        }
                    };

#if WINDOWS_PHONE
                    Assembly asm = AppDomain.CurrentDomain.GetAssemblies().Find(asmPredicate);
#else
                    Assembly asm = Array.Find<Assembly>(AppDomain.CurrentDomain.GetAssemblies(), asmPredicate);
#endif
                    if (asm == null) // Couldn't find assembly... ditch
                        break;
                    else
                        return Parse(r, asm); //BuildCache(new Type[] { Array.Find<Type>(asm.GetTypes(), typeComparator) });
                }
                //i++;
            }

            resultContext.AddResultDetail(new ResultDetail(ResultDetailType.Error, String.Format("Could not find a type to de-serialize '{0}' into", r.Name), r.ToString(), null));
            resultContext.Code = ResultCode.Rejected;
            return resultContext;
        }