001/** 002The contents of this file are subject to the Mozilla Public License Version 1.1 003(the "License"); you may not use this file except in compliance with the License. 004You may obtain a copy of the License at http://www.mozilla.org/MPL/ 005Software distributed under the License is distributed on an "AS IS" basis, 006WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 007specific language governing rights and limitations under the License. 008 009The Original Code is "Message.java". Description: 010"Represents a complete HL7 message including all structures, segments, and fields" 011 012The Initial Developer of the Original Code is University Health Network. Copyright (C) 0132001. All Rights Reserved. 014 015Contributor(s): ______________________________________. 016 017Alternatively, the contents of this file may be used under the terms of the 018GNU General Public License (the ?GPL?), in which case the provisions of the GPL are 019applicable instead of those above. If you wish to allow use of your version of this 020file only under the terms of the GPL and not to allow others to use your version 021of this file under the MPL, indicate your decision by deleting the provisions above 022and replace them with the notice and other provisions required by the GPL License. 023If you do not delete the provisions above, a recipient may use your version of 024this file under either the MPL or the GPL. 025 026 */ 027 028package ca.uhn.hl7v2.model; 029 030import ca.uhn.hl7v2.AcknowledgmentCode; 031import ca.uhn.hl7v2.HL7Exception; 032import ca.uhn.hl7v2.HapiContext; 033import ca.uhn.hl7v2.parser.Parser; 034import ca.uhn.hl7v2.parser.PipeParser; 035import ca.uhn.hl7v2.validation.ValidationContext; 036import java.io.IOException; 037 038/** 039 * <p> 040 * Represents a complete HL7 message including all structures, segments, and fields. 041 * </p> 042 * <p> 043 * Note this it is not recommended to implement this interface directly, as it is subject to change. 044 * Instead, extend abstract implementations for your model classes, such as {@link AbstractMessage} 045 * and {@link AbstractGroup} 046 * </p> 047 * 048 * @author Bryan Tripp (bryan_tripp@sourceforge.net) 049 */ 050public interface Message extends Group { 051 052 /** 053 * Returns the version number of the HL7 version in which this message structure is defined 054 * (e.g. "2.4") 055 */ 056 public abstract String getVersion(); 057 058 /** 059 * @return the set of validation rules that applies to this message 060 * 061 * @deprecated ValidationContext instances private for Message instances will be removed in the 062 * next release. Use getParser().getValidationContext(). 063 */ 064 public abstract ValidationContext getValidationContext(); 065 066 /** 067 * @param theContext the set of validation rules that are to apply to this message 068 * 069 * @deprecated ValidationContext instances private for Message instances will be removed in the 070 * next release. Use 071 * {@link HapiContext#setValidationContext(ValidationContext)} then. 072 */ 073 public void setValidationContext(ValidationContext theContext); 074 075 /** 076 * Convenience method which retrieves the field separator value from the first field of the 077 * first segment. 078 * 079 * Typically, the first segment is MSH, so this method will retrieve the value of MSH-1. 080 * 081 * @return The field separator 082 * @throws HL7Exception If an error occurs 083 * @since 1.0 084 */ 085 public Character getFieldSeparatorValue() throws HL7Exception; 086 087 /** 088 * Convenience method which retrieves the encoding characters value from the second field of the 089 * first segment. 090 * 091 * Typically, the first segment is MSH, so this method will retrieve the value of MSH-2. 092 * 093 * @return The encoding characters 094 * @throws HL7Exception If an error occurs 095 * @since 1.0 096 */ 097 public String getEncodingCharactersValue() throws HL7Exception; 098 099 /** 100 * Sets the parser to be used when parse/encode methods are called on this Message, as well as 101 * its children. It is recommended that if these methods are going to be called, a parser be 102 * supplied with the validation context wanted. Where possible, the parser should be reused for 103 * best performance, unless thread safety is an issue. 104 * 105 * Note that not all parsers can be used. As of version 1.0, only {@link PipeParser} supports 106 * this functionality 107 */ 108 public void setParser(Parser parser); 109 110 /** 111 * Returns the parser to be used when parse/encode methods are called on this Message, as well 112 * as its children. The default value is a new {@link PipeParser} 113 */ 114 public Parser getParser(); 115 116 /** 117 * Parses the string into this message using the parser returned by {@link #getParser() } 118 */ 119 public void parse(String string) throws HL7Exception; 120 121 /** 122 * Encodes this message using the parser returned by {@link #getParser() } 123 */ 124 public String encode() throws HL7Exception; 125 126 /** 127 * <p> 128 * Generates and returns an ACK message which would be used to acknowledge this message 129 * successfully, with an MSA-1 code of "AA". The ACK generated will be of the same version as 130 * the value of MSH-12 in this message (as opposed to the version of the message class instance, 131 * if they are different) 132 * </p> 133 * 134 * <p> 135 * Note that this method will fail if it is not possible to generate an ACK for any reason, such 136 * as 137 * <ul> 138 * <li>Message version is invalid</li> 139 * <li>First segment is not an MSH</li> 140 * </p> 141 * 142 * @throws HL7Exception If the message can not be constructed 143 * @throws IOException If a failure occurs in generating a control ID for the message 144 */ 145 public Message generateACK() throws HL7Exception, IOException; 146 147 /** 148 * <p> 149 * Generates and returns an ACK message which would be used to acknowledge this message 150 * successfully. The ACK generated will be of the same version as the value of MSH-12 in this 151 * message (as opposed to the version of the message class instance, if they are different) 152 * </p> 153 * 154 * <p> 155 * Note that this method will fail if it is not possible to generate an ACK for any reason, such 156 * as 157 * <ul> 158 * <li>Message version is invalid</li> 159 * <li>First segment is not an MSH</li> 160 * </p> 161 * 162 * @param theAcknowldegementCode The acknowledement code (MSA-1) to supply. If null, defaults to 163 * "AA". To generate a typical NAK, use "AE" 164 * @param theException The exceptions used to populate the ERR segment (if any) 165 * @throws HL7Exception If the message can not be constructed 166 * @throws IOException If a failure occurs in generating a control ID for the message 167 * 168 * @deprecated use {@link #generateACK(AcknowledgmentCode, HL7Exception)} 169 */ 170 public Message generateACK(String theAcknowldegementCode, HL7Exception theException) 171 throws HL7Exception, IOException; 172 173 /** 174 * <p> 175 * Generates and returns an ACK message which would be used to acknowledge this message 176 * successfully. The ACK generated will be of the same version as the value of MSH-12 in this 177 * message (as opposed to the version of the message class instance, if they are different) 178 * </p> 179 * 180 * <p> 181 * Note that this method will fail if it is not possible to generate an ACK for any reason, such 182 * as 183 * <ul> 184 * <li>Message version is invalid</li> 185 * <li>First segment is not an MSH</li> 186 * </p> 187 * 188 * @param theAcknowlegementCode If null, defaults to 189 * AcknowledgmentCode.AA. To generate a typical NAK, use AcknowledgmentCode.AE 190 * @param theException The exceptions used to populate the ERR segment (if any) 191 * @throws HL7Exception If the message can not be constructed 192 * @throws IOException If a failure occurs in generating a control ID for the message 193 */ 194 public Message generateACK(AcknowledgmentCode theAcknowlegementCode, HL7Exception theException) 195 throws HL7Exception, IOException; 196 /** 197 * <p> 198 * Prints a summary of the contents and structure of this message. This is useful for debugging 199 * purposes, if you want to figure out where in the structure of a message a given segment has 200 * been placed. 201 * </p> 202 * <p> 203 * For instance, the following message (containing a few quirks for demonstration purposes): 204 * <code> 205 * <pre>MSH|^~\\&|^QueryServices||||20021011161756.297-0500||ADT^A01|1|D|2.4\r 206 * EVN|R01 207 * EVN|R02 208 * PID|1 209 * IN1|1 210 * IN1|2 211 * PID|2</pre></code> ...produces the following output: <code> 212 * <pre>ADT_A01 (start) 213 * MSH - MSH|^~\&|^QueryServices||||20021011161756.297-0500||ADT^A01|1|D|2.4 214 * EVN - EVN|R01 215 * [ { EVN2 } ] (non-standard) - EVN|R02 216 * PID - PID|1 217 * [ PD1 ] - Not populated 218 * [ { ROL } ] - Not populated 219 * [ { NK1 } ] - Not populated 220 * PV1 - Not populated 221 * [ PV2 ] - Not populated 222 * [ { ROL2 } ] - Not populated 223 * [ { DB1 } ] - Not populated 224 * [ { OBX } ] - Not populated 225 * [ { AL1 } ] - Not populated 226 * [ { DG1 } ] - Not populated 227 * [ DRG ] - Not populated 228 * PROCEDURE (start) 229 * [{ 230 * PR1 - Not populated 231 * [ { ROL } ] - Not populated 232 * }] 233 * PROCEDURE (end) 234 * [ { GT1 } ] - Not populated 235 * INSURANCE (start) 236 * [{ 237 * IN1 - IN1|1 238 * [ IN2 ] - Not populated 239 * [ { IN3 } ] - Not populated 240 * [ { ROL } ] - Not populated 241 * }] 242 * [{ 243 * IN1 - IN1|2 244 * [ { PID } ] (non-standard) - PID|2 245 * [ IN2 ] - Not populated 246 * [ { IN3 } ] - Not populated 247 * [ { ROL } ] - Not populated 248 * }] 249 * INSURANCE (end) 250 * [ ACC ] - Not populated 251 * [ UB1 ] - Not populated 252 * [ UB2 ] - Not populated 253 * [ PDA ] - Not populated 254 * ADT_A01 (end) 255 * </pre></code> 256 * </p> 257 * 258 * @return A summary of the structure 259 * @throws HL7Exception If any problems occur encoding the structure 260 */ 261 public String printStructure() throws HL7Exception; 262 263}