001    package org.vmdb.hl7;
002    
003    /**
004     * <p><Title:> Coded Element (CE) 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 CEElement extends HL7Element {
013       private String sNm = "CE";
014       private String sRl = "ST [ST][ST][ST][ST][ST]";
015    
016       /**
017        * Construct a Coded 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 CEElement( int iLevel ) {
022          super( iLevel );
023          setName( sNm );
024          setRule( sRl );
025          setType( "CE" );
026       }
027    
028       /**
029        * Construct a Coded Element using the default name and type constants
030        * at the default level FIELD.
031        */
032       public CEElement() {
033          super( FIELD );
034          setName( sNm );
035          setRule( sRl );
036          setType( "CE" );
037       }
038    
039       /**
040        * Construct a Coded Element setting its value.<br><br>
041        * Uses the default name and type constants at the default level FIELD
042        * @param sIdentifier String with the code for the value.
043        * @param sText String with the value spelled out as English text.
044        * @param sSystem String with the name of the coding system abbreviated.
045        */
046       public CEElement( String sIdentifier, String sText, String sSystem) {
047          super( FIELD );
048          setName( sNm );
049          setRule( sRl );
050          setType( "CE" );
051          setIdentifier( sIdentifier );
052          setText( sText );
053          setCodingSystem( sSystem );
054       }
055    
056       /**
057        * Construct a Coded Element setting its value.<br><br>
058        * Uses the default name and type constants at the default level FIELD
059        * @param sIdentifier String with the code for the value.
060        * @param sText String with the value spelled out as English text.
061        * @param sSystem String with the name of the coding system abbreviated.
062        * @param sAltIdentifier String with the code for the value.
063        * @param sAltText String with the value spelled out as English text.
064        * @param sAltSystem String with the name of the coding system abbreviated.
065        */
066       public CEElement( String sIdentifier, String sText, String sSystem,
067                         String sAltIdentifier, String sAltText, String sAltSystem ) {
068          super( FIELD );
069          setName( sNm );
070          setRule( sRl );
071          setType( "CE" );
072          setIdentifier( sIdentifier );
073          setText( sText );
074          setCodingSystem( sSystem );
075          setAltIdentifier( sAltIdentifier );
076          setAltText( sAltText );
077          setAltCodingSystem( sAltSystem );
078       }
079    
080       /**
081        * Copy constructor to clone away const'ness when using constant value CEs
082        */
083       public CEElement( CEElement ceIn ) {
084          super( FIELD );
085          setName( sNm );
086          setRule( sRl );
087          setType( "CE" );
088          initialize();
089          this.setName( ceIn.getName() );
090          this.setIdentifier( ceIn.getIdentifier() );
091          this.setText( ceIn.getText() );
092          this.setCodingSystem( ceIn.getCodingSystem() );
093          String sAltId = ceIn.getAltIdentifier();
094          if( sAltId.length() > 0 )
095             this.setAltIdentifier( sAltId );
096          String sAltText = ceIn.getAltText();
097          if( sAltText.length() > 0 )
098             this.setAltText( sAltText );
099          String sAltCodingSystem = ceIn.getAltCodingSystem();
100          if( sAltCodingSystem.length() > 0 )
101             this.setAltCodingSystem( sAltCodingSystem );
102       }
103    
104       public CEElement Clone() {
105          return new CEElement( this );
106       }
107    
108       public Object clone() { return Clone(); }
109    
110       /**
111        * Does this CEElement code the same thing as the second?
112        * @param CEElement To compare
113        * @return boolean true if the two match on identifier plus code system
114        * for either main or alternate identifier
115        */
116       public boolean equals( CEElement ce2 ) {
117          if( getIdentifier().equals( ce2.getIdentifier() )&&
118              getCodingSystem().equals( ce2.getCodingSystem() ) ) {
119             return true;
120          }
121          if( getIdentifier().equals( ce2.getAltIdentifier() ) &&
122              getCodingSystem().equals( ce2.getAltCodingSystem() ) ) {
123             return true;
124          }
125          if( getAltIdentifier().equals( ce2.getIdentifier() ) &&
126              getAltCodingSystem().equals( ce2.getCodingSystem() ) ) {
127             return true;
128          }
129          return false;
130       }
131    
132       /**
133        * Set the coded value of an existing Coded Element.
134        * @param sIdentifier String with the code for the value.
135        */
136       public void setIdentifier( String sIdentifier ) {
137          HL7Element e = new SimpleElement( iLevel + 1 );
138          e.setType( "ST" );
139          e.setName( "CE.1" );
140          e.setValue( sIdentifier );
141          try {
142             setComponent( e, 1 );
143          } catch( MalformedFieldException mfe ) {
144             mfe.printStackTrace();
145          }
146       }
147    
148       /**
149        * Get the coded value of an existing Coded Element.
150        * @return String with the code for the value.
151        */
152       public String getIdentifier() {
153          HL7Element e = getComponent( 1 );
154          if( e != null )
155             return e.toString();
156          else
157             return "";
158       }
159    
160       /**
161        * Set the text value of an existing Coded Element.
162        * @param sText String with the value spelled out as English text.
163        */
164       public void setText( String sText ) {
165          HL7Element e = new SimpleElement( iLevel + 1 );
166          e.setType( "ST" );
167          e.setName( "CE.2" );
168          e.setValue( sText );
169          try {
170             setComponent( e, 2 );
171          } catch( MalformedFieldException mfe ) {
172             mfe.printStackTrace();
173          }
174       }
175    
176       /**
177        * Get the text value of an existing Coded Element.
178        * @return String with the value spelled out as English text.
179        */
180       public String getText() {
181          HL7Element e = getComponent( 2 );
182          if( e != null )
183             return e.toString();
184          else
185             return "";
186       }
187    
188       /**
189        * Set the coding system used in an existing Coded Element.
190        * @param sSystem String with the name of the coding system abbreviated.
191        */
192       public void setCodingSystem( String sCodeSystem ) {
193          HL7Element e = new SimpleElement( iLevel + 1 );
194          e.setType( "ST" );
195          e.setName( "CE.3" );
196          e.setValue( sCodeSystem );
197          try {
198             setComponent( e, 3 );
199          } catch( MalformedFieldException mfe ) {
200             mfe.printStackTrace();
201          }
202       }
203    
204       /**
205        * Get the coding system used in an existing Coded Element.
206        * @return String with the name of the coding system abbreviated.
207        */
208       public String getCodingSystem() {
209          HL7Element e = getComponent( 3 );
210          if( e != null )
211             return e.toString();
212          else
213             return "";
214       }
215    
216       /**
217        * Set the alternate coded value of an existing Coded Element.<br><br>
218        * The alternate code is a different way of coding the same meaning.  If a
219        * second concept is to be sent, it belongs in a different element, <i>not</i>
220        * in the alternate identifier.
221        * @param sAltId String with the code for the value.
222        */
223       public void setAltIdentifier( String sAltId ) {
224          HL7Element e = new SimpleElement( iLevel + 1 );
225          e.setType( "ST" );
226          e.setName( "CE.4" );
227          e.setValue( sAltId );
228          try {
229             setComponent( e, 4 );
230          } catch( MalformedFieldException mfe ) {
231             mfe.printStackTrace();
232          }
233       }
234    
235       /**
236        * Get the alternate coded value of an existing Coded Element.
237        * @return String with the code for the value.
238        */
239       public String getAltIdentifier() {
240          HL7Element e = getComponent( 4 );
241          if( e != null )
242             return e.toString();
243          else
244             return "";
245       }
246    
247       /**
248        * Set the alternate text value of an existing Coded Element.<br><br>
249        * If this component is left blank, it is assumed that the description text
250        * is the same as the primary.
251        * @param sAltText String with the value spelled out as English text.
252        */
253       public void setAltText( String sAltText ) {
254          HL7Element e = new SimpleElement( iLevel + 1 );
255          e.setType( "ST" );
256          e.setName( "CE.5" );
257          e.setValue( sAltText );
258          try {
259             setComponent( e, 5 );
260          } catch( MalformedFieldException mfe ) {
261             mfe.printStackTrace();
262          }
263       }
264    
265       /**
266        * Get the alternate text value of an existing Coded Element.
267        * @return String with the value spelled out as English text.
268        */
269       public String getAltText() {
270          HL7Element e = getComponent( 5 );
271          if( e != null )
272             return e.toString();
273          else
274             return "";
275       }
276    
277       /**
278        * Set the alternate coding system used in an existing Coded Element.<br><br>
279        * If this component is left blank, it is assumed that the alternate coding
280        * system is a local code.
281        * @param sAltSystem String with the name of the coding system abbreviated.
282        */
283       public void setAltCodingSystem( String sAltSystem ) {
284          HL7Element e = new SimpleElement( iLevel + 1 );
285          e.setType( "ST" );
286          e.setName( "CE.6" );
287          e.setValue( sAltSystem );
288          try {
289             setComponent( e, 6 );
290          } catch( MalformedFieldException mfe ) {
291             mfe.printStackTrace();
292          }
293       }
294    
295       /**
296        * Get the alternate coding system used in an existing Coded Element.
297        * @return String with the name of the coding system abbreviated.
298        */
299       public String getAltCodingSystem() {
300          HL7Element e = getComponent( 6 );
301          if( e != null )
302             return e.toString();
303          else
304             return "";
305       }
306    
307    } // End class CEElement
308