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 */
026package ca.uhn.hl7v2.model.primitive;
027
028import ca.uhn.hl7v2.model.AbstractPrimitive;
029import ca.uhn.hl7v2.model.DataTypeException;
030import 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@SuppressWarnings("serial")
040public abstract class TM extends AbstractPrimitive {
041
042    private CommonTM myDetail;
043    
044    /**
045     * @param theMessage message to which this Type belongs
046     */
047    public TM(Message theMessage) {
048        super(theMessage);
049    }
050
051    private CommonTM getDetail() throws DataTypeException {
052        if (myDetail == null) {
053            myDetail = new CommonTM(getValue());
054        }
055        return myDetail;
056    }
057    
058    /**
059     * @see AbstractPrimitive#setValue(java.lang.String)
060     * @throws DataTypeException if the value is incorrectly formatted and either validation is 
061     *      enabled for this primitive or detail setters / getters have been called, forcing further
062     *      parsing.   
063     */
064    public void setValue(String theValue) throws DataTypeException {
065        super.setValue(theValue);
066        
067        if (myDetail != null) {
068            myDetail.setValue(theValue);
069        }
070    }
071    
072    /**
073     * @see AbstractPrimitive#getValue
074     */
075    public String getValue() {
076        String result = super.getValue();
077        
078        if (myDetail != null) {
079            result = myDetail.getValue();
080        }
081        
082        return result;
083    }
084    
085    /**
086     * @see CommonTM#setHourPrecision(int)
087     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
088     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
089     *      this method is called.  
090     */
091    public void setHourPrecision(int hr) throws DataTypeException {
092        getDetail().setHourPrecision(hr);       
093    }    
094    
095    /**
096     * @see CommonTM#setHourMinutePrecision(int, int)
097     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
098     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
099     *      this method is called.  
100     */
101    public void setHourMinutePrecision(int hr, int min) throws DataTypeException {
102        getDetail().setHourMinutePrecision(hr,min);        
103    }
104        
105    /**
106     * @see CommonTM#setHourMinSecondPrecision(int, int, float)
107     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
108     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
109     *      this method is called.  
110     */
111    public void setHourMinSecondPrecision(int hr, int min, float sec) throws DataTypeException {
112        getDetail().setHourMinSecondPrecision(hr,min,sec);        
113    }
114    
115    /**
116     * @see CommonTM#setOffset(int)
117     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
118     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
119     *      this method is called.  
120     */
121    public void setOffset(int signedOffset) throws DataTypeException {
122        getDetail().setOffset(signedOffset);        
123    }
124    
125    /**
126     * Returns the hour as an integer.
127     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
128     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
129     *      this method is called.  
130     */
131    public int getHour() throws DataTypeException {
132        return getDetail().getHour();
133    }
134    
135    /**
136     * Returns the minute as an integer.
137     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
138     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
139     *      this method is called.  
140     */
141    public int getMinute() throws DataTypeException {
142        return getDetail().getMinute();
143    }
144    
145    /**
146     * Returns the second as an integer.
147     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
148     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
149     *      this method is called.  
150     */
151    public int getSecond() throws DataTypeException {
152        return getDetail().getSecond();
153    }
154    
155    /**
156     * Returns the fractional second value as a float.
157     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
158     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
159     *      this method is called.  
160     */
161    public float getFractSecond() throws DataTypeException {
162        return getDetail().getFractSecond();
163    }
164    
165    /**
166     * Returns the GMT offset value as an integer.
167     * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
168     *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
169     *      this method is called.  
170     */
171    public int getGMTOffset() throws DataTypeException {
172        return getDetail().getGMTOffset();
173    }
174    
175}