/// <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) { // Read value before we lose context string valStr = s.GetAttribute("value"); // Create retval PQR retVal = CDFormatter.Parse <PQR>(s, Host, 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 if (valStr != null && valStr.Contains(".")) { retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1; } else { retVal.Precision = 0; } retVal.Value = (decimal?)Util.FromWireFormat(valStr, typeof(decimal?)); // Validate ANYFormatter fmtr = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; fmtr.Validate(retVal, pathName, result); return(retVal); }
public T Parse <T>(XmlReader xr, DatatypeFormatterParseResult result) where T : ANY, new() { ANYFormatter baseFormatter = new ANYFormatter(); // Base formatter T retVal = baseFormatter.Parse <T>(xr, result); // If it is null return the null flavor if (retVal.NullFlavor != null) { return(retVal); } PropertyInfo pi = typeof(T).GetProperty("Value"); try { // Value if (xr.GetAttribute("value") != null) { pi.SetValue(retVal, Util.FromWireFormat(xr.GetAttribute("value"), pi.PropertyType), null); } } catch (Exception e) { result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, xr.ToString(), e)); } return(retVal); }
/// <summary> /// Parse the TN from the XmlReader <paramref name="s"/>. /// </summary> /// <param name="s">XmlReader stream to parse from.</param> /// <returns>Parsed TN.</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { ANYFormatter baseFormatter = new ANYFormatter(); TN tn = baseFormatter.Parse <TN>(s, result); // Parse the mixed content and add it to the list. if (!s.IsEmptyElement) { string oldName = s.LocalName; ENXP tnPart = new ENXP(""); while (s.Read() && s.NodeType != System.Xml.XmlNodeType.EndElement && s.LocalName != oldName) { if (s.NodeType == System.Xml.XmlNodeType.Text || s.NodeType == System.Xml.XmlNodeType.CDATA) { tnPart.Value += s.Value; } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } tn.Part.Add(tnPart); } return(tn); }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Represent the ST as an ED and serialize the ED ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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())); } }
/// <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); }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Get an instance ref ICodedSimple instance_ics = (ICodedSimple)o; // Do a base format ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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())); //} }
/// <summary> /// Parse the object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse ANYFormatter anyFormatter = new ANYFormatter(); GTS retVal = anyFormatter.Parse <GTS>(s, result); // Is there any need to continue? if (retVal.NullFlavor != null) { return(retVal); } // Now determine the type of GTS string typeName = s.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance"); IDatatypeFormatter formatter; // Parse the type switch (typeName) { case "IVL_TS": formatter = new IVLFormatter(); break; case "PIVL_TS": formatter = new PIVLFormatter(); break; case "EIVL_TS": formatter = new EIVLFormatter(); break; case "SXPR_TS": formatter = new SXPRFormatter(); break; case "SXCM_TS": formatter = new SXCMFormatter(); break; default: result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Error, String.Format("Cannot parse a GTS Hull of type '{0}'", typeName), s.ToString(), null)); return(null); } // Graph the Hull formatter.Host = this.Host; formatter.GenericArguments = new Type[] { typeof(TS) }; retVal.Hull = formatter.Parse(s, result) as SXCM <TS>; // Correct the flavor, the flavor of the hull becomes the flavor of the object retVal.Flavor = retVal.Flavor ?? retVal.Hull.Flavor; retVal.Hull.Flavor = null; retVal.NullFlavor = retVal.NullFlavor ?? (retVal.Hull.NullFlavor != null ? retVal.Hull.NullFlavor.Clone() as CS <NullFlavor> : null); retVal.Hull.NullFlavor = null; // Set the details return(retVal); }
/// <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); }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Get an instance ref TEL instance_tel = (TEL)o; // Do a base format ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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 } //foreach (SXCM<TS> up in instance_tel.UseablePeriod) //{ // // Start element // s.WriteStartElement("useablePeriod", "urn:hl7-org:v3"); // // Attributes for SXCM // if(up.Operator != null) // s.WriteAttributeString("operator", Util.ToWireFormat(up.Operator)); // // Timestamp portion // TSFormatter tsFormatter = new TSFormatter(); // tsFormatter.Graph(s, (TS)up, result); // s.WriteEndElement(); // end usablePeriod //} }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { AD instance = o as AD; // Do a base format ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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)); } 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)); } 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(); } }
public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { ANYFormatter pdvFormatter = new ANYFormatter(); // parse PDV portion Type uvpType = typeof(UVP <>).MakeGenericType(GenericArguments); ConstructorInfo ci = uvpType.GetConstructor(Type.EmptyTypes); ANY retVal = ci.Invoke(null) as ANY; // Property information PropertyInfo probabilityProperty = uvpType.GetProperty("Probability"), valueProperty = uvpType.GetProperty("Value"); // Clean the if (s.GetAttribute("type", DatatypeFormatter.NS_XSI) != null && s is XmlStateReader) { (s as XmlStateReader).AddFakeAttribute("type", Util.CreateXSITypeName(GenericArguments[0])); } // Probability if (s.GetAttribute("probability") != null) { 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 { probabilityProperty.SetValue(retVal, prob, null); } } // Set value var hostResult = Host.Parse(s, GenericArguments[0]); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); valueProperty.SetValue(retVal, hostResult.Structure, null); // Move null flavors and flavors up ANY resultAny = hostResult.Structure as ANY; retVal.NullFlavor = resultAny.NullFlavor; resultAny.NullFlavor = null; retVal.Flavor = resultAny.Flavor; resultAny.Flavor = null; // 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 from</param> /// <returns>The parsed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // The SC to return. ANYFormatter baseFormatter = new ANYFormatter(); SC sc = baseFormatter.Parse <SC>(s, result); if (sc.NullFlavor != null) { return(sc); } if (s.GetAttribute("code") != null || s.GetAttribute("codeSystem") != null || s.GetAttribute("codeSystemVersion") != null || s.GetAttribute("codeSystemName") != null || s.GetAttribute("displayName") != null) { sc.Code = new CD <string>(); } if (s.GetAttribute("code") != null) { sc.Code.Code = Util.Convert <CodeValue <String> >(s.GetAttribute("code")); } if (s.GetAttribute("codeSystem") != null) { sc.Code.CodeSystem = s.GetAttribute("codeSystem"); } if (s.GetAttribute("codeSystemVersion") != null) { sc.Code.CodeSystemVersion = s.GetAttribute("codeSystemVersion"); } if (s.GetAttribute("codeSystemName") != null) { sc.Code.CodeSystemName = s.GetAttribute("codeSystemName"); } if (s.GetAttribute("displayName") != null) { sc.Code.DisplayName = s.GetAttribute("displayName"); } // Read the ST parts STFormatter stFormatter = new STFormatter(); ST st = (ST)stFormatter.Parse(s, result); sc.Language = st.Language; sc.Value = st.Value; return(sc); }
public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse TS BL retVal = baseFormatter.Parse <BL>(s, result); // Now parse our data out... Attributes if (s.GetAttribute("value") != null) { retVal.Value = Convert.ToBoolean(s.GetAttribute("value")); } return(retVal); }
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)); } }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { TN tn = (TN)o; ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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 InsufficientRepetionsResultDetail(ResultDetailType.Warning, "TN is only permitted to have one part", s.ToString())); } }
/// <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())); } }
/// <summary> /// Parse this object /// </summary> public object Parse(XmlReader s, DatatypeFormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse CS II retVal = baseFormatter.Parse <II>(s, result); // Now parse our data out... Attributes if (s.GetAttribute("root") != null) { retVal.Root = s.GetAttribute("root"); } if (s.GetAttribute("extension") != null) { retVal.Extension = s.GetAttribute("extension"); } if (s.GetAttribute("displayable") != null) { retVal.Displayable = (bool)Util.FromWireFormat(s.GetAttribute("displayable"), typeof(bool)); } if (s.GetAttribute("use") != null) { switch (s.GetAttribute("use")) { case "VER": retVal.Scope = IdentifierScope.VersionIdentifier; break; case "BUS": retVal.Scope = IdentifierScope.BusinessIdentifier; break; } } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }
public void Graph(XmlWriter xw, object o, DatatypeFormatterGraphResult result) { // Graph this object to the stream ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(xw, o, result); // Graph the any part of this if (o.GetType().GetProperty("NullFlavor").GetValue(o, null) != null) { return; // No further graphing } // Now comes the fun part .. we'll need to graph the Value property onto the stream, object valueValue = o.GetType().GetProperty("Value").GetValue(o, null); if (valueValue != null) { xw.WriteAttributeString("value", Util.ToWireFormat(valueValue)); } }
/// <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) { 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)))); } else if (instance.Value.HasValue) { s.WriteAttributeString("value", instance.Value.Value.ToString()); } // 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())); } }
/// <summary> /// Grap the object to a stream /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ADXP instance = o as ADXP; // Start with part type and code attributes ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.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.Code != null) { if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { s.WriteAttributeString("code", instance.Code); } else { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code", "ADXP", s.ToString())); } } 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", "ADXP", s.ToString())); } if (instance.CodeSystemVersion != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystemVersion", "ADXP", s.ToString())); } }
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()); } }
/// <summary> /// Parse an ADXP from stream <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse CS ADXP retVal = baseFormatter.Parse <ADXP>(s, result); // Now parse our data out... if (!s.IsEmptyElement) { if (s.GetAttribute("code") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { retVal.Code = s.GetAttribute("code"); } else { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "code", "ADXP", s.ToString())); } // Read next for text elemnt string sName = s.Name; s.Read(); while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name)) { if (s.NodeType == System.Xml.XmlNodeType.Text) { retVal.Value = s.Value; } s.Read(); } } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse function /// </summary> /// <param name="s"></param> /// <returns></returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { var retVal = CDFormatter.Parse <CD <String> >(s, Host, result); CO instance = new CO(); instance.Code = retVal; // Propogate if (instance.Code != null) { instance.Flavor = instance.Code.Flavor; instance.NullFlavor = instance.Code.NullFlavor; instance.Code.NullFlavor = null; instance.Code.Flavor = null; } ANYFormatter fmtr = new ANYFormatter(); fmtr.Validate(instance, s.ToString(), result); return(instance); }
/// <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 void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { // Get an instance ref TS instance_ts = (TS)o; // Do a base format ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(s, o, result); // Null flavor if (((ANY)o).NullFlavor != null) { return; } // Timestamp if (instance_ts.Value != null) { s.WriteAttributeString("value", o.ToString()); } }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The XmlReader to parse from</param> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse TS TS retVal = baseFormatter.Parse <TS>(s, result); // Now parse our data out... Attributes if (s.GetAttribute("value") != null) { retVal.Value = s.GetAttribute("value"); } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse an ENXP from stream <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse CS ENXP retVal = baseFormatter.Parse <ENXP>(s, result); // Part Type is ignored by this formatter but qualifier is not if (s.GetAttribute("qualifier") != null) { retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier")); } // Now parse our data out... if (!s.IsEmptyElement) { // Read next for text elemnt string sName = s.Name; s.Read(); while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name)) { if (s.NodeType == System.Xml.XmlNodeType.Text) { retVal.Value = s.Value; } s.Read(); } } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.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) { // Graph this UVP to the stream ANYFormatter pdvFormatter = new ANYFormatter(); pdvFormatter.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 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); }
/// <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 } }
/// <summary> /// Graph object <paramref name="o"/> onto <paramref name="s"/> /// </summary> public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANYFormatter anyFormatter = new ANYFormatter(); anyFormatter.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"); Host.GraphObject(s, (IGraphable)eventValue); s.WriteEndElement(); } if (offsetValue != null) { s.WriteStartElement("offset", "urn:hl7-org:v3"); Host.GraphObject(s, (IGraphable)offsetValue); s.WriteEndElement(); } }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse</param> /// <returns>The parsed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Parse the address parts // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse CS AD retVal = baseFormatter.Parse <AD>(s, result); // Now parse our data out... Attributes if (s.GetAttribute("use") != null) { retVal.Use = (SET <CS <PostalAddressUse> >)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET <CS <PostalAddressUse> >)); } if (s.GetAttribute("isNotOrdered") != null) { retVal.IsNotOrdered = (bool)Util.FromWireFormat(s.GetAttribute("isNotOrdered"), typeof(bool)); } // Loop through content // 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 { AddressPartType?adxpType; // Address part type // JF - This is a Canadian extension if (s.LocalName == "useablePeriod") // Usable Period, since this is an SXCM we'll need to read manually { // Useable period doesn't exist GTSFormatter sxcmFormatter = new GTSFormatter(); sxcmFormatter.Host = this.Host; retVal.UseablePeriod = sxcmFormatter.Parse(s, result) as GTS; } if (reverseMapping.TryGetValue(s.LocalName, out adxpType)) // Reverse map exists, so this is a part { ADXPFormatter adxpFormatter = new ADXPFormatter(); // ADXP Formatter adxpFormatter.Host = this.Host; ADXP part = (ADXP)adxpFormatter.Parse(s, result); // Parse part.Type = adxpType; retVal.Part.Add(part); // Add to AD } } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details } finally { if (oldName == s.Name) { s.Read(); // Read if we need to } } } } #endregion // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }