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 "TM.java". Description:
10 * "Represents an HL7 TM (time) datatype."
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 package ca.uhn.hl7v2.model.primitive;
27
28 import ca.uhn.hl7v2.model.AbstractPrimitive;
29 import ca.uhn.hl7v2.model.DataTypeException;
30 import ca.uhn.hl7v2.model.Message;
31
32 /**
33 * Represents an HL7 TM (time) datatype.
34 *
35 * @author <a href="mailto:neal.acharya@uhn.on.ca">Neal Acharya</a>
36 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
37 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:51 $ by $Author: jamesagnew $
38 */
39 @SuppressWarnings("serial")
40 public abstract class TM extends AbstractPrimitive {
41
42 private CommonTM myDetail;
43
44 /**
45 * @param theMessage message to which this Type belongs
46 */
47 public TM(Message theMessage) {
48 super(theMessage);
49 }
50
51 private CommonTM getDetail() throws DataTypeException {
52 if (myDetail == null) {
53 myDetail = new CommonTM(getValue());
54 }
55 return myDetail;
56 }
57
58 /**
59 * @see AbstractPrimitive#setValue(java.lang.String)
60 * @throws DataTypeException if the value is incorrectly formatted and either validation is
61 * enabled for this primitive or detail setters / getters have been called, forcing further
62 * parsing.
63 */
64 public void setValue(String theValue) throws DataTypeException {
65 super.setValue(theValue);
66
67 if (myDetail != null) {
68 myDetail.setValue(theValue);
69 }
70 }
71
72 /**
73 * @see AbstractPrimitive#getValue
74 */
75 public String getValue() {
76 String result = super.getValue();
77
78 if (myDetail != null) {
79 result = myDetail.getValue();
80 }
81
82 return result;
83 }
84
85 /**
86 * @see CommonTM#setHourPrecision(int)
87 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this
88 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until
89 * this method is called.
90 */
91 public void setHourPrecision(int hr) throws DataTypeException {
92 getDetail().setHourPrecision(hr);
93 }
94
95 /**
96 * @see CommonTM#setHourMinutePrecision(int, int)
97 * @throws DataTypeException if the value is incorrectly formatted. If validation is enabled, this
98 * exception should be thrown at setValue(), but if not, detailed parsing may be deferred until
99 * 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 }