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 VAR message segment (Variance). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>VAR-1: Variance Instance ID (EI) <b> </b>
027         * <li>VAR-2: Documented Date/Time (TS) <b> </b>
028         * <li>VAR-3: Stated Variance Date/Time (TS) <b>optional </b>
029         * <li>VAR-4: Variance Originator (XCN) <b>optional repeating</b>
030         * <li>VAR-5: Variance Classification (CE) <b>optional </b>
031         * <li>VAR-6: Variance Description (ST) <b>optional repeating</b>
032     * </ul>
033     */
034    public class VAR extends AbstractSegment {
035    
036        /** 
037         * Creates a new VAR segment
038         */
039        public VAR(Group parent, ModelClassFactory factory) {
040           super(parent, factory);
041           init(factory);
042        }
043    
044        private void init(ModelClassFactory factory) {
045           try {
046                                      this.add(EI.class, true, 1, 60, new Object[]{ getMessage(), new Integer(0) }, "Variance Instance ID");
047                                      this.add(TS.class, true, 1, 26, new Object[]{ getMessage(), new Integer(0) }, "Documented Date/Time");
048                                      this.add(TS.class, false, 1, 26, new Object[]{ getMessage(), new Integer(0) }, "Stated Variance Date/Time");
049                                      this.add(XCN.class, false, 0, 250, new Object[]{ getMessage(), new Integer(0) }, "Variance Originator");
050                                      this.add(CE.class, false, 1, 250, new Object[]{ getMessage(), new Integer(0) }, "Variance Classification");
051                                      this.add(ST.class, false, 0, 512, new Object[]{ getMessage(), new Integer(0) }, "Variance Description");
052           } catch(HL7Exception e) {
053              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating VAR - this is probably a bug in the source code generator.", e);
054           }
055        }
056    
057    
058    
059        /**
060         * Returns
061         * VAR-1: "Variance Instance ID" - creates it if necessary
062         */
063        public EI getVarianceInstanceID() { 
064            EI ret = null;
065            try {
066                Type t = this.getField(1, 0);
067                ret = (EI)t;
068            } catch (ClassCastException cce) {
069                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
070                throw new RuntimeException(cce);
071            } catch (HL7Exception he) {
072                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
073                throw new RuntimeException(he);
074            }
075            return ret;
076        }
077    
078    
079        /**
080         * Returns
081         * VAR-1: "Variance Instance ID" - creates it if necessary
082         */
083        public EI getVar1_VarianceInstanceID() { 
084            EI ret = null;
085            try {
086                Type t = this.getField(1, 0);
087                ret = (EI)t;
088            } catch (ClassCastException cce) {
089                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
090                throw new RuntimeException(cce);
091            } catch (HL7Exception he) {
092                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
093                throw new RuntimeException(he);
094            }
095            return ret;
096        }
097    
098    
099    
100        /**
101         * Returns
102         * VAR-2: "Documented Date/Time" - creates it if necessary
103         */
104        public TS getDocumentedDateTime() { 
105            TS ret = null;
106            try {
107                Type t = this.getField(2, 0);
108                ret = (TS)t;
109            } catch (ClassCastException cce) {
110                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
111                throw new RuntimeException(cce);
112            } catch (HL7Exception he) {
113                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
114                throw new RuntimeException(he);
115            }
116            return ret;
117        }
118    
119    
120        /**
121         * Returns
122         * VAR-2: "Documented Date/Time" - creates it if necessary
123         */
124        public TS getVar2_DocumentedDateTime() { 
125            TS ret = null;
126            try {
127                Type t = this.getField(2, 0);
128                ret = (TS)t;
129            } catch (ClassCastException cce) {
130                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
131                throw new RuntimeException(cce);
132            } catch (HL7Exception he) {
133                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
134                throw new RuntimeException(he);
135            }
136            return ret;
137        }
138    
139    
140    
141        /**
142         * Returns
143         * VAR-3: "Stated Variance Date/Time" - creates it if necessary
144         */
145        public TS getStatedVarianceDateTime() { 
146            TS ret = null;
147            try {
148                Type t = this.getField(3, 0);
149                ret = (TS)t;
150            } catch (ClassCastException cce) {
151                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
152                throw new RuntimeException(cce);
153            } catch (HL7Exception he) {
154                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
155                throw new RuntimeException(he);
156            }
157            return ret;
158        }
159    
160    
161        /**
162         * Returns
163         * VAR-3: "Stated Variance Date/Time" - creates it if necessary
164         */
165        public TS getVar3_StatedVarianceDateTime() { 
166            TS ret = null;
167            try {
168                Type t = this.getField(3, 0);
169                ret = (TS)t;
170            } catch (ClassCastException cce) {
171                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
172                throw new RuntimeException(cce);
173            } catch (HL7Exception he) {
174                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
175                throw new RuntimeException(he);
176            }
177            return ret;
178        }
179    
180    
181        /**
182         * Returns all repetitions of Variance Originator (VAR-4).
183         */
184        public XCN[] getVarianceOriginator() {
185            XCN[] ret = null;
186            try {
187                Type[] t = this.getField(4);  
188                ret = new XCN[t.length];
189                for (int i = 0; i < ret.length; i++) {
190                    ret[i] = (XCN)t[i];
191                }
192            } catch (ClassCastException cce) {
193                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
194                throw new RuntimeException(cce);
195            } catch (HL7Exception he) {
196                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
197                throw new RuntimeException(he);
198            }
199            return ret;
200        }
201    
202    
203        /**
204         * Returns a count of the current number of repetitions of Variance Originator (VAR-4).
205         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
206         * it will return zero.
207         */
208        public int getVarianceOriginatorReps() {
209            XCN[] ret = null;
210            try {
211                Type[] t = this.getField(4);
212                return t.length;  
213            } catch (ClassCastException cce) {
214                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
215                throw new RuntimeException(cce);
216            } catch (HL7Exception he) {
217                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
218                throw new RuntimeException(he);
219            }
220        }
221    
222    
223        /**
224         * Returns a specific repetition of
225         * VAR-4: "Variance Originator" - creates it if necessary
226         *
227         * @param rep The repetition index (0-indexed)
228         */
229        public XCN getVarianceOriginator(int rep) { 
230            XCN ret = null;
231            try {
232                Type t = this.getField(4, rep);
233                ret = (XCN)t;
234            } catch (ClassCastException cce) {
235                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
236                throw new RuntimeException(cce);
237            } catch (HL7Exception he) {
238                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
239                throw new RuntimeException(he);
240            }
241            return ret;
242        }
243    
244        /**
245         * Returns a specific repetition of
246         * VAR-4: "Variance Originator" - creates it if necessary
247         *
248         * @param rep The repetition index (0-indexed)
249         */
250        public XCN getVar4_VarianceOriginator(int rep) { 
251            XCN ret = null;
252            try {
253                Type t = this.getField(4, rep);
254                ret = (XCN)t;
255            } catch (ClassCastException cce) {
256                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
257                throw new RuntimeException(cce);
258            } catch (HL7Exception he) {
259                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
260                throw new RuntimeException(he);
261            }
262            return ret;
263        }
264    
265    
266        /**
267         * Returns a count of the current number of repetitions of Variance Originator (VAR-4).
268         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
269         * it will return zero.
270         */
271        public int getVar4_VarianceOriginatorReps() {
272            XCN[] ret = null;
273            try {
274                Type[] t = this.getField(4);
275                return t.length;  
276            } catch (ClassCastException cce) {
277                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
278                throw new RuntimeException(cce);
279            } catch (HL7Exception he) {
280                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
281                throw new RuntimeException(he);
282            }
283        }
284    
285    
286    
287        /**
288         * Inserts a repetition of
289         * VAR-4: "Variance Originator" at a specific index
290         *
291         * @param rep The repetition index (0-indexed)
292         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
293         */
294        public XCN insertVarianceOriginator(int rep) throws HL7Exception { 
295            return (XCN) super.insertRepetition(4, rep);
296        }
297    
298    
299    
300        /**
301         * Inserts a repetition of
302         * VAR-4: "Variance Originator" at a specific index
303         *
304         * @param rep The repetition index (0-indexed)
305         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
306         */
307        public XCN insertVar4_VarianceOriginator(int rep) throws HL7Exception { 
308            return (XCN) super.insertRepetition(4, rep);
309        }
310    
311    
312        /**
313         * Removes a repetition of
314         * VAR-4: "Variance Originator" at a specific index
315         *
316         * @param rep The repetition index (0-indexed)
317         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
318         */
319        public XCN removeVarianceOriginator(int rep) throws HL7Exception { 
320            return (XCN) super.removeRepetition(4, rep);
321        }
322    
323    
324        /**
325         * Removes a repetition of
326         * VAR-4: "Variance Originator" at a specific index
327         *
328         * @param rep The repetition index (0-indexed)
329         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
330         */
331        public XCN removeVar4_VarianceOriginator(int rep) throws HL7Exception { 
332            return (XCN) super.removeRepetition(4, rep);
333        }
334    
335    
336    
337    
338        /**
339         * Returns
340         * VAR-5: "Variance Classification" - creates it if necessary
341         */
342        public CE getVarianceClassification() { 
343            CE ret = null;
344            try {
345                Type t = this.getField(5, 0);
346                ret = (CE)t;
347            } catch (ClassCastException cce) {
348                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
349                throw new RuntimeException(cce);
350            } catch (HL7Exception he) {
351                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
352                throw new RuntimeException(he);
353            }
354            return ret;
355        }
356    
357    
358        /**
359         * Returns
360         * VAR-5: "Variance Classification" - creates it if necessary
361         */
362        public CE getVar5_VarianceClassification() { 
363            CE ret = null;
364            try {
365                Type t = this.getField(5, 0);
366                ret = (CE)t;
367            } catch (ClassCastException cce) {
368                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
369                throw new RuntimeException(cce);
370            } catch (HL7Exception he) {
371                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
372                throw new RuntimeException(he);
373            }
374            return ret;
375        }
376    
377    
378        /**
379         * Returns all repetitions of Variance Description (VAR-6).
380         */
381        public ST[] getVarianceDescription() {
382            ST[] ret = null;
383            try {
384                Type[] t = this.getField(6);  
385                ret = new ST[t.length];
386                for (int i = 0; i < ret.length; i++) {
387                    ret[i] = (ST)t[i];
388                }
389            } catch (ClassCastException cce) {
390                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
391                throw new RuntimeException(cce);
392            } catch (HL7Exception he) {
393                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
394                throw new RuntimeException(he);
395            }
396            return ret;
397        }
398    
399    
400        /**
401         * Returns a count of the current number of repetitions of Variance Description (VAR-6).
402         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
403         * it will return zero.
404         */
405        public int getVarianceDescriptionReps() {
406            ST[] ret = null;
407            try {
408                Type[] t = this.getField(6);
409                return t.length;  
410            } catch (ClassCastException cce) {
411                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
412                throw new RuntimeException(cce);
413            } catch (HL7Exception he) {
414                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
415                throw new RuntimeException(he);
416            }
417        }
418    
419    
420        /**
421         * Returns a specific repetition of
422         * VAR-6: "Variance Description" - creates it if necessary
423         *
424         * @param rep The repetition index (0-indexed)
425         */
426        public ST getVarianceDescription(int rep) { 
427            ST ret = null;
428            try {
429                Type t = this.getField(6, rep);
430                ret = (ST)t;
431            } catch (ClassCastException cce) {
432                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
433                throw new RuntimeException(cce);
434            } catch (HL7Exception he) {
435                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
436                throw new RuntimeException(he);
437            }
438            return ret;
439        }
440    
441        /**
442         * Returns a specific repetition of
443         * VAR-6: "Variance Description" - creates it if necessary
444         *
445         * @param rep The repetition index (0-indexed)
446         */
447        public ST getVar6_VarianceDescription(int rep) { 
448            ST ret = null;
449            try {
450                Type t = this.getField(6, rep);
451                ret = (ST)t;
452            } catch (ClassCastException cce) {
453                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
454                throw new RuntimeException(cce);
455            } catch (HL7Exception he) {
456                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
457                throw new RuntimeException(he);
458            }
459            return ret;
460        }
461    
462    
463        /**
464         * Returns a count of the current number of repetitions of Variance Description (VAR-6).
465         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
466         * it will return zero.
467         */
468        public int getVar6_VarianceDescriptionReps() {
469            ST[] ret = null;
470            try {
471                Type[] t = this.getField(6);
472                return t.length;  
473            } catch (ClassCastException cce) {
474                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
475                throw new RuntimeException(cce);
476            } catch (HL7Exception he) {
477                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
478                throw new RuntimeException(he);
479            }
480        }
481    
482    
483    
484        /**
485         * Inserts a repetition of
486         * VAR-6: "Variance Description" at a specific index
487         *
488         * @param rep The repetition index (0-indexed)
489         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
490         */
491        public ST insertVarianceDescription(int rep) throws HL7Exception { 
492            return (ST) super.insertRepetition(6, rep);
493        }
494    
495    
496    
497        /**
498         * Inserts a repetition of
499         * VAR-6: "Variance Description" at a specific index
500         *
501         * @param rep The repetition index (0-indexed)
502         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
503         */
504        public ST insertVar6_VarianceDescription(int rep) throws HL7Exception { 
505            return (ST) super.insertRepetition(6, rep);
506        }
507    
508    
509        /**
510         * Removes a repetition of
511         * VAR-6: "Variance Description" at a specific index
512         *
513         * @param rep The repetition index (0-indexed)
514         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
515         */
516        public ST removeVarianceDescription(int rep) throws HL7Exception { 
517            return (ST) super.removeRepetition(6, rep);
518        }
519    
520    
521        /**
522         * Removes a repetition of
523         * VAR-6: "Variance Description" at a specific index
524         *
525         * @param rep The repetition index (0-indexed)
526         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
527         */
528        public ST removeVar6_VarianceDescription(int rep) throws HL7Exception { 
529            return (ST) super.removeRepetition(6, rep);
530        }
531    
532    
533    
534    
535    
536    
537        /** {@inheritDoc} */   
538        protected Type createNewTypeWithoutReflection(int field) {
539           switch (field) {
540              case 0: return new EI(getMessage());
541              case 1: return new TS(getMessage());
542              case 2: return new TS(getMessage());
543              case 3: return new XCN(getMessage());
544              case 4: return new CE(getMessage());
545              case 5: return new ST(getMessage());
546              default: return null;
547           }
548       }
549    
550    
551    }
552