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.segment;
009    
010    // import ca.uhn.hl7v2.model.v24.group.*;
011    import ca.uhn.hl7v2.model.v24.datatype.*;
012    import ca.uhn.log.HapiLogFactory;
013    import ca.uhn.hl7v2.HL7Exception;
014    import ca.uhn.hl7v2.parser.ModelClassFactory;
015    import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
016    import ca.uhn.hl7v2.model.AbstractMessage;
017    import ca.uhn.hl7v2.model.Group;
018    import ca.uhn.hl7v2.model.Type;
019    import ca.uhn.hl7v2.model.AbstractSegment;
020    import ca.uhn.hl7v2.model.Varies;
021    
022    /**
023     *<p>Represents an HL7 NTE message segment (Notes and Comments). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>NTE-1: Set ID - NTE (SI) <b>optional </b>
027         * <li>NTE-2: Source of Comment (ID) <b>optional </b>
028         * <li>NTE-3: Comment (FT) <b>optional repeating</b>
029         * <li>NTE-4: Comment Type (CE) <b>optional </b>
030     * </ul>
031     */
032    public class NTE extends AbstractSegment {
033    
034        /** 
035         * Creates a new NTE segment
036         */
037        public NTE(Group parent, ModelClassFactory factory) {
038           super(parent, factory);
039           init(factory);
040        }
041    
042        private void init(ModelClassFactory factory) {
043           try {
044                                      this.add(SI.class, false, 1, 4, new Object[]{ getMessage(), new Integer(0) }, "Set ID - NTE");
045                                      this.add(ID.class, false, 1, 8, new Object[]{ getMessage() }, "Source of Comment");
046                                      this.add(FT.class, false, 0, 65536, new Object[]{ getMessage(), new Integer(0) }, "Comment");
047                                      this.add(CE.class, false, 1, 250, new Object[]{ getMessage(), new Integer(364) }, "Comment Type");
048           } catch(HL7Exception e) {
049              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating NTE - this is probably a bug in the source code generator.", e);
050           }
051        }
052    
053    
054    
055        /**
056         * Returns
057         * NTE-1: "Set ID - NTE" - creates it if necessary
058         */
059        public SI getSetIDNTE() { 
060            SI ret = null;
061            try {
062                Type t = this.getField(1, 0);
063                ret = (SI)t;
064            } catch (ClassCastException cce) {
065                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
066                throw new RuntimeException(cce);
067            } catch (HL7Exception he) {
068                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
069                throw new RuntimeException(he);
070            }
071            return ret;
072        }
073    
074    
075        /**
076         * Returns
077         * NTE-1: "Set ID - NTE" - creates it if necessary
078         */
079        public SI getNte1_SetIDNTE() { 
080            SI ret = null;
081            try {
082                Type t = this.getField(1, 0);
083                ret = (SI)t;
084            } catch (ClassCastException cce) {
085                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
086                throw new RuntimeException(cce);
087            } catch (HL7Exception he) {
088                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
089                throw new RuntimeException(he);
090            }
091            return ret;
092        }
093    
094    
095    
096        /**
097         * Returns
098         * NTE-2: "Source of Comment" - creates it if necessary
099         */
100        public ID getSourceOfComment() { 
101            ID ret = null;
102            try {
103                Type t = this.getField(2, 0);
104                ret = (ID)t;
105            } catch (ClassCastException cce) {
106                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
107                throw new RuntimeException(cce);
108            } catch (HL7Exception he) {
109                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
110                throw new RuntimeException(he);
111            }
112            return ret;
113        }
114    
115    
116        /**
117         * Returns
118         * NTE-2: "Source of Comment" - creates it if necessary
119         */
120        public ID getNte2_SourceOfComment() { 
121            ID ret = null;
122            try {
123                Type t = this.getField(2, 0);
124                ret = (ID)t;
125            } catch (ClassCastException cce) {
126                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
127                throw new RuntimeException(cce);
128            } catch (HL7Exception he) {
129                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
130                throw new RuntimeException(he);
131            }
132            return ret;
133        }
134    
135    
136        /**
137         * Returns all repetitions of Comment (NTE-3).
138         */
139        public FT[] getComment() {
140            FT[] ret = null;
141            try {
142                Type[] t = this.getField(3);  
143                ret = new FT[t.length];
144                for (int i = 0; i < ret.length; i++) {
145                    ret[i] = (FT)t[i];
146                }
147            } catch (ClassCastException cce) {
148                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
149                throw new RuntimeException(cce);
150            } catch (HL7Exception he) {
151                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
152                throw new RuntimeException(he);
153            }
154            return ret;
155        }
156    
157    
158        /**
159         * Returns a count of the current number of repetitions of Comment (NTE-3).
160         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
161         * it will return zero.
162         */
163        public int getCommentReps() {
164            FT[] ret = null;
165            try {
166                Type[] t = this.getField(3);
167                return t.length;  
168            } catch (ClassCastException cce) {
169                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
170                throw new RuntimeException(cce);
171            } catch (HL7Exception he) {
172                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
173                throw new RuntimeException(he);
174            }
175        }
176    
177    
178        /**
179         * Returns a specific repetition of
180         * NTE-3: "Comment" - creates it if necessary
181         *
182         * @param rep The repetition index (0-indexed)
183         */
184        public FT getComment(int rep) { 
185            FT ret = null;
186            try {
187                Type t = this.getField(3, rep);
188                ret = (FT)t;
189            } catch (ClassCastException cce) {
190                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
191                throw new RuntimeException(cce);
192            } catch (HL7Exception he) {
193                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
194                throw new RuntimeException(he);
195            }
196            return ret;
197        }
198    
199        /**
200         * Returns a specific repetition of
201         * NTE-3: "Comment" - creates it if necessary
202         *
203         * @param rep The repetition index (0-indexed)
204         */
205        public FT getNte3_Comment(int rep) { 
206            FT ret = null;
207            try {
208                Type t = this.getField(3, rep);
209                ret = (FT)t;
210            } catch (ClassCastException cce) {
211                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
212                throw new RuntimeException(cce);
213            } catch (HL7Exception he) {
214                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
215                throw new RuntimeException(he);
216            }
217            return ret;
218        }
219    
220    
221        /**
222         * Returns a count of the current number of repetitions of Comment (NTE-3).
223         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
224         * it will return zero.
225         */
226        public int getNte3_CommentReps() {
227            FT[] ret = null;
228            try {
229                Type[] t = this.getField(3);
230                return t.length;  
231            } catch (ClassCastException cce) {
232                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
233                throw new RuntimeException(cce);
234            } catch (HL7Exception he) {
235                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
236                throw new RuntimeException(he);
237            }
238        }
239    
240    
241    
242        /**
243         * Inserts a repetition of
244         * NTE-3: "Comment" at a specific index
245         *
246         * @param rep The repetition index (0-indexed)
247         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
248         */
249        public FT insertComment(int rep) throws HL7Exception { 
250            return (FT) super.insertRepetition(3, rep);
251        }
252    
253    
254    
255        /**
256         * Inserts a repetition of
257         * NTE-3: "Comment" at a specific index
258         *
259         * @param rep The repetition index (0-indexed)
260         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
261         */
262        public FT insertNte3_Comment(int rep) throws HL7Exception { 
263            return (FT) super.insertRepetition(3, rep);
264        }
265    
266    
267        /**
268         * Removes a repetition of
269         * NTE-3: "Comment" at a specific index
270         *
271         * @param rep The repetition index (0-indexed)
272         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
273         */
274        public FT removeComment(int rep) throws HL7Exception { 
275            return (FT) super.removeRepetition(3, rep);
276        }
277    
278    
279        /**
280         * Removes a repetition of
281         * NTE-3: "Comment" at a specific index
282         *
283         * @param rep The repetition index (0-indexed)
284         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
285         */
286        public FT removeNte3_Comment(int rep) throws HL7Exception { 
287            return (FT) super.removeRepetition(3, rep);
288        }
289    
290    
291    
292    
293        /**
294         * Returns
295         * NTE-4: "Comment Type" - creates it if necessary
296         */
297        public CE getCommentType() { 
298            CE ret = null;
299            try {
300                Type t = this.getField(4, 0);
301                ret = (CE)t;
302            } catch (ClassCastException cce) {
303                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
304                throw new RuntimeException(cce);
305            } catch (HL7Exception he) {
306                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
307                throw new RuntimeException(he);
308            }
309            return ret;
310        }
311    
312    
313        /**
314         * Returns
315         * NTE-4: "Comment Type" - creates it if necessary
316         */
317        public CE getNte4_CommentType() { 
318            CE ret = null;
319            try {
320                Type t = this.getField(4, 0);
321                ret = (CE)t;
322            } catch (ClassCastException cce) {
323                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
324                throw new RuntimeException(cce);
325            } catch (HL7Exception he) {
326                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
327                throw new RuntimeException(he);
328            }
329            return ret;
330        }
331    
332    
333    
334    
335    
336        /** {@inheritDoc} */   
337        protected Type createNewTypeWithoutReflection(int field) {
338           switch (field) {
339              case 0: return new SI(getMessage());
340              case 1: return new ID(getMessage(), new Integer( 105 ));
341              case 2: return new FT(getMessage());
342              case 3: return new CE(getMessage());
343              default: return null;
344           }
345       }
346    
347    
348    }
349