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     */
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 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    public abstract class DT extends AbstractPrimitive {
040    
041        private CommonDT myDetail;
042        
043        /**
044         * @param theMessage message to which this Type belongs
045         */
046        public DT(Message theMessage) {
047            super(theMessage);
048        }
049        
050        private CommonDT getDetail() throws DataTypeException {
051            if (myDetail == null) {
052                myDetail = new CommonDT(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 CommonDT#setYearPrecision(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 setYearPrecision(int yr) throws DataTypeException {
091            getDetail().setYearPrecision(yr);       
092        }
093        
094        /**
095         * @see CommonDT#setYearMonthPrecision(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 setYearMonthPrecision(int yr, int mnth) throws DataTypeException {
101            getDetail().setYearMonthPrecision(yr,mnth);         
102        }
103        
104        /**
105         * @see CommonDT#setYearMonthDayPrecision(int, int, int)
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 setYearMonthDayPrecision(int yr, int mnth, int dy) throws DataTypeException {
111            getDetail().setYearMonthDayPrecision(yr,mnth,dy);        
112        }
113        
114        /**
115         * Returns the year as an integer.
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 int getYear() throws DataTypeException {
121            return getDetail().getYear();
122        }
123        
124        /**
125         * Returns the month 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 getMonth() throws DataTypeException {
131            return getDetail().getMonth();
132        }
133        
134        /**
135         * Returns the day 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 getDay() throws DataTypeException {
141            return getDetail().getDay();
142        }
143    }