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