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 BTS message segment (Batch Trailer). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>BTS-1: Batch Message Count (ST) <b>optional </b>
027         * <li>BTS-2: Batch Comment (ST) <b>optional </b>
028         * <li>BTS-3: Batch Totals (NM) <b>optional repeating</b>
029     * </ul>
030     */
031    public class BTS extends AbstractSegment {
032    
033        /** 
034         * Creates a new BTS segment
035         */
036        public BTS(Group parent, ModelClassFactory factory) {
037           super(parent, factory);
038           init(factory);
039        }
040    
041        private void init(ModelClassFactory factory) {
042           try {
043                                      this.add(ST.class, false, 1, 10, new Object[]{ getMessage(), new Integer(0) }, "Batch Message Count");
044                                      this.add(ST.class, false, 1, 80, new Object[]{ getMessage(), new Integer(0) }, "Batch Comment");
045                                      this.add(NM.class, false, 0, 100, new Object[]{ getMessage(), new Integer(0) }, "Batch Totals");
046           } catch(HL7Exception e) {
047              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating BTS - this is probably a bug in the source code generator.", e);
048           }
049        }
050    
051    
052    
053        /**
054         * Returns
055         * BTS-1: "Batch Message Count" - creates it if necessary
056         */
057        public ST getBatchMessageCount() { 
058            ST ret = null;
059            try {
060                Type t = this.getField(1, 0);
061                ret = (ST)t;
062            } catch (ClassCastException cce) {
063                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
064                throw new RuntimeException(cce);
065            } catch (HL7Exception he) {
066                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
067                throw new RuntimeException(he);
068            }
069            return ret;
070        }
071    
072    
073        /**
074         * Returns
075         * BTS-1: "Batch Message Count" - creates it if necessary
076         */
077        public ST getBts1_BatchMessageCount() { 
078            ST ret = null;
079            try {
080                Type t = this.getField(1, 0);
081                ret = (ST)t;
082            } catch (ClassCastException cce) {
083                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
084                throw new RuntimeException(cce);
085            } catch (HL7Exception he) {
086                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
087                throw new RuntimeException(he);
088            }
089            return ret;
090        }
091    
092    
093    
094        /**
095         * Returns
096         * BTS-2: "Batch Comment" - creates it if necessary
097         */
098        public ST getBatchComment() { 
099            ST ret = null;
100            try {
101                Type t = this.getField(2, 0);
102                ret = (ST)t;
103            } catch (ClassCastException cce) {
104                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
105                throw new RuntimeException(cce);
106            } catch (HL7Exception he) {
107                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
108                throw new RuntimeException(he);
109            }
110            return ret;
111        }
112    
113    
114        /**
115         * Returns
116         * BTS-2: "Batch Comment" - creates it if necessary
117         */
118        public ST getBts2_BatchComment() { 
119            ST ret = null;
120            try {
121                Type t = this.getField(2, 0);
122                ret = (ST)t;
123            } catch (ClassCastException cce) {
124                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
125                throw new RuntimeException(cce);
126            } catch (HL7Exception he) {
127                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
128                throw new RuntimeException(he);
129            }
130            return ret;
131        }
132    
133    
134        /**
135         * Returns all repetitions of Batch Totals (BTS-3).
136         */
137        public NM[] getBatchTotals() {
138            NM[] ret = null;
139            try {
140                Type[] t = this.getField(3);  
141                ret = new NM[t.length];
142                for (int i = 0; i < ret.length; i++) {
143                    ret[i] = (NM)t[i];
144                }
145            } catch (ClassCastException cce) {
146                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
147                throw new RuntimeException(cce);
148            } catch (HL7Exception he) {
149                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
150                throw new RuntimeException(he);
151            }
152            return ret;
153        }
154    
155    
156        /**
157         * Returns a count of the current number of repetitions of Batch Totals (BTS-3).
158         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
159         * it will return zero.
160         */
161        public int getBatchTotalsReps() {
162            NM[] ret = null;
163            try {
164                Type[] t = this.getField(3);
165                return t.length;  
166            } catch (ClassCastException cce) {
167                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
168                throw new RuntimeException(cce);
169            } catch (HL7Exception he) {
170                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
171                throw new RuntimeException(he);
172            }
173        }
174    
175    
176        /**
177         * Returns a specific repetition of
178         * BTS-3: "Batch Totals" - creates it if necessary
179         *
180         * @param rep The repetition index (0-indexed)
181         */
182        public NM getBatchTotals(int rep) { 
183            NM ret = null;
184            try {
185                Type t = this.getField(3, rep);
186                ret = (NM)t;
187            } catch (ClassCastException cce) {
188                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
189                throw new RuntimeException(cce);
190            } catch (HL7Exception he) {
191                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
192                throw new RuntimeException(he);
193            }
194            return ret;
195        }
196    
197        /**
198         * Returns a specific repetition of
199         * BTS-3: "Batch Totals" - creates it if necessary
200         *
201         * @param rep The repetition index (0-indexed)
202         */
203        public NM getBts3_BatchTotals(int rep) { 
204            NM ret = null;
205            try {
206                Type t = this.getField(3, rep);
207                ret = (NM)t;
208            } catch (ClassCastException cce) {
209                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
210                throw new RuntimeException(cce);
211            } catch (HL7Exception he) {
212                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
213                throw new RuntimeException(he);
214            }
215            return ret;
216        }
217    
218    
219        /**
220         * Returns a count of the current number of repetitions of Batch Totals (BTS-3).
221         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
222         * it will return zero.
223         */
224        public int getBts3_BatchTotalsReps() {
225            NM[] ret = null;
226            try {
227                Type[] t = this.getField(3);
228                return t.length;  
229            } catch (ClassCastException cce) {
230                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
231                throw new RuntimeException(cce);
232            } catch (HL7Exception he) {
233                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
234                throw new RuntimeException(he);
235            }
236        }
237    
238    
239    
240        /**
241         * Inserts a repetition of
242         * BTS-3: "Batch Totals" at a specific index
243         *
244         * @param rep The repetition index (0-indexed)
245         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
246         */
247        public NM insertBatchTotals(int rep) throws HL7Exception { 
248            return (NM) super.insertRepetition(3, rep);
249        }
250    
251    
252    
253        /**
254         * Inserts a repetition of
255         * BTS-3: "Batch Totals" at a specific index
256         *
257         * @param rep The repetition index (0-indexed)
258         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
259         */
260        public NM insertBts3_BatchTotals(int rep) throws HL7Exception { 
261            return (NM) super.insertRepetition(3, rep);
262        }
263    
264    
265        /**
266         * Removes a repetition of
267         * BTS-3: "Batch Totals" at a specific index
268         *
269         * @param rep The repetition index (0-indexed)
270         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
271         */
272        public NM removeBatchTotals(int rep) throws HL7Exception { 
273            return (NM) super.removeRepetition(3, rep);
274        }
275    
276    
277        /**
278         * Removes a repetition of
279         * BTS-3: "Batch Totals" at a specific index
280         *
281         * @param rep The repetition index (0-indexed)
282         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
283         */
284        public NM removeBts3_BatchTotals(int rep) throws HL7Exception { 
285            return (NM) super.removeRepetition(3, rep);
286        }
287    
288    
289    
290    
291    
292    
293        /** {@inheritDoc} */   
294        protected Type createNewTypeWithoutReflection(int field) {
295           switch (field) {
296              case 0: return new ST(getMessage());
297              case 1: return new ST(getMessage());
298              case 2: return new NM(getMessage());
299              default: return null;
300           }
301       }
302    
303    
304    }
305