Пример #1
0
        /// <summary> Extracts selected fields from a message.
        ///
        /// </summary>
        /// <param name="theMessageText">an unparsed message from which to get fields
        /// </param>
        /// <param name="thePathSpecs">Terser-like paths to fields in the message.  See documentation
        /// for Terser.  These paths are identical except that they start with the segment
        /// name (search flags and group names are to be omitted as they are not relevant
        /// with unparsed ER7 messages).
        /// </param>
        /// <returns> field values corresponding to the given paths
        /// </returns>
        /// <throws>  HL7Exception </throws>
        public static System.String[] getFields(System.String theMessageText, System.String[] thePathSpecs)
        {
            NuGenDatumPath[] paths = new NuGenDatumPath[thePathSpecs.Length];
            for (int i = 0; i < thePathSpecs.Length; i++)
            {
                SupportClass.Tokenizer tok     = new SupportClass.Tokenizer(thePathSpecs[i], "-", false);
                System.String          segSpec = tok.NextToken();
                tok = new SupportClass.Tokenizer(segSpec, "()", false);
                System.String segName = tok.NextToken();
                if (segName.Length != 3)
                {
                    throw new NuGenHL7Exception("In field path, " + segName + " is not a valid segment name");
                }
                int segRep = 0;
                if (tok.HasMoreTokens())
                {
                    System.String rep = tok.NextToken();
                    try
                    {
                        segRep = System.Int32.Parse(rep);
                    }
                    catch (System.FormatException e)
                    {
                        throw new NuGenHL7Exception("In field path, segment rep" + rep + " is not valid", e);
                    }
                }

                int[] indices = Terser.getIndices(thePathSpecs[i]);
                paths[i] = new NuGenDatumPath();
                paths[i].add(segName).add(segRep);
                paths[i].add(indices[0]).add(indices[1]).add(indices[2]).add(indices[3]);
            }
            return(getFields(theMessageText, paths));
        }