/// <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> /// Gets the list of supported properties /// </summary> /// <returns></returns> public List<System.Reflection.PropertyInfo> GetSupportedProperties() { var retVal = new QTYFormatter().GetSupportedProperties(); retVal.AddRange(new PropertyInfo[] { typeof(INT).GetProperty("Value"), typeof(INT).GetProperty("Expression"), typeof(INT).GetProperty("OriginalText"), typeof(INT).GetProperty("Uncertainty"), typeof(INT).GetProperty("UncertainRange") }); return retVal; }
/// <summary> /// Graph object <paramref name="o"/> onto <paramref name="s"/> /// </summary> /// <param name="s">The stream being graphed to</param> /// <param name="o">The object being graphed</param> /// <param name="result">The result of the graph operation</param> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // Graph the QTY portions QTYFormatter qty = new QTYFormatter(); qty.Host = this.Host; qty.Graph(s, o, result); // Any null flavors IAny anyO = o as IAny; IPrimitiveDataValue ipdv = o as IPrimitiveDataValue; if (anyO.NullFlavor != null) return; // PDV Value does not support value if (ipdv.Value != null) result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(MARC.Everest.Connectors.ResultDetailType.Warning, "Value", "RTO", s.ToString())); // Get the numerator / denominator PropertyInfo numeratorProperty = o.GetType().GetProperty("Numerator"), denominatorProperty = o.GetType().GetProperty("Denominator"); object numerator = numeratorProperty.GetValue(o, null), denominator = denominatorProperty.GetValue(o, null); // Serialize the numerator if (numerator != null) { s.WriteStartElement("numerator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(numerator.GetType()); // Write the type if (this.Host.Host == null) s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); else s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); var hostResult = this.Host.Graph(s, (IGraphable)numerator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } // Serialize Denominator if (denominator != null) { s.WriteStartElement("denominator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(denominator.GetType()); // Write the type if (this.Host.Host == null) s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); else s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); var hostResult = this.Host.Graph(s, (IGraphable)denominator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } }
/// <summary> /// Gets the list of supported properties /// </summary> /// <returns></returns> public List<System.Reflection.PropertyInfo> GetSupportedProperties() { var retVal = new QTYFormatter().GetSupportedProperties(); retVal.AddRange(new PropertyInfo[] { typeof(CO).GetProperty("Code"), typeof(CO).GetProperty("Value"), }); 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; }