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.datatype;
009    
010    import ca.uhn.hl7v2.model.Composite;
011    import ca.uhn.hl7v2.model.DataTypeException;
012    import ca.uhn.hl7v2.model.Message;
013    import ca.uhn.hl7v2.model.Type;
014    import ca.uhn.hl7v2.model.AbstractType;
015    import ca.uhn.log.HapiLogFactory;
016    
017    /**
018     * <p>Represents an HL7 CP (composite price) data type. 
019     * This type consists of the following components:</p>
020     * <ul>
021     * <li>price (MO)
022     * <li>price type (ID)
023     * <li>from value (NM)
024     * <li>to value (NM)
025     * <li>range units (CE)
026     * <li>range type (ID)
027     * </ul>
028     */
029    public class CP extends AbstractType implements Composite {
030    
031        private Type[] data;
032    
033        /** 
034         * Creates a new CP type
035         */
036        public CP(Message message) {
037            super(message);
038            init();
039        }
040    
041        private void init() {
042            data = new Type[6];    
043            data[0] = new MO(getMessage());
044            data[1] = new ID(getMessage(), 205);
045            data[2] = new NM(getMessage());
046            data[3] = new NM(getMessage());
047            data[4] = new CE(getMessage());
048            data[5] = new ID(getMessage(), 298);
049        }
050    
051    
052        /**
053         * Returns an array containing the data elements.
054         */
055        public Type[] getComponents() { 
056            return this.data; 
057        }
058    
059        /**
060         * Returns an individual data component.
061         *
062         * @param number The component number (0-indexed)
063         * @throws DataTypeException if the given element number is out of range.
064         */
065        public Type getComponent(int number) throws DataTypeException { 
066    
067            try { 
068                return this.data[number]; 
069            } catch (ArrayIndexOutOfBoundsException e) { 
070                throw new DataTypeException("Element " + number + " doesn't exist (Type " + getClass().getName() + " has only " + this.data.length + " components)"); 
071            } 
072        } 
073    
074    
075        /**
076         * Returns price (component #1).  This is a convenience method that saves you from 
077         * casting and handling an exception.
078         */
079        public MO getPrice() {
080           MO ret = null;
081           try {
082              ret = (MO)getComponent(0);
083           } catch (DataTypeException e) {
084              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
085              throw new RuntimeException(e);
086           }
087           return ret;
088        }
089    
090        
091        /**
092         * Returns price (component #1).  This is a convenience method that saves you from 
093         * casting and handling an exception.
094         */
095        public MO getCp1_Price() {
096           MO ret = null;
097           try {
098              ret = (MO)getComponent(0);
099           } catch (DataTypeException e) {
100              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
101              throw new RuntimeException(e);
102           }
103           return ret;
104        }
105    
106    
107        /**
108         * Returns price type (component #2).  This is a convenience method that saves you from 
109         * casting and handling an exception.
110         */
111        public ID getPriceType() {
112           ID ret = null;
113           try {
114              ret = (ID)getComponent(1);
115           } catch (DataTypeException e) {
116              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
117              throw new RuntimeException(e);
118           }
119           return ret;
120        }
121    
122        
123        /**
124         * Returns price type (component #2).  This is a convenience method that saves you from 
125         * casting and handling an exception.
126         */
127        public ID getCp2_PriceType() {
128           ID ret = null;
129           try {
130              ret = (ID)getComponent(1);
131           } catch (DataTypeException e) {
132              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
133              throw new RuntimeException(e);
134           }
135           return ret;
136        }
137    
138    
139        /**
140         * Returns from value (component #3).  This is a convenience method that saves you from 
141         * casting and handling an exception.
142         */
143        public NM getFromValue() {
144           NM ret = null;
145           try {
146              ret = (NM)getComponent(2);
147           } catch (DataTypeException e) {
148              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
149              throw new RuntimeException(e);
150           }
151           return ret;
152        }
153    
154        
155        /**
156         * Returns from value (component #3).  This is a convenience method that saves you from 
157         * casting and handling an exception.
158         */
159        public NM getCp3_FromValue() {
160           NM ret = null;
161           try {
162              ret = (NM)getComponent(2);
163           } catch (DataTypeException e) {
164              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
165              throw new RuntimeException(e);
166           }
167           return ret;
168        }
169    
170    
171        /**
172         * Returns to value (component #4).  This is a convenience method that saves you from 
173         * casting and handling an exception.
174         */
175        public NM getToValue() {
176           NM ret = null;
177           try {
178              ret = (NM)getComponent(3);
179           } catch (DataTypeException e) {
180              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
181              throw new RuntimeException(e);
182           }
183           return ret;
184        }
185    
186        
187        /**
188         * Returns to value (component #4).  This is a convenience method that saves you from 
189         * casting and handling an exception.
190         */
191        public NM getCp4_ToValue() {
192           NM ret = null;
193           try {
194              ret = (NM)getComponent(3);
195           } catch (DataTypeException e) {
196              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
197              throw new RuntimeException(e);
198           }
199           return ret;
200        }
201    
202    
203        /**
204         * Returns range units (component #5).  This is a convenience method that saves you from 
205         * casting and handling an exception.
206         */
207        public CE getRangeUnits() {
208           CE ret = null;
209           try {
210              ret = (CE)getComponent(4);
211           } catch (DataTypeException e) {
212              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
213              throw new RuntimeException(e);
214           }
215           return ret;
216        }
217    
218        
219        /**
220         * Returns range units (component #5).  This is a convenience method that saves you from 
221         * casting and handling an exception.
222         */
223        public CE getCp5_RangeUnits() {
224           CE ret = null;
225           try {
226              ret = (CE)getComponent(4);
227           } catch (DataTypeException e) {
228              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
229              throw new RuntimeException(e);
230           }
231           return ret;
232        }
233    
234    
235        /**
236         * Returns range type (component #6).  This is a convenience method that saves you from 
237         * casting and handling an exception.
238         */
239        public ID getRangeType() {
240           ID ret = null;
241           try {
242              ret = (ID)getComponent(5);
243           } catch (DataTypeException e) {
244              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
245              throw new RuntimeException(e);
246           }
247           return ret;
248        }
249    
250        
251        /**
252         * Returns range type (component #6).  This is a convenience method that saves you from 
253         * casting and handling an exception.
254         */
255        public ID getCp6_RangeType() {
256           ID ret = null;
257           try {
258              ret = (ID)getComponent(5);
259           } catch (DataTypeException e) {
260              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected problem accessing known data type component - this is a bug.", e);
261              throw new RuntimeException(e);
262           }
263           return ret;
264        }
265    
266    
267    
268    }
269