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 "TSComponentOne.java". Description: 010 * "Represents an HL7 timestamp, which is related to the HL7 TS type." 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 027 package ca.uhn.hl7v2.model.primitive; 028 029 import ca.uhn.hl7v2.model.AbstractPrimitive; 030 import ca.uhn.hl7v2.model.DataTypeException; 031 import ca.uhn.hl7v2.model.Message; 032 033 /** 034 * Represents an HL7 timestamp, which is related to the HL7 TS type. In version 2.5, 035 * TS is a composite type. The first component is type DTM, which corresponds to this class 036 * (actually model.v25.datatype.DTM inherits from this class at time of writing). In HL7 versions 037 * 2.2-2.4, it wasn't perfectly clear whether TS was composite or primitive. HAPI interprets 038 * it as composite, with the first component having a type that isn't defined by HL7, and we call 039 * this type TSComponentOne. In v2.1, TS is primitive, and corresponds one-to-one with this class. 040 * 041 * @author <a href="mailto:neal.acharya@uhn.on.ca">Neal Acharya</a> 042 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a> 043 * @version $Revision: 1.1 $ updated on $Date: 2007/02/19 02:24:51 $ by $Author: jamesagnew $ 044 */ 045 public abstract class TSComponentOne extends AbstractPrimitive { 046 047 private CommonTS myDetail; 048 049 /** 050 * @param theMessage message to which this Type belongs 051 */ 052 public TSComponentOne(Message theMessage) { 053 super(theMessage); 054 } 055 056 private CommonTS getDetail() throws DataTypeException { 057 if (myDetail == null) { 058 myDetail = new CommonTS(getValue()); 059 } 060 return myDetail; 061 } 062 063 /** 064 * @see AbstractPrimitive#setValue(java.lang.String) 065 * @throws DataTypeException if the value is incorrectly formatted and either validation is 066 * enabled for this primitive or detail setters / getters have been called, forcing further 067 * parsing. 068 */ 069 public void setValue(String theValue) throws DataTypeException { 070 super.setValue(theValue); 071 072 if (myDetail != null) { 073 myDetail.setValue(theValue); 074 } 075 } 076 077 /** 078 * @see AbstractPrimitive#getValue 079 */ 080 public String getValue() { 081 String result = super.getValue(); 082 083 if (myDetail != null) { 084 result = myDetail.getValue(); 085 } 086 087 return result; 088 } 089 090 /** 091 * @see CommonTS#setDatePrecision(int, int, int) 092 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 093 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 094 * this method is called. 095 */ 096 public void setDatePrecision(int yr, int mnth, int dy) throws DataTypeException { 097 getDetail().setDatePrecision(yr,mnth,dy); 098 } 099 100 /** 101 * @see CommonTS#setDateMinutePrecision(int, int, int, int, int) 102 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 103 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 104 * this method is called. 105 */ 106 public void setDateMinutePrecision(int yr, int mnth, int dy, int hr, int min) throws DataTypeException { 107 getDetail().setDateMinutePrecision(yr,mnth,dy,hr,min); 108 } 109 110 /** 111 * @see CommonTS#setDateSecondPrecision(int, int, int, int, int, float) 112 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 113 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 114 * this method is called. 115 */ 116 public void setDateSecondPrecision(int yr, int mnth, int dy, int hr, int min, float sec) throws DataTypeException { 117 getDetail().setDateSecondPrecision(yr,mnth,dy,hr,min,sec); 118 } 119 120 /** 121 * @see CommonTS#setOffset(int) 122 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 123 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 124 * this method is called. 125 */ 126 public void setOffset(int signedOffset) throws DataTypeException { 127 getDetail().setOffset(signedOffset); 128 } 129 130 /** 131 * Returns the year as an integer. 132 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 133 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 134 * this method is called. 135 */ 136 public int getYear() throws DataTypeException { 137 return getDetail().getYear(); 138 } 139 140 /** 141 * Returns the month as an integer. 142 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 143 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 144 * this method is called. 145 */ 146 public int getMonth() throws DataTypeException { 147 return getDetail().getMonth(); 148 } 149 150 /** 151 * Returns the day as an integer. 152 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 153 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 154 * this method is called. 155 */ 156 public int getDay() throws DataTypeException { 157 return getDetail().getDay(); 158 } 159 160 /** 161 * Returns the hour as an integer. 162 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 163 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 164 * this method is called. 165 */ 166 public int getHour() throws DataTypeException { 167 return getDetail().getHour(); 168 } 169 170 /** 171 * Returns the minute as an integer. 172 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 173 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 174 * this method is called. 175 */ 176 public int getMinute() throws DataTypeException { 177 return getDetail().getMinute(); 178 } 179 180 /** 181 * Returns the second as an integer. 182 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 183 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 184 * this method is called. 185 */ 186 public int getSecond() throws DataTypeException { 187 return getDetail().getSecond(); 188 } 189 190 /** 191 * Returns the fractional second value as a float. 192 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 193 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 194 * this method is called. 195 */ 196 public float getFractSecond() throws DataTypeException { 197 return getDetail().getFractSecond(); 198 } 199 200 /** 201 * Returns the GMT offset value as an integer. 202 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this 203 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until 204 * this method is called. 205 */ 206 public int getGMTOffset() throws DataTypeException { 207 return getDetail().getGMTOffset(); 208 } 209 210 /** Returns the name of the type (used in XML encoding and profile checking) */ 211 // public String getName() { 212 // return "NM"; //seems to be called an NM in XML representation prior to 2.5 213 // } 214 215 }