コード例 #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 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);
        }
コード例 #2
0
ファイル: PipeParser.cs プロジェクト: snosrap/nhapi
        /// <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;
        }
コード例 #3
0
        /// <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);
            }
        }