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 LRL message segment (Location Relationship). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>LRL-1: Primary Key Value - LRL (PL) <b> </b>
027         * <li>LRL-2: Segment Action Code (ID) <b>optional </b>
028         * <li>LRL-3: Segment Unique Key (EI) <b>optional </b>
029         * <li>LRL-4: Location Relationship ID (CE) <b> </b>
030         * <li>LRL-5: Organizational Location Relationship Value (XON) <b>optional repeating</b>
031         * <li>LRL-6: Patient Location Relationship Value (PL) <b>optional </b>
032     * </ul>
033     */
034    public class LRL extends AbstractSegment {
035    
036        /** 
037         * Creates a new LRL segment
038         */
039        public LRL(Group parent, ModelClassFactory factory) {
040           super(parent, factory);
041           init(factory);
042        }
043    
044        private void init(ModelClassFactory factory) {
045           try {
046                                      this.add(PL.class, true, 1, 200, new Object[]{ getMessage(), new Integer(0) }, "Primary Key Value - LRL");
047                                      this.add(ID.class, false, 1, 3, new Object[]{ getMessage() }, "Segment Action Code");
048                                      this.add(EI.class, false, 1, 80, new Object[]{ getMessage(), new Integer(0) }, "Segment Unique Key");
049                                      this.add(CE.class, true, 1, 250, new Object[]{ getMessage(), new Integer(325) }, "Location Relationship ID");
050                                      this.add(XON.class, false, 0, 250, new Object[]{ getMessage(), new Integer(0) }, "Organizational Location Relationship Value");
051                                      this.add(PL.class, false, 1, 80, new Object[]{ getMessage(), new Integer(0) }, "Patient Location Relationship Value");
052           } catch(HL7Exception e) {
053              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating LRL - this is probably a bug in the source code generator.", e);
054           }
055        }
056    
057    
058    
059        /**
060         * Returns
061         * LRL-1: "Primary Key Value - LRL" - creates it if necessary
062         */
063        public PL getPrimaryKeyValueLRL() { 
064            PL ret = null;
065            try {
066                Type t = this.getField(1, 0);
067                ret = (PL)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         * LRL-1: "Primary Key Value - LRL" - creates it if necessary
082         */
083        public PL getLrl1_PrimaryKeyValueLRL() { 
084            PL ret = null;
085            try {
086                Type t = this.getField(1, 0);
087                ret = (PL)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         * LRL-2: "Segment Action Code" - creates it if necessary
103         */
104        public ID getSegmentActionCode() { 
105            ID ret = null;
106            try {
107                Type t = this.getField(2, 0);
108                ret = (ID)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         * LRL-2: "Segment Action Code" - creates it if necessary
123         */
124        public ID getLrl2_SegmentActionCode() { 
125            ID ret = null;
126            try {
127                Type t = this.getField(2, 0);
128                ret = (ID)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         * LRL-3: "Segment Unique Key" - creates it if necessary
144         */
145        public EI getSegmentUniqueKey() { 
146            EI ret = null;
147            try {
148                Type t = this.getField(3, 0);
149                ret = (EI)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         * LRL-3: "Segment Unique Key" - creates it if necessary
164         */
165        public EI getLrl3_SegmentUniqueKey() { 
166            EI ret = null;
167            try {
168                Type t = this.getField(3, 0);
169                ret = (EI)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        /**
183         * Returns
184         * LRL-4: "Location Relationship ID" - creates it if necessary
185         */
186        public CE getLocationRelationshipID() { 
187            CE ret = null;
188            try {
189                Type t = this.getField(4, 0);
190                ret = (CE)t;
191            } catch (ClassCastException cce) {
192                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
193                throw new RuntimeException(cce);
194            } catch (HL7Exception he) {
195                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
196                throw new RuntimeException(he);
197            }
198            return ret;
199        }
200    
201    
202        /**
203         * Returns
204         * LRL-4: "Location Relationship ID" - creates it if necessary
205         */
206        public CE getLrl4_LocationRelationshipID() { 
207            CE ret = null;
208            try {
209                Type t = this.getField(4, 0);
210                ret = (CE)t;
211            } catch (ClassCastException cce) {
212                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
213                throw new RuntimeException(cce);
214            } catch (HL7Exception he) {
215                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
216                throw new RuntimeException(he);
217            }
218            return ret;
219        }
220    
221    
222        /**
223         * Returns all repetitions of Organizational Location Relationship Value (LRL-5).
224         */
225        public XON[] getOrganizationalLocationRelationshipValue() {
226            XON[] ret = null;
227            try {
228                Type[] t = this.getField(5);  
229                ret = new XON[t.length];
230                for (int i = 0; i < ret.length; i++) {
231                    ret[i] = (XON)t[i];
232                }
233            } catch (ClassCastException cce) {
234                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
235                throw new RuntimeException(cce);
236            } catch (HL7Exception he) {
237                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
238                throw new RuntimeException(he);
239            }
240            return ret;
241        }
242    
243    
244        /**
245         * Returns a count of the current number of repetitions of Organizational Location Relationship Value (LRL-5).
246         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
247         * it will return zero.
248         */
249        public int getOrganizationalLocationRelationshipValueReps() {
250            XON[] ret = null;
251            try {
252                Type[] t = this.getField(5);
253                return t.length;  
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        }
262    
263    
264        /**
265         * Returns a specific repetition of
266         * LRL-5: "Organizational Location Relationship Value" - creates it if necessary
267         *
268         * @param rep The repetition index (0-indexed)
269         */
270        public XON getOrganizationalLocationRelationshipValue(int rep) { 
271            XON ret = null;
272            try {
273                Type t = this.getField(5, rep);
274                ret = (XON)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         * Returns a specific repetition of
287         * LRL-5: "Organizational Location Relationship Value" - creates it if necessary
288         *
289         * @param rep The repetition index (0-indexed)
290         */
291        public XON getLrl5_OrganizationalLocationRelationshipValue(int rep) { 
292            XON ret = null;
293            try {
294                Type t = this.getField(5, rep);
295                ret = (XON)t;
296            } catch (ClassCastException cce) {
297                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
298                throw new RuntimeException(cce);
299            } catch (HL7Exception he) {
300                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
301                throw new RuntimeException(he);
302            }
303            return ret;
304        }
305    
306    
307        /**
308         * Returns a count of the current number of repetitions of Organizational Location Relationship Value (LRL-5).
309         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
310         * it will return zero.
311         */
312        public int getLrl5_OrganizationalLocationRelationshipValueReps() {
313            XON[] ret = null;
314            try {
315                Type[] t = this.getField(5);
316                return t.length;  
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        }
325    
326    
327    
328        /**
329         * Inserts a repetition of
330         * LRL-5: "Organizational Location Relationship Value" at a specific index
331         *
332         * @param rep The repetition index (0-indexed)
333         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
334         */
335        public XON insertOrganizationalLocationRelationshipValue(int rep) throws HL7Exception { 
336            return (XON) super.insertRepetition(5, rep);
337        }
338    
339    
340    
341        /**
342         * Inserts a repetition of
343         * LRL-5: "Organizational Location Relationship Value" at a specific index
344         *
345         * @param rep The repetition index (0-indexed)
346         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
347         */
348        public XON insertLrl5_OrganizationalLocationRelationshipValue(int rep) throws HL7Exception { 
349            return (XON) super.insertRepetition(5, rep);
350        }
351    
352    
353        /**
354         * Removes a repetition of
355         * LRL-5: "Organizational Location Relationship Value" at a specific index
356         *
357         * @param rep The repetition index (0-indexed)
358         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
359         */
360        public XON removeOrganizationalLocationRelationshipValue(int rep) throws HL7Exception { 
361            return (XON) super.removeRepetition(5, rep);
362        }
363    
364    
365        /**
366         * Removes a repetition of
367         * LRL-5: "Organizational Location Relationship Value" at a specific index
368         *
369         * @param rep The repetition index (0-indexed)
370         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
371         */
372        public XON removeLrl5_OrganizationalLocationRelationshipValue(int rep) throws HL7Exception { 
373            return (XON) super.removeRepetition(5, rep);
374        }
375    
376    
377    
378    
379        /**
380         * Returns
381         * LRL-6: "Patient Location Relationship Value" - creates it if necessary
382         */
383        public PL getPatientLocationRelationshipValue() { 
384            PL ret = null;
385            try {
386                Type t = this.getField(6, 0);
387                ret = (PL)t;
388            } catch (ClassCastException cce) {
389                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
390                throw new RuntimeException(cce);
391            } catch (HL7Exception he) {
392                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
393                throw new RuntimeException(he);
394            }
395            return ret;
396        }
397    
398    
399        /**
400         * Returns
401         * LRL-6: "Patient Location Relationship Value" - creates it if necessary
402         */
403        public PL getLrl6_PatientLocationRelationshipValue() { 
404            PL ret = null;
405            try {
406                Type t = this.getField(6, 0);
407                ret = (PL)t;
408            } catch (ClassCastException cce) {
409                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
410                throw new RuntimeException(cce);
411            } catch (HL7Exception he) {
412                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
413                throw new RuntimeException(he);
414            }
415            return ret;
416        }
417    
418    
419    
420    
421    
422        /** {@inheritDoc} */   
423        protected Type createNewTypeWithoutReflection(int field) {
424           switch (field) {
425              case 0: return new PL(getMessage());
426              case 1: return new ID(getMessage(), new Integer( 206 ));
427              case 2: return new EI(getMessage());
428              case 3: return new CE(getMessage());
429              case 4: return new XON(getMessage());
430              case 5: return new PL(getMessage());
431              default: return null;
432           }
433       }
434    
435    
436    }
437