View Javadoc

1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is "IStructureDefinition.java"
10   *
11   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
12   * 2001.  All Rights Reserved.
13   *
14   * Contributor(s):
15   *
16   * Alternatively, the contents of this file may be used under the terms of the
17   * GNU General Public License (the  �GPL�), in which case the provisions of the GPL are
18   * applicable instead of those above.  If you wish to allow use of your version of this
19   * file only under the terms of the GPL and not to allow others to use your version
20   * of this file under the MPL, indicate your decision by deleting  the provisions above
21   * and replace  them with the notice and other provisions required by the GPL License.
22   * If you do not delete the provisions above, a recipient may use your version of
23   * this file under either the MPL or the GPL.
24   *
25   */
26  
27  
28  package ca.uhn.hl7v2.parser;
29  
30  import java.util.List;
31  import java.util.Set;
32  
33  import ca.uhn.hl7v2.model.Group;
34  import ca.uhn.hl7v2.model.Structure;
35  
36  /**
37   * Contains information about the composition of a given type of {@link Structure}.
38   * At runtime, parsers will use accessors provided by various structure types (messages, groups,
39   * segments) to determine the structure of a messages. Structure definitions are used
40   * to cache that information between parse calls.
41   */
42  public interface IStructureDefinition {
43  
44      /**
45       * @return Returns this structure's first sibling (in other words, its
46       *         parent's first child). Returns
47       *         <code>null<code> if this is the first sibling, or if this has no parent
48       */
49      IStructureDefinition getFirstSibling();
50  
51      /**
52       * @return Returns the next leaf (segment) after this one, within the same
53       * group, only if one exists and this structure is also a leaf. Otherwise returns <code>null</code>.
54       */
55      IStructureDefinition getNextLeaf();
56  
57      /**
58       * @return The name of the segment, as it is known to it's parent. This
59       * will differ from {{@link #getName()}} in the case of multiple segments
60       * with the same name in a group, e.g. the two PID segments in ADT_A17,
61       * where the second one it known as PID2 to it's parent. 
62       */
63      String getNameAsItAppearsInParent();
64      
65      /**
66       * @return Returns the name of this structure
67       */
68      String getName();
69  
70      /**
71       * @return Returns true if this structure is a segment
72       */
73      boolean isSegment();
74  
75      /**
76       * @return Returns true if this is a repeatable structure
77       */
78      boolean isRepeating();
79  
80      /**
81       * @return Returns all children of this structure definition
82       */
83      List<StructureDefinition> getChildren();
84  
85      /**
86       * @return Returns the index of the position of this structure
87       * within it's parent's children
88       */
89      int getPosition();
90  
91      /**
92       * @return Returns the parent structure of this structure, if one exists.
93       * Otherwise, returns null.
94       */
95      IStructureDefinition getParent();
96  
97      /**
98       * @return Returns true if this structure is the final child of it's parent.
99       */
100     boolean isFinalChildOfParent();
101 
102     /**
103      * @return Returns this structure's next sibling within it's parent, if any.
104      */
105     IStructureDefinition getNextSibling();
106 
107     /**
108      * @return Does this structure have children (i.e. is it not a segment)
109      */
110     boolean hasChildren();
111 
112     /**
113      * Should only be called on a leaf node (segment). Returns the names
114      * of all valid children which may follow this one, at any level in the
115      * hierarchy (including as later siblings of parent structures to
116      * this one)
117      *
118      * @return the names of all valid children which may follow this one
119      */
120     Set<String> getNamesOfAllPossibleFollowingLeaves();
121 
122     /**
123      * @return structure definition of first child of null if there is no child
124      */
125     IStructureDefinition getFirstChild();
126 
127     /**
128      * Returns the names of any possible children that could be the first
129      * required child of this group.
130      *
131      * For instance, for the group below "ORC" and "OBR" would both be
132      * returned, as they are both potential first children of this group.
133      *
134      * Note that the name returned by {@link #getName() this.getName()}
135      * is also returned.
136      *
137      * <code>
138      *               ORDER_OBSERVATION
139      *	  {
140      *	  [ ORC ]
141      *	  OBR
142      *	  [ { NTE } ]
143      *	  [ CTD ]
144      *	                OBSERVATION
145      *	     {
146      *	     [ OBX ]
147      *	     [ { NTE } ]
148      *	     }
149      *	                OBSERVATION
150      *	  [ { FT1 } ]
151      *	  [ { CTI } ]
152      *	  }
153      *	                ORDER_OBSERVATION
154      *	   </code>
155      *
156      *
157      * @return the names of any possible children that could be the first
158      * required child of this group
159      */
160     Set<String> getAllPossibleFirstChildren();
161 
162     /**
163      * @return Returns the names of all children of this structure, including first elements within child groups
164      */
165     Set<String> getAllChildNames();
166 
167     /**
168      * @return true if this element a choice element
169      *
170      * @see Group#isChoiceElement(String)
171      */
172     boolean isChoiceElement();
173     
174     /**
175      * @return true if this a required structure within it's parent
176      */
177     boolean isRequired();
178 
179 }