Beispiel #1
0
        /// <summary> Returns the index of the given structure as a child of the
        /// given parent.  Returns null if the child isn't found.
        /// </summary>
        public static Index getIndex(IGroup parent, IStructure child)
        {
            Index index = null;

            System.String[] names = parent.Names;
            for (int i = 0; i < names.Length; i++)
            {
                if (names[i].StartsWith(child.GetStructureName()))
                {
                    try
                    {
                        IStructure[] reps = parent.GetAll(names[i]);
                        for (int j = 0; j < reps.Length; j++)
                        {
                            if (child == reps[j])
                            {
                                index = new Index(names[i], j);
                                break;
                            }
                        }
                    }
                    catch (HL7Exception e)
                    {
                        log.Error("", e);
                        throw new System.ApplicationException("Internal HL7Exception finding structure index: " + e.Message);
                    }
                }
            }
            return(index);
        }
Beispiel #2
0
        /// <summary> Returns the index of the given structure as a child of the
        /// given parent.  Returns null if the child isn't found.
        /// </summary>
        public static Index GetIndex(IGroup parent, IStructure child)
        {
            Index index = null;
            var   names = parent.Names;

            for (var i = 0; i < names.Length; i++)
            {
                if (names[i].StartsWith(child.GetStructureName(), StringComparison.Ordinal))
                {
                    try
                    {
                        var reps = parent.GetAll(names[i]);
                        for (var j = 0; j < reps.Length; j++)
                        {
                            if (child == reps[j])
                            {
                                index = new Index(names[i], j);
                                break;
                            }
                        }
                    }
                    catch (HL7Exception e)
                    {
                        Log.Error(string.Empty, e);
                        throw new ApplicationException("Internal HL7Exception finding structure index: " + e.Message);
                    }
                }
            }

            return(index);
        }
Beispiel #3
0
        /// <summary> As getSegment() but will only return a group.</summary>
        public virtual IGroup getGroup(String namePattern, int rep)
        {
            IStructure s = GetStructure(namePattern, rep);

            if (!typeof(IGroup).IsAssignableFrom(s.GetType()))
            {
                throw new HL7Exception(s.GetStructureName() + " is not a group", HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            return((IGroup)s);
        }
        /// <summary> Returns the first segment with a name matching the given pattern that is a sibling of
        /// the structure at the current location.  Other parts of the message are
        /// not searched (in contrast to findSegment).
        /// As a special case, if the pointer is at the root, the children of the root
        /// are searched.
        /// </summary>
        /// <param name="segmentName">the name of the segment to get.  The wildcad * means any number
        /// of arbitrary characters; the wildard ? one arbitrary character
        /// (eg "P*" or "*ID" or "???" or "P??" would match on PID).
        /// </param>
        /// <param name="rep">the repetition of the segment to return
        /// </param>
        public virtual ISegment getSegment(System.String namePattern, int rep)
        {
            IStructure s = GetStructure(namePattern, rep);

            if (!typeof(ISegment).IsAssignableFrom(s.GetType()))
            {
                throw new HL7Exception(s.GetStructureName() + " is not a segment", HL7Exception.APPLICATION_INTERNAL_ERROR);
            }
            return((ISegment)s);
        }
Beispiel #5
0
            /// <summary>   Evaluate the object. </summary>
            ///
            /// <param name="obj">  The object. </param>
            ///
            /// <returns>   true if it succeeds, false if it fails. </returns>

            public virtual bool evaluate(System.Object obj)
            {
                IStructure s = (IStructure)obj;

                NHapi.Base.Parser.PipeParser.log.Debug(
                    "PipeParser iterating message in direction " + this.name + " at " + s.GetStructureName());
                if (System.Text.RegularExpressions.Regex.IsMatch(s.GetStructureName(), this.name + "\\d*"))
                {
                    return(true);
                }
                return(false);
            }
Beispiel #6
0
            public virtual bool evaluate(Object obj)
            {
                IStructure s = (IStructure)obj;

                log.Debug("PipeParser iterating message in direction " + name + " at " + s.GetStructureName());
                if (Regex.IsMatch(s.GetStructureName(), name + "\\d*"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Beispiel #7
0
        private StructureDefinition CreateStructureDefinition(IStructure theStructure, ref StructureDefinition thePreviousLeaf)
        {
            var result = new StructureDefinition
            {
                Name = theStructure.GetStructureName(),
            };

            if (theStructure is IGroup)
            {
                result.IsSegment = false;
                var group      = (IGroup)theStructure;
                var index      = 0;
                var childNames = group.Names.ToList();

                foreach (var nextName in childNames)
                {
                    var nextChild           = group.GetStructure(nextName);
                    var structureDefinition = CreateStructureDefinition(nextChild, ref thePreviousLeaf);

                    structureDefinition.NameAsItAppearsInParent = nextName;
                    structureDefinition.IsRepeating             = group.IsRepeating(nextName);
                    structureDefinition.IsRequired      = group.IsRequired(nextName);
                    structureDefinition.IsChoiceElement = group.IsChoiceElement(nextName);
                    structureDefinition.Position        = index++;
                    structureDefinition.Parent          = result;

                    result.Children.Add(structureDefinition);
                }
            }
            else
            {
                if (thePreviousLeaf != null)
                {
                    thePreviousLeaf.NextLeaf = result;
                }

                thePreviousLeaf  = result;
                result.IsSegment = true;
            }

            return(result);
        }
Beispiel #8
0
        /* for configurability (maybe to add later, replacing hard-coded options
         * in nextFromEndOfGroup) ...
         * public void setSearchLevel(String level) {
         * if (WHOLE_GROUP.equals(level)) {
         * this.findUpToFirstRequired = false;
         * this.findFirstDescendentsOnly = false;
         * } else if (FIRST_DESCENDENTS_ONLY.equals(level)) {
         * this.findUpToFirstRequired = false;
         * this.findFirstDescendentsOnly = true;
         * } else if (UP_TO_FIRST_REQUIRED.equals(level)) {
         * this.findUpToFirstRequired = true;
         * this.findFirstDescendentsOnly = false;
         * } else {
         * throw IllegalArgumentException(level + " is not a valid search level.  Should be WHOLE_GROUP, etc.");
         * }
         * }
         *
         * public String getSearchLevel() {
         * String level = WHOLE_GROUP;
         * if (this.findFirstDescendentsOnly) {
         * level = FIRST_DESCENDENTS_ONLY;
         * } else if (this.findUpTpFirstRequired) {
         * level = UP_TO_FIRST_REQUIRED;
         * }
         * return level;
         * }*/

        #region Public Methods and Operators

        /// <summary>
        /// Determines whether the given structure matches the given name, or contains a child that does.
        /// </summary>
        ///
        /// <exception cref="ApplicationException"> Thrown when an Application error condition occurs. </exception>
        ///
        /// <param name="s">                    the structure to check. </param>
        /// <param name="name">                 the name to look for. </param>
        /// <param name="firstDescendentsOnly"> only checks first descendents (i.e. first child, first
        ///                                     child of first child, etc.)  In theory the first child of
        ///                                     a group should always be present, and we don't use this
        ///                                     method with subsequent children because finding the next
        ///                                     position within a group is straightforward.  </param>
        /// <param name="upToFirstRequired">    only checks first descendents and of their siblings up to
        ///                                     the first required one.  This may be needed because in
        ///                                     practice some first children of groups are not required.  </param>
        ///
        /// <returns>   true if the object is in this collection, false if not. </returns>

        public static bool contains(IStructure s, System.String name, bool firstDescendentsOnly, bool upToFirstRequired)
        {
            bool contains = false;

            if (typeof(ISegment).IsAssignableFrom(s.GetType()))
            {
                if (s.GetStructureName().Equals(name))
                {
                    contains = true;
                }
            }
            else
            {
                IGroup          g     = (IGroup)s;
                System.String[] names = g.Names;
                for (int i = 0; i < names.Length && !contains; i++)
                {
                    try
                    {
                        contains = MessageIterator.contains(
                            g.GetStructure(names[i], 0),
                            name,
                            firstDescendentsOnly,
                            upToFirstRequired);
                        if (firstDescendentsOnly)
                        {
                            break;
                        }
                        if (upToFirstRequired && g.IsRequired(names[i]))
                        {
                            break;
                        }
                    }
                    catch (HL7Exception e)
                    {
                        throw new System.ApplicationException("HL7Exception due to bad index: " + e.Message);
                    }
                }
            }
            return(contains);
        }
Beispiel #9
0
        /* for configurability (maybe to add later, replacing hard-coded options
         * in nextFromEndOfGroup) ...
         * public void setSearchLevel(String level) {
         * if (WHOLE_GROUP.equals(level)) {
         * this.findUpToFirstRequired = false;
         * this.findFirstDescendentsOnly = false;
         * } else if (FIRST_DESCENDENTS_ONLY.equals(level)) {
         * this.findUpToFirstRequired = false;
         * this.findFirstDescendentsOnly = true;
         * } else if (UP_TO_FIRST_REQUIRED.equals(level)) {
         * this.findUpToFirstRequired = true;
         * this.findFirstDescendentsOnly = false;
         * } else {
         * throw IllegalArgumentException(level + " is not a valid search level.  Should be WHOLE_GROUP, etc.");
         * }
         * }
         *
         * public String getSearchLevel() {
         * String level = WHOLE_GROUP;
         * if (this.findFirstDescendentsOnly) {
         * level = FIRST_DESCENDENTS_ONLY;
         * } else if (this.findUpTpFirstRequired) {
         * level = UP_TO_FIRST_REQUIRED;
         * }
         * return level;
         * }*/


        /// <summary> Returns true if another object exists in the iteration sequence.  </summary>
        public virtual bool MoveNext()
        {
            bool has = true;

            if (next_Renamed_Field == null)
            {
                if (typeof(IGroup).IsAssignableFrom(currentStructure.GetType()))
                {
                    groupNext((IGroup)currentStructure);
                }
                else
                {
                    IGroup   parent          = currentStructure.ParentStructure;
                    Index    i               = getIndex(parent, currentStructure);
                    Position currentPosition = new Position(parent, i);

                    try
                    {
                        if (parent.IsRepeating(i.name) && currentStructure.GetStructureName().Equals(direction))
                        {
                            nextRep(currentPosition);
                        }
                        else
                        {
                            has = nextPosition(currentPosition, this.direction, this.handleUnexpectedSegments);
                        }
                    }
                    catch (HL7Exception e)
                    {
                        throw new System.ApplicationException("HL7Exception arising from bad index: " + e.Message);
                    }
                }
            }
            log.Debug("MessageIterator.hasNext() in direction " + this.direction + "? " + has);
            return(has);
        }
Beispiel #10
0
 /// <summary> Returns the index of the given structure as a child of the 
 /// given parent.  Returns null if the child isn't found. 
 /// </summary>
 public static Index getIndex(IGroup parent, IStructure child)
 {
     Index index = null;
     System.String[] names = parent.Names;
     for (int i = 0; i < names.Length; i++)
     {
         if (names[i].StartsWith(child.GetStructureName()))
         {
             try
             {
                 IStructure[] reps = parent.GetAll(names[i]);
                 for (int j = 0; j < reps.Length; j++)
                 {
                     if (child == reps[j])
                     {
                         index = new Index(names[i], j);
                         break;
                     }
                 }
             }
             catch (HL7Exception e)
             {
                 log.Error("", e);
                 throw new System.ApplicationException("Internal HL7Exception finding structure index: " + e.Message);
             }
         }
     }
     return index;
 }
Beispiel #11
0
 /// <summary> Determines whether the given structure matches the given name, or contains 
 /// a child that does.  
 /// </summary>
 /// <param name="s">the structure to check 
 /// </param>
 /// <param name="name">the name to look for 
 /// </param>
 /// <param name="firstDescendentsOnly">only checks first descendents (i.e. first 
 /// child, first child of first child, etc.)  In theory the first child 
 /// of a group should always be present, and we don't use this method with 
 /// subsequent children because finding the next position within a group is 
 /// straightforward.  
 /// </param>
 /// <param name="upToFirstRequired">only checks first descendents and of their siblings 
 /// up to the first required one.  This may be needed because in practice 
 /// some first children of groups are not required.  
 /// </param>
 public static bool contains(IStructure s, System.String name, bool firstDescendentsOnly, bool upToFirstRequired)
 {
     bool contains = false;
     if (typeof(ISegment).IsAssignableFrom(s.GetType()))
     {
         if (s.GetStructureName().Equals(name))
             contains = true;
     }
     else
     {
         IGroup g = (IGroup)s;
         System.String[] names = g.Names;
         for (int i = 0; i < names.Length && !contains; i++)
         {
             try
             {
                 contains = MessageIterator.contains(g.GetStructure(names[i], 0), name, firstDescendentsOnly, upToFirstRequired);
                 if (firstDescendentsOnly)
                     break;
                 if (upToFirstRequired && g.IsRequired(names[i]))
                     break;
             }
             catch (HL7Exception e)
             {
                 throw new System.ApplicationException("HL7Exception due to bad index: " + e.Message);
             }
         }
     }
     return contains;
 }