예제 #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 override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Graph this UVP to the stream
            base.Graph(s, o, result);
            
            // Add probability 
            if ((o as ANY).NullFlavor != null)
                return; // No need for this

            object probValue = o.GetType().GetProperty("Probability").GetValue(o, null),
                valueValue = o.GetType().GetProperty("Value").GetValue(o, null);

            // Output XSI:TYPE
            // TODO: Safety check this method in the future
            s.WriteAttributeString("xsi","type", DatatypeFormatter.NS_XSI, Util.CreateXSITypeName(o.GetType()));

            if (probValue != null)
                s.WriteAttributeString("probability", Util.ToWireFormat(probValue));
            
            // Graph the value
            ANY anyValue = valueValue as ANY;
            if (anyValue == null)
                return;

            var hostResult = this.Host.Graph(s, anyValue);
            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);

        }
예제 #2
0
        /// <summary>
        /// Graph the object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlWriter to graph object to</param>
        /// <param name="o">The object to graph</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref
            TEL instance_tel = (TEL)o;

            // Do a base format
            base.Graph(s, o, result);

            // Null flavor
            if (((ANY)o).NullFlavor != null)
                return;

            // Attributes
            if (instance_tel.Value != null)
                s.WriteAttributeString("value", instance_tel.Value);
            if (instance_tel.Use != null && instance_tel.Use.Items != null
                && instance_tel.Use.Items.Count > 0)
                s.WriteAttributeString("use", Util.ToWireFormat(instance_tel.Use));
            if (instance_tel.Capabilities != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(
                    ResultDetailType.Warning, "Capabilities", "TEL", s.ToString()));

            // Elements
            if (instance_tel.UseablePeriod != null)
            {
                s.WriteStartElement("useablePeriod", "urn:hl7-org:v3");
                GTSFormatter formatterHelper = new GTSFormatter();
                formatterHelper.Host = this.Host;
                formatterHelper.Graph(s, instance_tel.UseablePeriod, result);
                s.WriteEndElement(); // usable period
            }
             
        }
예제 #3
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            Type sxprType = typeof(SXPR<>);
            Type sxprGenericType = sxprType.MakeGenericType(GenericArguments);

            // Format the base type
            baseFormatter.Graph(s, o, result);

            // Was a nullflavor present
            if ((o as ANY).NullFlavor != null)
                return;

            // Current path
            string currentPath = s is XmlStateWriter ? (s as XmlStateWriter).CurrentPath : "NA";

            // Graph the operator
            PropertyInfo operatorProperty = sxprGenericType.GetProperty("Operator"),
                componentProperty = sxprGenericType.GetProperty("Terms");
            SetOperator? operatorValue = (SetOperator?)operatorProperty.GetValue(o, null);
            IEnumerable componentValue = (IEnumerable)componentProperty.GetValue(o, null);

            // Write the operator out
            if (operatorValue != null)
                s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));

            // Elements
            if (componentValue != null)
            {
                int count = 0;
                foreach (var component in componentValue)
                {
                    s.WriteStartElement("comp", "urn:hl7-org:v3");
                    object value = component;
                    var compType = component.GetType();

                    string xsiTypeName = Util.CreateXSITypeName(compType);

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

                    if (count == 0) // the first element should have no operator
                    {
                        var pi = compType.GetProperty("Operator");
                        if (pi.GetValue(component, null) != null)
                            result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "Operator won't be represented in the first object in the SXCM", s.ToString(), null));
                        pi.SetValue(component, null, null);
                    }

                    var hostGraphResult = Host.Graph(s, (IGraphable)value);
                    result.AddResultDetail(hostGraphResult.Details);

                    s.WriteEndElement(); // comp
                    count++;
                }
            }
        }
예제 #4
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Represent the ST as an ED and serialize the ED
            base.Graph(s, o, result);
            
            ST instance = o as ST;

            // Get rid of these attributes
            if (result.CompatibilityMode != DatatypeFormatterCompatibilityMode.ClinicalDocumentArchitecture)
            {
                // In R1 data types an ST is a restriction of an ED with these attributes fixed
                s.WriteAttributeString("mediaType", "text/plain");
                s.WriteAttributeString("representation", "TXT");
            }

            // Language
            if (instance.Language != null)
                s.WriteAttributeString("language", instance.Language);
            
            // Content
            s.WriteString(instance.Value);

            // Translation
            if (instance.Translation != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Translation", "ST", s.ToString()));
            
        }
예제 #5
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 override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
		// We don't use base.graph() here because we want to control the value property
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);
            REAL instance = o as REAL;

            if (instance.NullFlavor != null) return; // Don't graph anymore

            // Precision
            if (instance.Value.HasValue && instance.Precision != 0)
                s.WriteAttributeString("value", instance.Value.Value.ToString(String.Format("0.{0}", new String('0', instance.Precision), DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator), DatatypeFormatter.FormatterCulture));
            else if (instance.Value.HasValue)
                s.WriteAttributeString("value", instance.Value.Value.ToString(DatatypeFormatter.FormatterCulture));

            // Unsupported properties
            if (instance.Expression != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "REAL", s.ToString()));
            if (instance.OriginalText != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "REAL", s.ToString()));
            if (instance.Uncertainty != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "REAL", s.ToString()));
            if (instance.UncertaintyType != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "REAL", s.ToString()));
            if (instance.UncertainRange != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "REAL", s.ToString()));

             
        }
예제 #6
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlWriter to graph to</param>
        /// <param name="o">The object to graph</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref
            ICodedValue instance_ics = (ICodedValue)o;

            // Do a base format
            base.Graph(s, o, result);

            // Format the coded simple
            if (instance_ics.CodeSystem != null) 
                s.WriteAttributeString("codeSystem", instance_ics.CodeSystem);
            if (instance_ics.CodeSystemName != null)
                s.WriteAttributeString("codeSystemName", instance_ics.CodeSystemName);
            if (instance_ics.CodeSystemVersion != null)
                s.WriteAttributeString("codeSystemVersion", instance_ics.CodeSystemVersion);
            if (instance_ics.DisplayName != null)
                s.WriteAttributeString("displayName", instance_ics.DisplayName);
            if (instance_ics.OriginalText != null) // Original Text
            {
                EDFormatter edFormatter = new EDFormatter();
                s.WriteStartElement("originalText", "urn:hl7-org:v3");
                edFormatter.Graph(s, instance_ics.OriginalText, result);
                s.WriteEndElement();
            }
            if (!String.IsNullOrEmpty(instance_ics.ValueSet))
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValueSet", "CV", s.ToString()));
            if (!String.IsNullOrEmpty(instance_ics.ValueSetVersion))
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValueSetVersion", "CV", s.ToString()));


        }
예제 #7
0
        /// <summary>
        /// Grap the object to a stream
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {

            ENXP instance = o as ENXP;

            // Start with part type and code attributes
            base.Graph(s, o, result);

            if (instance.NullFlavor != null)
                return;
            
            // Now format our data
            if (instance.Type != null && result.CompatibilityMode != DatatypeFormatterCompatibilityMode.ClinicalDocumentArchitecture)
                s.WriteAttributeString("partType", Util.ToWireFormat(instance.Type));
            if (instance.Qualifier != null && !instance.Qualifier.IsEmpty)
                s.WriteAttributeString("qualifier", Util.ToWireFormat(instance.Qualifier));
            if (instance.Code != null && result.CompatibilityMode != DatatypeFormatterCompatibilityMode.Canadian)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code", "ENXP", s.ToString()));
            else if(instance.Code != null)
                s.WriteAttributeString("code", instance.Code);
            if (instance.Value != null)
                s.WriteValue(instance.Value);
            if (instance.CodeSystem != null) // Warn if there is no way to represent this in R1
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystem", "ENXP", s.ToString()));
            if(instance.CodeSystemVersion != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystemVersion", "ENXP", s.ToString()));

        }
예제 #8
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Want to control the output of value
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);
            MO instance = o as MO;

            if (instance.NullFlavor != null) return; // Don't graph anymore

            if (instance.Expression != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "PQ", s.ToString()));
            if (instance.OriginalText != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "PQ", s.ToString()));
            if (instance.Uncertainty != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "PQ", s.ToString()));
            if (instance.UncertaintyType != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "PQ", s.ToString()));
            if (instance.UncertainRange != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "PQ", s.ToString()));
            if (instance.Currency != null)
                s.WriteAttributeString("currency", instance.Currency);

            // Precision
            if (instance.Precision != null && instance.Precision != 0 && instance.Value.HasValue)
                s.WriteAttributeString("value", instance.Value.Value.ToString(String.Format("0.{0}", new String('0', instance.Precision), DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator), DatatypeFormatter.FormatterCulture));
            else if (instance.Value.HasValue)
                s.WriteAttributeString("value", instance.Value.Value.ToString(DatatypeFormatter.FormatterCulture));

            
        }
예제 #9
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            base.Graph(s, o, result);
            
            // Now graph the attributes
            Type eivlType = o.GetType();
            object eventValue = eivlType.GetProperty("Event").GetValue(o, null),
                offsetValue = eivlType.GetProperty("Offset").GetValue(o, null),
                operatorValue = eivlType.GetProperty("Operator").GetValue(o, null);

            // Append the attributes to the writer
            if ((o as ANY).NullFlavor != null)
                return; // Nothing to report
            if (operatorValue != null)
                s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));

            // Write elements
            if (eventValue != null)
            {
                s.WriteStartElement("event", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)eventValue);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
            if (offsetValue != null)
            {
                s.WriteStartElement("offset", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)offsetValue);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

        }
예제 #10
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to graph to</param>
        /// <param name="o">The object to graph</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {

            base.Graph(s, o, result); // Graph the base data


            // If there is no null flavor then graph the rest of the object
            if (((ANY)o).IsNull)
                return;

            object invertedValue = o.GetType().GetProperty("Inverted").GetValue(o, null),
                nameValue = o.GetType().GetProperty("Name").GetValue(o, null),
                valueValue = o.GetType().GetProperty("Value").GetValue(o, null);

            // Graph the structural attributes
            s.WriteAttributeString("inverted", Util.ToWireFormat(invertedValue));

            // Graph the non-structural elements
            if (nameValue != null)
            {
                s.WriteStartElement("name", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, nameValue as IGraphable);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement(); // end name
            }
            if (valueValue != null)
            {
                s.WriteStartElement("value", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, valueValue as IGraphable);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement(); // end value
            }

        }
예제 #11
0
        /// <summary>
        /// Graph the object <paramref name="o"/> to <paramref name="s"/>
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            
            // Cast the object to GTS
            GTS instance = o as GTS;

            // Hull instance corrections
            if (instance.Hull != null)
            {
                if (instance.Hull.NullFlavor != null)
                {
                    instance.NullFlavor = instance.NullFlavor ?? instance.Hull.NullFlavor;
                    instance.Hull.NullFlavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.NullFlavor", "NullFlavor", instance.NullFlavor, s.ToString()));
                }
                if (instance.Hull.Flavor != null)
                {
                    instance.Flavor = instance.Flavor ?? instance.Hull.Flavor;
                    instance.Hull.Flavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.Flavor", "Flavor", instance.Flavor, s.ToString()));
                }
            }


            // Graph the base
            base.Graph(s, o as ANY, result);


            // Determine what type of hull we have
            if (instance.NullFlavor != null) // Null flavor specified, no hull will be graphed
            {
                return;
            }
            else if(instance.Hull == null)
            {
                result.AddResultDetail(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Cannot graph a GTS with a Null Hull", s.ToString()));
                return;
            }

            object instanceHull = instance.Hull;

            if (instanceHull.GetType().Name.StartsWith("QS"))
                instanceHull = instanceHull.GetType().GetMethod("TranslateToSXPR").Invoke(instanceHull, null);
            
            // Not for CDA:
            // FIX: We use GetType comparison because IS has side effects in that all IVL, PIVL, etc. are instances.
            if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.ClinicalDocumentArchitecture && (instanceHull.GetType().Equals(typeof(SXCM<TS>))))
                ;
            else
            {
                string xsiTypeName = Util.CreateXSITypeName(instanceHull.GetType());
                s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName);
            }

            // Output the formatting
            var hostResult = this.Host.Graph(s, (IGraphable)instanceHull);
            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);

        }
예제 #12
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse from</param>
        /// <param name="o">The object to parse</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ENFormatter baseFormatter = new ENFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;

            // Format
            baseFormatter.Graph(s, o, result);
        }
예제 #13
0
        /// <summary>
        /// Graph to the stream
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
             
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, String.Format("{0} cannot be graphed by the R1 formatter directly, processing as SXPR", this.HandlesType), s.ToString(), null));

            // Convert o as SXPR
            base.Graph(s, o.GetType().GetMethod("TranslateToSXPR").Invoke(o, null), result);


        }
예제 #14
0
        /// <summary>
        /// Graph to the stream
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "QSU cannot be graphed by the R1 formatter directly, processing as SXPR", s.ToString(), null));
            SXPRFormatter formatter = new SXPRFormatter();
            formatter.Host = this.Host;
            formatter.GenericArguments = this.GenericArguments;

            // Convert o as SXPR
            formatter.Graph(s, o.GetType().GetMethod("TranslateToSXPR").Invoke(o, null), result);
        }
예제 #15
0
        public virtual void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {

            // Has this formatter found the elemScopeStack yet?
            string currentElementName = null;

            // TODO: Make all parameters XmlStateWriters, next release of Everest
            // TODO: Don't have enough time to test what this may change upstream
            if (s is XmlStateWriter)
                currentElementName = (s as XmlStateWriter).CurrentElement.Name;
            else
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, "Can't represent a SET or LIST using this Xml Stream as it does not inherit from an XmlStateWriter", s.ToString(), null));
                return;
            }

            // Graph base
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.Graph(s, o, result);
            if (((ANY)o).IsNull) return;


            // Write the array
            IEnumerable instance = (IEnumerable)o;

            
            int count = 0;

            // Get each element in the instance
            IEnumerator enumerator = instance.GetEnumerator();

            if (!enumerator.MoveNext()) return; // No elements

            // Loop through elements
            while (enumerator.Current != null)
            {
                if (count != 0) // Not the first element, write the element name again
                    s.WriteStartElement(currentElementName, "urn:hl7-org:v3");

                // JF: Output XSI:Type
                if (GenericArguments != null && !enumerator.Current.GetType().Equals(GenericArguments[0]))
                {
                    string xsiTypeName = Util.CreateXSITypeName(enumerator.Current.GetType());
                    s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName);
                }

                var hostResult = Host.Graph(s, (IGraphable)enumerator.Current);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                if (!enumerator.MoveNext()) break; // No further objects
                s.WriteEndElement();
                count++;
            }
        }
예제 #16
0
        /// <summary>
        /// Graphs the object <paramref name="o"/> onto the stream.
        /// </summary>
        /// <param name="s">The XmlWriter stream to write to.</param>
        /// <param name="o">The object to graph.</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            TN tn = (TN)o;
            base.Graph(s, o, result);

            if (tn.Part.Count > 0 && tn.NullFlavor == null)
                s.WriteString(tn.Part[0].Value);
            if (tn.Part.Count > 1)
                result.AddResultDetail(new InsufficientRepetitionsResultDetail(ResultDetailType.Warning,
                    "TN is only permitted to have one part",
                    s.ToString()));
        }
예제 #17
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream</param>
        /// <param name="o">The object</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            SETFormatter formatter = new SETFormatter();
            formatter.Host = this.Host;

            // Create new generic arguments
            var uvpType = typeof(UVP<>);
            var genType = uvpType.MakeGenericType(GenericArguments);

            formatter.GenericArguments = new Type[] { genType };

            formatter.Graph(s, o, result);
        }
예제 #18
0
        /// <summary>
        /// Graph the object <paramref name="o"/> to <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Cast the object to GTS
            GTS instance = o as GTS;

            // Hull instance corrections
            if (instance.Hull != null)
            {
                if (instance.Hull.NullFlavor != null)
                {
                    instance.NullFlavor = instance.NullFlavor ?? instance.Hull.NullFlavor;
                    instance.Hull.NullFlavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.NullFlavor", "NullFlavor", instance.NullFlavor, s.ToString()));
                }
                if (instance.Hull.Flavor != null)
                {
                    instance.Flavor = instance.Flavor ?? instance.Hull.Flavor;
                    instance.Hull.Flavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.Flavor", "Flavor", instance.Flavor, s.ToString()));
                }
            }

            ANYFormatter anyFormatter = new ANYFormatter();

            // Graph the base
            anyFormatter.Graph(s, o as ANY, result);

            // Determine what type of hull we have
            if (instance.NullFlavor != null) // Null flavor specified, no hull will be graphed
            {
                return;
            }
            else if(instance.Hull == null)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, "Cannot graph a GTS with a Null Hull", s.ToString()));
                return;
            }

            object instanceHull = instance.Hull;

            if (instanceHull.GetType().Name.StartsWith("QS"))
                instanceHull = instanceHull.GetType().GetMethod("TranslateToSXPR").Invoke(instanceHull, null);

            string xsiTypeName = Util.CreateXSITypeName(instanceHull.GetType());
            s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName);

            // Output the formatting
            var hostResult = this.Host.Graph(s, (IGraphable)instanceHull);
            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);
        }
예제 #19
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Graph(s, o, result);

            // Null ?
            BL instance = o as BL;
            if (instance.NullFlavor != null)
                return;

            // Format
            if (instance.Value != null)
                s.WriteAttributeString("value", string.Format("{0}", instance.Value).ToLower());
        }
예제 #20
0
        public void Graph(XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            II instance = o as II;

            // Base graph
            base.Graph(s, o as ANY, result);

            // Handle II graphing
            if (instance.IsNull)
                return;
            if(instance.Root != null) // root
                s.WriteAttributeString("root", instance.Root);
            if (instance.Extension != null) // extension
                s.WriteAttributeString("extension", instance.Extension);
            if (instance.AssigningAuthorityName != null) // assigning authority
                s.WriteAttributeString("assigningAuthorityName", instance.AssigningAuthorityName);
            
            if(instance.Displayable != null)
                s.WriteAttributeString("displayable", instance.Displayable.ToString().ToLower());

            // JF - Use is not permitted
            if (instance.Scope != null && instance.Scope.HasValue)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                    switch (instance.Scope.Value)
                    {
                        case IdentifierScope.VersionIdentifier:
                            s.WriteAttributeString("use", "VER");
                            break;
                        case IdentifierScope.BusinessIdentifier:
                            s.WriteAttributeString("use", "BUS");
                            break;
                        default:
                            result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Scope", "II", s.ToString()));
                            break;
                    }
                else
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Scope", "II", s.ToString()));
            }

            // Non supported features
            if (instance.IdentifierName != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "IdentifierName", "II", s.ToString()));
            if(instance.Reliability != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Reliability", "II", s.ToString()));

        }
예제 #21
0
        /// <summary>
        /// Graph the object <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <param name="s">The xmlwriter to write to</param>
        /// <param name="o">The object to graph</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref
            TS instance_ts = (TS)o;

            // Do a base format
            base.Graph(s, o, result);

            // Null flavor
            if (((ANY)o).NullFlavor != null)
                return;
            
            // Timestamp
            if (instance_ts.Value != null)
                s.WriteAttributeString("value", o.ToString());

        }
예제 #22
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream</param>
        /// <param name="o">The object</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // When graphing an NPPD, we're actually graphing a set of UVP, for example
            // NPPD<INT> is really SET<UVP<INT>> 
            // This is why we do the formatting in such an odd way

            result.AddResultDetail(new MARC.Everest.Connectors.NotImplementedResultDetail(Connectors.ResultDetailType.Warning, "The NPPD type is not an official R1 data type, the data has been graphed but may not be interpreted by remote systems", s.ToString()));

            SETFormatter formatter = new SETFormatter();
            formatter.Host = this.Host;
            // Create new generic arguments
            var uvpType = typeof(UVP<>);
            var genType = uvpType.MakeGenericType(GenericArguments);

            formatter.GenericArguments = new Type[] { genType };

            formatter.Graph(s, o, result);
        }
예제 #23
0
        /// <summary>
        /// Graph this object to the specified stream
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ENFormatter formatter = new ENFormatter() { Host = this.Host };

            // Validate and remove any incriminating data
            ON instance = o as ON;
                for(int i = instance.Part.Count - 1; i >= 0; i--)
                    if (instance.Part[i].Type == EntityNamePartType.Family ||
                        instance.Part[i].Type == EntityNamePartType.Given)
                    {
                        result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                            String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", instance.Part[i]),
                            s.ToString(),
                            null));
                        instance.Part.RemoveAt(i);
                    }
            formatter.Graph(s, o, result);
        }
예제 #24
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()));
        }
예제 #25
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Want to control output of the value attribute

            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);
            PQ instance = o as PQ;

            if (instance.NullFlavor != null) return; // Don't graph anymore

            if (instance.CodingRationale != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodingRationale", "PQ", s.ToString()));
            if (instance.Expression != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "PQ", s.ToString()));
            if (instance.OriginalText != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "PQ", s.ToString()));
            if (instance.Uncertainty != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "PQ", s.ToString()));
            if (instance.UncertaintyType != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "PQ", s.ToString()));
            if (instance.UncertainRange != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "PQ", s.ToString()));
            if (instance.Unit != null)
                s.WriteAttributeString("unit", instance.Unit);
            
            // Precision
            if (instance.Precision != null && instance.Precision != 0 && instance.Value.HasValue)
                s.WriteAttributeString("value", instance.Value.Value.ToString(String.Format("0.{0}", new String('0', instance.Precision)), DatatypeFormatter.FormatterCulture));
            else if(instance.Value.HasValue)
                s.WriteAttributeString("value", instance.Value.Value.ToString(DatatypeFormatter.FormatterCulture));

            
            if (instance.Translation != null)
                foreach (var trans in instance.Translation)
                {
                    s.WriteStartElement("translation", "urn:hl7-org:v3");
                    PQRFormatter pqrFormatter = new PQRFormatter();
                    pqrFormatter.Graph(s, trans, result);
                    s.WriteEndElement();
                }

            
        }
예제 #26
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Since PQR is a CV , we can use the CD formatter to graph the basic attributes onto the stream
            PQR instance = o as PQR;

            if (instance.NullFlavor == null)
            { // Null, no need to format

                // Watch out for nargles
                if (instance.Precision != null && instance.Precision != 0 && instance.Value.HasValue)
                    s.WriteAttributeString("value", instance.Value.Value.ToString(String.Format("0.{0}", new String('0', instance.Precision), DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator), DatatypeFormatter.FormatterCulture));
                else if (instance.Value.HasValue)
                    s.WriteAttributeString("value", instance.Value.Value.ToString(DatatypeFormatter.FormatterCulture));
            }

            base.Graph(s, o as PQR, result);

           
        }
예제 #27
0
        /// <summary>
        /// Parse an SXCM
        /// </summary>
        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "s")]
        //public SXCM<T> Parse<T>(System.Xml.XmlReader s, DatatypeFormatterParseResult result) where T :  IAny, new()
        //{
        //    // Return value
        //    //SXCM<T> retVal = base.Parse<SXCM<TS>>(s result);

        //    //// Operator
        //    //if (s.GetAttribute("operator") != null)
        //    //    retVal.Operator = (SetOperator?)Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator));

        //    //return retVal;
        //    //result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Error, "SXCM is an abstract class and cannot be instantiated by itself", s.ToString(), null));
        //    //return null;
        //}

        #region IDatatypeFormatter Members

        
        /// <summary>
        /// Graph the SXCM to the console
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Output the object
            Type t = o.GetType();
            ANY any = (ANY)o;
            base.Graph(s, o, result);

            object oper = t.GetProperty("Operator").GetValue(o, null),
                valu = t.GetProperty("Value").GetValue(o, null);
            if (oper != null && any.NullFlavor == null)
                s.WriteAttributeString("operator", Util.ToWireFormat(oper));

            // Format the object
            if (valu != null)
            {
                var formatter = DatatypeFormatter.GetFormatter(valu.GetType());
                formatter.Host = this.Host;
                formatter.Graph(s, valu, result);
            }
        }
예제 #28
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref 
            ICodedSimple instance_ics = (ICodedSimple)o;

           base.Graph(s, o as ANY, result);

            // Format the coded simple
            if (instance_ics.CodeValue != null && ((ANY)o).NullFlavor == null)
                s.WriteAttributeString("code", Util.ToWireFormat(instance_ics.CodeValue));
            //if ((o is CS<String> || o.GetType().GetGenericTypeDefinition() == typeof(CS<>)))
            //{
            //    if (instance_ics.CodeSystem != null) // Warn if there is no way to represent this in R1
            //        result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystem", "CS", s.ToString()));
            //    else if (instance_ics.CodeSystemName != null)
            //        result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystemName", "CS", s.ToString()));
            //    else if (instance_ics.CodeSystemVersion != null)
            //        result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystemVersion", "CS", s.ToString()));
            //}
        }
예제 #29
0
        /// <summary>
        /// Graphs the object <paramref name="o"/> onto the stream
        /// <paramref name="s"/>.
        /// </summary>
        /// <param name="s">The XmlWriter stream to graph to.</param>
        /// <param name="o">The object to graph.</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Serialize CS
            SC cs = (SC)o;

            // Serialize ST 
            if (((ANY)o).NullFlavor != null)
                return;
            else if(cs.Code != null && !cs.Code.IsNull)
            {
                if (cs.Code.Code != null)
                    s.WriteAttributeString("code", Util.ToWireFormat(cs.Code));
                if (cs.Code.CodeSystem != null)
                    s.WriteAttributeString("codeSystem", Util.ToWireFormat(cs.Code.CodeSystem));
                if (cs.Code.CodeSystemName != null)
                    s.WriteAttributeString("codeSystemName", Util.ToWireFormat(cs.Code.CodeSystemName));
                if (cs.Code.CodeSystemVersion != null)
                    s.WriteAttributeString("codeSystemVersion", Util.ToWireFormat(cs.Code.CodeSystemVersion));
                if (cs.Code.DisplayName != null)
                    s.WriteAttributeString("displayName", Util.ToWireFormat(cs.Code.DisplayName));
                
                // Not supported properties
                if (cs.Code.ValueSet != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.ValueSet", "SC", s.ToString()));
                if (cs.Code.ValueSetVersion != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.ValueSetVersion", "SC", s.ToString()));
                if(cs.Code.CodingRationale != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.CodingRationale", "SC", s.ToString()));
                if (cs.Code.OriginalText != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.OriginalText", "SC", s.ToString()));
                if (cs.Code.Qualifier != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Qualifier", "SC", s.ToString()));
                if (cs.Code.Translation != null)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Translation", "SC", s.ToString()));
            }

            ST st = (ST)o;
            base.Graph(s, st, result);
            
        }
예제 #30
0
        /// <summary>
        /// Graph this object to the specified stream
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {


            // Validate and remove any incriminating data
            ON instance = o as ON;
            instance = new ON(instance.Use, instance.Part);
            instance.NullFlavor = (o as IAny).NullFlavor;
            instance.Flavor = (o as IAny).Flavor;

                for(int i = instance.Part.Count - 1; i >= 0; i--)
                    if (instance.Part[i].Type == EntityNamePartType.Family ||
                        instance.Part[i].Type == EntityNamePartType.Given)
                    {
                        result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                            String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", instance.Part[i]),
                            s.ToString(),
                            null));
                        instance.Part.RemoveAt(i);
                    }
            base.Graph(s, instance, result);
        }
예제 #31
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            base.Graph(s, o as ANY, result);
            AD instance = o as AD;

            // Null flavor
            if (instance == null || instance.NullFlavor != null)
            {
                return;
            }

            // use
            if (instance.Use != null)
            {
                s.WriteAttributeString("use", Util.ToWireFormat(instance.Use));
            }

            if (instance.IsNotOrdered != null)
            {
                s.WriteAttributeString("isNotOrdered", instance.IsNotOrdered.ToString().ToLower());
            }

            // parts
            if (instance.Part != null)
            {
                foreach (ADXP part in instance.Part)
                {
                    if (mapping.ContainsKey(part.Type ?? AddressPartType.AddressLine))
                    {
                        s.WriteStartElement(mapping[part.Type ?? AddressPartType.AddressLine], "urn:hl7-org:v3");
                    }
                    else
                    {
                        throw new MessageValidationException(string.Format("Can't represent address part '{0}' in datatypes R1 at '{1}'", part.Type, (s as XmlStateWriter).CurrentPath));
                    }

                    if (part is ADXPPL)
                    {
                        ADXPPLFormatter adFormatter = new ADXPPLFormatter();
                        adFormatter.Graph(s, part, result);
                    }
                    else
                    {
                        ADXPFormatter adFormatter = new ADXPFormatter();
                        adFormatter.Graph(s, part, result);
                    }

                    s.WriteEndElement();
                }
            }

            // Useable period
            if (instance.UseablePeriod != null)
            {
                s.WriteStartElement("useablePeriod", "urn:hl7-org:v3");
                GTSFormatter gtsFormatter = new GTSFormatter();
                gtsFormatter.Host = this.Host;
                gtsFormatter.Graph(s, instance.UseablePeriod, result);
                s.WriteEndElement();     // useable
            }
        }
예제 #32
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));
            }
        }
예제 #33
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);
            PQ instance = o as PQ;

            if (instance.NullFlavor != null)
            {
                return;                              // Don't graph anymore
            }
            if (instance.CodingRationale != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodingRationale", "PQ", s.ToString()));
            }
            if (instance.Expression != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "PQ", s.ToString()));
            }
            if (instance.OriginalText != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "PQ", s.ToString()));
            }
            if (instance.Uncertainty != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "PQ", s.ToString()));
            }
            if (instance.UncertaintyType != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "PQ", s.ToString()));
            }
            if (instance.UncertainRange != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "PQ", s.ToString()));
            }
            if (instance.Unit != null)
            {
                s.WriteAttributeString("unit", instance.Unit);
            }

            // Precision
            if (instance.Precision != null && instance.Precision != 0 && instance.Value.HasValue)
            {
                s.WriteAttributeString("value", instance.Value.Value.ToString(String.Format("0.{0}", new String('0', instance.Precision))));
            }
            else if (instance.Value.HasValue)
            {
                s.WriteAttributeString("value", instance.Value.Value.ToString());
            }


            if (instance.Translation != null)
            {
                foreach (var trans in instance.Translation)
                {
                    s.WriteStartElement("translation", "urn:hl7-org:v3");
                    PQRFormatter pqrFormatter = new PQRFormatter();
                    pqrFormatter.Graph(s, trans, result);
                    s.WriteEndElement();
                }
            }
        }
예제 #34
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANY            instance = o as ANY;
            XmlStateWriter stw      = s as XmlStateWriter;

            // Now render
            if (instance == null)
            {
                throw new InvalidOperationException("Could not cast object to the ANY data type");
            }
            else if (instance.NullFlavor != null)
            {
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            }
            else if (instance.Flavor != null)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    s.WriteAttributeString("specializationType", instance.Flavor);
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString()));
                }
            }

            string currentElementName = "";

            if (s is MARC.Everest.Xml.XmlStateWriter)
            {
                currentElementName = (s as MARC.Everest.Xml.XmlStateWriter).CurrentPath;
            }

            // Validate
            if (result.ValidateConformance && !instance.Validate())
            {
                result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, o.GetType().Name, currentElementName));
            }

            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, currentElementName));
                result.AddResultDetail(flavor);
            }

            // Warn if items can't be represented in R1
            if (instance.ControlActExt != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", currentElementName));
            }
            if (instance.ControlActRoot != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", currentElementName));
            }
            if (instance.ValidTimeHigh != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", currentElementName));
            }
            if (instance.ValidTimeLow != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", currentElementName));
            }
            if (instance.UpdateMode != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", currentElementName));
            }
        }
예제 #35
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            Type sxprType        = typeof(SXPR <>);
            Type sxprGenericType = sxprType.MakeGenericType(GenericArguments);

            // Format the base type
            base.Graph(s, o, result);

            // Was a nullflavor present
            if ((o as ANY).NullFlavor != null)
            {
                return;
            }

            // Current path
            string currentPath = s is XmlStateWriter ? (s as XmlStateWriter).CurrentPath : "NA";

            // Graph the operator
            PropertyInfo operatorProperty  = sxprGenericType.GetProperty("Operator"),
                         componentProperty = sxprGenericType.GetProperty("Terms");
            SetOperator?operatorValue      = (SetOperator?)operatorProperty.GetValue(o, null);
            IEnumerable componentValue     = (IEnumerable)componentProperty.GetValue(o, null);

            // Write the operator out
            if (operatorValue != null)
            {
                s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));
            }

            // Elements
            if (componentValue != null)
            {
                int count = 0;
                foreach (var component in componentValue)
                {
                    s.WriteStartElement("comp", "urn:hl7-org:v3");
                    object value    = component;
                    var    compType = component.GetType();

                    string xsiTypeName = Util.CreateXSITypeName(compType);

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

                    if (count == 0) // the first element should have no operator
                    {
                        var pi = compType.GetProperty("Operator");
                        if (pi.GetValue(component, null) != null)
                        {
                            result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "Operator won't be represented in the first object in the SXPR", s.ToString(), null));
                        }
                        pi.SetValue(component, null, null);
                    }

                    var hostGraphResult = Host.Graph(s, (IGraphable)value);
                    result.AddResultDetail(hostGraphResult.Details);

                    s.WriteEndElement(); // comp
                    count++;
                }
            }
        }
예제 #36
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            EN instance = o as EN;

            // Do a base format
            base.Graph(s, o as ANY, result);

            // Null flavor
            if (instance.NullFlavor != null)
            {
                return;
            }

            // use
            if (instance.Use != null)
            {
                s.WriteAttributeString("use", Util.ToWireFormat(instance.Use));
            }

            // parts
            if (instance.Part != null)
            {
                foreach (ENXP part in instance.Part)
                {
                    EntityNamePartType?pt = part.Type;
                    SET <CS <EntityNamePartQualifier> > qualifiers = new SET <CS <EntityNamePartQualifier> >();
                    if (part.Qualifier != null)
                    {
                        foreach (var qlf in part.Qualifier)
                        {
                            qualifiers.Add(qlf.Clone() as CS <EntityNamePartQualifier>);
                        }
                    }

                    // Title part type?
                    if (pt == EntityNamePartType.Title)
                    {
                        part.Qualifier.Add(new CS <EntityNamePartQualifier>()
                        {
                            Code = CodeValue <EntityNamePartQualifier> .Parse("TITLE")
                        }
                                           );
                        pt = null;
                    }

                    // Possible to match qualifier to a part tpye if none specified!
                    if (!qualifiers.IsEmpty)
                    {
                        CS <EntityNamePartQualifier> pfx = qualifiers.Find(a => a.Code.Equals(EntityNamePartQualifier.Prefix)),
                                                     sfx = qualifiers.Find(a => a.Code.Equals(EntityNamePartQualifier.Suffix));
                        if (pfx != null)
                        {
                            pt = EntityNamePartType.Prefix;
                            qualifiers.Remove(pfx);
                        }
                        else if (sfx != null)
                        {
                            pt = EntityNamePartType.Suffix;
                            qualifiers.Remove(sfx);
                        }
                    }

                    // Part type is not set so do it inline
                    if (pt == null)
                    {
                        if (!qualifiers.IsEmpty)
                        {
                            result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "Part has qualifier but is not being rendered as a type element, qualifier will be dropped", s.ToString(), null));
                        }
                        s.WriteString(part.Value);
                    }
                    else if (mapping.ContainsKey(pt))
                    {
                        var prt = part.Clone() as ENXP;
                        prt.Type      = pt;
                        prt.Qualifier = qualifiers;
                        s.WriteStartElement(mapping[pt], "urn:hl7-org:v3");
                        ENXPFormatter enFormatter = new ENXPFormatter();
                        enFormatter.Graph(s, prt, result);
                        s.WriteEndElement();
                    }
                    else
                    {
                        throw new MessageValidationException(string.Format("Can't represent entity name part '{0}' in datatypes R1 at '{1}'", pt, (s as XmlStateWriter).CurrentPath));
                    }
                }
            }

            // Bug: 2102 - Graph the validTime element. Since the HXIT
            // class in R2 already has validTimeLow and validTimeHigh
            // what we'll do is map these attributes to the validTime element
            if (instance.ValidTimeLow != null || instance.ValidTimeHigh != null)
            {
                IVL <TS> validTime = new IVL <TS>(instance.ValidTimeLow, instance.ValidTimeHigh);
                s.WriteStartElement("validTime", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, validTime);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement(); // valid time
            }
        }
예제 #37
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Format the UVP to the wire
            UVPFormatter uvpFormatter = new UVPFormatter();

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

            if ((o as ANY).NullFlavor != null)
            {
                return;
            }

            // Get the value of the elements, since it is a generic type
            Type   ivlType           = o.GetType();
            object 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", "URG", s.ToString()));
            }
            if (lowClosedValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "LowClosed", "URG", s.ToString()));
            }
            if (highClosedValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "HighClosed", "URG", s.ToString()));
            }

            if (lowValue != null && highValue != null) // low & high
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)lowValue);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                s.WriteStartElement("high", "urn:hl7-org:v3");
                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 URG 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 URG 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");
                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 URG 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 URG 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");
                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 URG 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 URG 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");
                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");
                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)
            {
                ;
            }
            //DOC: The next comment makes no sence, further documentation required.
            // No need for this ;
            else
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error,
                                                        "Can't create a valid representation of URG 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));
            }
        }
예제 #38
0
        public virtual void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Has this formatter found the elemScopeStack yet?
            string currentElementName = null;

            // TODO: Make all parameters XmlStateWriters, next release of Everest
            // TODO: Don't have enough time to test what this may change upstream
            if (s is XmlStateWriter)
            {
                currentElementName = (s as XmlStateWriter).CurrentElement.Name;
            }
            else
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, "Can't represent a SET or LIST using this Xml Stream as it does not inherit from an XmlStateWriter", s.ToString(), null));
                return;
            }

            // Graph base
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host = this.Host;
            baseFormatter.Graph(s, o, result);
            if (((ANY)o).IsNull)
            {
                return;
            }


            // Write the array
            IEnumerable instance = (IEnumerable)o;


            int count = 0;

            // Get each element in the instance
            IEnumerator enumerator = instance.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return;                         // No elements
            }
            // Loop through elements
            while (enumerator.Current != null)
            {
                if (count != 0) // Not the first element, write the element name again
                {
                    s.WriteStartElement(currentElementName, "urn:hl7-org:v3");
                }

                // JF: Output XSI:Type
                if (GenericArguments != null && !enumerator.Current.GetType().Equals(GenericArguments[0]))
                {
                    string xsiTypeName = Util.CreateXSITypeName(enumerator.Current.GetType());
                    s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName);
                }

                var hostResult = Host.Graph(s, (IGraphable)enumerator.Current);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                if (!enumerator.MoveNext())
                {
                    break;                         // No further objects
                }
                s.WriteEndElement();
                count++;
            }
        }
예제 #39
0
        /// <summary>
        /// Graph the object <paramref name="o"/> to <paramref name="s"/>
        /// </summary>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Cast the object to GTS
            GTS instance = o as GTS;

            // Hull instance corrections
            if (instance.Hull != null)
            {
                if (instance.Hull.NullFlavor != null)
                {
                    instance.NullFlavor      = instance.NullFlavor ?? instance.Hull.NullFlavor;
                    instance.Hull.NullFlavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.NullFlavor", "NullFlavor", instance.NullFlavor, s.ToString()));
                }
                if (instance.Hull.Flavor != null)
                {
                    instance.Flavor      = instance.Flavor ?? instance.Hull.Flavor;
                    instance.Hull.Flavor = null;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Hull.Flavor", "Flavor", instance.Flavor, s.ToString()));
                }
            }


            // Graph the base
            base.Graph(s, o as ANY, result);


            // Determine what type of hull we have
            if (instance.NullFlavor != null) // Null flavor specified, no hull will be graphed
            {
                return;
            }
            else if (instance.Hull == null)
            {
                result.AddResultDetail(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Cannot graph a GTS with a Null Hull", s.ToString()));
                return;
            }

            object instanceHull = instance.Hull;

            if (instanceHull.GetType().Name.StartsWith("QS"))
            {
                instanceHull = instanceHull.GetType().GetMethod("TranslateToSXPR").Invoke(instanceHull, null);
            }

            // Not for CDA:
            // FIX: We use GetType comparison because IS has side effects in that all IVL, PIVL, etc. are instances.
            if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.ClinicalDocumentArchitecture && (instanceHull.GetType().Equals(typeof(SXCM <TS>))))
            {
                ;
            }
            else
            {
                string xsiTypeName = Util.CreateXSITypeName(instanceHull.GetType());
                s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName);
            }

            // Output the formatting
            var hostResult = this.Host.Graph(s, (IGraphable)instanceHull);

            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);
        }
예제 #40
0
 /// <summary>
 /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
 /// </summary>
 /// <param name="s">The stream</param>
 /// <param name="o">The object</param>
 public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
 {
     base.Graph(s, o, result);
 }
예제 #41
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            // Since this is a generic type, we'll need to get the values we're interested in
            // for the formatting operation
            Type   oType       = o.GetType();
            object numerator   = oType.GetProperty("Numerator").GetValue(o, null),
                   denominator = oType.GetProperty("Denominator").GetValue(o, null);

            // Check for the QTY members
            QTY <Nullable <Double> > qtyPortion = o as QTY <Nullable <Double> >;

            // Check for non-representable properties
            if (qtyPortion.Expression != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "RTO", s.ToString()));
            }
            if (qtyPortion.OriginalText != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "RTO", s.ToString()));
            }
            if (qtyPortion.Uncertainty != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "RTO", s.ToString()));
            }
            if (qtyPortion.UncertaintyType != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "RTO", s.ToString()));
            }
            if (qtyPortion.UncertainRange != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "RTO", s.ToString()));
            }
            if (qtyPortion.Value != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Value", "RTO", s.ToString()));
            }


            IXmlStructureFormatter serFormatter = Host;

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

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

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

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

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

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

                var hostResult = serFormatter.Graph(s, (IGraphable)denominator);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

            // Append details
            //details.AddRange(serFormatter.Details);
        }
예제 #42
0
        /// <summary>
        /// Graph the object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlWriter to write the object to</param>
        /// <param name="o">The object to graph</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get an instance ref
            ED instance_ed = (ED)o;

            // Do a base format
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            // Null flavor
            if (((ANY)o).NullFlavor != null)
            {
                return;
            }

            // Attributes
            s.WriteAttributeString("representation", Util.ToWireFormat(instance_ed.Representation));
            if (instance_ed.MediaType != null)
            {
                s.WriteAttributeString("mediaType", Util.ToWireFormat(instance_ed.MediaType));
            }
            if (instance_ed.Language != null)
            {
                s.WriteAttributeString("language", instance_ed.Language);
            }
            if (instance_ed.Compression != null)
            {
                s.WriteAttributeString("compression", Util.ToWireFormat(instance_ed.Compression));
            }
            if (instance_ed.IntegrityCheck != null)
            {
                s.WriteAttributeString("integrityCheck", Convert.ToBase64String(instance_ed.IntegrityCheck));
            }
            if (instance_ed.Description != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Description", "ED", s.ToString()));
            }
            if (instance_ed.IntegrityCheckAlgorithm != null)
            {
                // Incorrect representation of the SHA1 and SHA256 names in r1
                switch ((EncapsulatedDataIntegrityAlgorithm)instance_ed.IntegrityCheckAlgorithm)
                {
                case EncapsulatedDataIntegrityAlgorithm.SHA1:
                    s.WriteAttributeString("integrityCheckAlgorithm", "SHA-1");
                    break;

                case EncapsulatedDataIntegrityAlgorithm.SHA256:
                    s.WriteAttributeString("integrityCheckAlgorithm", "SHA-256");
                    break;
                }
            }

            // Elements
            if (instance_ed.Reference != null)
            {
                TELFormatter refFormatter = new TELFormatter();
                s.WriteStartElement("reference", "urn:hl7-org:v3");
                refFormatter.Graph(s, instance_ed.Reference, result);
                s.WriteEndElement();
            }
            if (instance_ed.Thumbnail != null)
            {
                EDFormatter thumbFormatter = new EDFormatter();
                s.WriteStartElement("thumbnail", "urn:hl7-org:v3");
                thumbFormatter.Graph(s, instance_ed.Thumbnail, result);
                s.WriteEndElement();
            }
            if (instance_ed.Translation != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Translation", "ED", s.ToString()));
            }
            Encoding textEncoding = System.Text.Encoding.UTF8;

            // Value
            if (instance_ed.Data != null && instance_ed.Data.Length > 0)
            {
                if (instance_ed.Representation == EncapsulatedDataRepresentation.B64)
                {
                    s.WriteBase64(instance_ed.Data, 0, instance_ed.Data.Length);
                }
                else if (instance_ed.Representation == EncapsulatedDataRepresentation.TXT)
                {
                    s.WriteString(textEncoding.GetString(instance_ed.Data));
                }
                else
                {
                    char[] charBuffer = textEncoding.GetChars(instance_ed.Data);
                    s.WriteRaw(charBuffer, 0, charBuffer.Length);
                }
            }
        }
예제 #43
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            base.Graph(s, o, result);

            // Now graph the attributes
            Type   pivlType                  = o.GetType();
            object valueValue                = pivlType.GetProperty("Value").GetValue(o, null),
                   operatorValue             = pivlType.GetProperty("Operator").GetValue(o, null),
                   alignmentValue            = pivlType.GetProperty("Alignment").GetValue(o, null),
                   phaseValue                = pivlType.GetProperty("Phase").GetValue(o, null),
                   periodValue               = pivlType.GetProperty("Period").GetValue(o, null),
                   institutionSpecifiedValue = pivlType.GetProperty("InstitutionSpecified").GetValue(o, null),
                   countValue                = pivlType.GetProperty("Count").GetValue(o, null),
                   frequencyValue            = pivlType.GetProperty("Frequency").GetValue(o, null);

            // Append the attributes to the writer
            if ((o as ANY).NullFlavor != null)
            {
                return; // Nothing to report
            }
            if (valueValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Value", "PIVL", s.ToString()));
            }
            //s.WriteAttributeString("value", Util.ToWireFormat(valueValue));
            if (operatorValue != null)
            {
                s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));
            }
            if (alignmentValue != null)
            {
                s.WriteAttributeString("alignment", Util.ToWireFormat(alignmentValue));
            }
            if (institutionSpecifiedValue != null)
            {
                s.WriteAttributeString("institutionSpecified", Util.ToWireFormat(institutionSpecifiedValue));
            }

            if (countValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Count", "PIVL", s.ToString()));
            }

            // Write elements
            if (phaseValue != null)
            {
                s.WriteStartElement("phase", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)phaseValue);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

            if (frequencyValue != null)
            {
                // JF - Frequency is not supported by UV R1
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    s.WriteStartElement("frequency", "urn:hl7-org:v3");
                    var hostResult = this.Host.Graph(s, (IGraphable)frequencyValue);
                    result.AddResultDetail(hostResult.Details);
                    result.Code = hostResult.Code;
                    s.WriteEndElement();
                }
                else
                {
                    RTO <INT, PQ> rto = frequencyValue as RTO <INT, PQ>;
                    periodValue = rto.Denominator / rto.Numerator;
                    result.AddResultDetail(new PropertyValuePropagatedResultDetail(ResultDetailType.Warning, "Frequency", "Period", periodValue, s.ToString()));
                    s.WriteStartElement("period", "urn:hl7-org:v3");
                    var hostResult = Host.Graph(s, (IGraphable)periodValue);
                    result.AddResultDetail(hostResult.Details);
                    result.Code = hostResult.Code;
                    s.WriteEndElement();
                }
            }
            else if (periodValue != null)
            {
                s.WriteStartElement("period", "urn:hl7-org:v3");
                var hostResult = Host.Graph(s, (IGraphable)periodValue);
                result.AddResultDetail(hostResult.Details);
                result.Code = hostResult.Code;
                s.WriteEndElement();
            }
        }
예제 #44
0
        /// <summary>
        /// Graphs the object <paramref name="o"/> onto the stream
        /// <paramref name="s"/>.
        /// </summary>
        /// <param name="s">The XmlWriter stream to graph to.</param>
        /// <param name="o">The object to graph.</param>
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Serialize CS
            SC cs = (SC)o;

            // Serialize ST
            if (((ANY)o).NullFlavor != null)
            {
                return;
            }
            else if (cs.Code != null && !cs.Code.IsNull)
            {
                if (cs.Code.Code != null)
                {
                    s.WriteAttributeString("code", Util.ToWireFormat(cs.Code));
                }
                if (cs.Code.CodeSystem != null)
                {
                    s.WriteAttributeString("codeSystem", Util.ToWireFormat(cs.Code.CodeSystem));
                }
                if (cs.Code.CodeSystemName != null)
                {
                    s.WriteAttributeString("codeSystemName", Util.ToWireFormat(cs.Code.CodeSystemName));
                }
                if (cs.Code.CodeSystemVersion != null)
                {
                    s.WriteAttributeString("codeSystemVersion", Util.ToWireFormat(cs.Code.CodeSystemVersion));
                }
                if (cs.Code.DisplayName != null)
                {
                    s.WriteAttributeString("displayName", Util.ToWireFormat(cs.Code.DisplayName));
                }

                // Not supported properties
                if (cs.Code.ValueSet != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.ValueSet", "SC", s.ToString()));
                }
                if (cs.Code.ValueSetVersion != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.ValueSetVersion", "SC", s.ToString()));
                }
                if (cs.Code.CodingRationale != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.CodingRationale", "SC", s.ToString()));
                }
                if (cs.Code.OriginalText != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.OriginalText", "SC", s.ToString()));
                }
                if (cs.Code.Qualifier != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Qualifier", "SC", s.ToString()));
                }
                if (cs.Code.Translation != null)
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Translation", "SC", s.ToString()));
                }
            }

            ST st = (ST)o;

            base.Graph(s, st, result);
        }
예제 #45
0
        public virtual void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANY            instance = o as ANY;
            XmlStateWriter stw      = s as XmlStateWriter;

            // Now render
            if (instance == null)
            {
                throw new InvalidOperationException("Could not cast object to the ANY data type");
            }
            else if (instance.NullFlavor != null)
            {
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            }
            else if (instance.Flavor != null)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    s.WriteAttributeString("specializationType", instance.Flavor);
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString()));
                }
            }

            // Validate
            if (result.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = s.ToString();
                    result.AddResultDetail(r);
                }
                result.Code = ResultCode.Rejected;
            }
            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
                if (result.Code < ResultCode.AcceptedNonConformant)
                {
                    result.Code = ResultCode.AcceptedNonConformant;
                }
            }

            // Warn if items can't be represented in R1
            if (instance.ControlActExt != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", s.ToString()));
            }
            if (instance.ControlActRoot != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", s.ToString()));
            }
            if (instance.ValidTimeHigh != null && !(instance is EN))
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", s.ToString()));
            }
            if (instance.ValidTimeLow != null && !(instance is EN))
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", s.ToString()));
            }
            if (instance.UpdateMode != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", s.ToString()));
            }
        }