View Javadoc

1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is "PopulateOBXSegment.java".  Description:
10   * "Example Code"
11   *
12   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13   * 2001.  All Rights Reserved.
14   *
15   * Contributor(s): James Agnew
16   *
17   * Alternatively, the contents of this file may be used under the terms of the
18   * GNU General Public License (the  �GPL�), in which case the provisions of the GPL are
19   * applicable instead of those above.  If you wish to allow use of your version of this
20   * file only under the terms of the GPL and not to allow others to use your version
21   * of this file under the MPL, indicate your decision by deleting  the provisions above
22   * and replace  them with the notice and other provisions required by the GPL License.
23   * If you do not delete the provisions above, a recipient may use your version of
24   * this file under either the MPL or the GPL.
25   *
26   */
27  
28  package ca.uhn.hl7v2.examples;
29  
30  import ca.uhn.hl7v2.HL7Exception;
31  import ca.uhn.hl7v2.model.Varies;
32  import ca.uhn.hl7v2.model.v25.datatype.CE;
33  import ca.uhn.hl7v2.model.v25.datatype.ST;
34  import ca.uhn.hl7v2.model.v25.datatype.TX;
35  import ca.uhn.hl7v2.model.v25.group.ORU_R01_ORDER_OBSERVATION;
36  import ca.uhn.hl7v2.model.v25.message.ORU_R01;
37  import ca.uhn.hl7v2.model.v25.segment.OBR;
38  import ca.uhn.hl7v2.model.v25.segment.OBX;
39  import ca.uhn.hl7v2.parser.PipeParser;
40  
41  /**
42   * Example code for populating an OBX segment
43   * 
44   * @author <a href="mailto:jamesagnew@sourceforge.net">James Agnew</a>
45   * @version $Revision: 1.1 $ updated on $Date: 2009/03/19 13:09:26 $ by $Author: jamesagnew $
46   */
47  public class PopulateOBXSegment
48  {
49  
50      /**
51       * We are going to create an ORU_R01 message, for the purpose of demonstrating the creation and
52       * population of an OBX segment.
53       * 
54       * The following message snippet is drawn (and modified for simplicity) 
55       * from section 7.4.2.4 of the HL7 2.5 specification.
56       * 
57       * <code>
58       * OBR|1||1234^LAB|88304 
59       * OBX|1|CE|88304|1|T57000^GALLBLADDER^SNM
60       * OBX|2|TX|88304|1|THIS IS A NORMAL GALLBLADDER 
61       * OBX|3|TX|88304&MDT|1|MICROSCOPIC EXAM SHOWS HISTOLOGICALLY NORMAL GALLBLADDER TISSUE
62       * </code>
63       * 
64       * The following code attempts to generate this message structure.
65       * 
66       * The HL7 spec defines, the following structure for an ORU^R01 message, represented in HAPI by
67       * the segment group:
68       * 
69       * <code>
70       *                      ORDER_OBSERVATION
71       *       {
72       *       [ ORC ]
73       *       OBR
74       *       [ { NTE } ]
75       *                     TIMING_QTY
76       *          [{
77       *          TQ1
78       *          [ { TQ2 } ]
79       *          }]
80       *                     TIMING_QTY
81       *       [ CTD ]
82       *                     OBSERVATION
83       *          [{
84       *          OBX
85       *          [ { NTE } ]
86       *          }]
87       *                     OBSERVATION
88       *       [ { FT1 } ]
89       *       [ { CTI } ]
90       *                     SPECIMEN
91       *          [{
92       *          SPM
93       *          [ { OBX } ]
94       *          }]
95       *                     SPECIMEN
96       *       }
97       *                     ORDER_OBSERVATION
98       * </code>
99       * 
100      * @param args
101      *            The arguments
102      * @throws HL7Exception
103      *             If any processing problem occurs
104      */
105     public static void main(String[] args) throws HL7Exception {
106 
107         // First, a message object is constructed
108         ORU_R01 message = new ORU_R01();
109 
110         // A few basic MSH fields are populated. In a real situation, this would not be enough
111         // to produce a valid message, but for demonstration purposes we'll skip a few
112         // fields.
113         message.getMSH().getEncodingCharacters().setValue("^~\\&");
114         message.getMSH().getFieldSeparator().setValue("|");
115 
116         ORU_R01_ORDER_OBSERVATION orderObservation = message.getPATIENT_RESULT().getORDER_OBSERVATION();
117 
118         // Populate the OBR
119         OBR obr = orderObservation.getOBR();
120         obr.getSetIDOBR().setValue("1");
121         obr.getFillerOrderNumber().getEntityIdentifier().setValue("1234");
122         obr.getFillerOrderNumber().getNamespaceID().setValue("LAB");
123         obr.getUniversalServiceIdentifier().getIdentifier().setValue("88304");
124         
125         // Populate the first OBX
126         OBX obx = orderObservation.getOBSERVATION(0).getOBX();
127         obx.getSetIDOBX().setValue("1");
128         obx.getObservationIdentifier().getIdentifier().setValue("88304");
129         obx.getObservationSubID().setValue("1");
130 
131         // The first OBX has a value type of CE. So first, we populate OBX-2 with "CE"...
132         obx.getValueType().setValue("CE");
133         
134         // ... then we create a CE instance to put in OBX-5.
135         CE ce = new CE(message);
136         ce.getIdentifier().setValue("T57000");
137         ce.getText().setValue("GALLBLADDER");
138         ce.getNameOfCodingSystem().setValue("SNM");
139         Varies value = obx.getObservationValue(0);
140         value.setData(ce);
141         
142         // Now we populate the second OBX
143         obx = orderObservation.getOBSERVATION(1).getOBX();
144         obx.getSetIDOBX().setValue("2");
145         obx.getObservationSubID().setValue("1");
146 
147         // The second OBX in the sample message has an extra subcomponent at
148         // OBX-3-1. This component is actually an ST, but the HL7 specification allows
149         // extra subcomponents to be tacked on to the end of a component. This is
150         // uncommon, but HAPI nontheless allows it.
151         ST observationIdentifier = obx.getObservationIdentifier().getIdentifier();
152         observationIdentifier.setValue("88304");
153         ST extraSubcomponent = new ST(message);
154         extraSubcomponent.setValue("MDT");
155         observationIdentifier.getExtraComponents().getComponent(0).setData(extraSubcomponent );
156 
157         // The first OBX has a value type of TX. So first, we populate OBX-2 with "TX"...
158         obx.getValueType().setValue("TX");
159         
160         // ... then we create a CE instance to put in OBX-5.
161         TX tx = new TX(message);
162         tx.setValue("MICROSCOPIC EXAM SHOWS HISTOLOGICALLY NORMAL GALLBLADDER TISSUE");
163         value = obx.getObservationValue(0);
164         value.setData(tx);
165 
166         // Print the message (remember, the MSH segment was not fully or correctly populated)
167         System.out.append(new PipeParser().encode(message));
168 
169         /*
170          * MSH|^~\&
171          * OBR|1||1234^LAB|88304
172          * OBX|1|CE|88304|1|T57000^GALLBLADDER^SNM
173          * OBX|2|TX|88304&MDT|1|MICROSCOPIC EXAM SHOWS HISTOLOGICALLY NORMAL GALLBLADDER TISSUE
174          */
175     }
176 
177 }