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 028 package ca.uhn.hl7v2.parser; 029 030 import ca.uhn.hl7v2.model.Structure; 031 import java.util.List; 032 import java.util.Set; 033 034 /** 035 * Contains information about the composition of a given type of {@link Structure}. 036 * At runtime, parsers will use accessors provided by various structure types (messages, groups, 037 * segments) to determine the structure of a messages. Structure definitions are used 038 * to cache that information between parse calls. 039 */ 040 public interface IStructureDefinition { 041 042 /** 043 * @return Returns this structure's first sibling (in other words, its 044 * parent's first child). Returns 045 * <code>null<code> if this is the first sibling, or if this has no parent 046 */ 047 IStructureDefinition getFirstSibling(); 048 049 /** 050 * @return Returns the next leaf (segment) after this one, within the same 051 * group, only if one exists and this structure is also a leaf. Otherwise returns <code>null</code>. 052 */ 053 IStructureDefinition getNextLeaf(); 054 055 /** 056 * @return The name of the segment, as it is known to it's parent. This 057 * will differ from {{@link #getName()}} in the case of multiple segments 058 * with the same name in a group, e.g. the two PID segments in ADT_A17, 059 * where the second one it known as PID2 to it's parent. 060 */ 061 String getNameAsItAppearsInParent(); 062 063 /** 064 * @return Returns the name of this structure 065 */ 066 String getName(); 067 068 /** 069 * @return Returns true if this structure is a segment 070 */ 071 boolean isSegment(); 072 073 /** 074 * @return Returns true if this is a repeatable structure 075 */ 076 boolean isRepeating(); 077 078 /** 079 * @return Returns all children of this structure definition 080 */ 081 List<StructureDefinition> getChildren(); 082 083 /** 084 * @return Returns the index of the position of this structure 085 * within it's parent's children 086 */ 087 int getPosition(); 088 089 /** 090 * @return Returns the parent structure of this structure, if one exists. 091 * Otherwise, returns null. 092 */ 093 IStructureDefinition getParent(); 094 095 /** 096 * @return Returns true if this structure is the final child of it's parent. 097 */ 098 boolean isFinalChildOfParent(); 099 100 /** 101 * @return Returns this structure's next sibling within it's parent, if any. 102 */ 103 IStructureDefinition getNextSibling(); 104 105 /** 106 * @return Does this structure have children (i.e. is it not a segment) 107 */ 108 boolean hasChildren(); 109 110 /** 111 * Should only be called on a leaf node (segment). Returns the names 112 * of all valid children which may follow this one, at any level in the 113 * hierarchy (including as later siblings of parent structures to 114 * this one) 115 */ 116 Set<String> getNamesOfAllPossibleFollowingLeaves(); 117 118 /** 119 * May return null 120 * @return 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 Set<String> getAllPossibleFirstChildren(); 155 156 /** 157 * @return Returns the names of all children of this structure 158 */ 159 Set<String> getAllChildNames(); 160 161 /** 162 * @return Is this a required structure within it's parent 163 */ 164 boolean isRequired(); 165 }