Пример #1
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to graph to</param>
        /// <param name="o">The object to graph</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            PDVFormatter pdvFormatter = new PDVFormatter();
            var          instance     = o as INT;

            pdvFormatter.Graph(s, instance, result);

            // Unsupported properties
            if (instance.Expression != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "INT", s.ToString()));
            }
            if (instance.OriginalText != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "INT", s.ToString()));
            }
            if (instance.Uncertainty != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "INT", s.ToString()));
            }
            if (instance.UncertaintyType != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "INT", s.ToString()));
            }
            if (instance.UncertainRange != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyRange", "INT", s.ToString()));
            }
        }
Пример #2
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            PDVFormatter baseFormatter = new PDVFormatter();

            baseFormatter.Graph(s, o, result);

            if ((o as ANY).NullFlavor != null)
            {
                return;                                // Nullflavor so the formatter doesn't format anything
            }
            // 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);

            // Warn the developer if there are any properties that can't be represented in R1
            if (originalTextValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "IVL", s.ToString()));
            }
            if (lowClosedValue != null || highClosedValue != null)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                        "The properties 'LowClosed' and 'HighClosed' properties will be used as low/@inclusive and high/@inclusive attributes for R1 formatting", s.ToString(), null));
            }

            // Representations of the IVL type
            if (operatorValue != null)
            {
                s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));
            }


            if (lowValue != null && highValue != null) // low & high
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");
                if (lowClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(lowClosedValue));
                }

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

                var hostResult = Host.Graph(s, (IGraphable)lowValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();

                s.WriteStartElement("high", "urn:hl7-org:v3");
                if (highClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(highClosedValue));
                }

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

                hostResult  = Host.Graph(s, (IGraphable)highValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();

                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, high, value can't be represented together in an IVL data type in R1. Only formatting low and high", s.ToString(), null));
                }
                if (widthValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, high, width can't be represented together in an IVL data type in R1. Only formatting low and high", s.ToString(), null));
                }
                #endregion
            }
            else if (lowValue != null && widthValue != null) // Low & width
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");
                if (lowClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(lowClosedValue));
                }

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


                var hostResult = Host.Graph(s, (IGraphable)lowValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                s.WriteStartElement("width", "urn:hl7-org:v3");
                hostResult  = Host.Graph(s, (IGraphable)widthValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();

                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, width, value can't be represented together in an IVL data type in R1. Only formatting low and width", s.ToString(), null));
                }
                if (highValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, width, high can't be represented together in an IVL data type in R1. Only formatting low and width", s.ToString(), null));
                }
                #endregion
            }
            else if (highValue != null && widthValue != null) // high & width
            {
                s.WriteStartElement("width", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)widthValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                s.WriteStartElement("high", "urn:hl7-org:v3");
                if (highClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(highClosedValue));
                }

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

                hostResult  = Host.Graph(s, (IGraphable)highValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();

                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "high, width, value can't be represented together in an IVL data type in R1. Only formatting width and high", s.ToString(), null));
                }
                if (lowValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "high, width, low can't be represented together in an IVL data type in R1. Only formatting width and high", s.ToString(), null));
                }
                #endregion
            }
            else if (lowValue != null) // low only
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");
                if (lowClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(lowClosedValue));
                }

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

                var hostResult = Host.Graph(s, (IGraphable)lowValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            else if (highValue != null) // High only
            {
                s.WriteStartElement("high", "urn:hl7-org:v3");
                if (highClosedValue != null)
                {
                    s.WriteAttributeString("inclusive", Util.ToWireFormat(highClosedValue));
                }

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

                var hostResult = Host.Graph(s, (IGraphable)highValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            else if (widthValue != null) // width only
            {
                s.WriteStartElement("width", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)widthValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            else if (valueValue != null)
            {
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                                           ResultDetailType.Warning, "Though XML ITS supports it, use of the IVL 'value' attribute should be avoided. The data has been serialized but may be uninterpretable by anoher system", s.ToString(), null));
                //DOC: Further documentation required.
            }
            // No need for this ;
            else
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error,
                                                        "Can't create a valid representation of IVL using the supplied data for data types R1. Valid IVL must have [low & [high | width]] | [high & width] | high | value to satisfy data type R1 constraints",
                                                        s.ToString(), null));
            }
        }