/** * Sets the string value of the field specified. See class docs for location spec syntax. * * @param spec primitive path specification * @param value value to be set * @throws HL7Exception if the primitive does not exist */ public void set(String spec, String value) throws HL7Exception { StringTokenizer tok = new StringTokenizer(spec, "-", false); Segment segment = getSegment(tok.nextToken()); int[] ind = getIndices(spec); log.trace("Setting {} seg: {} ind: {} {} {} {}", new Object[] { spec, segment.getName(), ind[0], ind[1], ind[2], ind[3] }); set(segment, ind[0], ind[1], ind[2], ind[3], value); }
/** * Sets the string value of the field specified. See class docs for location spec syntax. * * @param spec primitive path specification * @param value value to be set * @throws HL7Exception if the primitive does not exist */ public void set(String spec, String value) throws HL7Exception { StringTokenizer tok = new StringTokenizer(spec, "-", false); Segment segment = getSegment(tok.nextToken()); int[] ind = getIndices(spec); log.trace("Setting {} seg: {} ind: {} {} {} {}", new Object[] { spec, segment.getName(), ind[0], ind[1], ind[2], ind[3] }); set(segment, ind[0], ind[1], ind[2], ind[3], value); }
/** * Fill segments for HL7 versions before 2.5. * <p/> * HL7 versions before 2.5 require to set MSA-1 and MSA-3. The ERR segment only has one * repeatable field (ERR-1) with components containing details about the exception. * * @param response the raw response message * @param acknowledgmentCode acknowledgment code * @param repetition repetition of the ERR segment that shall be popualted * @throws HL7Exception */ private Message populateResponseBefore25(Message response, AcknowledgmentCode acknowledgmentCode, int repetition) throws HL7Exception { // TODO define what should happen if there is no MSA or ERR Segment msa = (Segment) response.get("MSA"); Terser.set(msa, 1, 0, 1, 1, acknowledgmentCode.name()); Terser.set(msa, 3, 0, 1, 1, errorCode.getMessage()); Segment err = (Segment) response.get("ERR"); if (location != null) { if (location.getSegmentName() != null) Terser.set(err, 1, repetition, 1, 1, location.getSegmentName()); if (location.getField() > 0) Terser.set(err, 1, repetition, 3, 1, Integer.toString(location.getField())); } Terser.set(err, 1, repetition, 4, 1, Integer.toString(errorCode.getCode())); Terser.set(err, 1, repetition, 4, 2, errorCode.getMessage()); Terser.set(err, 1, repetition, 4, 3, ErrorCode.codeTable()); Terser.set(err, 1, repetition, 4, 5, getMessage()); return response; }
/** * Fill segments for HL7 versions before 2.5. * <p/> * HL7 versions before 2.5 require to set MSA-1 and MSA-3. The ERR segment only has one * repeatable field (ERR-1) with components containing details about the exception. * * @param response the raw response message * @param acknowledgmentCode acknowledgment code * @param repetition repetition of the ERR segment that shall be popualted * @throws HL7Exception */ private Message populateResponseBefore25(Message response, AcknowledgmentCode acknowledgmentCode, int repetition) throws HL7Exception { // TODO define what should happen if there is no MSA or ERR Segment msa = (Segment) response.get("MSA"); Terser.set(msa, 1, 0, 1, 1, acknowledgmentCode.name()); Terser.set(msa, 3, 0, 1, 1, errorCode.getMessage()); Segment err = (Segment) response.get("ERR"); if (location != null) { if (location.getSegmentName() != null) Terser.set(err, 1, repetition, 1, 1, location.getSegmentName()); if (location.getField() > 0) Terser.set(err, 1, repetition, 3, 1, Integer.toString(location.getField())); } Terser.set(err, 1, repetition, 4, 1, Integer.toString(errorCode.getCode())); Terser.set(err, 1, repetition, 4, 2, errorCode.getMessage()); Terser.set(err, 1, repetition, 4, 3, ErrorCode.codeTable()); Terser.set(err, 1, repetition, 4, 5, getMessage()); return response; }
public Message createNak0(Message originalMessage, HL7Exception e, AcknowledgmentCode ackTypeCode) throws HL7Exception { AbstractMessage ack = (AbstractMessage) MessageUtils.response( originalMessage, messageType, triggerEvent); LOG.info("Creating NAK response event of type {}", ack.getClass().getName()); e.populateResponse(ack, ackTypeCode, 0); Segment msa = (Segment) ack.get("MSA"); Terser.set(msa, 1, 0, 1, 1, ackTypeCode.name()); Segment ackQak = (Segment) ack.get("QAK"); Segment origQpd = (Segment) originalMessage.get("QPD"); if (origQpd != null) { String queryTag = Terser.get(origQpd, 2, 0, 1, 1); Terser.set(ackQak, 1, 0, 1, 1, queryTag); LOG.debug("Set QAK-1 to {}", queryTag); } Terser.set(ackQak, 2, 0, 1, 1, "AE"); // create a dummy QPD segment, it will be replaced with proper contents by // org.openehealth.ipf.platform.camel.ihe.hl7v2.intercept.consumer.ConsumerSegmentEchoingInterceptor Segment ackQpd = (Segment) ack.get("QPD"); Terser.set(ackQpd, 1, 0, 1, 1, "dummy"); return ack; }
Segment msh = (Segment) get("MSH"); Version version = Version.versionOf(getVersion()); Terser.set(msh, 1, 0, 1, 1, "|"); Terser.set(msh, 2, 0, 1, 1, Version.V27.isGreaterThan(version) ? "^~\\&" : "^~\\&#"); GregorianCalendar now = new GregorianCalendar(); Terser.set(msh, 7, 0, 1, 1, CommonTS.toHl7TSFormat(now)); Terser.set(msh, 9, 0, 1, 1, messageCode); Terser.set(msh, 9, 0, 2, 1, messageTriggerEvent); Terser.set(msh, 10, 0, 1, 1, getParser().getParserConfiguration().getIdGenerator().getID()); Terser.set(msh, 11, 0, 1, 1, processingId); Terser.set(msh, 12, 0, 1, 1, getVersion()); if (StringUtil.isNotBlank(messageCode) && StringUtil.isNotBlank(messageTriggerEvent)) { String structure = eventMap.get(messageCode + "_" + messageTriggerEvent); Terser.set(msh, 9, 0, 3, 1, structure); className = className.substring(lastIndexOf + 1); if (className.matches("[A-Z]{3}_[A-Z0-9]{3}")) { Terser.set(msh, 9, 0, 3, 1, className);
Terser.set(msa, 1, 0, 1, 1, acknowledgmentCode.name()); Segment err = (Segment) response.get("ERR", repetition); if (location != null) { if (location.getSegmentName() != null) Terser.set(err, 2, 0, 1, 1, location.getSegmentName()); if (location.getSegmentRepetition() > 0) Terser.set(err, 2, 0, 2, 1, Integer.toString(location.getSegmentRepetition())); if (location.getField() > 0) Terser.set(err, 2, 0, 3, 1, Integer.toString(location.getField())); if (location.getFieldRepetition() > 0) Terser.set(err, 2, 0, 4, 1, Integer.toString(location.getFieldRepetition())); if (location.getComponent() > 0) Terser.set(err, 2, 0, 5, 1, Integer.toString(location.getComponent())); if (location.getSubcomponent() > 0) Terser.set(err, 2, 0, 6, 1, Integer.toString(location.getSubcomponent())); Terser.set(err, 3, 0, 1, 1, Integer.toString(errorCode.getCode())); Terser.set(err, 3, 0, 2, 1, errorCode.getMessage()); Terser.set(err, 3, 0, 3, 1, ErrorCode.codeTable()); Terser.set(err, 3, 0, 9, 1, getMessage()); Terser.set(err, 4, 0, 1, 1, "E"); return response;
Terser.set(msa, 1, 0, 1, 1, acknowledgmentCode.name()); Segment err = (Segment) response.get("ERR", repetition); if (location != null) { if (location.getSegmentName() != null) Terser.set(err, 2, 0, 1, 1, location.getSegmentName()); if (location.getSegmentRepetition() > 0) Terser.set(err, 2, 0, 2, 1, Integer.toString(location.getSegmentRepetition())); if (location.getField() > 0) Terser.set(err, 2, 0, 3, 1, Integer.toString(location.getField())); if (location.getFieldRepetition() > 0) Terser.set(err, 2, 0, 4, 1, Integer.toString(location.getFieldRepetition())); if (location.getComponent() > 0) Terser.set(err, 2, 0, 5, 1, Integer.toString(location.getComponent())); if (location.getSubcomponent() > 0) Terser.set(err, 2, 0, 6, 1, Integer.toString(location.getSubcomponent())); Terser.set(err, 3, 0, 1, 1, Integer.toString(errorCode.getCode())); Terser.set(err, 3, 0, 2, 1, errorCode.getMessage()); Terser.set(err, 3, 0, 3, 1, ErrorCode.codeTable()); Terser.set(err, 3, 0, 9, 1, getMessage()); Terser.set(err, 4, 0, 1, 1, "E"); return response;
Segment msh = (Segment) get("MSH"); Version version = Version.versionOf(getVersion()); Terser.set(msh, 1, 0, 1, 1, "|"); Terser.set(msh, 2, 0, 1, 1, Version.V27.isGreaterThan(version) ? "^~\\&" : "^~\\&#"); GregorianCalendar now = new GregorianCalendar(); Terser.set(msh, 7, 0, 1, 1, CommonTS.toHl7TSFormat(now)); Terser.set(msh, 9, 0, 1, 1, messageCode); Terser.set(msh, 9, 0, 2, 1, messageTriggerEvent); Terser.set(msh, 10, 0, 1, 1, getParser().getParserConfiguration().getIdGenerator().getID()); Terser.set(msh, 11, 0, 1, 1, processingId); Terser.set(msh, 12, 0, 1, 1, getVersion()); if (StringUtil.isNotBlank(messageCode) && StringUtil.isNotBlank(messageTriggerEvent)) { String structure = eventMap.get(messageCode + "_" + messageTriggerEvent); Terser.set(msh, 9, 0, 3, 1, structure); className = className.substring(lastIndexOf + 1); if (className.matches("[A-Z]{3}_[A-Z0-9]{3}")) { Terser.set(msh, 9, 0, 3, 1, className);
/** * <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; }
Terser.set(mshOut, 1, 0, 1, 1, fieldSep); Terser.set(mshOut, 2, 0, 1, 1, encChars); GregorianCalendar now = new GregorianCalendar(); now.setTime(new Date()); Terser.set(mshOut, 7, 0, 1, 1, CommonTS.toHl7TSFormat(now)); Terser.set(mshOut, 9, 0, 1, 1, "ACK"); Terser.set(mshOut, 9, 0, 2, 1, Terser.get(mshIn, 9, 0, 2, 1)); String v = mshOut.getMessage().getVersion(); if (v != null) { Version version = Version.versionOf(v); if (version != null && !Version.V25.isGreaterThan(version)) { Terser.set(mshOut, 9, 0, 3, 1, "ACK"); Terser.set(mshOut, 10, 0, 1, 1, mshIn.getMessage().getParser().getParserConfiguration().getIdGenerator().getID()); Terser.set(mshOut, 11, 0, 1, 1, procID); versionId = Version.highestAvailableVersionOrDefault().getVersion(); Terser.set(mshOut, 12, 0, 1, 1, versionId); Terser.set(mshOut, 3, 0, 1, 1, Terser.get(mshIn, 5, 0, 1, 1)); Terser.set(mshOut, 4, 0, 1, 1, Terser.get(mshIn, 6, 0, 1, 1)); Terser.set(mshOut, 5, 0, 1, 1, Terser.get(mshIn, 3, 0, 1, 1)); Terser.set(mshOut, 6, 0, 1, 1, Terser.get(mshIn, 4, 0, 1, 1)); Terser.set(msaOut, 1, 0, 1, 1, code.name()); Terser.set(msaOut, 2, 0, 1, 1, Terser.get(mshIn, 10, 0, 1, 1)); return out;
Terser.set(mshOut, 1, 0, 1, 1, fieldSep); Terser.set(mshOut, 2, 0, 1, 1, encChars); GregorianCalendar now = new GregorianCalendar(); now.setTime(new Date()); Terser.set(mshOut, 7, 0, 1, 1, CommonTS.toHl7TSFormat(now)); Terser.set(mshOut, 9, 0, 1, 1, "ACK"); Terser.set(mshOut, 9, 0, 2, 1, Terser.get(mshIn, 9, 0, 2, 1)); String v = mshOut.getMessage().getVersion(); if (v != null) { Version version = Version.versionOf(v); if (version != null && !Version.V25.isGreaterThan(version)) { Terser.set(mshOut, 9, 0, 3, 1, "ACK"); Terser.set(mshOut, 10, 0, 1, 1, mshIn.getMessage().getParser().getParserConfiguration().getIdGenerator().getID()); Terser.set(mshOut, 11, 0, 1, 1, procID); versionId = Version.highestAvailableVersionOrDefault().getVersion(); Terser.set(mshOut, 12, 0, 1, 1, versionId); Terser.set(mshOut, 3, 0, 1, 1, Terser.get(mshIn, 5, 0, 1, 1)); Terser.set(mshOut, 4, 0, 1, 1, Terser.get(mshIn, 6, 0, 1, 1)); Terser.set(mshOut, 5, 0, 1, 1, Terser.get(mshIn, 3, 0, 1, 1)); Terser.set(mshOut, 6, 0, 1, 1, Terser.get(mshIn, 4, 0, 1, 1)); Terser.set(msaOut, 1, 0, 1, 1, code.name()); Terser.set(msaOut, 2, 0, 1, 1, Terser.get(mshIn, 10, 0, 1, 1)); return out;
public void run() { try { // get message ID String ID = generator.getID(); Message out = parser.parse(outText); Terser tOut = new Terser(out); tOut.set("/MSH-10", ID); // send, get response Message in = initiator.sendAndReceive(out); // get ACK ID Terser tIn = new Terser(in); String ackID = tIn.get("/MSA-2"); if (ID.equals(ackID)) { System.out.println("OK - ack ID matches"); } else { throw new RuntimeException( "Ack ID for message " + ID + " is " + ackID); } } catch (Exception e) { e.printStackTrace(); } } });
public static void set(Segment segment, Location location, String value) throws HL7Exception { set(segment, location.getField(), location.getFieldRepetition(), location.getComponent(), location.getSubcomponent(), value); }
public static void set(Segment segment, Location location, String value) throws HL7Exception { set(segment, location.getField(), location.getFieldRepetition(), location.getComponent(), location.getSubcomponent(), value); }
public void run() { try { // get message ID String ID = generator.getID(); Message out = parser.parse(outText); Terser tOut = new Terser(out); tOut.set("/MSH-10", ID); // send, get response Message in = initiator.sendAndReceive(out); // get ACK ID Terser tIn = new Terser(in); String ackID = tIn.get("/MSA-2"); if (ID.equals(ackID)) { System.out.println("OK - ack ID matches"); } else { throw new RuntimeException( "Ack ID for message " + ID + " is " + ackID); } } catch (Exception e) { e.printStackTrace(); } } });
fieldOffset = 1; Terser.set(destination, 1, 0, 1, 1, String.valueOf(encodingChars.getFieldSeparator()));
fieldOffset = 1; Terser.set(destination, 1, 0, 1, 1, String.valueOf(encodingChars.getFieldSeparator()));
fieldOffset = 1; Terser.set(destination, 1, 0, 1, 1, String.valueOf(encodingChars.getFieldSeparator()));