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 RXC message segment (Pharmacy/Treatment Component Order). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>RXC-1: RX Component Type (ID) <b> </b>
027         * <li>RXC-2: Component Code (CE) <b> </b>
028         * <li>RXC-3: Component Amount (NM) <b> </b>
029         * <li>RXC-4: Component Units (CE) <b> </b>
030         * <li>RXC-5: Component Strength (NM) <b>optional </b>
031         * <li>RXC-6: Component Strength Units (CE) <b>optional </b>
032         * <li>RXC-7: Supplementary Code (CE) <b>optional repeating</b>
033     * </ul>
034     */
035    public class RXC extends AbstractSegment {
036    
037        /** 
038         * Creates a new RXC segment
039         */
040        public RXC(Group parent, ModelClassFactory factory) {
041           super(parent, factory);
042           init(factory);
043        }
044    
045        private void init(ModelClassFactory factory) {
046           try {
047                                      this.add(ID.class, true, 1, 1, new Object[]{ getMessage() }, "RX Component Type");
048                                      this.add(CE.class, true, 1, 250, new Object[]{ getMessage(), new Integer(0) }, "Component Code");
049                                      this.add(NM.class, true, 1, 20, new Object[]{ getMessage(), new Integer(0) }, "Component Amount");
050                                      this.add(CE.class, true, 1, 250, new Object[]{ getMessage(), new Integer(0) }, "Component Units");
051                                      this.add(NM.class, false, 1, 20, new Object[]{ getMessage(), new Integer(0) }, "Component Strength");
052                                      this.add(CE.class, false, 1, 250, new Object[]{ getMessage(), new Integer(0) }, "Component Strength Units");
053                                      this.add(CE.class, false, 0, 250, new Object[]{ getMessage(), new Integer(0) }, "Supplementary Code");
054           } catch(HL7Exception e) {
055              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating RXC - this is probably a bug in the source code generator.", e);
056           }
057        }
058    
059    
060    
061        /**
062         * Returns
063         * RXC-1: "RX Component Type" - creates it if necessary
064         */
065        public ID getRXComponentType() { 
066            ID ret = null;
067            try {
068                Type t = this.getField(1, 0);
069                ret = (ID)t;
070            } catch (ClassCastException cce) {
071                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
072                throw new RuntimeException(cce);
073            } catch (HL7Exception he) {
074                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
075                throw new RuntimeException(he);
076            }
077            return ret;
078        }
079    
080    
081        /**
082         * Returns
083         * RXC-1: "RX Component Type" - creates it if necessary
084         */
085        public ID getRxc1_RXComponentType() { 
086            ID ret = null;
087            try {
088                Type t = this.getField(1, 0);
089                ret = (ID)t;
090            } catch (ClassCastException cce) {
091                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
092                throw new RuntimeException(cce);
093            } catch (HL7Exception he) {
094                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
095                throw new RuntimeException(he);
096            }
097            return ret;
098        }
099    
100    
101    
102        /**
103         * Returns
104         * RXC-2: "Component Code" - creates it if necessary
105         */
106        public CE getComponentCode() { 
107            CE ret = null;
108            try {
109                Type t = this.getField(2, 0);
110                ret = (CE)t;
111            } catch (ClassCastException cce) {
112                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
113                throw new RuntimeException(cce);
114            } catch (HL7Exception he) {
115                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
116                throw new RuntimeException(he);
117            }
118            return ret;
119        }
120    
121    
122        /**
123         * Returns
124         * RXC-2: "Component Code" - creates it if necessary
125         */
126        public CE getRxc2_ComponentCode() { 
127            CE ret = null;
128            try {
129                Type t = this.getField(2, 0);
130                ret = (CE)t;
131            } catch (ClassCastException cce) {
132                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
133                throw new RuntimeException(cce);
134            } catch (HL7Exception he) {
135                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
136                throw new RuntimeException(he);
137            }
138            return ret;
139        }
140    
141    
142    
143        /**
144         * Returns
145         * RXC-3: "Component Amount" - creates it if necessary
146         */
147        public NM getComponentAmount() { 
148            NM ret = null;
149            try {
150                Type t = this.getField(3, 0);
151                ret = (NM)t;
152            } catch (ClassCastException cce) {
153                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
154                throw new RuntimeException(cce);
155            } catch (HL7Exception he) {
156                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
157                throw new RuntimeException(he);
158            }
159            return ret;
160        }
161    
162    
163        /**
164         * Returns
165         * RXC-3: "Component Amount" - creates it if necessary
166         */
167        public NM getRxc3_ComponentAmount() { 
168            NM ret = null;
169            try {
170                Type t = this.getField(3, 0);
171                ret = (NM)t;
172            } catch (ClassCastException cce) {
173                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
174                throw new RuntimeException(cce);
175            } catch (HL7Exception he) {
176                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
177                throw new RuntimeException(he);
178            }
179            return ret;
180        }
181    
182    
183    
184        /**
185         * Returns
186         * RXC-4: "Component Units" - creates it if necessary
187         */
188        public CE getComponentUnits() { 
189            CE ret = null;
190            try {
191                Type t = this.getField(4, 0);
192                ret = (CE)t;
193            } catch (ClassCastException cce) {
194                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
195                throw new RuntimeException(cce);
196            } catch (HL7Exception he) {
197                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
198                throw new RuntimeException(he);
199            }
200            return ret;
201        }
202    
203    
204        /**
205         * Returns
206         * RXC-4: "Component Units" - creates it if necessary
207         */
208        public CE getRxc4_ComponentUnits() { 
209            CE ret = null;
210            try {
211                Type t = this.getField(4, 0);
212                ret = (CE)t;
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            return ret;
221        }
222    
223    
224    
225        /**
226         * Returns
227         * RXC-5: "Component Strength" - creates it if necessary
228         */
229        public NM getComponentStrength() { 
230            NM ret = null;
231            try {
232                Type t = this.getField(5, 0);
233                ret = (NM)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        /**
246         * Returns
247         * RXC-5: "Component Strength" - creates it if necessary
248         */
249        public NM getRxc5_ComponentStrength() { 
250            NM ret = null;
251            try {
252                Type t = this.getField(5, 0);
253                ret = (NM)t;
254            } catch (ClassCastException cce) {
255                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
256                throw new RuntimeException(cce);
257            } catch (HL7Exception he) {
258                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
259                throw new RuntimeException(he);
260            }
261            return ret;
262        }
263    
264    
265    
266        /**
267         * Returns
268         * RXC-6: "Component Strength Units" - creates it if necessary
269         */
270        public CE getComponentStrengthUnits() { 
271            CE ret = null;
272            try {
273                Type t = this.getField(6, 0);
274                ret = (CE)t;
275            } catch (ClassCastException cce) {
276                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
277                throw new RuntimeException(cce);
278            } catch (HL7Exception he) {
279                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
280                throw new RuntimeException(he);
281            }
282            return ret;
283        }
284    
285    
286        /**
287         * Returns
288         * RXC-6: "Component Strength Units" - creates it if necessary
289         */
290        public CE getRxc6_ComponentStrengthUnits() { 
291            CE ret = null;
292            try {
293                Type t = this.getField(6, 0);
294                ret = (CE)t;
295            } catch (ClassCastException cce) {
296                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
297                throw new RuntimeException(cce);
298            } catch (HL7Exception he) {
299                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
300                throw new RuntimeException(he);
301            }
302            return ret;
303        }
304    
305    
306        /**
307         * Returns all repetitions of Supplementary Code (RXC-7).
308         */
309        public CE[] getSupplementaryCode() {
310            CE[] ret = null;
311            try {
312                Type[] t = this.getField(7);  
313                ret = new CE[t.length];
314                for (int i = 0; i < ret.length; i++) {
315                    ret[i] = (CE)t[i];
316                }
317            } catch (ClassCastException cce) {
318                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
319                throw new RuntimeException(cce);
320            } catch (HL7Exception he) {
321                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
322                throw new RuntimeException(he);
323            }
324            return ret;
325        }
326    
327    
328        /**
329         * Returns a count of the current number of repetitions of Supplementary Code (RXC-7).
330         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
331         * it will return zero.
332         */
333        public int getSupplementaryCodeReps() {
334            CE[] ret = null;
335            try {
336                Type[] t = this.getField(7);
337                return t.length;  
338            } catch (ClassCastException cce) {
339                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
340                throw new RuntimeException(cce);
341            } catch (HL7Exception he) {
342                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
343                throw new RuntimeException(he);
344            }
345        }
346    
347    
348        /**
349         * Returns a specific repetition of
350         * RXC-7: "Supplementary Code" - creates it if necessary
351         *
352         * @param rep The repetition index (0-indexed)
353         */
354        public CE getSupplementaryCode(int rep) { 
355            CE ret = null;
356            try {
357                Type t = this.getField(7, rep);
358                ret = (CE)t;
359            } catch (ClassCastException cce) {
360                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
361                throw new RuntimeException(cce);
362            } catch (HL7Exception he) {
363                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
364                throw new RuntimeException(he);
365            }
366            return ret;
367        }
368    
369        /**
370         * Returns a specific repetition of
371         * RXC-7: "Supplementary Code" - creates it if necessary
372         *
373         * @param rep The repetition index (0-indexed)
374         */
375        public CE getRxc7_SupplementaryCode(int rep) { 
376            CE ret = null;
377            try {
378                Type t = this.getField(7, rep);
379                ret = (CE)t;
380            } catch (ClassCastException cce) {
381                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
382                throw new RuntimeException(cce);
383            } catch (HL7Exception he) {
384                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
385                throw new RuntimeException(he);
386            }
387            return ret;
388        }
389    
390    
391        /**
392         * Returns a count of the current number of repetitions of Supplementary Code (RXC-7).
393         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
394         * it will return zero.
395         */
396        public int getRxc7_SupplementaryCodeReps() {
397            CE[] ret = null;
398            try {
399                Type[] t = this.getField(7);
400                return t.length;  
401            } catch (ClassCastException cce) {
402                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
403                throw new RuntimeException(cce);
404            } catch (HL7Exception he) {
405                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
406                throw new RuntimeException(he);
407            }
408        }
409    
410    
411    
412        /**
413         * Inserts a repetition of
414         * RXC-7: "Supplementary Code" at a specific index
415         *
416         * @param rep The repetition index (0-indexed)
417         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
418         */
419        public CE insertSupplementaryCode(int rep) throws HL7Exception { 
420            return (CE) super.insertRepetition(7, rep);
421        }
422    
423    
424    
425        /**
426         * Inserts a repetition of
427         * RXC-7: "Supplementary Code" at a specific index
428         *
429         * @param rep The repetition index (0-indexed)
430         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
431         */
432        public CE insertRxc7_SupplementaryCode(int rep) throws HL7Exception { 
433            return (CE) super.insertRepetition(7, rep);
434        }
435    
436    
437        /**
438         * Removes a repetition of
439         * RXC-7: "Supplementary Code" at a specific index
440         *
441         * @param rep The repetition index (0-indexed)
442         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
443         */
444        public CE removeSupplementaryCode(int rep) throws HL7Exception { 
445            return (CE) super.removeRepetition(7, rep);
446        }
447    
448    
449        /**
450         * Removes a repetition of
451         * RXC-7: "Supplementary Code" at a specific index
452         *
453         * @param rep The repetition index (0-indexed)
454         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
455         */
456        public CE removeRxc7_SupplementaryCode(int rep) throws HL7Exception { 
457            return (CE) super.removeRepetition(7, rep);
458        }
459    
460    
461    
462    
463    
464    
465        /** {@inheritDoc} */   
466        protected Type createNewTypeWithoutReflection(int field) {
467           switch (field) {
468              case 0: return new ID(getMessage(), new Integer( 166 ));
469              case 1: return new CE(getMessage());
470              case 2: return new NM(getMessage());
471              case 3: return new CE(getMessage());
472              case 4: return new NM(getMessage());
473              case 5: return new CE(getMessage());
474              case 6: return new CE(getMessage());
475              default: return null;
476           }
477       }
478    
479    
480    }
481