/** * For response messages, returns the value of MSA-2 (the message ID of the message sent by the * sending system). This value may be needed prior to main message parsing, so that * (particularly in a multi-threaded scenario) the message can be routed to the thread that sent * the request. We need this information first so that any parse exceptions are thrown to the * correct thread. Implementers of Parsers should take care to make the implementation of this * method very fast and robust. Returns null if MSA-2 can not be found (e.g. if the message is * not a response message). Trims whitespace from around the MSA-2 field. */ public String getAckID(String message) { String ackID = null; try { ackID = parseLeaf(message, "msa.2", 0).trim(); } catch (HL7Exception e) { /* OK ... assume it isn't a response message */ } return ackID; }
/** * For response messages, returns the value of MSA-2 (the message ID of the message sent by the * sending system). This value may be needed prior to main message parsing, so that * (particularly in a multi-threaded scenario) the message can be routed to the thread that sent * the request. We need this information first so that any parse exceptions are thrown to the * correct thread. Implementers of Parsers should take care to make the implementation of this * method very fast and robust. Returns null if MSA-2 can not be found (e.g. if the message is * not a response message). Trims whitespace from around the MSA-2 field. */ public String getAckID(String message) { String ackID = null; try { ackID = parseLeaf(message, "msa.2", 0).trim(); } catch (HL7Exception e) { /* OK ... assume it isn't a response message */ } return ackID; }
/** * <p> * Returns a minimal amount of data from a message string, including only the data needed to * send a response to the remote system. This includes the following fields: * <ul> * <li>field separator</li> * <li>encoding characters</li> * <li>processing ID</li> * <li>message control ID</li> * </ul> * This method is intended for use when there is an error parsing a message, (so the Message * object is unavailable) but an error message must be sent back to the remote system including * some of the information in the inbound message. This method parses only that required * information, hopefully avoiding the condition that caused the original error. * </p> */ public Segment getCriticalResponseData(String message) throws HL7Exception { String version = getVersion(message); Segment criticalData = Parser.makeControlMSH(version, getFactory()); Terser.set(criticalData, 1, 0, 1, 1, parseLeaf(message, "MSH.1", 0)); Terser.set(criticalData, 2, 0, 1, 1, parseLeaf(message, "MSH.2", 0)); Terser.set(criticalData, 10, 0, 1, 1, parseLeaf(message, "MSH.10", 0)); String procID = parseLeaf(message, "MSH.11", 0); if (procID == null || procID.length() == 0) { procID = parseLeaf(message, "PT.1", message.indexOf("MSH.11")); // this field is a composite in later versions } Terser.set(criticalData, 11, 0, 1, 1, procID); return criticalData; }
/** * <p> * Returns a minimal amount of data from a message string, including only the data needed to * send a response to the remote system. This includes the following fields: * <ul> * <li>field separator</li> * <li>encoding characters</li> * <li>processing ID</li> * <li>message control ID</li> * </ul> * This method is intended for use when there is an error parsing a message, (so the Message * object is unavailable) but an error message must be sent back to the remote system including * some of the information in the inbound message. This method parses only that required * information, hopefully avoiding the condition that caused the original error. * </p> */ public Segment getCriticalResponseData(String message) throws HL7Exception { String version = getVersion(message); Segment criticalData = Parser.makeControlMSH(version, getFactory()); Terser.set(criticalData, 1, 0, 1, 1, parseLeaf(message, "MSH.1", 0)); Terser.set(criticalData, 2, 0, 1, 1, parseLeaf(message, "MSH.2", 0)); Terser.set(criticalData, 10, 0, 1, 1, parseLeaf(message, "MSH.10", 0)); String procID = parseLeaf(message, "MSH.11", 0); if (procID == null || procID.length() == 0) { procID = parseLeaf(message, "PT.1", message.indexOf("MSH.11")); // this field is a composite in later versions } Terser.set(criticalData, 11, 0, 1, 1, procID); return criticalData; }