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 ERR message segment (Error). 
024     * This segment has the following fields:</p>
025     * <ul>
026         * <li>ERR-1: Error Code and Location (ELD) <b> repeating</b>
027     * </ul>
028     */
029    public class ERR extends AbstractSegment {
030    
031        /** 
032         * Creates a new ERR segment
033         */
034        public ERR(Group parent, ModelClassFactory factory) {
035           super(parent, factory);
036           init(factory);
037        }
038    
039        private void init(ModelClassFactory factory) {
040           try {
041                                      this.add(ELD.class, true, 0, 80, new Object[]{ getMessage(), new Integer(0) }, "Error Code and Location");
042           } catch(HL7Exception e) {
043              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating ERR - this is probably a bug in the source code generator.", e);
044           }
045        }
046    
047    
048        /**
049         * Returns all repetitions of Error Code and Location (ERR-1).
050         */
051        public ELD[] getErrorCodeAndLocation() {
052            ELD[] ret = null;
053            try {
054                Type[] t = this.getField(1);  
055                ret = new ELD[t.length];
056                for (int i = 0; i < ret.length; i++) {
057                    ret[i] = (ELD)t[i];
058                }
059            } catch (ClassCastException cce) {
060                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
061                throw new RuntimeException(cce);
062            } catch (HL7Exception he) {
063                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
064                throw new RuntimeException(he);
065            }
066            return ret;
067        }
068    
069    
070        /**
071         * Returns a count of the current number of repetitions of Error Code and Location (ERR-1).
072         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
073         * it will return zero.
074         */
075        public int getErrorCodeAndLocationReps() {
076            ELD[] ret = null;
077            try {
078                Type[] t = this.getField(1);
079                return t.length;  
080            } catch (ClassCastException cce) {
081                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
082                throw new RuntimeException(cce);
083            } catch (HL7Exception he) {
084                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
085                throw new RuntimeException(he);
086            }
087        }
088    
089    
090        /**
091         * Returns a specific repetition of
092         * ERR-1: "Error Code and Location" - creates it if necessary
093         *
094         * @param rep The repetition index (0-indexed)
095         */
096        public ELD getErrorCodeAndLocation(int rep) { 
097            ELD ret = null;
098            try {
099                Type t = this.getField(1, rep);
100                ret = (ELD)t;
101            } catch (ClassCastException cce) {
102                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
103                throw new RuntimeException(cce);
104            } catch (HL7Exception he) {
105                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
106                throw new RuntimeException(he);
107            }
108            return ret;
109        }
110    
111        /**
112         * Returns a specific repetition of
113         * ERR-1: "Error Code and Location" - creates it if necessary
114         *
115         * @param rep The repetition index (0-indexed)
116         */
117        public ELD getErr1_ErrorCodeAndLocation(int rep) { 
118            ELD ret = null;
119            try {
120                Type t = this.getField(1, rep);
121                ret = (ELD)t;
122            } catch (ClassCastException cce) {
123                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
124                throw new RuntimeException(cce);
125            } catch (HL7Exception he) {
126                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
127                throw new RuntimeException(he);
128            }
129            return ret;
130        }
131    
132    
133        /**
134         * Returns a count of the current number of repetitions of Error Code and Location (ERR-1).
135         * This method does not create a repetition, so if no repetitions have currently been defined or accessed,
136         * it will return zero.
137         */
138        public int getErr1_ErrorCodeAndLocationReps() {
139            ELD[] ret = null;
140            try {
141                Type[] t = this.getField(1);
142                return t.length;  
143            } catch (ClassCastException cce) {
144                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", cce);
145                throw new RuntimeException(cce);
146            } catch (HL7Exception he) {
147                HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem obtaining field value.  This is a bug.", he);
148                throw new RuntimeException(he);
149            }
150        }
151    
152    
153    
154        /**
155         * Inserts a repetition of
156         * ERR-1: "Error Code and Location" at a specific index
157         *
158         * @param rep The repetition index (0-indexed)
159         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
160         */
161        public ELD insertErrorCodeAndLocation(int rep) throws HL7Exception { 
162            return (ELD) super.insertRepetition(1, rep);
163        }
164    
165    
166    
167        /**
168         * Inserts a repetition of
169         * ERR-1: "Error Code and Location" at a specific index
170         *
171         * @param rep The repetition index (0-indexed)
172         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
173         */
174        public ELD insertErr1_ErrorCodeAndLocation(int rep) throws HL7Exception { 
175            return (ELD) super.insertRepetition(1, rep);
176        }
177    
178    
179        /**
180         * Removes a repetition of
181         * ERR-1: "Error Code and Location" at a specific index
182         *
183         * @param rep The repetition index (0-indexed)
184         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
185         */
186        public ELD removeErrorCodeAndLocation(int rep) throws HL7Exception { 
187            return (ELD) super.removeRepetition(1, rep);
188        }
189    
190    
191        /**
192         * Removes a repetition of
193         * ERR-1: "Error Code and Location" at a specific index
194         *
195         * @param rep The repetition index (0-indexed)
196         * @throws HL7Exception If the rep is invalid (below 0, or too high for the allowable repetitions)
197         */
198        public ELD removeErr1_ErrorCodeAndLocation(int rep) throws HL7Exception { 
199            return (ELD) super.removeRepetition(1, rep);
200        }
201    
202    
203    
204    
205    
206    
207        /** {@inheritDoc} */   
208        protected Type createNewTypeWithoutReflection(int field) {
209           switch (field) {
210              case 0: return new ELD(getMessage());
211              default: return null;
212           }
213       }
214    
215    
216    }
217