001 package org.vmdb.hl7; 002 003 /** 004 * <p><Title:> Structured Numeric (SN) 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 * <p>Used for numeric ranges and open ranges like > 100</p> 009 * @author Michael K. Martin 010 * @version 1.0 011 */ 012 013 public class SNElement extends HL7Element { 014 private String sNm = "SN"; 015 private String sRl = "ST NM[ST][NM]"; 016 017 /** 018 * Construct a Structured Numeric Element using the default name and type constants. 019 * @param iLevel One of the constants for specifying level as FIELD, COMPONENT, or 020 * SUBCOMPONENT. Default FIELD. 021 */ 022 public SNElement( int iLevel ) { 023 super( iLevel ); 024 setName( sNm ); 025 setRule( sRl ); 026 setType( "SN" ); 027 } 028 029 /** 030 * Construct a Structured Numeric Element using the default name and type constants 031 * at the default level FIELD. 032 */ 033 public SNElement() { 034 super( FIELD ); 035 setName( sNm ); 036 setRule( sRl ); 037 setType( "SN" ); 038 } 039 040 public String getValue() { 041 String sComparator = getComparator(); 042 String sNum1 = getNum1(); 043 String sSep = getSeparator(); 044 String sNum2 = getNum2(); 045 StringBuffer sb = new StringBuffer(); 046 if( sComparator != null && !sComparator.equals( "=" ) ) { 047 sb.append( sComparator ); 048 sb.append( " " ); 049 } 050 if( sNum1 != null && !sNum1.equals( "" )) sb.append( sNum1 ); 051 if( sSep != null && !sSep.equals( "" ) && sNum2 != null && !sNum2.equals( "" ) ) { 052 sb.append( " " ); 053 sb.append( sSep ); 054 sb.append( " " ); 055 } 056 if( sNum2 != null && !sNum2.equals( "" )) sb.append( sNum2 ); 057 return sb.toString(); 058 } 059 060 public void setComparator( String sComparator ) { 061 HL7Element e = new SimpleElement( iLevel + 1 ); 062 e.setType( "ST" ); 063 e.setName( "SN.1" ); 064 e.setValue( sComparator ); 065 try { 066 setComponent( e, 1 ); 067 } catch( MalformedFieldException mfe ) { 068 mfe.printStackTrace(); 069 } 070 } 071 072 public String getComparator() { 073 HL7Element e = getComponent( 1 ); 074 if( e != null ) 075 return e.toString(); 076 else 077 return ""; 078 } 079 080 public void setNum1( String sNum1 ) { 081 HL7Element e = new SimpleElement( iLevel + 1 ); 082 e.setType( "NM" ); 083 e.setName( "SN.2" ); 084 e.setValue( sNum1 ); 085 try { 086 setComponent( e, 2 ); 087 } catch( MalformedFieldException mfe ) { 088 mfe.printStackTrace(); 089 } 090 } 091 092 public String getNum1() { 093 HL7Element e = getComponent( 2 ); 094 if( e != null ) 095 return e.toString(); 096 else 097 return ""; 098 } 099 100 public void setSeparator( String sSeparator ) { 101 HL7Element e = new SimpleElement( iLevel + 1 ); 102 e.setType( "ST" ); 103 e.setName( "SN.3" ); 104 e.setValue( sSeparator ); 105 try { 106 setComponent( e, 3 ); 107 } catch( MalformedFieldException mfe ) { 108 mfe.printStackTrace(); 109 } 110 } 111 112 public String getSeparator() { 113 HL7Element e = getComponent( 3 ); 114 if( e != null ) 115 return e.toString(); 116 else 117 return ""; 118 } 119 120 public void setNum2( String sNum2 ) { 121 HL7Element e = new SimpleElement( iLevel + 1 ); 122 e.setType( "NM" ); 123 e.setName( "SN.3" ); 124 e.setValue( sNum2 ); 125 try { 126 setComponent( e, 4 ); 127 } catch( MalformedFieldException mfe ) { 128 mfe.printStackTrace(); 129 } 130 } 131 132 public String getNum2() { 133 HL7Element e = getComponent( 4 ); 134 if( e != null ) 135 return e.toString(); 136 else 137 return ""; 138 } 139 140 } // End class SNElement 141