001    /**
002     * The contents of this file are subject to the Mozilla Public License Version 1.1
003     * (the "License"); you may not use this file except in compliance with the License.
004     * You may obtain a copy of the License at http://www.mozilla.org/MPL/
005     * Software distributed under the License is distributed on an "AS IS" basis,
006     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007     * specific language governing rights and limitations under the License.
008     *
009     * The Original Code is "TM.java".  Description:
010     * "Represents an HL7 TM (time) datatype."
011     *
012     * The Initial Developer of the Original Code is University Health Network. Copyright (C)
013     * 2005.  All Rights Reserved.
014     *
015     * Contributor(s): ______________________________________.
016     *
017     * Alternatively, the contents of this file may be used under the terms of the
018     * GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are
019     * applicable instead of those above.  If you wish to allow use of your version of this
020     * file only under the terms of the GPL and not to allow others to use your version
021     * of this file under the MPL, indicate your decision by deleting  the provisions above
022     * and replace  them with the notice and other provisions required by the GPL License.
023     * If you do not delete the provisions above, a recipient may use your version of
024     * this file under either the MPL or the GPL.
025     */
026    package ca.uhn.hl7v2.model.primitive;
027    
028    import ca.uhn.hl7v2.model.AbstractPrimitive;
029    import ca.uhn.hl7v2.model.DataTypeException;
030    import ca.uhn.hl7v2.model.Message;
031    
032    /**
033     * Represents an HL7 TM (time) datatype. 
034     * 
035     * @author <a href="mailto:neal.acharya@uhn.on.ca">Neal Acharya</a>
036     * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
037     * @version $Revision: 1.1 $ updated on $Date: 2007/02/19 02:24:51 $ by $Author: jamesagnew $
038     */
039    public abstract class TM extends AbstractPrimitive {
040    
041        private CommonTM myDetail;
042        
043        /**
044         * @param theMessage message to which this Type belongs
045         */
046        public TM(Message theMessage) {
047            super(theMessage);
048        }
049    
050        private CommonTM getDetail() throws DataTypeException {
051            if (myDetail == null) {
052                myDetail = new CommonTM(getValue());
053            }
054            return myDetail;
055        }
056        
057        /**
058         * @see AbstractPrimitive#setValue(java.lang.String)
059         * @throws DataTypeException if the value is incorrectly formatted and either validation is 
060         *      enabled for this primitive or detail setters / getters have been called, forcing further
061         *      parsing.   
062         */
063        public void setValue(String theValue) throws DataTypeException {
064            super.setValue(theValue);
065            
066            if (myDetail != null) {
067                myDetail.setValue(theValue);
068            }
069        }
070        
071        /**
072         * @see AbstractPrimitive#getValue
073         */
074        public String getValue() {
075            String result = super.getValue();
076            
077            if (myDetail != null) {
078                result = myDetail.getValue();
079            }
080            
081            return result;
082        }
083        
084        /**
085         * @see CommonTM#setHourPrecision(int)
086         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
087         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
088         *      this method is called.  
089         */
090        public void setHourPrecision(int hr) throws DataTypeException {
091            getDetail().setHourPrecision(hr);       
092        }    
093        
094        /**
095         * @see CommonTM#setHourMinutePrecision(int, int)
096         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
097         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
098         *      this method is called.  
099         */
100        public void setHourMinutePrecision(int hr, int min) throws DataTypeException {
101            getDetail().setHourMinutePrecision(hr,min);        
102        }
103            
104        /**
105         * @see CommonTM#setHourMinSecondPrecision(int, int, float)
106         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
107         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
108         *      this method is called.  
109         */
110        public void setHourMinSecondPrecision(int hr, int min, float sec) throws DataTypeException {
111            getDetail().setHourMinSecondPrecision(hr,min,sec);        
112        }
113        
114        /**
115         * @see CommonTM#setOffset(int)
116         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
117         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
118         *      this method is called.  
119         */
120        public void setOffset(int signedOffset) throws DataTypeException {
121            getDetail().setOffset(signedOffset);        
122        }
123        
124        /**
125         * Returns the hour as an integer.
126         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
127         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
128         *      this method is called.  
129         */
130        public int getHour() throws DataTypeException {
131            return getDetail().getHour();
132        }
133        
134        /**
135         * Returns the minute as an integer.
136         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
137         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
138         *      this method is called.  
139         */
140        public int getMinute() throws DataTypeException {
141            return getDetail().getMinute();
142        }
143        
144        /**
145         * Returns the second as an integer.
146         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
147         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
148         *      this method is called.  
149         */
150        public int getSecond() throws DataTypeException {
151            return getDetail().getSecond();
152        }
153        
154        /**
155         * Returns the fractional second value as a float.
156         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
157         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
158         *      this method is called.  
159         */
160        public float getFractSecond() throws DataTypeException {
161            return getDetail().getFractSecond();
162        }
163        
164        /**
165         * Returns the GMT offset value as an integer.
166         * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
167         *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
168         *      this method is called.  
169         */
170        public int getGMTOffset() throws DataTypeException {
171            return getDetail().getGMTOffset();
172        }
173        
174    }