001 package org.vmdb.hl7;
002
003 /**
004 * <p><Title:> Date/Time Range (DR) Element. </p>
005 * <p>Description: HL7 Network Connectivity For VMDB. </p>
006 * <p>Copyright: Copyright (c) 2002-2003. </p>
007 * <p>Company: Veterinary Medical Database (VMDB). </p>
008 * @author Michael K. Martin
009 * @version 1.0
010 */
011
012 public class DRElement extends HL7Element {
013 private String sNm = "DR";
014 private String sRl = "TS TS";
015
016 /**
017 * Construct a Date/Time Range Element using the default name and type constants.
018 * @param iLevel One of the constants for specifying level as FIELD, COMPONENT, or
019 * SUBCOMPONENT. Default FIELD.
020 */
021 public DRElement( int iLevel ) {
022 super( iLevel );
023 setName( sNm );
024 setRule( sRl );
025 }
026
027 /**
028 * Construct a Date/Time Range Element using the default name and type constants
029 * at the default level FIELD.
030 */
031 public DRElement() {
032 super( FIELD );
033 setName( sNm );
034 setRule( sRl );
035 }
036
037 /**
038 * Set the actual ISO formatted start datetime string.<br><br>
039 * TODO: Add a convenience method to set this from normal strings or date variables
040 * @param sDateTime String is ISO format start date/time.
041 */
042 public void setStartDateTime( String sDateTime ) {
043 TSElement e = new TSElement( iLevel + 1 );
044 e.setName( "DR.1" );
045 e.setDateTime( sDateTime );
046 try {
047 setComponent( e, 1 );
048 } catch( MalformedFieldException mfe ) {
049 mfe.printStackTrace();
050 }
051 }
052
053 /**
054 * Set start datetime string and precision.<br><br>
055 * Note: From the HL7 documentation,
056 * "In prior versions of HL7, an optional second component indicates the degree of
057 * precision of the time stamp (Y = year, L = month, D = day, H = hour,
058 * M = minute, S = second). This optional second component is retained only for
059 * purposes of backward compatibility."
060 * @param sDateTime String is ISO format start date/time.
061 * @param sPrecision String with the precision of the start date/time
062 */
063 public void setStartDateTime( String sDateTime, String sPrecision ) {
064 TSElement e = new TSElement( iLevel + 1 );
065 e.setName( "DR.1" );
066 e.setDateTime( sDateTime );
067 e.setPrecision( sPrecision );
068 try {
069 setComponent( e, 1 );
070 } catch( MalformedFieldException mfe ) {
071 mfe.printStackTrace();
072 }
073 }
074
075 /**
076 * Get the start date/time as a TS Element object
077 * @return TSElement with start date/time set.
078 */
079 public TSElement getStartDateTime() {
080 return (TSElement)getComponent( 1 );
081 }
082
083 /**
084 * Set the actual ISO formatted end datetime string.<br><br>
085 * TODO: Add a convenience method to set this from normal strings or date variables
086 * @param sDateTime String is ISO format end date/time.
087 */
088 public void setEndDateTime( String sDateTime ) {
089 TSElement e = new TSElement( iLevel + 1 );
090 e.setName( "DR.1" );
091 e.setDateTime( sDateTime );
092 try {
093 setComponent( e, 1 );
094 } catch( MalformedFieldException mfe ) {
095 mfe.printStackTrace();
096 }
097 }
098
099 /**
100 * Set end datetime string and precision.<br><br>
101 * Note: From the HL7 documentation,
102 * "In prior versions of HL7, an optional second component indicates the degree of
103 * precision of the time stamp (Y = year, L = month, D = day, H = hour,
104 * M = minute, S = second). This optional second component is retained only for
105 * purposes of backward compatibility."
106 * @param sDateTime String is ISO format end date/time.
107 * @param sPrecision String with the precision of the end date/time
108 */
109 public void setEndDateTime( String sDateTime, String sPrecision ) {
110 TSElement e = new TSElement( iLevel + 1 );
111 e.setName( "DR.2" );
112 e.setDateTime( sDateTime );
113 e.setPrecision( sPrecision );
114 try {
115 setComponent( e, 2 );
116 } catch( MalformedFieldException mfe ) {
117 mfe.printStackTrace();
118 }
119 }
120
121 /**
122 * Get the end date/time as a TS Element object
123 * @return TSElement with end date/time set.
124 */
125 public TSElement getEndDateTime() {
126 return (TSElement)getComponent( 2 );
127 }
128
129 } // End class DRElement
130