| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DT |
|
| 1.3;1.3 |
| 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 "DT.java". Description: | |
| 10 | * "Note: The class description below has been excerpted from the Hl7 2.3.0 documentation" | |
| 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 DT (date) 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 DT extends AbstractPrimitive { | |
| 41 | ||
| 42 | private CommonDT myDetail; | |
| 43 | ||
| 44 | /** | |
| 45 | * @param theMessage message to which this Type belongs | |
| 46 | */ | |
| 47 | public DT(Message theMessage) { | |
| 48 | 10549 | super(theMessage); |
| 49 | 10549 | } |
| 50 | ||
| 51 | private CommonDT getDetail() throws DataTypeException { | |
| 52 | 220 | if (myDetail == null) { |
| 53 | 220 | myDetail = new CommonDT(getValue()); |
| 54 | } | |
| 55 | 220 | 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 | 345 | super.setValue(theValue); |
| 66 | ||
| 67 | 265 | if (myDetail != null) { |
| 68 | 0 | myDetail.setValue(theValue); |
| 69 | } | |
| 70 | 265 | } |
| 71 | ||
| 72 | /** | |
| 73 | * @see AbstractPrimitive#getValue | |
| 74 | */ | |
| 75 | public String getValue() { | |
| 76 | 5677 | String result = super.getValue(); |
| 77 | ||
| 78 | 5677 | if (myDetail != null) { |
| 79 | 105 | result = myDetail.getValue(); |
| 80 | } | |
| 81 | ||
| 82 | 5677 | return result; |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * @see CommonDT#setYearPrecision(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 setYearPrecision(int yr) throws DataTypeException { | |
| 92 | 45 | getDetail().setYearPrecision(yr); |
| 93 | 20 | } |
| 94 | ||
| 95 | /** | |
| 96 | * @see CommonDT#setYearMonthPrecision(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 setYearMonthPrecision(int yr, int mnth) throws DataTypeException { | |
| 102 | 70 | getDetail().setYearMonthPrecision(yr,mnth); |
| 103 | 35 | } |
| 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 | 90 | getDetail().setYearMonthDayPrecision(yr,mnth,dy); |
| 113 | 50 | } |
| 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 | 5 | 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 | 5 | 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 | 5 | return getDetail().getDay(); |
| 143 | } | |
| 144 | } |