Example #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);
        }
Example #2
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));
     }
 }
		/// <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;
		}
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
            /// <summary>try to dump whatever we've got in m_chars to m_props,
            /// with a key of m_curPath.toString().
            /// </summary>
            protected internal virtual void  tryToDumpDataToProps()
            {
                if ((m_curPath.size() >= 2) && (m_depthWithinUselessElement == -1))
                {
                    /* m_curPath.toString() will be the property key whose value will be
                     * m_chars.
                     *
                     * This is (part of) what m_lastDumpedPath is for: With, for example "<ZYX.9>
                     * <PT.1>P</PT.1> </ZYX.9>" we might have had a m_curPath containing something
                     * like [ZYX, 0, 9, 0, 0] when we exited the PT.1 element.  (note: internal
                     * DatumPath elements are 0-indexed, string representations of DatumPaths and
                     * the XML text is 1-indexed.)  So in m_props the key for "P" would have been
                     * "ZYX[0]-9[0]-1-1".  (the last "-1" is a default that got added by
                     * toString()).
                     *
                     * Then we would have exited the PT.3 element, changed m_curPath to [ZYX, 0,
                     * 9, 0], picked up the whitespace between </PT.3> and </ZYX.9>, and when
                     * exiting the ZYX.9 element, we might have written that whitespace to m_props
                     * with a key of the toString() of [ZYX, 0, 9, 0]; that is, "ZYX[0]-9[0]-1-1":
                     * the same as the key for the "P" ... clobbering "P" in m_props with
                     * whitespace.
                     *
                     * But since we know that HL7 fields / components / etc are always in order
                     * (numerically), we can count on m_lastDumpedPath and use
                     * DatumPath.numbersLessThan to avoid the clobbering.
                     */
                    if ((m_lastDumpedPath.get_Renamed(0).Equals(m_curPath.get_Renamed(0)))?(m_lastDumpedPath.numbersLessThan(m_curPath)):true)
                    {
                        if (m_depthWithinUsefulElement >= 0)
                        {
                            // TODO: remove!  or assert
                            if (SupportClass.ContainsKeySupport(m_props, "" + m_curPath))
                            {
                                System.Console.Error.WriteLine("ALAAAARM: CLOBBERING PROPERTY in " + GetType());
                            }

                            m_props["" + m_curPath] = "" + m_chars;
                            m_lastDumpedPath.copy(m_curPath);
                            m_chars.Remove(0, m_chars.Length - 0);
                        }
                    }
                }
            }
Example #7
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);
        }
		/// <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));
		}
		/* 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;
		}
Example #10
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;
			}
Example #11
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);
            }