public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { CO instance = (o as ANY).Clone() as CO; // We'll be modifying data instance.Code = (instance.Code ?? new CD <String>()).Clone() as CD <String>; // CO is identical on the wire as a cv in dt r1 CVFormatter formatter = new CVFormatter(); formatter.Host = this.Host; // First, is the instance null? if (instance == null) { return; } else if (instance.IsNull) { if (instance.Code == null) { instance.Code = new CD <string>(); } else if (instance.Code.IsNull) { result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "NullFlavor from CO instance will overwrite NullFlavor from Code Property", s.ToString(), null)); } instance.Code.NullFlavor = instance.NullFlavor; } else if (instance.Flavor != null) { if (instance.Code == null) { instance.Code = new CD <string>(); } else if (instance.Code.Flavor != null) { result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "Flavor from CO instance will overwrite Flavor from Code Property", s.ToString(), null)); } instance.Code.Flavor = instance.Flavor; } // Graph formatter.Graph(s, instance.Code, result); // Append details if (instance.Value != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Value", "CO", s.ToString())); } else if (instance.Code != null && instance.Code.Qualifier != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Qualifier", "CO", s.ToString())); } else if (instance.Code != null && instance.Code.Translation != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Translation", "CO", s.ToString())); } }
public 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 CVFormatter formatter = new CVFormatter(); PQR instance = o as PQR; if (instance.NullFlavor != null) { return; // 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)))); } else if (instance.Value.HasValue) { s.WriteAttributeString("value", instance.Value.Value.ToString()); } formatter.Graph(s, o as PQR, result); }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Get an instance ref ICodedEquivalents instance_ics = (ICodedEquivalents)o; // Do a base format CVFormatter baseFormatter = new CVFormatter(); baseFormatter.Graph(s, o, result); // Format the coded simple if (instance_ics.Translation != null) // Original Text { foreach (IGraphable ig in instance_ics.Translation) { s.WriteStartElement("translation", "urn:hl7-org:v3"); var hostResult = Host.Graph(s, ig); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } } }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(s, o, result); // Graph the base data // If there is no null flavor then graph the rest of the object 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"); CVFormatter cdFormatter = new CVFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, nameValue, result); s.WriteEndElement(); // end name } if (valueValue != null) { s.WriteStartElement("value"); CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, valueValue, result); s.WriteEndElement(); // end value } }
public 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 CVFormatter formatter = new CVFormatter(); PQR instance = o as PQR; if (instance.NullFlavor != null) return; // 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)))); else if (instance.Value.HasValue) s.WriteAttributeString("value", instance.Value.Value.ToString()); formatter.Graph(s, o as PQR, result); }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Get an instance ref ICodedEquivalents instance_ics = (ICodedEquivalents)o; // Do a base format CVFormatter baseFormatter = new CVFormatter(); baseFormatter.Graph(s, o, result); // Format the coded simple if (instance_ics.Translation != null) // Original Text { foreach (IGraphable ig in instance_ics.Translation) { s.WriteStartElement("translation", "urn:hl7-org:v3"); var hostResult = Host.Graph(s, ig); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } } }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse the object from</param> /// <returns>The constructed object</returns> public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { Type crGenericType = typeof(CR<>).MakeGenericType(GenericArguments); ConstructorInfo ci = crGenericType.GetConstructor(Type.EmptyTypes); if (ci == null) throw new InvalidOperationException("Type being parsed must have parameterless constructor"); object instance = ci.Invoke(null); // NullFlavor ? if (s.GetAttribute("nullFlavor") != null) ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor)); // JF - Supported only in CA extensions to R1 data types if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) ((ANY)instance).Flavor = s.GetAttribute("specializationType"); // Inverted if (s.GetAttribute("inverted") != null) crGenericType.GetProperty("Inverted").SetValue(instance, Util.FromWireFormat(s.GetAttribute("inverted"), typeof(bool)), null); #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 == "name") // Format using ED { CVFormatter cvFormatter = new CVFormatter(); cvFormatter.Host = this.Host; cvFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Name").SetValue(instance, Util.FromWireFormat(cvFormatter.Parse(s, result), crGenericType.GetProperty("Name").PropertyType), null); } else if (s.LocalName == "value") { CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(cdFormatter.Parse(s, result), crGenericType.GetProperty("Value").PropertyType), null); } else result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } 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(); } } } #endregion base.Validate((ANY)instance, s.ToString(), result); return instance; }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(s, o, result); // Graph the base data // If there is no null flavor then graph the rest of the object 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"); CVFormatter cdFormatter = new CVFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, nameValue, result); s.WriteEndElement(); // end name } if (valueValue != null) { s.WriteStartElement("value"); CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, valueValue, result); s.WriteEndElement(); // end value } }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { CO instance = (o as ANY).Clone() as CO; // We'll be modifying data instance.Code = (instance.Code ?? new CD<String>()).Clone() as CD<String>; // CO is identical on the wire as a cv in dt r1 CVFormatter formatter = new CVFormatter(); formatter.Host = this.Host; // First, is the instance null? if (instance == null) return; else if (instance.IsNull) { if (instance.Code == null) instance.Code = new CD<string>(); else if (instance.Code.IsNull) result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "NullFlavor from CO instance will overwrite NullFlavor from Code Property", s.ToString(), null)); instance.Code.NullFlavor = instance.NullFlavor; } else if (instance.Flavor != null) { if (instance.Code == null) instance.Code = new CD<string>(); else if (instance.Code.Flavor != null) result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "Flavor from CO instance will overwrite Flavor from Code Property", s.ToString(), null)); instance.Code.Flavor = instance.Flavor; } // Graph formatter.Graph(s, instance.Code, result); // Append details if(instance.Value != null) result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Value", "CO", s.ToString())); else if(instance.Code != null && instance.Code.Qualifier != null) result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Qualifier", "CO", s.ToString())); else if (instance.Code != null && instance.Code.Translation != null) result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code.Translation", "CO", s.ToString())); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse the object from</param> /// <returns>The constructed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { Type crGenericType = typeof(CR <>).MakeGenericType(GenericArguments); ConstructorInfo ci = crGenericType.GetConstructor(Type.EmptyTypes); if (ci == null) { throw new InvalidOperationException("Type being parsed must have parameterless constructor"); } object instance = ci.Invoke(null); // NullFlavor ? if (s.GetAttribute("nullFlavor") != null) { ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor)); } else { // JF - Supported only in CA extensions to R1 data types if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { ((ANY)instance).Flavor = s.GetAttribute("specializationType"); } // Inverted if (s.GetAttribute("inverted") != null) { crGenericType.GetProperty("Inverted").SetValue(instance, Util.FromWireFormat(s.GetAttribute("inverted"), typeof(bool)), null); } #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 == "name") // Format using ED { CVFormatter cvFormatter = new CVFormatter(); cvFormatter.Host = this.Host; cvFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Name").SetValue(instance, Util.FromWireFormat(cvFormatter.Parse(s, result), crGenericType.GetProperty("Name").PropertyType), null); } else if (s.LocalName == "value") { CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(cdFormatter.Parse(s, result), crGenericType.GetProperty("Value").PropertyType), null); } } 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(); } } } } #endregion } return(instance); }