001    package org.vmdb.hl7;
002    
003    /**
004     * <p><Title:> Observation Request (OBR) Segment. </p>
005     * <p>Description: Network Connectivity For VMDB. </p>
006     * <p>Copyright: Copyright (c) 2002-2003. </p>
007     * <p>Company: Veterinary Medical Database (VMDB). </p>
008     * Now is the time
009     * <p>For VMDB reporting, the OBR defines the observations made during the
010     * patient visit. These fall into two general categories: physical
011     * observations about the patient and impressions concerning the patientÕs
012     * condition at the end of the visit. The values for these observations
013     * are reported in OBX segments, which are described below.  There can
014     * be many OBXÕs per OBR, but only one OBR per PV1.  Since all of the
015     * observations named in this segment are being reported after the fact for
016     * VMDB reporting, elements that are commonly used to track the status of an
017     * order as well as the specific filler and placer information are unneeded.
018     * Thus only a very few elements in this segment are needed by the ORU message.
019     * See HL7 Standard Chapter 4 for details.</p>
020     * @author Michael K. Martin
021     * @version 1.0
022     */
023    
024    public class OBRSegment extends HL7Segment {
025       private String sNm = "OBR";
026       private String sRl =
027                   "DT[SI][EI][EI]CE[ID][TS]TS[TS][CQ][XCN][ID][CE][ST][TS]" +
028                   "[CM][XCN][XTN][ST][ST][ST][ST][TS][CM][ID]ID[CM][TQ][XCN]" +
029                   "[CM][ID][CE][CM][CM][CM][CM][TS][NM][CE][CE][CE][ID][ID]" +
030                   "[CE][CE][CE][CE][CE]";
031    
032       /**
033        * Construct an empty OBR segment.
034        */
035       public OBRSegment() {
036          setName( sNm );
037          setRule( sRl );
038       }
039    
040       /**
041        * Construct an empty OBR segment, setting its containing message
042        * object.
043        * @param msgParent HL7SegmentContainer (Message or Loop) object that
044        * contains this segment.
045        */
046       public OBRSegment( HL7SegmentContainer msgParent ) {
047          super( msgParent );
048          setName( sNm );
049          setRule( sRl );
050       }
051    
052          /**
053           * Set the coded universal service identifier from the
054           * individual components of a CE element.
055           * @param sCode code value normally snomed
056           * @param sText spelled out term
057           * @param sSystem normally snomed
058           */
059       public void setUniversalServiceId( String sCode, String sText, String sCodeType ) {
060          CEElement ceE = new CEElement( sCode, sText, sCodeType );
061          ceE.setName( "OBR.4" );
062          try {
063             setField( ceE, 4 );
064          }
065          catch( ArrayIndexOutOfBoundsException ae ) {
066             ae.printStackTrace();
067          }
068          catch( MalformedSegmentException mfe ) {
069             mfe.printStackTrace();
070          }
071       }
072    
073          /**
074           * Set the coded universal service identifier.
075           * This version takes a preformed CE element
076           * @param ceServiceId CEElement usually a constant from LOINC or SNOMED
077           */
078       public void setUniversalServiceId( CEElement ceServiceId ) {
079          ceServiceId.setName( "OBR.4" );
080          try {
081             setField( ceServiceId, 4 );
082          }
083          catch( ArrayIndexOutOfBoundsException ae ) {
084             ae.printStackTrace();
085          }
086          catch( MalformedSegmentException mfe ) {
087             mfe.printStackTrace();
088          }
089       }
090    
091       /**
092        * Get the universal service identifier as the complete CEElement.
093        * @return CEElement with coded species
094        */
095       public CEElement getUniversalServiceId() {
096          return (CEElement)getField( 4 );
097       }
098    
099       /**
100        * Get just the text of the Universal Service Id.
101        * @return String with id text spelled out.
102        */
103       public String getUniversalServiceIdText() {
104          CEElement ceE = (CEElement)getField( 4 );
105          if( ceE != null )
106             return ceE.getText();
107          else
108             return "";
109       }
110    
111       /**
112        * Set the observation date/time of the message to string formatted date/time.
113        * @param sDateTime String with date/time in yyyyMMddHHmmss format
114        */
115       public void setObservationDateTime( String sDateTime ) {
116          TSElement tse = new TSElement();
117          tse.setName( "OBR.7" );
118          tse.setDateTime( sDateTime );
119          try {
120             setField( tse, 7 );
121          }
122          catch( ArrayIndexOutOfBoundsException ae ) {
123             ae.printStackTrace();
124          }
125          catch( MalformedSegmentException mfe ) {
126             mfe.printStackTrace();
127          }
128       }
129    
130       /**
131        * Get the observation date/time as a string.
132        * @return String date/time
133        */
134       public String getObservationDateTime() {
135          TSElement tse = (TSElement)getField( 7 );
136          if( tse != null )
137             return tse.getDateTime();
138          else
139             return "";
140       }
141    
142       /**
143        * Set the result status code.
144        * @param sStatus String with date in ISO format
145        */
146       public void setResultStatus( String sStatus ) {
147          try {
148             setField( sStatus, 25 );
149          }
150          catch( ArrayIndexOutOfBoundsException ae ) {
151             ae.printStackTrace();
152          }
153       }
154    
155       /**
156        * Get Result status code.
157        * @return String with status code
158        */
159       public String getResultStatus() {
160          HL7Element e = getField(25);
161          if( e != null )
162             return e.getValue();
163          else
164             return "";
165       }
166    
167    } // End class OBRSegment