001    /*
002     * This class is an auto-generated source file for a HAPI
003     * HL7 v2.x standard structure class.
004     *
005     * For more information, visit: http://hl7api.sourceforge.net/
006     */
007    
008    package ca.uhn.hl7v2.model.v24.datatype;
009    
010    import ca.uhn.hl7v2.model.Composite;
011    import ca.uhn.hl7v2.model.DataTypeException;
012    import ca.uhn.hl7v2.model.Message;
013    import ca.uhn.hl7v2.model.Type;
014    import ca.uhn.hl7v2.model.AbstractType;
015    import ca.uhn.log.HapiLogFactory;
016    
017    /**
018     * <p>Represents an HL7 ED (encapsulated data) data type. 
019     * This type consists of the following components:</p>
020     * <ul>
021     * <li>source application (HD)
022     * <li>type of data (ID)
023     * <li>data subtype (ID)
024     * <li>encoding (ID)
025     * <li>data (ST)
026     * </ul>
027     */
028    public class ED extends AbstractType implements Composite {
029    
030        private Type[] data;
031    
032        /** 
033         * Creates a new ED type
034         */
035        public ED(Message message) {
036            super(message);
037            init();
038        }
039    
040        private void init() {
041            data = new Type[5];    
042            data[0] = new HD(getMessage());
043            data[1] = new ID(getMessage(), 191);
044            data[2] = new ID(getMessage(), 291);
045            data[3] = new ID(getMessage(), 299);
046            data[4] = new ST(getMessage());
047        }
048    
049    
050        /**
051         * Returns an array containing the data elements.
052         */
053        public Type[] getComponents() { 
054            return this.data; 
055        }
056    
057        /**
058         * Returns an individual data component.
059         *
060         * @param number The component number (0-indexed)
061         * @throws DataTypeException if the given element number is out of range.
062         */
063        public Type getComponent(int number) throws DataTypeException { 
064    
065            try { 
066                return this.data[number]; 
067            } catch (ArrayIndexOutOfBoundsException e) { 
068                throw new DataTypeException("Element " + number + " doesn't exist (Type " + getClass().getName() + " has only " + this.data.length + " components)"); 
069            } 
070        } 
071    
072    
073        /**
074         * Returns source application (component #1).  This is a convenience method that saves you from 
075         * casting and handling an exception.
076         */
077        public HD getSourceApplication() {
078           HD ret = null;
079           try {
080              ret = (HD)getComponent(0);
081           } catch (DataTypeException e) {
082              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
083              throw new RuntimeException(e);
084           }
085           return ret;
086        }
087    
088        
089        /**
090         * Returns source application (component #1).  This is a convenience method that saves you from 
091         * casting and handling an exception.
092         */
093        public HD getEd1_SourceApplication() {
094           HD ret = null;
095           try {
096              ret = (HD)getComponent(0);
097           } catch (DataTypeException e) {
098              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
099              throw new RuntimeException(e);
100           }
101           return ret;
102        }
103    
104    
105        /**
106         * Returns type of data (component #2).  This is a convenience method that saves you from 
107         * casting and handling an exception.
108         */
109        public ID getTypeOfData() {
110           ID ret = null;
111           try {
112              ret = (ID)getComponent(1);
113           } catch (DataTypeException e) {
114              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
115              throw new RuntimeException(e);
116           }
117           return ret;
118        }
119    
120        
121        /**
122         * Returns type of data (component #2).  This is a convenience method that saves you from 
123         * casting and handling an exception.
124         */
125        public ID getEd2_TypeOfData() {
126           ID ret = null;
127           try {
128              ret = (ID)getComponent(1);
129           } catch (DataTypeException e) {
130              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
131              throw new RuntimeException(e);
132           }
133           return ret;
134        }
135    
136    
137        /**
138         * Returns data subtype (component #3).  This is a convenience method that saves you from 
139         * casting and handling an exception.
140         */
141        public ID getDataSubtype() {
142           ID ret = null;
143           try {
144              ret = (ID)getComponent(2);
145           } catch (DataTypeException e) {
146              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
147              throw new RuntimeException(e);
148           }
149           return ret;
150        }
151    
152        
153        /**
154         * Returns data subtype (component #3).  This is a convenience method that saves you from 
155         * casting and handling an exception.
156         */
157        public ID getEd3_DataSubtype() {
158           ID ret = null;
159           try {
160              ret = (ID)getComponent(2);
161           } catch (DataTypeException e) {
162              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
163              throw new RuntimeException(e);
164           }
165           return ret;
166        }
167    
168    
169        /**
170         * Returns encoding (component #4).  This is a convenience method that saves you from 
171         * casting and handling an exception.
172         */
173        public ID getEncoding() {
174           ID ret = null;
175           try {
176              ret = (ID)getComponent(3);
177           } catch (DataTypeException e) {
178              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
179              throw new RuntimeException(e);
180           }
181           return ret;
182        }
183    
184        
185        /**
186         * Returns encoding (component #4).  This is a convenience method that saves you from 
187         * casting and handling an exception.
188         */
189        public ID getEd4_Encoding() {
190           ID ret = null;
191           try {
192              ret = (ID)getComponent(3);
193           } catch (DataTypeException e) {
194              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
195              throw new RuntimeException(e);
196           }
197           return ret;
198        }
199    
200    
201        /**
202         * Returns data (component #5).  This is a convenience method that saves you from 
203         * casting and handling an exception.
204         */
205        public ST getData() {
206           ST ret = null;
207           try {
208              ret = (ST)getComponent(4);
209           } catch (DataTypeException e) {
210              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
211              throw new RuntimeException(e);
212           }
213           return ret;
214        }
215    
216        
217        /**
218         * Returns data (component #5).  This is a convenience method that saves you from 
219         * casting and handling an exception.
220         */
221        public ST getEd5_Data() {
222           ST ret = null;
223           try {
224              ret = (ST)getComponent(4);
225           } catch (DataTypeException e) {
226              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
227              throw new RuntimeException(e);
228           }
229           return ret;
230        }
231    
232    
233    
234    }
235