コード例 #1
0
ファイル: QSETFormatter.cs プロジェクト: oneminot/everest
        /// <summary>
        /// Parse a QS* class from a QSET formatter
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // First off, there is no way to determine which of the classes it is..
            
            // Try using the xsi type
            var fmtr = new DatatypeR2Formatter().GetFormatter(s.GetAttribute("type", DatatypeR2Formatter.NS_XSI));
            if (fmtr == null) // No formatter available, add a result
            {
                result.AddResultDetail(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Cannot determine type of QSET to parse, use xsi:type to specify a type", s.ToString()));
                return null;
            }

            // Parse using the formatter
            // Fix: EV-876
            fmtr.GenericArguments = this.GenericArguments;
            fmtr.Host = this.Host; 
            return fmtr.Parse(s, result);
        }
コード例 #2
0
        /// <summary>
        /// Serialize as a string
        /// </summary>
        internal static String SerializeAsString(IGraphable graph)
        {
            DatatypeR2Formatter fmtr = new DatatypeR2Formatter();
            StringWriter        sw   = new StringWriter();
            XmlStateWriter      xsw  = new XmlStateWriter(XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Indent = true
            }));

            xsw.WriteStartElement("test", "urn:hl7-org:v3");
            xsw.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            var result = fmtr.Graph(xsw, graph);

            xsw.WriteEndElement();
            xsw.Flush();
            sw.Flush();
            System.Diagnostics.Trace.WriteLine(sw.ToString());
            Assert.AreEqual(ResultCode.Accepted, result.Code);
            return(sw.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Graph the base
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            // Do not graph if null flavor is present
            if ((o as ANY).NullFlavor != null)
            {
                return;
            }

            var originalText = o as IOriginalText;

            // Write out the original text first
            if (originalText.OriginalText != null)
            {
                s.WriteStartElement("originalText", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, originalText.OriginalText);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

            // Now the terms
            foreach (var term in (o as IEnumerable))
            {
                s.WriteStartElement("term", "urn:hl7-org:v3");


                // JF: Output XSI:Type
                string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(term.GetType());
                s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName);
                var hostResult = this.Host.Graph(s, term as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
        }
コード例 #4
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/> storing
        /// details in <paramref name="result"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Cast to strongly typed data
            IColl collInstance = o as IColl;
            IAny  anyInstance  = o as IAny;

            // Base formatter
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host = this.Host;
            baseFormatter.Graph(s, o, result);

            // Graphing a COLL is easy, we just iterate over the items
            if (anyInstance.NullFlavor == null)
            {
                foreach (var itm in collInstance)
                {
                    // Start the item tag
                    s.WriteStartElement("item", "urn:hl7-org:v3");

                    // Output an XSI type if the type does not match the generic parameter
                    if (itm.GetType() != GenericArguments[0])
                    {
                        var xsiName = DatatypeR2Formatter.CreateXSITypeName(itm.GetType());
                        s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiName);
                    }

                    // Format the item
                    var hostResult = this.Host.Graph(s, itm as IGraphable);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);

                    // End of item tag
                    s.WriteEndElement();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Format base attributes
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            if ((o as ANY).NullFlavor != null)
            {
                return;                                // no need to continue formatting
            }
            // Get the values the formatter needs to represent in XML
            Type   ivlType           = o.GetType();
            object operatorValue     = ivlType.GetProperty("Operator").GetValue(o, null),
                   lowValue          = ivlType.GetProperty("Low").GetValue(o, null),
                   highValue         = ivlType.GetProperty("High").GetValue(o, null),
                   widthValue        = ivlType.GetProperty("Width").GetValue(o, null),
                   originalTextValue = ivlType.GetProperty("OriginalText").GetValue(o, null),
                   lowClosedValue    = ivlType.GetProperty("LowClosed").GetValue(o, null),
                   highClosedValue   = ivlType.GetProperty("HighClosed").GetValue(o, null),
                   valueValue        = ivlType.GetProperty("Value").GetValue(o, null);

            // Low / high closed
            if (lowClosedValue != null)
            {
                s.WriteAttributeString("lowClosed", Util.ToWireFormat(lowClosedValue));
            }
            if (highClosedValue != null)
            {
                s.WriteAttributeString("highClosed", Util.ToWireFormat(highClosedValue));
            }
            if (operatorValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Operator", "IVL", s.ToString()));
            }

            // Original text
            if (originalTextValue != null)
            {
                s.WriteStartElement("originalText", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, originalTextValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

            bool invalidCombo = false;

            // Valid combinations
            if (lowValue != null)
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");

                // Low value XSI?
                if (lowValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(lowValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, lowValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                if (highValue != null)
                {
                    s.WriteStartElement("high", "urn:hl7-org:v3");

                    if (highValue.GetType() != GenericArguments[0])
                    {
                        s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(highValue.GetType()));
                    }

                    hostResult  = this.Host.Graph(s, highValue as IGraphable);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    s.WriteEndElement();
                }
                invalidCombo |= valueValue != null || widthValue != null;
            }
            else if (highValue != null)
            {
                s.WriteStartElement("high", "urn:hl7-org:v3");

                // High value XSI
                if (highValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(highValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, highValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                invalidCombo |= valueValue != null || widthValue != null;
            }
            if (widthValue != null && ((lowValue == null) ^ (highValue == null) || lowValue == null && highValue == null))
            {
                s.WriteStartElement("width", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, widthValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                if (valueValue != null)
                {
                    s.WriteStartElement("any", "urn:hl7-org:v3");

                    // Value value xsi type
                    if (valueValue.GetType() != GenericArguments[0])
                    {
                        s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(valueValue.GetType()));
                    }

                    hostResult  = this.Host.Graph(s, valueValue as IGraphable);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    s.WriteEndElement();
                }
                invalidCombo |= lowValue != null || highValue != null;
            }
            else if (valueValue != null)
            {
                s.WriteStartElement("any", "urn:hl7-org:v3");

                // Value value xsi type
                if (valueValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(valueValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, valueValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                invalidCombo |= lowValue != null || highValue != null;
            }
            else
            {
                invalidCombo = true;
            }

            // Invalid combination, warn
            if (invalidCombo)
            {
                result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "This IVL is not conformant to the ISO21090 data types specification. Only 'Value' and/or 'Width', or 'Low' and/or 'High' are permitted. All data has been serialized but may not be interpreted by a remote system", s.ToString(), null));
            }
        }
コード例 #6
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type ivlType        = typeof(IVL <>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "IVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "IVL", s.ToString()));
                }

                // Get property information
                PropertyInfo lowProperty          = ivlGenericType.GetProperty("Low"),
                             highProperty         = ivlGenericType.GetProperty("High"),
                             widthProperty        = ivlGenericType.GetProperty("Width"),
                             valueProperty        = ivlGenericType.GetProperty("Value"),
                             originalTextProperty = ivlGenericType.GetProperty("OriginalText"),
                             lowClosedProperty    = ivlGenericType.GetProperty("LowClosed"),
                             highClosedProperty   = ivlGenericType.GetProperty("HighClosed");

                // Attributes
                if (s.GetAttribute("lowClosed") != null)
                {
                    lowClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("lowClosed")), null);
                }
                if (s.GetAttribute("highClosed") != null)
                {
                    highClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("highClosed")), null);
                }

                // Now process the elements
                #region Elements
                if (!s.IsEmptyElement)
                {
                    int    sDepth = s.Depth;
                    string sName  = s.Name;

                    s.Read();
                    // string Name
                    while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                    {
                        string oldName = s.Name; // Name
                        try
                        {
                            if (s.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "low":
                                    setProperty = lowProperty;
                                    break;

                                case "high":
                                    setProperty = highProperty;
                                    break;

                                case "any":
                                    setProperty = valueProperty;
                                    break;

                                case "width":
                                    setProperty = widthProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("Element '{0}' is not supported in IVL", s.LocalName), s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion

                // Validate combination
                if (!((lowProperty.GetValue(instance, null) != null || highProperty.GetValue(instance, null) != null) ^ (valueProperty.GetValue(instance, null) != null || widthProperty.GetValue(instance, null) != null)))
                {
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "IVL instance is not comformant to ISO21090 data types specification. 'Value' and/or 'Width', or 'Low' and/or 'High' are compliant representations.", s.ToString(), null));
                }
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
コード例 #7
0
ファイル: PIVLFormatter.cs プロジェクト: zzllkk2003/everest
        /// <summary>
        /// Parse an instance of PIVL from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type pivlType       = typeof(PIVL <>);
            Type ivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "PIVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "PIVL", s.ToString()));
                }

                // Get property information
                PropertyInfo alignmentProperty            = ivlGenericType.GetProperty("Alignment"),
                             phaseProperty                = ivlGenericType.GetProperty("Phase"),
                             periodProperty               = ivlGenericType.GetProperty("Period"),
                             institutionSpecifiedProperty = ivlGenericType.GetProperty("InstitutionSpecified"),
                             countProperty                = ivlGenericType.GetProperty("Count"),
                             frequencyProperty            = ivlGenericType.GetProperty("Frequency"),
                             originalTextProperty         = ivlGenericType.GetProperty("OriginalText");

                // Attributes
                if (s.GetAttribute("isFlexible") != null)
                {
                    institutionSpecifiedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("isFlexible")), null);
                }
                if (s.GetAttribute("alignment") != null)
                {
                    alignmentProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), alignmentProperty.PropertyType), null);
                }
                if (s.GetAttribute("count") != null)
                {
                    countProperty.SetValue(instance, Util.Convert <INT>(s.GetAttribute("count")), null);
                }

                // Now process the elements
                #region Elements
                if (!s.IsEmptyElement)
                {
                    int    sDepth = s.Depth;
                    string sName  = s.Name;

                    s.Read();
                    // string Name
                    while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                    {
                        string oldName = s.Name; // Name
                        try
                        {
                            if (s.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "phase":
                                    setProperty = phaseProperty;
                                    break;

                                case "frequency":
                                    setProperty = frequencyProperty;
                                    break;

                                case "period":
                                    setProperty = periodProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
コード例 #8
0
        /// <summary>
        /// Parse from wire level format
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Any formatter for the base attributes
            ANYFormatter baseFormatter = new ANYFormatter();
            // Create the types
            Type qsiType        = typeof(QSU <>);
            Type qsiGenericType = qsiType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = qsiGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            // Read internal elements
            if ((instance as ANY).NullFlavor != null)
            {
                return(instance);
            }

            // Now process the elements
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                LIST <IGraphable> termList = new LIST <IGraphable>(4);

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            switch (s.LocalName)
                            {
                            case "originalText":
                            {
                                var hostResult = this.Host.Parse(s, typeof(ED));
                                result.Code = hostResult.Code;
                                result.AddResultDetail(hostResult.Details);
                                (instance as IOriginalText).OriginalText = hostResult.Structure as ED;
                                break;
                            }

                            case "term":
                            {
                                var hostResult = this.Host.Parse(s, typeof(IGraphable));
                                result.Code = hostResult.Code;
                                result.AddResultDetail(hostResult.Details);
                                termList.Add(hostResult.Structure as IGraphable);
                                break;
                            }

                            default:
                                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                break;
                            }
                        }
                    }
                    catch (MessageValidationException e) // Message validation error
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }

                // Set term list
                ((IListContainer)instance).ContainedList = termList;
            }
            #endregion

            // Validate
            baseFormatter.Validate(instance as ANY, s.ToString(), result);

            return(instance);
        }
コード例 #9
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host             = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;
            ANY tRetVal = baseFormatter.Parse <ANY>(s);

            // Construct an instance of the SLIST
            var          slistType   = typeof(SLIST <>).MakeGenericType(this.GenericArguments);
            var          constructor = slistType.GetConstructor(Type.EmptyTypes);
            ISampledList retVal      = constructor.Invoke(null) as ISampledList;

            DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY);

            // Parse the return value
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        // Origin
                        if (s.LocalName == "origin" && retVal.Origin == null)
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Origin = parseResult.Structure as IQuantity;
                        }
                        else if (s.LocalName == "origin")
                        {
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "origin may only be supplied once", s.ToString()));
                        }
                        // Scale
                        else if (s.LocalName == "scale" && retVal.Scale == null)
                        {
                            var parseResult = Host.Parse(s, typeof(IQuantity));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Scale = parseResult.Structure as IQuantity;
                        }
                        else if (s.LocalName == "scale")
                        {
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "scale may only be supplied once", s.ToString()));
                        }
                        // Digit
                        else if (s.LocalName == "digit")
                        {
                            var parseResult = Host.Parse(s, typeof(INT));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Items.Add(parseResult.Structure as INT);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            // Validate
            baseFormatter.Validate(retVal as ANY, s.ToString(), result);
            return(retVal);
        }
コード例 #10
0
        /// <summary>
        /// Parse an object from <paramref name="s"/> into an instance of QSP
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type qspType        = typeof(QSP <>);
            Type qspGenericType = qspType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = qspGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Get property information
                PropertyInfo lowProperty          = qspGenericType.GetProperty("Low"),
                             highProperty         = qspGenericType.GetProperty("High"),
                             originalTextProperty = qspGenericType.GetProperty("OriginalText");

                // Now process the elements
                #region Elements
                if (!s.IsEmptyElement)
                {
                    int    sDepth = s.Depth;
                    string sName  = s.Name;

                    s.Read();
                    // string Name
                    while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                    {
                        string oldName = s.Name; // Name
                        try
                        {
                            if (s.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "low":
                                    setProperty = lowProperty;
                                    break;

                                case "high":
                                    setProperty = highProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
コード例 #11
0
ファイル: UVPFormatter.cs プロジェクト: zzllkk2003/everest
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host             = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;

            // Graph
            var tRetVal = baseFormatter.Parse <ANY>(s);
            var uvpType = typeof(UVP <>);
            var genType = uvpType.MakeGenericType(this.GenericArguments);

            // Construct
            var          constructor = genType.GetConstructor(Type.EmptyTypes);
            IProbability retVal      = constructor.Invoke(null) as IProbability;

            // Copy base attributes
            DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY);

            // Parse UVP properties
            if (s.GetAttribute("probability") != null)
            {
                string tProb = s.GetAttribute("probability");
                try
                {
                    retVal.Probability = Decimal.Parse(tProb);
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Now process the elements
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.LocalName == "value" && retVal.Value == null)
                        {
                            var hostResult = this.Host.Parse(s, GenericArguments[0]);
                            result.AddResultDetail(hostResult.Details);
                            retVal.Value = hostResult.Structure;
                        }
                        else if (s.LocalName == "value")
                        {
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Value can only be set once on an instance of UVP", s.ToString()));
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e) // Message validation error
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            // validate
            baseFormatter.Validate(retVal as ANY, s.ToString(), result);
            return(retVal);
        }
コード例 #12
0
ファイル: RTOFormatter.cs プロジェクト: zzllkk2003/everest
        /// <summary>
        /// Graph object <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream being graphed to</param>
        /// <param name="o">The object being graphed</param>
        /// <param name="result">The result of the graph operation</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Graph the QTY portions
            QTYFormatter qty = new QTYFormatter();

            qty.Host = this.Host;
            qty.Graph(s, o, result);

            // Any null flavors
            IAny anyO = o as IAny;
            IPrimitiveDataValue ipdv = o as IPrimitiveDataValue;

            if (anyO.NullFlavor != null)
            {
                return;
            }

            // PDV Value does not support value
            if (ipdv.Value != null)
            {
                result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(MARC.Everest.Connectors.ResultDetailType.Warning, "Value", "RTO", s.ToString()));
            }

            // Get the numerator / denominator
            PropertyInfo numeratorProperty   = o.GetType().GetProperty("Numerator"),
                         denominatorProperty = o.GetType().GetProperty("Denominator");
            object numerator   = numeratorProperty.GetValue(o, null),
                   denominator = denominatorProperty.GetValue(o, null);

            // Serialize the numerator
            if (numerator != null)
            {
                s.WriteStartElement("numerator", "urn:hl7-org:v3");

                // Write the XSI type
                string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(numerator.GetType());

                // Write the type
                if (this.Host.Host == null)
                {
                    s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString());
                }
                else
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString());
                }

                var hostResult = this.Host.Graph(s, (IGraphable)numerator);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            // Serialize Denominator
            if (denominator != null)
            {
                s.WriteStartElement("denominator", "urn:hl7-org:v3");

                // Write the XSI type
                string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(denominator.GetType());

                // Write the type
                if (this.Host.Host == null)
                {
                    s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString());
                }
                else
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString());
                }

                var hostResult = this.Host.Graph(s, (IGraphable)denominator);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
        }
コード例 #13
0
ファイル: RTOFormatter.cs プロジェクト: zzllkk2003/everest
        /// <summary>
        /// Parse the RTO
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type rtoType = typeof(RTO <,>);

            QTYFormatter baseFormatter = (new QTYFormatter()
            {
                Host = this.Host
            });
            // Quantity value, just read into a REAL
            var qty = baseFormatter.ParseAttributes <REAL>(s, result);

            // Temporary values
            IGraphable denominator = null,
                       numerator   = null;

            // Elements
            // This type is a little different in R2, basically we can't determine the generic
            // parameters by the XSI Type so we have to parse the num/denom manually, and
            // ensure that we have both, then we construct the object and set the properties
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        // Numerator
                        if (s.LocalName == "numerator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            numerator = parseResult.Structure;
                        }
                        // Denominator
                        else if (s.LocalName == "denominator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[1]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            denominator = parseResult.Structure;
                        }
                        else
                        {
                            baseFormatter.ParseElementsInline(s, qty, result);
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            try
            {
                // Construct the generic type (if possible)
                Type rtoGenericType = rtoType.MakeGenericType(new Type[]
                {
                    numerator == null ? typeof(IQuantity) : numerator.GetType(),
                    denominator == null ? typeof(IQuantity) : denominator.GetType()
                });

                // Create an instance of rto from the rtoType
                object instance = rtoGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

                // Get the values from the QTY and copy
                IQuantity rtoQty = instance as IQuantity;
                DatatypeR2Formatter.CopyBaseAttributes(qty, rtoQty as ANY);
                rtoQty.Expression      = qty.Expression;
                rtoQty.OriginalText    = qty.OriginalText;
                rtoQty.UncertainRange  = qty.UncertainRange;
                rtoQty.Uncertainty     = qty.Uncertainty;
                rtoQty.UncertaintyType = qty.UncertaintyType;

                // rto properties
                PropertyInfo numeratorProperty   = rtoGenericType.GetProperty("Numerator"),
                             denominatorProperty = rtoGenericType.GetProperty("Denominator");

                // Set the previously found properties
                numeratorProperty.SetValue(instance, Util.FromWireFormat(numerator, numeratorProperty.PropertyType), null);
                denominatorProperty.SetValue(instance, Util.FromWireFormat(denominator, denominatorProperty.PropertyType), null);

                // Validate
                ANYFormatter anyFormatter = new ANYFormatter();
                string       pathName     = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
                anyFormatter.Validate(instance as ANY, pathName, result);

                return(instance);
            }
            catch (Exception e)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, e));
                return(null);
            }
        }