예제 #1
0
        /// <summary> Returns the given rep of the structure at the current location.
        /// If at root, always returns the root (the rep is ignored).
        /// </summary>
        public virtual IStructure GetCurrentStructure(int rep)
        {
            IStructure ret = null;

            if (currentChild != -1)
            {
                var childName = childNames[currentChild];
                ret = CurrentGroup.GetStructure(childName, rep);
            }
            else
            {
                ret = CurrentGroup;
            }

            return(ret);
        }
예제 #2
0
        /// <summary> Iterates through the message tree to the next segment/group location (regardless
        /// of whether an instance of the segment exists).  If the end of the tree is
        /// reached, starts over at the root.  Only enters the first repetition of a
        /// repeating group -- explicit navigation (using the drill...() methods) is
        /// necessary to get to subsequent reps.
        /// </summary>
        /// <param name="segmentsOnly">if true, only stops at segments (not groups).
        /// </param>
        /// <param name="loop">if true, loops back to beginning when end of msg reached; if false,
        /// throws HL7Exception if end of msg reached.
        /// </param>
        public virtual void Iterate(bool segmentsOnly, bool loop)
        {
            IStructure start = null;

            if (currentChild == -1)
            {
                start = CurrentGroup;
            }
            else
            {
                start = CurrentGroup.GetStructure(childNames[currentChild]);
            }

            // using a non-existent direction and not allowing segment creation means that only
            // the first rep of anything is traversed.
            IEnumerator it = new MessageIterator(start, "doesn't exist", false);

            if (segmentsOnly)
            {
                FilterIterator.IPredicate predicate = new AnonymousClassPredicate(this);
                it = new FilterIterator(it, predicate);
            }

            if (it.MoveNext())
            {
                var next = (IStructure)it.Current;
                DrillHere(next);
            }
            else if (loop)
            {
                Reset();
            }
            else
            {
                throw new HL7Exception(
                          "End of message reached while iterating without loop",
                          ErrorCode.APPLICATION_INTERNAL_ERROR);
            }
        }
예제 #3
0
        /// <summary> Drills down into the group at the given index within the current
        /// group -- ie sets the location pointer to the first structure within the child.
        /// </summary>
        /// <param name="childNumber">the index of the group child into which to drill.
        /// </param>
        /// <param name="rep">the group repetition into which to drill.
        /// </param>
        public virtual void DrillDown(int childNumber, int rep)
        {
            if (childNumber != -1)
            {
                var s = CurrentGroup.GetStructure(childNames[childNumber], rep);
                if (!(s is IGroup))
                {
                    throw new HL7Exception("Can't drill into segment", ErrorCode.APPLICATION_INTERNAL_ERROR);
                }

                var group = (IGroup)s;

                // stack the current group and location
                var gc = new GroupContext(this, CurrentGroup, currentChild);
                ancestors.Add(gc);

                CurrentGroup = group;
            }

            currentChild = 0;
            childNames   = CurrentGroup.Names;
        }