Esempio n. 1
0
        /// <summary>toString() outputs the path (from segmentID onward) in the ZYX[a]-b[c]-d-e
        /// style (TODO: give it a name), suitable for a key in a map of
        /// message datum paths to values.
        /// </summary>
        /// <summary>Integer values are converted to strings directly (1 => "1") so when you
        /// constructed this you should have started counting from 1 for everything but
        /// the "repeat" fields, if you truly want the ZYX[a]-b[c]-d-e style.
        /// If toString() is called when this has a size in [1, 6) (=> missing numeric
        /// elments), then we act as though the elements in [size(), 6) are 0 or 1 as
        /// appropriate for each element.  We don't provide a default for the element 0
        /// (the String element): will throw an IndexOutOfBoundsException if (size() ==
        /// 1).
        /// eg. a (new DatumPath()).add(new String("ZYX")).add(2).add(6).toString()
        /// would yield "ZYX[2]-6[0]-1-1"
        /// </summary>
        public override System.String ToString()
        {
            System.Text.StringBuilder strbuf = new System.Text.StringBuilder(15);

            if (m_path.Count >= 1)
            {
                NuGenDatumPath extendedCopy = (NuGenDatumPath)this.Clone();
                extendedCopy.setSize(s_maxSize);

                for (int i = 0; i < extendedCopy.size(); ++i)
                {
                    if (i == 0)
                    {
                        strbuf.Append("" + ((System.String)extendedCopy.get_Renamed(0)));
                    }
                    else if ((i == 1) || (i == 3))
                    {
                        strbuf.Append("[" + ((System.Int32)extendedCopy.get_Renamed(i)) + "]");
                    }
                    else if ((i == 2) || (i == 4) || (i == 5))
                    {
                        strbuf.Append("-" + (((System.Int32)extendedCopy.get_Renamed(i))));
                    }
                }
            }
            else
            {
                throw new System.IndexOutOfRangeException();
            }

            return("" + strbuf);
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
            public virtual void  putDatum(System.Collections.ArrayList valNodeKey, System.String value_Renamed)
            {
                // make a DatumPath from valNodeKey and info in this:
                NuGenDatumPath valDatumPath = new NuGenDatumPath();

                valDatumPath.add(m_segmentId).add(m_segmentRepIdx);
                for (int i = 0; i < valNodeKey.Count; ++i)
                {
                    // valNodeKey: everything counts from 0 -- not so with DatumPath ... sigh.
                    int itval = ((System.Int32)valNodeKey[i]);
                    valDatumPath.add((System.Object)(i == 1?itval:itval + 1));
                }

                // see if valDatumPath passes m_msgMask:
                bool valDatumPathPassesMask = false;

                for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !valDatumPathPassesMask && maskIt.MoveNext();)
                {
                    valDatumPathPassesMask = valDatumPath.startsWith((NuGenDatumPath)(maskIt.Current));
                }

                if (valDatumPathPassesMask)
                {
                    m_props[valDatumPath.ToString()] = value_Renamed;
                }
            }
Esempio n. 4
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);
		}
Esempio n. 5
0
        /// <summary>pass in a whole segment (of type other than MSH), including message type
        /// at the start, according to encodingChars, and we'll parse the contents and
        /// put them in props.
        /// </summary>
        protected internal static void  parseSegmentWhole(System.Collections.Specialized.NameValueCollection props, System.Collections.IDictionary segmentId2nextRepIdx, System.Collections.ArrayList msgMask, NuGenEncodingCharacters encodingChars, System.String segment)
        {
            try
            {
                System.String segmentId = segment.Substring(0, (3) - (0));

                int currentSegmentRepIdx = 0;
                if (segmentId2nextRepIdx.Contains(segmentId))
                {
                    currentSegmentRepIdx = ((System.Int32)segmentId2nextRepIdx[segmentId]);
                }
                else
                {
                    currentSegmentRepIdx = 0;
                }
                segmentId2nextRepIdx[segmentId] = (System.Int32)(currentSegmentRepIdx + 1);

                // will only bother to parse this segment if any of it's contents will
                // be dumped to props.
                bool           parseThisSegment     = false;
                NuGenDatumPath segmentIdAsDatumPath = (new NuGenDatumPath()).add(segmentId);
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = segmentIdAsDatumPath.startsWith((NuGenDatumPath)(maskIt.Current));
                }
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = ((NuGenDatumPath)(maskIt.Current)).startsWith(segmentIdAsDatumPath);
                }

                if (parseThisSegment && (segment[3] == encodingChars.FieldSeparator))
                {
                    ER7SegmentHandler handler = new ER7SegmentHandler();
                    handler.m_props         = props;
                    handler.m_encodingChars = encodingChars;
                    handler.m_segmentId     = segmentId;
                    if (msgMask != null)
                    {
                        handler.m_msgMask = msgMask;
                    }
                    else
                    {
                        handler.m_msgMask = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                        handler.m_msgMask.Add(new NuGenDatumPath());                         // everything will pass this
                        // (every DatumPath startsWith the zero-length DatumPath)
                    }
                    handler.m_segmentRepIdx = currentSegmentRepIdx;

                    System.Collections.ArrayList nodeKey = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                    nodeKey.Add(0);
                    parseSegmentGuts(handler, segment.Substring(4), nodeKey);
                }
            }
            catch (System.NullReferenceException)
            {
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
Esempio n. 6
0
 /// <summary>like a copy constructor without the constructor </summary>
 public virtual void  copy(NuGenDatumPath other)
 {
     setSize(0);
     for (int i = 0; i < other.size(); ++i)
     {
         add(other.get_Renamed(i));
     }
 }
Esempio n. 7
0
		/// <summary>Works like String.startsWith: 
		/// returns true iff prefix.size() <= this.size()
		/// AND if, for 0 <= i < prefix.size(), this.get(i).equals(prefix.get(i))
		/// </summary>
		public virtual bool startsWith(NuGenDatumPath prefix)
		{
			bool ret = false;
			if (prefix.size() <= this.size())
			{
				ret = true;
				for (int i = 0; i < prefix.size(); ++i)
					ret &= this.get_Renamed(i).Equals(prefix.get_Renamed(i));
			}
			return ret;
		}
Esempio n. 8
0
        public static void  Main(System.String[] args)
        {
            NuGenDatumPath dp = new NuGenDatumPath();

            dp.add(new System.Text.StringBuilder("ZYX").ToString());
            dp.add((System.Object) 42);

            NuGenDatumPath dp2 = (new NuGenDatumPath()).add(new System.Text.StringBuilder().ToString()).add(-42);

            System.Console.Out.WriteLine(dp);
        }
Esempio n. 9
0
        /// <summary>Works like String.startsWith:
        /// returns true iff prefix.size() <= this.size()
        /// AND if, for 0 <= i < prefix.size(), this.get(i).equals(prefix.get(i))
        /// </summary>
        public virtual bool startsWith(NuGenDatumPath prefix)
        {
            bool ret = false;

            if (prefix.size() <= this.size())
            {
                ret = true;
                for (int i = 0; i < prefix.size(); ++i)
                {
                    ret &= this.get_Renamed(i).Equals(prefix.get_Renamed(i));
                }
            }
            return(ret);
        }
Esempio n. 10
0
        public override bool Equals(System.Object otherObject)
        {
            bool           ret   = false;
            NuGenDatumPath other = (NuGenDatumPath)otherObject;

            if (this.size() == other.size())
            {
                ret = true;
                for (int i = 0; i < this.size(); ++i)
                {
                    ret &= this.get_Renamed(i).Equals(other.get_Renamed(i));
                }
            }

            return(ret);
        }
Esempio n. 11
0
        /* Compare the numeric parts of "this" and "other".  string-style, start from
         * the left: if this[1] < other[1], then return true, if this[1] > other[1] then
         * return false, else repeat with [2] ... if we compare all elements, then return
         * false (they're the same.)
         *
         * What are actually compared are copies of this and other that have been grown
         * to s_maxSize (default values in effect), so they'll have the same size.
         *
         * This is just a little thing that gets used in the class XML.  Look there for
         * a justification of it's existence.
         *
         * ex. [1, 1, 1, 1] < [1, 1, 1, 2]
         * [1, 2, 1, 1] < [1, 2, 1, 2]
         * [1, 1, 5, 5] < [1, 2]
         * [1, 1] < [1, 1, 5, 5]
         */
        public virtual bool numbersLessThan(NuGenDatumPath other)
        {
            NuGenDatumPath extendedCopyThis = new NuGenDatumPath(this);

            extendedCopyThis.setSize(s_maxSize);

            NuGenDatumPath extendedCopyOther = new NuGenDatumPath(other);

            extendedCopyOther.setSize(s_maxSize);

            bool lessThan = false;

            for (int i = 1; !lessThan && (i < s_maxSize); ++i)
            {
                int this_i  = ((System.Int32)extendedCopyThis.get_Renamed(i));
                int other_i = ((System.Int32)extendedCopyOther.get_Renamed(i));
                lessThan |= (this_i < other_i);
            }

            return(lessThan);
        }
Esempio n. 12
0
		/// <summary> Gets selected fields from a message, as with String[] arg version but 
		/// using DatumPaths. 
		/// </summary>
		private static System.String[] getFields(System.String theMessageText, NuGenDatumPath[] thePaths)
		{
			System.String[] fields = new System.String[thePaths.Length];
			System.String encoding = ourParser.getEncoding(theMessageText);
			System.Collections.Specialized.NameValueCollection props = new System.Collections.Specialized.NameValueCollection();
			
			System.Collections.ArrayList mask = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			for (int i = 0; i < thePaths.Length; i++)
			{
				mask.Add(thePaths[i]);
			}
			
			if (encoding == null)
			{
				throw new NuGenHL7Exception("Message encoding is not recognized");
			}
			
			bool OK = false;
			if (encoding.Equals("VB"))
			{
				OK = NuGenER7.parseMessage(props, mask, theMessageText);
			}
			else if (encoding.Equals("XML"))
			{
				OK = NuGenXML.parseMessage(props, theMessageText, null);
			}
			
			if (!OK)
			{
				throw new NuGenHL7Exception("Parse failed");
			}
			
			for (int i = 0; i < fields.Length; i++)
			{
				fields[i] = props.Get(thePaths[i].ToString());
			}
			return fields;
		}
Esempio n. 13
0
		/// <summary>like a copy constructor without the constructor </summary>
		public virtual void  copy(NuGenDatumPath other)
		{
			setSize(0);
			for (int i = 0; i < other.size(); ++i)
				add(other.get_Renamed(i));
		}
Esempio n. 14
0
		/// <summary>copy constructor </summary>
		public NuGenDatumPath(NuGenDatumPath other):this()
		{
			
			copy(other);
		}
Esempio n. 15
0
		public static void  Main(System.String[] args)
		{
			NuGenDatumPath dp = new NuGenDatumPath();
			dp.add(new System.Text.StringBuilder("ZYX").ToString());
			dp.add((System.Object) 42);
			
			NuGenDatumPath dp2 = (new NuGenDatumPath()).add(new System.Text.StringBuilder().ToString()).add(- 42);
			
			System.Console.Out.WriteLine(dp);
		}
Esempio n. 16
0
		/* Compare the numeric parts of "this" and "other".  string-style, start from
		the left: if this[1] < other[1], then return true, if this[1] > other[1] then
		return false, else repeat with [2] ... if we compare all elements, then return
		false (they're the same.)
		
		What are actually compared are copies of this and other that have been grown
		to s_maxSize (default values in effect), so they'll have the same size.
		
		This is just a little thing that gets used in the class XML.  Look there for 
		a justification of it's existence.
		
		ex. [1, 1, 1, 1] < [1, 1, 1, 2] 
		[1, 2, 1, 1] < [1, 2, 1, 2]
		[1, 1, 5, 5] < [1, 2]
		[1, 1] < [1, 1, 5, 5] 
		*/
		public virtual bool numbersLessThan(NuGenDatumPath other)
		{
			NuGenDatumPath extendedCopyThis = new NuGenDatumPath(this);
			extendedCopyThis.setSize(s_maxSize);
			
			NuGenDatumPath extendedCopyOther = new NuGenDatumPath(other);
			extendedCopyOther.setSize(s_maxSize);
			
			bool lessThan = false;
			for (int i = 1; !lessThan && (i < s_maxSize); ++i)
			{
				int this_i = ((System.Int32) extendedCopyThis.get_Renamed(i));
				int other_i = ((System.Int32) extendedCopyOther.get_Renamed(i));
				lessThan |= (this_i < other_i);
			}
			
			return lessThan;
		}
Esempio n. 17
0
			/* doc location == msgID & curPath together.  
			If we've encountered an element called "elementNam", then this tries 
			to determine what it is, based on what we already know about the document.
			returns true if we can make sense of this new element name given the
			position we're at (represented by msgID / curPath), 
			false if we can't (which probably means this should be a useless element). 
			returning true doesn't mean that we actually changed msgID or curPath, it
			might mean that we just passed through a segment group element OK.
			*/
			protected internal static bool tryToGrowDocLocationFromElementName(System.Text.StringBuilder msgID, NuGenDatumPath curPath, System.Collections.IDictionary segmentId2nextRepIdx, NuGenDatumPath lastDumpedPath, System.String elementName)
			{
				bool ok = false; // ok == can we make sense of this new element?
				// hmm ... where are we in the document: 
				if ((msgID.Length == 0) && (curPath.size() == 0))
				{
					// we're entering a message
					msgID.Replace(msgID.ToString(0, msgID.Length - 0), elementName, 0, msgID.Length - 0);
					segmentId2nextRepIdx.Clear();
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() == 0))
				{
					// we're entering either a segment-group element (eg. <ADT_A01.PROCEDURE>)
					// or an actual segment element.
					if (!(elementName.StartsWith("" + msgID + '.')))
					{
						// must be an actual segment.
						curPath.add(elementName);
						
						if (segmentId2nextRepIdx.Contains(elementName))
							curPath.add(segmentId2nextRepIdx[elementName]);
						else
							curPath.add((System.Object) 0);
						
						segmentId2nextRepIdx[elementName] = (System.Int32) (((System.Int32) curPath.get_Renamed(curPath.size() - 1)) + 1);
					}
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() > 0))
				{
					// we're entering a field or a component or a subcomponent.
					if (curPath.size() == 2)
					{
						// we're entering a field element
						// all fields should start with segment-ID + '.' 
						if (elementName.StartsWith("" + curPath.get_Renamed(0) + '.'))
						{
							try
							{
								int fieldIdxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
								
								curPath.add((System.Object) fieldIdxFromElementName);
								
								// now add the repetition idx to curPath: 
								if ((lastDumpedPath.size() >= 4) && (((System.Int32) lastDumpedPath.get_Renamed(2)) == fieldIdxFromElementName))
								{
									// lastDumpedPath has a fieldIdx and a fieldRepIdx.
									curPath.add((System.Object) (((System.Int32) lastDumpedPath.get_Renamed(3)) + 1));
								}
								else
									curPath.add((System.Object) 0);
								
								ok = true;
							}
							catch (System.FormatException)
							{
							}
						} // else => this isn't a field -- must be useless.
					}
					else if ((curPath.size() == 4) || (curPath.size() == 5))
					{
						// we're entering a component or subcomponent element
						try
						{
							int idxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
							curPath.add((System.Object) idxFromElementName);
							ok = true;
						}
						catch (System.FormatException)
						{
						}
					}
				}
				return ok;
			}
Esempio n. 18
0
            /* doc location == msgID & curPath together.
             * If we've encountered an element called "elementNam", then this tries
             * to determine what it is, based on what we already know about the document.
             * returns true if we can make sense of this new element name given the
             * position we're at (represented by msgID / curPath),
             * false if we can't (which probably means this should be a useless element).
             * returning true doesn't mean that we actually changed msgID or curPath, it
             * might mean that we just passed through a segment group element OK.
             */
            protected internal static bool tryToGrowDocLocationFromElementName(System.Text.StringBuilder msgID, NuGenDatumPath curPath, System.Collections.IDictionary segmentId2nextRepIdx, NuGenDatumPath lastDumpedPath, System.String elementName)
            {
                bool ok = false;                 // ok == can we make sense of this new element?

                // hmm ... where are we in the document:
                if ((msgID.Length == 0) && (curPath.size() == 0))
                {
                    // we're entering a message
                    msgID.Replace(msgID.ToString(0, msgID.Length - 0), elementName, 0, msgID.Length - 0);
                    segmentId2nextRepIdx.Clear();
                    ok = true;
                }
                else if ((msgID.Length > 0) && (curPath.size() == 0))
                {
                    // we're entering either a segment-group element (eg. <ADT_A01.PROCEDURE>)
                    // or an actual segment element.
                    if (!(elementName.StartsWith("" + msgID + '.')))
                    {
                        // must be an actual segment.
                        curPath.add(elementName);

                        if (segmentId2nextRepIdx.Contains(elementName))
                        {
                            curPath.add(segmentId2nextRepIdx[elementName]);
                        }
                        else
                        {
                            curPath.add((System.Object) 0);
                        }

                        segmentId2nextRepIdx[elementName] = (System.Int32)(((System.Int32)curPath.get_Renamed(curPath.size() - 1)) + 1);
                    }
                    ok = true;
                }
                else if ((msgID.Length > 0) && (curPath.size() > 0))
                {
                    // we're entering a field or a component or a subcomponent.
                    if (curPath.size() == 2)
                    {
                        // we're entering a field element
                        // all fields should start with segment-ID + '.'
                        if (elementName.StartsWith("" + curPath.get_Renamed(0) + '.'))
                        {
                            try
                            {
                                int fieldIdxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));

                                curPath.add((System.Object)fieldIdxFromElementName);

                                // now add the repetition idx to curPath:
                                if ((lastDumpedPath.size() >= 4) && (((System.Int32)lastDumpedPath.get_Renamed(2)) == fieldIdxFromElementName))
                                {
                                    // lastDumpedPath has a fieldIdx and a fieldRepIdx.
                                    curPath.add((System.Object)(((System.Int32)lastDumpedPath.get_Renamed(3)) + 1));
                                }
                                else
                                {
                                    curPath.add((System.Object) 0);
                                }

                                ok = true;
                            }
                            catch (System.FormatException)
                            {
                            }
                        }                         // else => this isn't a field -- must be useless.
                    }
                    else if ((curPath.size() == 4) || (curPath.size() == 5))
                    {
                        // we're entering a component or subcomponent element
                        try
                        {
                            int idxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
                            curPath.add((System.Object)idxFromElementName);
                            ok = true;
                        }
                        catch (System.FormatException)
                        {
                        }
                    }
                }
                return(ok);
            }
Esempio n. 19
0
 /// <summary>copy constructor </summary>
 public NuGenDatumPath(NuGenDatumPath other) : this()
 {
     copy(other);
 }