001/**
002 * The contents of this file are subject to the Mozilla Public License Version 1.1
003 * (the "License"); you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
005 * Software distributed under the License is distributed on an "AS IS" basis,
006 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007 * specific language governing rights and limitations under the License.
008 *
009 * The Original Code is "IStructureDefinition.java"
010 *
011 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
012 * 2001.  All Rights Reserved.
013 *
014 * Contributor(s):
015 *
016 * Alternatively, the contents of this file may be used under the terms of the
017 * GNU General Public License (the  �GPL�), in which case the provisions of the GPL are
018 * applicable instead of those above.  If you wish to allow use of your version of this
019 * file only under the terms of the GPL and not to allow others to use your version
020 * of this file under the MPL, indicate your decision by deleting  the provisions above
021 * and replace  them with the notice and other provisions required by the GPL License.
022 * If you do not delete the provisions above, a recipient may use your version of
023 * this file under either the MPL or the GPL.
024 *
025 */
026
027
028package ca.uhn.hl7v2.parser;
029
030import java.util.List;
031import java.util.Set;
032
033/**
034 * Contains information about the composition of a given type of {@link ca.uhn.hl7v2.model.Structure Structure}.
035 * At runtime, parsers will use accessors provided by various structure types (messages, groups,
036 * segments) to determine the structure of a messages. Structure definitions are used
037 * to cache that information between parse calls.
038 */
039public interface IStructureDefinition {
040
041    /**
042     * @return Returns this structure's first sibling (in other words, its
043     *         parent's first child). Returns
044     *         <code>null<code> if this is the first sibling, or if this has no parent
045     */
046    IStructureDefinition getFirstSibling();
047
048    /**
049     * @return Returns the next leaf (segment) after this one, within the same
050     * group, only if one exists and this structure is also a leaf. Otherwise returns <code>null</code>.
051     */
052    IStructureDefinition getNextLeaf();
053
054    /**
055     * @return The name of the segment, as it is known to it's parent. This
056     * will differ from {{@link #getName()}} in the case of multiple segments
057     * with the same name in a group, e.g. the two PID segments in ADT_A17,
058     * where the second one it known as PID2 to it's parent. 
059     */
060    String getNameAsItAppearsInParent();
061    
062    /**
063     * @return Returns the name of this structure
064     */
065    String getName();
066
067    /**
068     * @return Returns true if this structure is a segment
069     */
070    boolean isSegment();
071
072    /**
073     * @return Returns true if this is a repeatable structure
074     */
075    boolean isRepeating();
076
077    /**
078     * @return Returns all children of this structure definition
079     */
080    List<StructureDefinition> getChildren();
081
082    /**
083     * @return Returns the index of the position of this structure
084     * within it's parent's children
085     */
086    int getPosition();
087
088    /**
089     * @return Returns the parent structure of this structure, if one exists.
090     * Otherwise, returns null.
091     */
092    IStructureDefinition getParent();
093
094    /**
095     * @return Returns true if this structure is the final child of it's parent.
096     */
097    boolean isFinalChildOfParent();
098
099    /**
100     * @return Returns this structure's next sibling within it's parent, if any.
101     */
102    IStructureDefinition getNextSibling();
103
104    /**
105     * @return Does this structure have children (i.e. is it not a segment)
106     */
107    boolean hasChildren();
108
109    /**
110     * Should only be called on a leaf node (segment). Returns the names
111     * of all valid children which may follow this one, at any level in the
112     * hierarchy (including as later siblings of parent structures to
113     * this one)
114     *
115     * @return the names of all valid children which may follow this one
116     */
117    Set<String> getNamesOfAllPossibleFollowingLeaves();
118
119    /**
120     * @return structure definition of first child of null if there is no child
121     */
122    IStructureDefinition getFirstChild();
123
124    /**
125     * Returns the names of any possible children that could be the first
126     * required child of this group.
127     *
128     * For instance, for the group below "ORC" and "OBR" would both be
129     * returned, as they are both potential first children of this group.
130     *
131     * Note that the name returned by {@link #getName() this.getName()}
132     * is also returned.
133     *
134     * <code>
135     *               ORDER_OBSERVATION
136     *    {
137     *    [ ORC ]
138     *    OBR
139     *    [ { NTE } ]
140     *    [ CTD ]
141     *                  OBSERVATION
142     *       {
143     *       [ OBX ]
144     *       [ { NTE } ]
145     *       }
146     *                  OBSERVATION
147     *    [ { FT1 } ]
148     *    [ { CTI } ]
149     *    }
150     *                  ORDER_OBSERVATION
151     *     </code>
152     *
153     *
154     * @return the names of any possible children that could be the first
155     * required child of this group
156     */
157    Set<String> getAllPossibleFirstChildren();
158
159    /**
160     * @return Returns the names of all children of this structure, including first elements within child groups
161     */
162    Set<String> getAllChildNames();
163
164    /**
165     * @return true if this element a choice element
166     *
167     * @see ca.uhn.hl7v2.model.Group#isChoiceElement(String)
168     */
169    boolean isChoiceElement();
170    
171    /**
172     * @return true if this a required structure within it's parent
173     */
174    boolean isRequired();
175
176}