/// <summary> /// Parse an object from stream <paramref name="s"/> /// </summary> /// <param name="s">The stream to read from</param> /// <returns>The parsed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { PDVFormatter pdvFormatter = new PDVFormatter(); MO retVal = pdvFormatter.Parse <MO>(s, result); if (s.GetAttribute("currency") != null) { retVal.Currency = s.GetAttribute("currency"); } // Precision is not supported in R1, but is still useful to have so // we will report the precision of the data that was on the wire string valStr = s.GetAttribute("value"); if (valStr != null && valStr.Contains(".")) { retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1; } else { retVal.Precision = 0; } // Validate ANYFormatter fmtr = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; fmtr.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse from</param> /// <returns>The parsed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { PDVFormatter pdvFormatter = new PDVFormatter(); INT retVal = pdvFormatter.Parse <INT>(s, result); return(retVal); }
/// <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())); } }
public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse the base PDV first PDVFormatter pdvFormatter = new PDVFormatter(); URG <Object> retVal = pdvFormatter.Parse <URG <Object> >(s, result); if (retVal.NullFlavor != null) // Null, no longer process { return(retVal); } if (s.GetAttribute("probability") != null) // Probability { decimal prob = (decimal)0.0f; if (!Decimal.TryParse(s.GetAttribute("probability"), out prob)) // Try to parse { result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, string.Format("Value '{0}' can't be processed into 'Probability' on data type UVP", s.GetAttribute("probability")), s.ToString(), null)); } else // Success, so assign { retVal.Probability = prob; } } // Serialization IXmlStructureFormatter serHost = this.Host; // Elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "low") // Low , parse using the proper type { var hostResult = serHost.Parse(s, GenericArguments[0]); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.Low = hostResult.Structure; } else if (s.LocalName == "width") // Width { var hostResult = serHost.Parse(s, typeof(PQ)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.Width = hostResult.Structure as PQ; } else if (s.LocalName == "high") // High { var hostResult = serHost.Parse(s, GenericArguments[0]); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.High = hostResult.Structure; } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate the data type ANYFormatter validator = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; validator.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse</param> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { PDVFormatter pdvFormatter = new PDVFormatter(); PQ retVal = pdvFormatter.Parse <PQ>(s, result); if (s.GetAttribute("unit") != null) { retVal.Unit = s.GetAttribute("unit"); } // Precision is not supported in R1, but is still useful to have so // we will report the precision of the data that was on the wire string valStr = s.GetAttribute("value"); if (valStr != null && valStr.Contains(".")) { retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1; } else { retVal.Precision = 0; } #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "translation") // Format using ED { SETFormatter pqrFormatter = new SETFormatter(); pqrFormatter.GenericArguments = new Type[] { typeof(PQR) }; pqrFormatter.Host = Host.Clone() as IXmlStructureFormatter; retVal.Translation = new SET <PQR>((LIST <IGraphable>)pqrFormatter.Parse(s, result)); // Parse ED //details.AddRange(pqrFormatter.Details); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate ANYFormatter fmtr = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; fmtr.Validate(retVal, pathName, result); return(retVal); }
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)); } }