/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { PDVFormatter qtyf = new PDVFormatter(); qtyf.Host = this.Host; var retVal = qtyf.Parse<INT>(s, result); return retVal; }
/// <summary> /// Graphs <paramref name="o"/> onto <paramref name="s"/> storing result /// in <paramref name="result"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // Get a strongly typed instance of o PQ opq = o as PQ; // Output additional attributes // Since a PQ with null flavor derived can still have a unit // we only want to check for null flavors not derived if (opq.NullFlavor == null || opq.NullFlavor.Equals(NullFlavor.Derived)) { if (opq.Unit != null) s.WriteAttributeString("unit", Util.ToWireFormat(opq.Unit)); if (opq.CodingRationale != null) s.WriteAttributeString("codingRationale", Util.ToWireFormat(opq.CodingRationale)); } // Output the PDV and QTY formatter helper data PDVFormatter pdvFormatter = new PDVFormatter(); pdvFormatter.Host = this.Host; pdvFormatter.Graph(s, o, result); // Output the translations (if they exist) if(opq.Translation != null && (opq.NullFlavor == null || opq.NullFlavor.Equals(NullFlavor.Derived))) foreach (var trans in opq.Translation) { s.WriteStartElement("translation", "urn:hl7-org:v3"); // Graph var hostResult = this.Host.Graph(s, trans); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { PDVFormatter qtyf = new PDVFormatter(); qtyf.Host = this.Host; return qtyf.Parse<REAL>(s, result); }
/// <summary> /// Parse the PQ back into a structure /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the base formatter PDVFormatter baseFormatter = new PDVFormatter(); baseFormatter.Host = this.Host; // Read temporary values string tCurrency = String.Empty; if(s.GetAttribute("currency") != null) tCurrency = s.GetAttribute("currency"); // Parse PDV content var retVal = baseFormatter.Parse<MO>(s, result); // Set PDV content retVal.Currency = tCurrency; // Validate ANYFormatter anyFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; anyFormatter.Validate(retVal as ANY, pathName, result); // Return instance return retVal; }
/// <summary> /// Graph <paramref name="o"/> onto <paramref name="s"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { PDVFormatter qtyf = new PDVFormatter(); qtyf.Host = this.Host; qtyf.Graph(s, o, result); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { PDVFormatter baseFormatter = new PDVFormatter(); baseFormatter.Host = this.Host; var retVal = baseFormatter.ParseAttributes<CO>(s, result); // Process the parts #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); QTYFormatter qtyf = new QTYFormatter(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Numerator if (s.LocalName == "code" && retVal.Code == null) { var parseResult = Host.Parse(s, typeof(CD<String>)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Code = parseResult.Structure as CD<String>; } else if (s.LocalName == "code") result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Code can only be assigned once", s.ToString())); else qtyf.ParseElementsInline(s, retVal, result); } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) s.Read(); } } } #endregion // Validate new ANYFormatter().Validate(retVal, s.ToString(), result); return retVal; }
/// <summary> /// Graphs <paramref name="o"/> onto <paramref name="s"/> storing result /// in <paramref name="result"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // Get a strongly typed instance of o MO omo = o as MO; // Output additional attributes // Since a MO with null flavor derived can still have a currency // we only want to check for null flavors not derived if (omo.NullFlavor == null || omo.NullFlavor.Equals(NullFlavor.Derived)) { if (omo.Currency != null) s.WriteAttributeString("currency", Util.ToWireFormat(omo.Currency)); } // Output the PDV and QTY formatter helper data PDVFormatter pdvFormatter = new PDVFormatter(); pdvFormatter.Host = this.Host; pdvFormatter.Graph(s, o, result); }
/// <summary> /// Graph <paramref name="o"/> onto <paramref name="s"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { PDVFormatter qtyf = new PDVFormatter(); qtyf.Host = this.Host; qtyf.Graph(s, o, result); CO instance = o as CO; // Code property if (instance.NullFlavor != null) return; if (instance.Code != null) { s.WriteStartElement("code", "urn:hl7-org:v3"); var hostResult = this.Host.Graph(s, instance.Code); result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } }
/// <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(); REAL retVal = pdvFormatter.Parse<REAL>(s, result); // 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> /// 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())); }
/// <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> /// 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 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 the PQ back into a structure /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the base formatter PDVFormatter baseFormatter = new PDVFormatter(); baseFormatter.Host = this.Host; // Read temporary values string tUnit = null; if(s.GetAttribute("unit") != null) tUnit = s.GetAttribute("unit"); SET<CodingRationale> tRationale = null; if (s.GetAttribute("codingRationale") != null) tRationale = Util.Convert<SET<CodingRationale>>(s.GetAttribute("codingRationale")); // Parse PDV content (only attributes) var retVal = baseFormatter.ParseAttributes<PQ>(s, result); // Set PDV content retVal.Unit = tUnit; retVal.CodingRationale = tRationale; // Process elements // This requires a QTY formatter as QTY elements may be // in the stream as well #region Elements if (!s.IsEmptyElement) { // Prepare a formatter to process QTY elements QTYFormatter qtyFormatter = new QTYFormatter(); qtyFormatter.Host = this.Host; // Exit markers int sDepth = s.Depth; string sName = s.Name; // Translations SET<PQR> translations = new SET<PQR>(); // Read the next element s.Read(); // Read until exit condition is fulfilled 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 { var hostResult = Host.Parse(s, typeof(PQR)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); translations.Add(hostResult.Structure as PQR); } else qtyFormatter.ParseElementsInline(s, retVal, result); } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e)); } finally { if (s.Name == oldName) s.Read(); } } // Set translations if (!translations.IsEmpty) retVal.Translation = translations; } #endregion // Validate ANYFormatter anyFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; anyFormatter.Validate(retVal as ANY, pathName, result); // REturn instance return retVal; }