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 RDF message segment (Table Row Definition). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>RDF-1: Number of Columns per Row (NM) <b> </b>
027         * <li>RDF-2: Column Description (RCD) <b> repeating</b>
028     * </ul>
029     */
030    public class RDF extends AbstractSegment {
031    
032        /** 
033         * Creates a new RDF segment
034         */
035        public RDF(Group parent, ModelClassFactory factory) {
036           super(parent, factory);
037           init(factory);
038        }
039    
040        private void init(ModelClassFactory factory) {
041           try {
042                                      this.add(NM.class, true, 1, 3, new Object[]{ getMessage(), new Integer(0) }, "Number of Columns per Row");
043                                      this.add(RCD.class, true, 0, 40, new Object[]{ getMessage(), new Integer(440) }, "Column Description");
044           } catch(HL7Exception e) {
045              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating RDF - this is probably a bug in the source code generator.", e);
046           }
047        }
048    
049    
050    
051        /**
052         * Returns
053         * RDF-1: "Number of Columns per Row" - creates it if necessary
054         */
055        public NM getNumberOfColumnsPerRow() { 
056            NM ret = null;
057            try {
058                Type t = this.getField(1, 0);
059                ret = (NM)t;
060            } catch (ClassCastException cce) {
061                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
062                throw new RuntimeException(cce);
063            } catch (HL7Exception he) {
064                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
065                throw new RuntimeException(he);
066            }
067            return ret;
068        }
069    
070    
071        /**
072         * Returns
073         * RDF-1: "Number of Columns per Row" - creates it if necessary
074         */
075        public NM getRdf1_NumberOfColumnsPerRow() { 
076            NM ret = null;
077            try {
078                Type t = this.getField(1, 0);
079                ret = (NM)t;
080            } catch (ClassCastException cce) {
081                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
082                throw new RuntimeException(cce);
083            } catch (HL7Exception he) {
084                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
085                throw new RuntimeException(he);
086            }
087            return ret;
088        }
089    
090    
091        /**
092         * Returns all repetitions of Column Description (RDF-2).
093         */
094        public RCD[] getColumnDescription() {
095            RCD[] ret = null;
096            try {
097                Type[] t = this.getField(2);  
098                ret = new RCD[t.length];
099                for (int i = 0; i < ret.length; i++) {
100                    ret[i] = (RCD)t[i];
101                }
102            } catch (ClassCastException cce) {
103                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
104                throw new RuntimeException(cce);
105            } catch (HL7Exception he) {
106                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
107                throw new RuntimeException(he);
108            }
109            return ret;
110        }
111    
112    
113        /**
114         * Returns a count of the current number of repetitions of Column Description (RDF-2).
115         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
116         * it will return zero.
117         */
118        public int getColumnDescriptionReps() {
119            RCD[] ret = null;
120            try {
121                Type[] t = this.getField(2);
122                return t.length;  
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        }
131    
132    
133        /**
134         * Returns a specific repetition of
135         * RDF-2: "Column Description" - creates it if necessary
136         *
137         * @param rep The repetition index (0-indexed)
138         */
139        public RCD getColumnDescription(int rep) { 
140            RCD ret = null;
141            try {
142                Type t = this.getField(2, rep);
143                ret = (RCD)t;
144            } catch (ClassCastException cce) {
145                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
146                throw new RuntimeException(cce);
147            } catch (HL7Exception he) {
148                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
149                throw new RuntimeException(he);
150            }
151            return ret;
152        }
153    
154        /**
155         * Returns a specific repetition of
156         * RDF-2: "Column Description" - creates it if necessary
157         *
158         * @param rep The repetition index (0-indexed)
159         */
160        public RCD getRdf2_ColumnDescription(int rep) { 
161            RCD ret = null;
162            try {
163                Type t = this.getField(2, rep);
164                ret = (RCD)t;
165            } catch (ClassCastException cce) {
166                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
167                throw new RuntimeException(cce);
168            } catch (HL7Exception he) {
169                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
170                throw new RuntimeException(he);
171            }
172            return ret;
173        }
174    
175    
176        /**
177         * Returns a count of the current number of repetitions of Column Description (RDF-2).
178         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
179         * it will return zero.
180         */
181        public int getRdf2_ColumnDescriptionReps() {
182            RCD[] ret = null;
183            try {
184                Type[] t = this.getField(2);
185                return t.length;  
186            } catch (ClassCastException cce) {
187                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
188                throw new RuntimeException(cce);
189            } catch (HL7Exception he) {
190                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
191                throw new RuntimeException(he);
192            }
193        }
194    
195    
196    
197        /**
198         * Inserts a repetition of
199         * RDF-2: "Column Description" at a specific index
200         *
201         * @param rep The repetition index (0-indexed)
202         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
203         */
204        public RCD insertColumnDescription(int rep) throws HL7Exception { 
205            return (RCD) super.insertRepetition(2, rep);
206        }
207    
208    
209    
210        /**
211         * Inserts a repetition of
212         * RDF-2: "Column Description" at a specific index
213         *
214         * @param rep The repetition index (0-indexed)
215         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
216         */
217        public RCD insertRdf2_ColumnDescription(int rep) throws HL7Exception { 
218            return (RCD) super.insertRepetition(2, rep);
219        }
220    
221    
222        /**
223         * Removes a repetition of
224         * RDF-2: "Column Description" at a specific index
225         *
226         * @param rep The repetition index (0-indexed)
227         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
228         */
229        public RCD removeColumnDescription(int rep) throws HL7Exception { 
230            return (RCD) super.removeRepetition(2, rep);
231        }
232    
233    
234        /**
235         * Removes a repetition of
236         * RDF-2: "Column Description" at a specific index
237         *
238         * @param rep The repetition index (0-indexed)
239         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
240         */
241        public RCD removeRdf2_ColumnDescription(int rep) throws HL7Exception { 
242            return (RCD) super.removeRepetition(2, rep);
243        }
244    
245    
246    
247    
248    
249    
250        /** {@inheritDoc} */   
251        protected Type createNewTypeWithoutReflection(int field) {
252           switch (field) {
253              case 0: return new NM(getMessage());
254              case 1: return new RCD(getMessage());
255              default: return null;
256           }
257       }
258    
259    
260    }
261