/// <summary> Encodes a Varies type by extracting it's data field and encoding that. Returns true /// if the data field (or one of its components) contains a value. /// </summary> private bool encodeVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement) { bool hasData = false; if (datatypeObject.Data != null) { hasData = encode(datatypeObject.Data, datatypeElement); } return(hasData); }
/// <summary> Parses an XML element into a Varies by determining whether the element is primitive or /// composite, calling setData() on the Varies with a new generic primitive or composite as appropriate, /// and then calling parse again with the new Type object. /// </summary> private void parseVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement) { //figure out what data type it holds //short nodeType = datatypeElement.getFirstChild().getNodeType(); if (!hasChildElement(datatypeElement)) { //it's a primitive datatypeObject.Data = new GenericPrimitive(datatypeObject.Message); } else { //it's a composite ... almost know what type, except that we don't have the version here datatypeObject.Data = new GenericComposite(datatypeObject.Message); } parse(datatypeObject.Data, datatypeElement); }
/// <summary> Populates the given Segment object with data from the given XML Element.</summary> /// <throws> HL7Exception if the XML Element does not have the correct name and structure </throws> /// <summary> for the given Segment, or if there is an error while setting individual field values. /// </summary> public virtual void parse(Segment segmentObject, System.Xml.XmlElement segmentElement) { //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'" SupportClass.HashSetSupport done = new SupportClass.HashSetSupport(); // for (int i = 1; i <= segmentObject.numFields(); i++) { // String elementName = makeElementName(segmentObject, i); // done.add(elementName); // parseReps(segmentObject, segmentElement, elementName, i); // } //UPGRADE_TODO: Method 'org.w3c.dom.Node.getChildNodes' was converted to 'System.Xml.XmlNode.ChildNodes' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.Xml.XmlNodeList all = segmentElement.ChildNodes; for (int i = 0; i < all.Count; i++) { System.String elementName = all.Item(i).Name; if (System.Convert.ToInt16(all.Item(i).NodeType) == (short)System.Xml.XmlNodeType.Element && !done.Contains(elementName)) { done.Add(elementName); int index = elementName.IndexOf('.'); if (index >= 0 && elementName.Length > index) { //properly formatted element System.String fieldNumString = elementName.Substring(index + 1); int fieldNum = System.Int32.Parse(fieldNumString); parseReps(segmentObject, segmentElement, elementName, fieldNum); } else { log.debug("Child of segment " + segmentObject.getStructureName() + " doesn't look like a field: " + elementName); } } } //set data type of OBX-5 if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(segmentObject, Factory); } }
/// <summary> Parses an XML element into a Varies by determining whether the element is primitive or /// composite, calling setData() on the Varies with a new generic primitive or composite as appropriate, /// and then calling parse again with the new Type object. /// </summary> private void parseVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement) { //figure out what data type it holds //short nodeType = datatypeElement.getFirstChild().getNodeType(); if (!hasChildElement(datatypeElement)) { //it's a primitive datatypeObject.Data = new GenericPrimitive(datatypeObject.Message); } else { //it's a composite ... almost know what type, except that we don't have the version here datatypeObject.Data = new GenericComposite(datatypeObject.Message); } parse(datatypeObject.Data, datatypeElement); }
/// <summary> Encodes a Varies type by extracting it's data field and encoding that. Returns true /// if the data field (or one of its components) contains a value. /// </summary> private bool encodeVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement) { bool hasData = false; if (datatypeObject.Data != null) { hasData = encode(datatypeObject.Data, datatypeElement); } return hasData; }
/// <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, EncodingCharacters encodingChars) { int fieldOffset = 0; if (isDelimDefSegment(destination.getStructureName())) { fieldOffset = 1; //set field 1 to fourth character of string Terser.Set(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)); if (log.DebugEnabled) { log.debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator); } //MSH-2 will get split incorrectly so we have to fudge it ... bool isMSH2 = isDelimDefSegment(destination.getStructureName()) && 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); log.debug(statusMessage.ToString()); //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 (HL7Exception e) { //set the field location and throw again ... e.FieldPosition = i; e.SegmentRepetition = MessageIterator.getIndex(destination.ParentGroup, destination).rep; e.SegmentName = destination.getStructureName(); throw e; } } } //set data type of OBX-5 if (destination.GetType().FullName.IndexOf("OBX") >= 0) { Varies.fixOBX5(destination, Factory); } }