/// <summary> Populates the given Type object with data from the given XML Element.</summary> public virtual void parse(Type datatypeObject, System.Xml.XmlElement datatypeElement) { if (datatypeObject is Varies) { parseVaries((Varies)datatypeObject, datatypeElement); } else if (datatypeObject is Primitive) { parsePrimitive((Primitive)datatypeObject, datatypeElement); } else if (datatypeObject is Composite) { parseComposite((Composite)datatypeObject, datatypeElement); } }
/// <summary> Fills a field with values from an unparsed string representing the field. </summary> /// <param name="destinationField">the field Type /// </param> /// <param name="data">the field string (including all components and subcomponents; not including field delimiters) /// </param> /// <param name="encodingCharacters">the encoding characters used in the message /// </param> private static void parse(Type destinationField, System.String data, NuGenEncodingCharacters encodingCharacters) { System.String[] components = split(data, System.Convert.ToString(encodingCharacters.ComponentSeparator)); for (int i = 0; i < components.Length; i++) { System.String[] subcomponents = split(components[i], System.Convert.ToString(encodingCharacters.SubcomponentSeparator)); for (int j = 0; j < subcomponents.Length; j++) { System.String val = subcomponents[j]; if (val != null) { val = NuGenEscape.unescape(val, encodingCharacters); } Terser.getPrimitive(destinationField, i + 1, j + 1).Value = val; } } }
/// <summary> Encodes the given Type, using the given encoding characters. /// It is assumed that the Type represents a complete field rather than a component. /// </summary> public static System.String encode(Type source, NuGenEncodingCharacters encodingChars) { System.Text.StringBuilder field = new System.Text.StringBuilder(); for (int i = 1; i <= Terser.numComponents(source); i++) { System.Text.StringBuilder comp = new System.Text.StringBuilder(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.Append(encodePrimitive(p, encodingChars)); comp.Append(encodingChars.SubcomponentSeparator); } field.Append(stripExtraDelimiters(comp.ToString(), encodingChars.SubcomponentSeparator)); field.Append(encodingChars.ComponentSeparator); } return(stripExtraDelimiters(field.ToString(), encodingChars.ComponentSeparator)); //return encode(source, encodingChars, false); }
/// <summary> Populates the given Element with data from the given Type, by inserting /// Elements corresponding to the Type's components and values. Returns true if /// the given type contains a value (i.e. for Primitives, if getValue() doesn't /// return null, and for Composites, if at least one underlying Primitive doesn't /// return null). /// </summary> private bool encode(Type datatypeObject, System.Xml.XmlElement datatypeElement) { bool hasData = false; if (datatypeObject is Varies) { hasData = encodeVaries((Varies)datatypeObject, datatypeElement); } else if (datatypeObject is Primitive) { hasData = encodePrimitive((Primitive)datatypeObject, datatypeElement); } else if (datatypeObject is Composite) { hasData = encodeComposite((Composite)datatypeObject, datatypeElement); } return(hasData); }
private void parse(System.String field, Segment segment, int num, NuGenEncodingCharacters ec) { if (field != null) { int rep = 0; int component = 1; int subcomponent = 1; Type type = segment.getField(num, rep); System.String delim = System.Convert.ToString(new char[] { ec.RepetitionSeparator, ec.ComponentSeparator, ec.SubcomponentSeparator }); for (SupportClass.Tokenizer tok = new SupportClass.Tokenizer(field, delim, true); tok.HasMoreTokens();) { System.String token = tok.NextToken(); char c = token[0]; if (c == ec.RepetitionSeparator) { rep++; component = 1; subcomponent = 1; type = segment.getField(num, rep); } else if (c == ec.ComponentSeparator) { component++; subcomponent = 1; } else if (c == ec.SubcomponentSeparator) { subcomponent++; } else { Primitive p = Terser.getPrimitive(type, component, subcomponent); p.Value = token; } } } }
/// <summary> Encodes the given Type, using the given encoding characters. /// It is assumed that the Type represents a complete field rather than a component. /// </summary> public static System.String encode(Type source, NuGenEncodingCharacters encodingChars) { System.Text.StringBuilder field = new System.Text.StringBuilder(); for (int i = 1; i <= Terser.numComponents(source); i++) { System.Text.StringBuilder comp = new System.Text.StringBuilder(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.Append(encodePrimitive(p, encodingChars)); comp.Append(encodingChars.SubcomponentSeparator); } field.Append(stripExtraDelimiters(comp.ToString(), encodingChars.SubcomponentSeparator)); field.Append(encodingChars.ComponentSeparator); } return stripExtraDelimiters(field.ToString(), encodingChars.ComponentSeparator); //return encode(source, encodingChars, false); }
/// <summary> Parses a segment string and populates the given Segment object. Unexpected fields are /// added as Varies' at the end of the segment. /// /// </summary> /// <throws> HL7Exception if the given string does not contain the </throws> /// <summary> given segment or if the string is not encoded properly /// </summary> public virtual void parse(Segment destination, System.String segment, NuGenEncodingCharacters encodingChars) { int fieldOffset = 0; if (isDelimDefSegment(destination.getName())) { fieldOffset = 1; //set field 1 to fourth character of string Terser.set_Renamed(destination, 1, 0, 1, 1, System.Convert.ToString(encodingChars.FieldSeparator)); } System.String[] fields = split(segment, System.Convert.ToString(encodingChars.FieldSeparator)); //destination.setName(fields[0]); for (int i = 1; i < fields.Length; i++) { System.String[] reps = split(fields[i], System.Convert.ToString(encodingChars.RepetitionSeparator)); //MSH-2 will get split incorrectly so we have to fudge it ... bool isMSH2 = isDelimDefSegment(destination.getName()) && i + fieldOffset == 2; if (isMSH2) { reps = new System.String[1]; reps[0] = fields[i]; } for (int j = 0; j < reps.Length; j++) { try { System.Text.StringBuilder statusMessage = new System.Text.StringBuilder("Parsing field "); statusMessage.Append(i + fieldOffset); statusMessage.Append(" repetition "); statusMessage.Append(j); //parse(destination.getField(i + fieldOffset, j), reps[j], encodingChars, false); Type field = destination.getField(i + fieldOffset, j); if (isMSH2) { Terser.getPrimitive(field, 1, 1).Value = reps[j]; } else { parse(field, reps[j], encodingChars); } } catch (NuGenHL7Exception e) { //set the field location and throw again ... e.FieldPosition = i; e.SegmentRepetition = MessageIterator.getIndex(destination.Parent, destination).rep; e.SegmentName = destination.getName(); throw e; } } } //set data type of OBX-5 if (destination.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(destination, Factory); } }
/// <summary> Populates the given Element with data from the given Type, by inserting /// Elements corresponding to the Type's components and values. Returns true if /// the given type contains a value (i.e. for Primitives, if getValue() doesn't /// return null, and for Composites, if at least one underlying Primitive doesn't /// return null). /// </summary> private bool encode(Type datatypeObject, System.Xml.XmlElement datatypeElement) { bool hasData = false; if (datatypeObject is Varies) { hasData = encodeVaries((Varies) datatypeObject, datatypeElement); } else if (datatypeObject is Primitive) { hasData = encodePrimitive((Primitive) datatypeObject, datatypeElement); } else if (datatypeObject is Composite) { hasData = encodeComposite((Composite) datatypeObject, datatypeElement); } return hasData; }
/// <summary> Populates the given Type object with data from the given XML Element.</summary> public virtual void parse(Type datatypeObject, System.Xml.XmlElement datatypeElement) { if (datatypeObject is Varies) { parseVaries((Varies) datatypeObject, datatypeElement); } else if (datatypeObject is Primitive) { parsePrimitive((Primitive) datatypeObject, datatypeElement); } else if (datatypeObject is Composite) { parseComposite((Composite) datatypeObject, datatypeElement); } }