Coverage Report - ca.uhn.hl7v2.model.primitive.TSComponentOne
 
Classes in this File Line Coverage Branch Coverage Complexity
TSComponentOne
65%
32/49
83%
5/6
1.125
 
 1  
 /**
 2  
  * The contents of this file are subject to the Mozilla Public License Version 1.1
 3  
  * (the "License"); you may not use this file except in compliance with the License.
 4  
  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 5  
  * Software distributed under the License is distributed on an "AS IS" basis,
 6  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
 7  
  * specific language governing rights and limitations under the License.
 8  
  *
 9  
  * The Original Code is "TSComponentOne.java".  Description:
 10  
  * "Represents an HL7 timestamp, which is related to the HL7 TS type."
 11  
  *
 12  
  * The Initial Developer of the Original Code is University Health Network. Copyright (C)
 13  
  * 2005.  All Rights Reserved.
 14  
  *
 15  
  * Contributor(s): ______________________________________.
 16  
  *
 17  
  * Alternatively, the contents of this file may be used under the terms of the
 18  
  * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
 19  
  * applicable instead of those above.  If you wish to allow use of your version of this
 20  
  * file only under the terms of the GPL and not to allow others to use your version
 21  
  * of this file under the MPL, indicate your decision by deleting  the provisions above
 22  
  * and replace  them with the notice and other provisions required by the GPL License.
 23  
  * If you do not delete the provisions above, a recipient may use your version of
 24  
  * this file under either the MPL or the GPL.
 25  
  */
 26  
 
 27  
 package ca.uhn.hl7v2.model.primitive;
 28  
 
 29  
 import java.util.Calendar;
 30  
 import java.util.Date;
 31  
 
 32  
 import ca.uhn.hl7v2.model.AbstractPrimitive;
 33  
 import ca.uhn.hl7v2.model.DataTypeException;
 34  
 import ca.uhn.hl7v2.model.Message;
 35  
 
 36  
 /**
 37  
  * Represents an HL7 timestamp, which is related to the HL7 TS type.  In version 2.5, 
 38  
  * TS is a composite type.  The first component is type DTM, which corresponds to this class
 39  
  * (actually model.v25.datatype.DTM inherits from this class at time of writing).  In HL7 versions 
 40  
  * 2.2-2.4, it wasn't perfectly clear whether TS was composite or primitive.  HAPI interprets  
 41  
  * it as composite, with the first component having a type that isn't defined by HL7, and we call 
 42  
  * this type TSComponentOne.  In v2.1, TS is primitive, and corresponds one-to-one with this class.   
 43  
  *  
 44  
  * @author <a href="mailto:neal.acharya@uhn.on.ca">Neal Acharya</a>
 45  
  * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
 46  
  * @version $Revision: 1.2 $ updated on $Date: 2011-02-21 17:55:08 $ by $Author: jamesagnew $
 47  
  */
 48  
 @SuppressWarnings("serial")
 49  
 public abstract class TSComponentOne extends AbstractPrimitive {
 50  
 
 51  
     private CommonTS myDetail;
 52  
     
 53  
     /**
 54  
      * @param theMessage message to which this Type belongs
 55  
      */
 56  
     public TSComponentOne(Message theMessage) {
 57  5047
         super(theMessage);
 58  5047
     }
 59  
 
 60  
     private CommonTS getDetail() throws DataTypeException {
 61  19
         if (myDetail == null) {
 62  12
             myDetail = new CommonTS(getValue());
 63  
         }
 64  17
         return myDetail;
 65  
     }
 66  
     
 67  
     /**
 68  
      * @see AbstractPrimitive#setValue(java.lang.String)
 69  
      * @throws DataTypeException if the value is incorrectly formatted and either validation is 
 70  
      *      enabled for this primitive or detail setters / getters have been called, forcing further
 71  
      *      parsing.   
 72  
      */
 73  
     public void setValue(String theValue) throws DataTypeException {
 74  1860
         super.setValue(theValue);
 75  
         
 76  1819
         if (myDetail != null) {
 77  0
             myDetail.setValue(theValue);
 78  
         }
 79  1819
     }
 80  
     
 81  
     /**
 82  
      * @see AbstractPrimitive#getValue
 83  
      */
 84  
     public String getValue() {
 85  1971
         String result = super.getValue();
 86  
         
 87  1971
         if (myDetail != null) {
 88  7
             result = myDetail.getValue();
 89  
         }
 90  
         
 91  1971
         return result;
 92  
     }
 93  
     
 94  
     /**
 95  
      * @see CommonTS#setDatePrecision(int, int, int)
 96  
      * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
 97  
      *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
 98  
      *      this method is called.  
 99  
      */
 100  
     public void setDatePrecision(int yr, int mnth, int dy) throws DataTypeException {
 101  0
         getDetail().setDatePrecision(yr,mnth,dy);        
 102  0
     }
 103  
     
 104  
     /**
 105  
      * @see CommonTS#setDateMinutePrecision(int, int, 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 setDateMinutePrecision(int yr, int mnth, int dy, int hr, int min) throws DataTypeException {
 111  0
         getDetail().setDateMinutePrecision(yr,mnth,dy,hr,min);        
 112  0
     }
 113  
     
 114  
     /**
 115  
      * @see CommonTS#setDateSecondPrecision(int, int, int, int, int, float)
 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 setDateSecondPrecision(int yr, int mnth, int dy, int hr, int min, float sec) throws DataTypeException {
 121  0
         getDetail().setDateSecondPrecision(yr,mnth,dy,hr,min,sec);        
 122  0
     }
 123  
     
 124  
     /**
 125  
      * @see CommonTS#setOffset(int)
 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 void setOffset(int signedOffset) throws DataTypeException {
 131  0
         getDetail().setOffset(signedOffset);        
 132  0
     }
 133  
     
 134  
     /**
 135  
      * Returns the year 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 getYear() throws DataTypeException {
 141  0
         return getDetail().getYear();
 142  
     }
 143  
     
 144  
     /**
 145  
      * Returns the month 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 getMonth() throws DataTypeException {
 151  0
         return getDetail().getMonth();
 152  
     }
 153  
     
 154  
     /**
 155  
      * Returns the day as an integer.
 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 int getDay() throws DataTypeException {
 161  0
         return getDetail().getDay();
 162  
     }
 163  
     
 164  
     /**
 165  
      * Returns the hour 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 getHour() throws DataTypeException {
 171  0
         return getDetail().getHour();
 172  
     }
 173  
     
 174  
     /**
 175  
      * Returns the minute as an integer.
 176  
      * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
 177  
      *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
 178  
      *      this method is called.  
 179  
      */
 180  
     public int getMinute() throws DataTypeException {
 181  0
        return getDetail().getMinute();
 182  
     }
 183  
     
 184  
     /**
 185  
      * Returns the second as an integer.
 186  
      * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
 187  
      *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
 188  
      *      this method is called.  
 189  
      */
 190  
     public int getSecond() throws DataTypeException {
 191  0
         return getDetail().getSecond();
 192  
     }
 193  
     
 194  
     /**
 195  
      * Returns the fractional second value as a float.
 196  
      * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
 197  
      *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
 198  
      *      this method is called.  
 199  
      */
 200  
     public float getFractSecond() throws DataTypeException {
 201  0
         return getDetail().getFractSecond();
 202  
     }
 203  
     
 204  
     /**
 205  
      * Returns the GMT offset value as an integer.
 206  
      * @throws DataTypeException if the value is incorrectly formatted.  If validation is enabled, this 
 207  
      *      exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 
 208  
      *      this method is called.  
 209  
      */
 210  
     public int getGMTOffset() throws DataTypeException {
 211  0
         return getDetail().getGMTOffset();
 212  
     }
 213  
     
 214  
     /**
 215  
      * Convenience setter which sets the value using a {@link Calendar} object.
 216  
      * 
 217  
      * Note: Sets fields using precision up to the millisecond, including timezone offset
 218  
      * 
 219  
      * @param theCalendar The calendar object from which to retrieve values 
 220  
      * @since 1.1 
 221  
      */
 222  
     public void setValue(Calendar theCalendar) throws DataTypeException {
 223  1
             setValue((String)null);
 224  1
         getDetail().setValue(theCalendar);
 225  1
     }
 226  
 
 227  
     /**
 228  
      * Convenience setter which sets the value using a {@link Calendar} object.
 229  
      * 
 230  
      * Note: Sets fields using precision up to the millisecond, and sets the timezone offset to
 231  
      * the current system offset
 232  
      * Note: Date is timezone-agnostic, representing always GMT time
 233  
      * 
 234  
      * @param theDate The date object from which to retrieve values 
 235  
      * @since 1.1 
 236  
      */
 237  
     public void setValue(Date theDate) throws DataTypeException {
 238  2
             setValue((String)null);
 239  2
         getDetail().setValue(theDate);
 240  2
     }
 241  
     
 242  
     /**
 243  
      * Convenience setter which sets the value using a {@link Calendar} object.
 244  
      * 
 245  
      * Note: Sets fields using precision up to the minute
 246  
      * 
 247  
      * @param theCalendar The calendar object from which to retrieve values 
 248  
      * @since 1.1 
 249  
      */
 250  
     public void setValueToMinute(Calendar theCalendar) throws DataTypeException {
 251  1
             setValue((String)null);
 252  1
         getDetail().setValueToMinute(theCalendar);
 253  1
     }
 254  
 
 255  
     /**
 256  
      * Convenience setter which sets the value using a {@link Date} object.
 257  
      * 
 258  
      * Note: Sets fields using precision up to the minute
 259  
      * Note: Date is timezone-agnostic, representing always GMT time
 260  
      * 
 261  
      * @param theDate The date object from which to retrieve values 
 262  
      * @since 1.1 
 263  
      */
 264  
     public void setValueToMinute(Date theDate) throws DataTypeException {
 265  1
             setValue((String)null);
 266  1
         getDetail().setValueToMinute(theDate);
 267  1
     }
 268  
 
 269  
     /**
 270  
      * Convenience setter which sets the value using a {@link Calendar} object.
 271  
      * 
 272  
      * Note: Sets fields using precision up to the second
 273  
      * 
 274  
      * @param theCalendar The calendar object from which to retrieve values 
 275  
      * @since 1.1 
 276  
      */
 277  
     public void setValueToSecond(Calendar theCalendar) throws DataTypeException {
 278  1
             setValue((String)null);
 279  1
         getDetail().setValueToSecond(theCalendar);
 280  1
     }
 281  
 
 282  
     /**
 283  
      * Convenience setter which sets the value using a {@link Date} object.
 284  
      * 
 285  
      * Note: Sets fields using precision up to the second
 286  
      * 
 287  
      * @param theDate The date object from which to retrieve values 
 288  
      * @since 1.1 
 289  
      */
 290  
     public void setValueToSecond(Date theDate) throws DataTypeException {
 291  1
             setValue((String)null);
 292  1
         getDetail().setValueToSecond(theDate);
 293  1
     }
 294  
 
 295  
     /**
 296  
      * Return the value as a calendar object
 297  
      * @since 1.1 
 298  
      * @throws DataTypeException If the current underlying string representation can not be parsed into a valid date/time
 299  
      */
 300  
     public Calendar getValueAsCalendar() throws DataTypeException {
 301  5
             return getDetail().getValueAsCalendar();
 302  
     }
 303  
 
 304  
     /**
 305  
      * Return the value as a date object
 306  
      * Note: Sets fields using precision up to the second
 307  
      * 
 308  
      * @since 1.1 
 309  
      * @throws DataTypeException If the current underlying string representation can not be parsed into a valid date/time
 310  
      */
 311  
     public Date getValueAsDate() throws DataTypeException {
 312  7
         return getDetail().getValueAsDate();
 313  
     }
 314  
     
 315  
     
 316  
     /** Returns the name of the type (used in XML encoding and profile checking)  */
 317  
 //    public String getName() {
 318  
 //        return "NM"; //seems to be called an NM in XML representation prior to 2.5  
 319  
 //    }
 320  
     
 321  
 }