Exemple #1
0
		/// <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 IMessage DoParse(String message, String version)
		{
			//try to instantiate a message object of the right class
			MessageStructure structure = GetStructure(message);
			IMessage m = InstantiateMessage(structure.messageStructure, version, structure.explicitlyDefined);

			//MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
			MessageIterator messageIter = new MessageIterator(m, "MSH", true);
			FilterIterator.IPredicate segmentsOnly = new AnonymousClassPredicate(this);
			FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly);

			String[] segments = Split(message, segDelim);
			EncodingCharacters encodingChars = GetEncodingChars(message);
			for (int i = 0; i < segments.Length; i++)
			{
				//get rid of any leading whitespace characters ...
				if (segments[i] != null && segments[i].Length > 0 && 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)
				{
					String name = segments[i].Substring(0, (3) - (0));
					log.Debug("Parsing segment " + name);

					messageIter.Direction = name;
					FilterIterator.IPredicate byDirection = new AnonymousClassPredicate1(name, this);
					FilterIterator dirIter = new FilterIterator(segmentIter, byDirection);
					if (dirIter.MoveNext())
					{
						Parse((ISegment) dirIter.Current, segments[i], encodingChars);
					}
				}
			}
			return m;
		}
Exemple #2
0
        /// <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 IMessage DoParse(String message, String version)
        {
            //try to instantiate a message object of the right class
            MessageStructure structure = GetStructure(message);
            IMessage m = InstantiateMessage(structure.messageStructure, version, structure.explicitlyDefined);

            //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message));
            MessageIterator messageIter = new MessageIterator(m, "MSH", true);
            FilterIterator.IPredicate segmentsOnly = new AnonymousClassPredicate(this);
            FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly);

            string lastSegmentName = null;
            String[] segments = Split(message, segDelim);
            EncodingCharacters encodingChars = GetEncodingChars(message);
            for (int i = 0; i < segments.Length; i++)
            {
                //get rid of any leading whitespace characters ...
                if (segments[i] != null && segments[i].Length > 0 && 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)
                {
                    String name = segments[i].Substring(0, (3) - (0));
                    log.Debug("Parsing segment " + name);
                    if (!name.Equals(lastSegmentName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        // If the message iterator passes a segment that is later encountered the message object won't be properly parsed.
                        // Rebuild the iterator for each segment, or fix iterator logic in handling unexpected segments.
                        messageIter = new MessageIterator(m, "MSH", true);
                        segmentsOnly = new AnonymousClassPredicate(this);
                        segmentIter = new FilterIterator(messageIter, segmentsOnly);
                        lastSegmentName = name;
                    }

                    messageIter.Direction = name;
                    FilterIterator.IPredicate byDirection = new AnonymousClassPredicate1(name, this);
                    FilterIterator dirIter = new FilterIterator(segmentIter, byDirection);
                    if (dirIter.MoveNext())
                    {
                        Parse((ISegment) dirIter.Current, segments[i], encodingChars);
                    }
                }
            }
            return m;
        }