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 CM2 message segment (Clinical Study Schedule Master). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>CM2-1: Set ID- CM2 (SI) <b>optional </b>
027         * <li>CM2-2: Scheduled Time Point (CE) <b> </b>
028         * <li>CM2-3: Description of Time Point (ST) <b>optional </b>
029         * <li>CM2-4: Events Scheduled This Time Point (CE) <b> repeating</b>
030     * </ul>
031     */
032    public class CM2 extends AbstractSegment {
033    
034        /** 
035         * Creates a new CM2 segment
036         */
037        public CM2(Group parent, ModelClassFactory factory) {
038           super(parent, factory);
039           init(factory);
040        }
041    
042        private void init(ModelClassFactory factory) {
043           try {
044                                      this.add(SI.class, false, 1, 4, new Object[]{ getMessage(), new Integer(0) }, "Set ID- CM2");
045                                      this.add(CE.class, true, 1, 250, new Object[]{ getMessage(), new Integer(9999) }, "Scheduled Time Point");
046                                      this.add(ST.class, false, 1, 300, new Object[]{ getMessage(), new Integer(0) }, "Description of Time Point");
047                                      this.add(CE.class, true, 200, 250, new Object[]{ getMessage(), new Integer(9999) }, "Events Scheduled This Time Point");
048           } catch(HL7Exception e) {
049              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating CM2 - this is probably a bug in the source code generator.", e);
050           }
051        }
052    
053    
054    
055        /**
056         * Returns
057         * CM2-1: "Set ID- CM2" - creates it if necessary
058         */
059        public SI getSetIDCM2() { 
060            SI ret = null;
061            try {
062                Type t = this.getField(1, 0);
063                ret = (SI)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         * CM2-1: "Set ID- CM2" - creates it if necessary
078         */
079        public SI getCm21_SetIDCM2() { 
080            SI ret = null;
081            try {
082                Type t = this.getField(1, 0);
083                ret = (SI)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        /**
097         * Returns
098         * CM2-2: "Scheduled Time Point" - creates it if necessary
099         */
100        public CE getScheduledTimePoint() { 
101            CE ret = null;
102            try {
103                Type t = this.getField(2, 0);
104                ret = (CE)t;
105            } catch (ClassCastException cce) {
106                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
107                throw new RuntimeException(cce);
108            } catch (HL7Exception he) {
109                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
110                throw new RuntimeException(he);
111            }
112            return ret;
113        }
114    
115    
116        /**
117         * Returns
118         * CM2-2: "Scheduled Time Point" - creates it if necessary
119         */
120        public CE getCm22_ScheduledTimePoint() { 
121            CE ret = null;
122            try {
123                Type t = this.getField(2, 0);
124                ret = (CE)t;
125            } catch (ClassCastException cce) {
126                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
127                throw new RuntimeException(cce);
128            } catch (HL7Exception he) {
129                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
130                throw new RuntimeException(he);
131            }
132            return ret;
133        }
134    
135    
136    
137        /**
138         * Returns
139         * CM2-3: "Description of Time Point" - creates it if necessary
140         */
141        public ST getDescriptionOfTimePoint() { 
142            ST ret = null;
143            try {
144                Type t = this.getField(3, 0);
145                ret = (ST)t;
146            } catch (ClassCastException cce) {
147                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
148                throw new RuntimeException(cce);
149            } catch (HL7Exception he) {
150                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
151                throw new RuntimeException(he);
152            }
153            return ret;
154        }
155    
156    
157        /**
158         * Returns
159         * CM2-3: "Description of Time Point" - creates it if necessary
160         */
161        public ST getCm23_DescriptionOfTimePoint() { 
162            ST ret = null;
163            try {
164                Type t = this.getField(3, 0);
165                ret = (ST)t;
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            return ret;
174        }
175    
176    
177        /**
178         * Returns all repetitions of Events Scheduled This Time Point (CM2-4).
179         */
180        public CE[] getEventsScheduledThisTimePoint() {
181            CE[] ret = null;
182            try {
183                Type[] t = this.getField(4);  
184                ret = new CE[t.length];
185                for (int i = 0; i < ret.length; i++) {
186                    ret[i] = (CE)t[i];
187                }
188            } catch (ClassCastException cce) {
189                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
190                throw new RuntimeException(cce);
191            } catch (HL7Exception he) {
192                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
193                throw new RuntimeException(he);
194            }
195            return ret;
196        }
197    
198    
199        /**
200         * Returns a count of the current number of repetitions of Events Scheduled This Time Point (CM2-4).
201         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
202         * it will return zero.
203         */
204        public int getEventsScheduledThisTimePointReps() {
205            CE[] ret = null;
206            try {
207                Type[] t = this.getField(4);
208                return t.length;  
209            } catch (ClassCastException cce) {
210                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
211                throw new RuntimeException(cce);
212            } catch (HL7Exception he) {
213                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
214                throw new RuntimeException(he);
215            }
216        }
217    
218    
219        /**
220         * Returns a specific repetition of
221         * CM2-4: "Events Scheduled This Time Point" - creates it if necessary
222         *
223         * @param rep The repetition index (0-indexed)
224         */
225        public CE getEventsScheduledThisTimePoint(int rep) { 
226            CE ret = null;
227            try {
228                Type t = this.getField(4, rep);
229                ret = (CE)t;
230            } catch (ClassCastException cce) {
231                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
232                throw new RuntimeException(cce);
233            } catch (HL7Exception he) {
234                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
235                throw new RuntimeException(he);
236            }
237            return ret;
238        }
239    
240        /**
241         * Returns a specific repetition of
242         * CM2-4: "Events Scheduled This Time Point" - creates it if necessary
243         *
244         * @param rep The repetition index (0-indexed)
245         */
246        public CE getCm24_EventsScheduledThisTimePoint(int rep) { 
247            CE ret = null;
248            try {
249                Type t = this.getField(4, rep);
250                ret = (CE)t;
251            } catch (ClassCastException cce) {
252                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
253                throw new RuntimeException(cce);
254            } catch (HL7Exception he) {
255                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
256                throw new RuntimeException(he);
257            }
258            return ret;
259        }
260    
261    
262        /**
263         * Returns a count of the current number of repetitions of Events Scheduled This Time Point (CM2-4).
264         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
265         * it will return zero.
266         */
267        public int getCm24_EventsScheduledThisTimePointReps() {
268            CE[] ret = null;
269            try {
270                Type[] t = this.getField(4);
271                return t.length;  
272            } catch (ClassCastException cce) {
273                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
274                throw new RuntimeException(cce);
275            } catch (HL7Exception he) {
276                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
277                throw new RuntimeException(he);
278            }
279        }
280    
281    
282    
283        /**
284         * Inserts a repetition of
285         * CM2-4: "Events Scheduled This Time Point" at a specific index
286         *
287         * @param rep The repetition index (0-indexed)
288         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
289         */
290        public CE insertEventsScheduledThisTimePoint(int rep) throws HL7Exception { 
291            return (CE) super.insertRepetition(4, rep);
292        }
293    
294    
295    
296        /**
297         * Inserts a repetition of
298         * CM2-4: "Events Scheduled This Time Point" at a specific index
299         *
300         * @param rep The repetition index (0-indexed)
301         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
302         */
303        public CE insertCm24_EventsScheduledThisTimePoint(int rep) throws HL7Exception { 
304            return (CE) super.insertRepetition(4, rep);
305        }
306    
307    
308        /**
309         * Removes a repetition of
310         * CM2-4: "Events Scheduled This Time Point" at a specific index
311         *
312         * @param rep The repetition index (0-indexed)
313         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
314         */
315        public CE removeEventsScheduledThisTimePoint(int rep) throws HL7Exception { 
316            return (CE) super.removeRepetition(4, rep);
317        }
318    
319    
320        /**
321         * Removes a repetition of
322         * CM2-4: "Events Scheduled This Time Point" at a specific index
323         *
324         * @param rep The repetition index (0-indexed)
325         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
326         */
327        public CE removeCm24_EventsScheduledThisTimePoint(int rep) throws HL7Exception { 
328            return (CE) super.removeRepetition(4, rep);
329        }
330    
331    
332    
333    
334    
335    
336        /** {@inheritDoc} */   
337        protected Type createNewTypeWithoutReflection(int field) {
338           switch (field) {
339              case 0: return new SI(getMessage());
340              case 1: return new CE(getMessage());
341              case 2: return new ST(getMessage());
342              case 3: return new CE(getMessage());
343              default: return null;
344           }
345       }
346    
347    
348    }
349