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 "DT.java".  Description:
010 * "Note: The class description below has been excerpted from the Hl7 2.3.0 documentation"
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 DT (date) 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 DT extends AbstractPrimitive {
041
042    private CommonDT myDetail;
043    
044    /**
045     * @param theMessage message to which this Type belongs
046     */
047    public DT(Message theMessage) {
048        super(theMessage);
049    }
050    
051    private CommonDT getDetail() throws DataTypeException {
052        if (myDetail == null) {
053            myDetail = new CommonDT(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 CommonDT#setYearPrecision(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 setYearPrecision(int yr) throws DataTypeException {
092        getDetail().setYearPrecision(yr);       
093    }
094    
095    /**
096     * @see CommonDT#setYearMonthPrecision(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 setYearMonthPrecision(int yr, int mnth) throws DataTypeException {
102        getDetail().setYearMonthPrecision(yr,mnth);         
103    }
104    
105    /**
106     * @see CommonDT#setYearMonthDayPrecision(int, int, int)
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 setYearMonthDayPrecision(int yr, int mnth, int dy) throws DataTypeException {
112        getDetail().setYearMonthDayPrecision(yr,mnth,dy);        
113    }
114    
115    /**
116     * Returns the year as an integer.
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 int getYear() throws DataTypeException {
122        return getDetail().getYear();
123    }
124    
125    /**
126     * Returns the month 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 getMonth() throws DataTypeException {
132        return getDetail().getMonth();
133    }
134    
135    /**
136     * Returns the day 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 getDay() throws DataTypeException {
142        return getDetail().getDay();
143    }
144}