001 package org.vmdb.hl7; 002 003 /** 004 * <p><Title:> Time Stamp (TS) 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 TSElement extends HL7Element { 013 private String sNm = "TS"; 014 private String sRl = "ST[ST]"; 015 016 /** 017 * Construct a Date/Time 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 TSElement( int iLevel ) { 022 super( iLevel ); 023 setName( sNm ); 024 setRule( sRl ); 025 setType( "TS" ); 026 } 027 028 /** 029 * Construct a Date/Time Element using the default name and type constants 030 * at the default level FIELD. 031 */ 032 public TSElement() { 033 super( FIELD ); 034 setName( sNm ); 035 setRule( sRl ); 036 setType( "TS" ); 037 } 038 039 /** 040 * Set the actual ISO formatted datetime string.<br><br> 041 * TODO: Add a convenience method to set this from normal strings or date variables 042 * @param sDateTime String is ISO format. 043 */ 044 public void setDateTime( String sDateTime ) { 045 if( size() > 1 ) { 046 HL7Element e = new SimpleElement( iLevel + 1 ); 047 e.setType( "ST" ); 048 e.setName( "TS.1" ); 049 e.setValue( sDateTime ); 050 try { 051 setComponent( e, 1 ); 052 } catch( MalformedFieldException mfe ) { 053 mfe.printStackTrace(); 054 } 055 } 056 else { 057 setValue( sDateTime ); 058 } 059 } 060 061 /** 062 * Get the actual ISO formatted datetime string. 063 * @return String date/time in ISO format. 064 */ 065 public String getDateTime() { 066 HL7Element e = getComponent( 1 ); 067 if( e != null ) 068 return e.getValue(); 069 else 070 return ""; 071 } 072 073 /** 074 * Set precision.<br><br> 075 * Note: From the HL7 documentation, 076 * "In prior versions of HL7, an optional second component indicates the degree of 077 * precision of the time stamp (Y = year, L = month, D = day, H = hour, 078 * M = minute, S = second). This optional second component is retained only for 079 * purposes of backward compatibility." 080 * @param sPrecision String with the precision of the date/time 081 */ 082 public void setPrecision( String sPrecision ) { 083 HL7Element e = new SimpleElement( iLevel + 1 ); 084 e.setType( "ST" ); 085 e.setName( "TS.2" ); 086 e.setValue( sPrecision ); 087 try { 088 setComponent( e, 2 ); 089 } catch( MalformedFieldException mfe ) { 090 mfe.printStackTrace(); 091 } 092 } 093 094 /** 095 * Get precision.<br><br> 096 * Note: From the HL7 documentation, 097 * "In prior versions of HL7, an optional second component indicates the degree of 098 * precision of the time stamp (Y = year, L = month, D = day, H = hour, 099 * M = minute, S = second). This optional second component is retained only for 100 * purposes of backward compatibility." 101 * @return String with the precision of the date/time 102 */ 103 public String getPrecision() { 104 HL7Element e = getComponent( 2 ); 105 if( e != null ) 106 return e.toString(); 107 else 108 return ""; 109 } 110 111 } // end class TSElement 112