//param childIndexName may have an integer on the end if >1 sibling with same name (e.g. NTE2) private void parseReps(System.Xml.XmlElement groupElement, Group groupObject, System.String messageName, System.String childName, System.String childIndexName) { System.Collections.IList reps = getChildElementsByTagName(groupElement, makeGroupElementName(messageName, childName)); log.debug("# of elements matching " + makeGroupElementName(messageName, childName) + ": " + reps.Count); if (groupObject.isRepeating(childIndexName)) { for (int i = 0; i < reps.Count; i++) { parseRep((System.Xml.XmlElement)reps[i], groupObject.get_Renamed(childIndexName, i)); } } else { if (reps.Count > 0) { parseRep((System.Xml.XmlElement)reps[0], groupObject.get_Renamed(childIndexName, 0)); } if (reps.Count > 1) { System.String newIndexName = groupObject.addNonstandardSegment(childName); for (int i = 1; i < reps.Count; i++) { parseRep((System.Xml.XmlElement)reps[i], groupObject.get_Renamed(newIndexName, i - 1)); } } } }
/// <summary> Finds a message or segment class by name and version.</summary> /// <param name="name">the segment or message structure name /// </param> /// <param name="version">the HL7 version /// </param> /// <param name="type">'message', 'group', 'segment', or 'datatype' /// </param> private static System.Type findClass(System.String name, System.String version, System.String type) { if (Parser.validVersion(version) == false) { throw new HL7Exception("The HL7 version " + version + " is not recognized", HL7Exception.UNSUPPORTED_VERSION_ID); } //get list of packages to search for the corresponding message class System.String[] packages = packageList(version); //get subpackage for component type System.String types = "message|group|segment|datatype"; if (types.IndexOf(type) < 0) { throw new HL7Exception("Can't find " + name + " for version " + version + " -- type must be " + types + " but is " + type); } System.String subpackage = type; //try to load class from each package System.Type compClass = null; int c = 0; while (compClass == null && c < packages.Length) { try { System.String p = packages[c]; if (!p.EndsWith(".")) { p = p + "."; } System.String classNameToTry = p + subpackage + "." + name; string assembly = GetAssemblyName(version); if (log.DebugEnabled) { log.debug("Trying to load: " + classNameToTry); } //UPGRADE_TODO: The differences in the format of parameters for method 'java.lang.Class.forName' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" compClass = System.Type.GetType(classNameToTry + "," + assembly); if (log.DebugEnabled) { log.debug("Loaded: " + classNameToTry + " class: " + compClass); } } //UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception) { /* just try next one */ } c++; } return(compClass); }
/// <summary> Parses a message string and returns the corresponding Message /// object. Unexpected segments added at the end of their group. /// /// </summary> /// <throws> HL7Exception if the message is not correctly formatted. </throws> /// <throws> EncodingNotSupportedException if the message encoded </throws> /// <summary> is not supported by this parser. /// </summary> protected internal override Message doParse(System.String message, System.String version) { //try to instantiate a message object of the right class MessageStructure structure = getStructure(message); Message m = instantiateMessage(structure.messageStructure, version, structure.explicitlyDefined); //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message)); MessageIterator messageIter = new MessageIterator(m, "MSH", true); FilterIterator.Predicate segmentsOnly = new AnonymousClassPredicate(this); FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly); System.String[] segments = split(message, segDelim); for (int i = 0; i < segments.Length; i++) { //get rid of any leading whitespace characters ... if (segments[i] != null && segments[i].Length > 0 && System.Char.IsWhiteSpace(segments[i][0])) { segments[i] = stripLeadingWhitespace(segments[i]); } //sometimes people put extra segment delimiters at end of msg ... if (segments[i] != null && segments[i].Length >= 3) { //UPGRADE_NOTE: Final was removed from the declaration of 'name '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String name = segments[i].Substring(0, (3) - (0)); log.debug("Parsing segment " + name); messageIter.Direction = name; FilterIterator.Predicate byDirection = new AnonymousClassPredicate1(name, this); FilterIterator dirIter = new FilterIterator(segmentIter, byDirection); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" if (dirIter.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" parse((Segment)dirIter.Current, segments[i], getEncodingChars(message)); } } } return(m); }
/// <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); } }