/// <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); char delim = '|'; 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) { System.String name; if (i == 0) { name = segments[i].Substring(0, (3) - (0)); delim = segments[i][3]; } else { name = segments[i].Substring(0, (segments[i].IndexOf((System.Char)delim)) - (0)); } messageIter.Direction = name; FilterIterator.Predicate byDirection = new AnonymousClassPredicate1(name, this); FilterIterator dirIter = new FilterIterator(segmentIter, byDirection); if (dirIter.MoveNext()) { parse((Segment)dirIter.Current, segments[i], getEncodingChars(message)); } } } return(m); }
/// <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); char delim = '|'; 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) { System.String name; if (i == 0) { name = segments[i].Substring(0, (3) - (0)); delim = segments[i][3]; } else { name = segments[i].Substring(0, (segments[i].IndexOf((System.Char) delim)) - (0)); } messageIter.Direction = name; FilterIterator.Predicate byDirection = new AnonymousClassPredicate1(name, this); FilterIterator dirIter = new FilterIterator(segmentIter, byDirection); if (dirIter.MoveNext()) { parse((Segment) dirIter.Current, segments[i], getEncodingChars(message)); } } } return m; }
/// <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); } }