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 LAN message segment (Language Detail). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>LAN-1: Set ID - LAN (SI) <b> </b>
027         * <li>LAN-2: Language Code (CE) <b> </b>
028         * <li>LAN-3: Language Ability Code (CE) <b>optional repeating</b>
029         * <li>LAN-4: Language Proficiency Code (CE) <b>optional </b>
030     * </ul>
031     */
032    public class LAN extends AbstractSegment {
033    
034        /** 
035         * Creates a new LAN segment
036         */
037        public LAN(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, true, 1, 60, new Object[]{ getMessage(), new Integer(0) }, "Set ID - LAN");
045                                      this.add(CE.class, true, 1, 250, new Object[]{ getMessage(), new Integer(296) }, "Language Code");
046                                      this.add(CE.class, false, 0, 250, new Object[]{ getMessage(), new Integer(403) }, "Language Ability Code");
047                                      this.add(CE.class, false, 1, 250, new Object[]{ getMessage(), new Integer(404) }, "Language Proficiency Code");
048           } catch(HL7Exception e) {
049              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating LAN - this is probably a bug in the source code generator.", e);
050           }
051        }
052    
053    
054    
055        /**
056         * Returns
057         * LAN-1: "Set ID - LAN" - creates it if necessary
058         */
059        public SI getSetIDLAN() { 
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         * LAN-1: "Set ID - LAN" - creates it if necessary
078         */
079        public SI getLan1_SetIDLAN() { 
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         * LAN-2: "Language Code" - creates it if necessary
099         */
100        public CE getLanguageCode() { 
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         * LAN-2: "Language Code" - creates it if necessary
119         */
120        public CE getLan2_LanguageCode() { 
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         * Returns all repetitions of Language Ability Code (LAN-3).
138         */
139        public CE[] getLanguageAbilityCode() {
140            CE[] ret = null;
141            try {
142                Type[] t = this.getField(3);  
143                ret = new CE[t.length];
144                for (int i = 0; i < ret.length; i++) {
145                    ret[i] = (CE)t[i];
146                }
147            } catch (ClassCastException cce) {
148                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
149                throw new RuntimeException(cce);
150            } catch (HL7Exception he) {
151                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
152                throw new RuntimeException(he);
153            }
154            return ret;
155        }
156    
157    
158        /**
159         * Returns a count of the current number of repetitions of Language Ability Code (LAN-3).
160         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
161         * it will return zero.
162         */
163        public int getLanguageAbilityCodeReps() {
164            CE[] ret = null;
165            try {
166                Type[] t = this.getField(3);
167                return t.length;  
168            } catch (ClassCastException cce) {
169                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
170                throw new RuntimeException(cce);
171            } catch (HL7Exception he) {
172                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
173                throw new RuntimeException(he);
174            }
175        }
176    
177    
178        /**
179         * Returns a specific repetition of
180         * LAN-3: "Language Ability Code" - creates it if necessary
181         *
182         * @param rep The repetition index (0-indexed)
183         */
184        public CE getLanguageAbilityCode(int rep) { 
185            CE ret = null;
186            try {
187                Type t = this.getField(3, rep);
188                ret = (CE)t;
189            } catch (ClassCastException cce) {
190                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
191                throw new RuntimeException(cce);
192            } catch (HL7Exception he) {
193                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
194                throw new RuntimeException(he);
195            }
196            return ret;
197        }
198    
199        /**
200         * Returns a specific repetition of
201         * LAN-3: "Language Ability Code" - creates it if necessary
202         *
203         * @param rep The repetition index (0-indexed)
204         */
205        public CE getLan3_LanguageAbilityCode(int rep) { 
206            CE ret = null;
207            try {
208                Type t = this.getField(3, rep);
209                ret = (CE)t;
210            } catch (ClassCastException cce) {
211                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
212                throw new RuntimeException(cce);
213            } catch (HL7Exception he) {
214                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
215                throw new RuntimeException(he);
216            }
217            return ret;
218        }
219    
220    
221        /**
222         * Returns a count of the current number of repetitions of Language Ability Code (LAN-3).
223         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
224         * it will return zero.
225         */
226        public int getLan3_LanguageAbilityCodeReps() {
227            CE[] ret = null;
228            try {
229                Type[] t = this.getField(3);
230                return t.length;  
231            } catch (ClassCastException cce) {
232                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
233                throw new RuntimeException(cce);
234            } catch (HL7Exception he) {
235                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
236                throw new RuntimeException(he);
237            }
238        }
239    
240    
241    
242        /**
243         * Inserts a repetition of
244         * LAN-3: "Language Ability Code" at a specific index
245         *
246         * @param rep The repetition index (0-indexed)
247         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
248         */
249        public CE insertLanguageAbilityCode(int rep) throws HL7Exception { 
250            return (CE) super.insertRepetition(3, rep);
251        }
252    
253    
254    
255        /**
256         * Inserts a repetition of
257         * LAN-3: "Language Ability Code" at a specific index
258         *
259         * @param rep The repetition index (0-indexed)
260         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
261         */
262        public CE insertLan3_LanguageAbilityCode(int rep) throws HL7Exception { 
263            return (CE) super.insertRepetition(3, rep);
264        }
265    
266    
267        /**
268         * Removes a repetition of
269         * LAN-3: "Language Ability Code" at a specific index
270         *
271         * @param rep The repetition index (0-indexed)
272         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
273         */
274        public CE removeLanguageAbilityCode(int rep) throws HL7Exception { 
275            return (CE) super.removeRepetition(3, rep);
276        }
277    
278    
279        /**
280         * Removes a repetition of
281         * LAN-3: "Language Ability Code" at a specific index
282         *
283         * @param rep The repetition index (0-indexed)
284         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
285         */
286        public CE removeLan3_LanguageAbilityCode(int rep) throws HL7Exception { 
287            return (CE) super.removeRepetition(3, rep);
288        }
289    
290    
291    
292    
293        /**
294         * Returns
295         * LAN-4: "Language Proficiency Code" - creates it if necessary
296         */
297        public CE getLanguageProficiencyCode() { 
298            CE ret = null;
299            try {
300                Type t = this.getField(4, 0);
301                ret = (CE)t;
302            } catch (ClassCastException cce) {
303                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
304                throw new RuntimeException(cce);
305            } catch (HL7Exception he) {
306                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
307                throw new RuntimeException(he);
308            }
309            return ret;
310        }
311    
312    
313        /**
314         * Returns
315         * LAN-4: "Language Proficiency Code" - creates it if necessary
316         */
317        public CE getLan4_LanguageProficiencyCode() { 
318            CE ret = null;
319            try {
320                Type t = this.getField(4, 0);
321                ret = (CE)t;
322            } catch (ClassCastException cce) {
323                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
324                throw new RuntimeException(cce);
325            } catch (HL7Exception he) {
326                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
327                throw new RuntimeException(he);
328            }
329            return ret;
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 CE(getMessage());
342              case 3: return new CE(getMessage());
343              default: return null;
344           }
345       }
346    
347    
348    }
349