/** * Creates an instance that uses the given <code>Parser</code> * @param theParser parser to use for parsing and encoding messages * @param theProcessor the <code>Processor</code> used to communicate * with the remote system */ public InitiatorImpl(Parser theParser, Processor theProcessor) { myMetadataFields = new ArrayList<String>(20); myParser = theParser; myProcessor = theProcessor; init(); }
/** * @see ca.uhn.hl7v2.protocol.Initiator#sendAndReceive(ca.uhn.hl7v2.model.Message) */ public Message sendAndReceive(Message theMessage) throws HL7Exception { Terser t = new Terser(theMessage); String appAckNeeded = t.get("/MSH-16"); String msgId = t.get("/MSH-10"); String messageText = getParser().encode(theMessage); Map<String, Object> metadata = getMetadata(theMessage); Transportable out = new TransportableImpl(messageText, metadata); if (needAck(appAckNeeded)) { myProcessor.reserve(msgId, getReceiveTimeout()); } myProcessor.send(out, getMaxRetries(), getRetryInterval()); Message in = null; if (needAck(appAckNeeded)) { Transportable received = myProcessor.receive(msgId, getReceiveTimeout()); if (received != null && received.getMessage() != null) { in = getParser().parse(received.getMessage()); } } return in; }
private Map<String, Object> getMetadata(Message theMessage) throws HL7Exception { Map<String, Object> md = new HashMap<String, Object>(); Terser t = new Terser(theMessage); //snapshot so concurrent changes won't break our iteration String[] fields = getMetadataFields().toArray(new String[0]); for (int i = 0; i < fields.length; i++) { String field = fields[i].toString(); String val = t.get(field); md.put(field, val); } return md; }
/** * @see ca.uhn.hl7v2.protocol.Initiator#sendAndReceive(ca.uhn.hl7v2.model.Message) */ public Message sendAndReceive(Message theMessage) throws HL7Exception { Terser t = new Terser(theMessage); String appAckNeeded = t.get("/MSH-16"); String msgId = t.get("/MSH-10"); String messageText = getParser().encode(theMessage); Map<String, Object> metadata = getMetadata(theMessage); Transportable out = new TransportableImpl(messageText, metadata); if (needAck(appAckNeeded)) { myProcessor.reserve(msgId, getReceiveTimeout()); } myProcessor.send(out, getMaxRetries(), getRetryInterval()); Message in = null; if (needAck(appAckNeeded)) { Transportable received = myProcessor.receive(msgId, getReceiveTimeout()); if (received != null && received.getMessage() != null) { in = getParser().parse(received.getMessage()); } } return in; }
private Map<String, Object> getMetadata(Message theMessage) throws HL7Exception { Map<String, Object> md = new HashMap<String, Object>(); Terser t = new Terser(theMessage); //snapshot so concurrent changes won't break our iteration String[] fields = getMetadataFields().toArray(new String[0]); for (int i = 0; i < fields.length; i++) { String field = fields[i].toString(); String val = t.get(field); md.put(field, val); } return md; }
/** * Creates an instance that uses the given <code>Parser</code> * @param theParser parser to use for parsing and encoding messages * @param theProcessor the <code>Processor</code> used to communicate * with the remote system */ public InitiatorImpl(Parser theParser, Processor theProcessor) { myMetadataFields = new ArrayList<String>(20); myParser = theParser; myProcessor = theProcessor; init(); }
/** * Creates an instance that uses a <code>GenericParser</code> * @param theProcessor the <code>Processor</code> used to communicate * with the remote system */ public InitiatorImpl(Processor theProcessor) { myMetadataFields = new ArrayList<String>(20); myMetadataFields.add("MSH-18"); //add character set by default myParser = new GenericParser(); myProcessor = theProcessor; init(); }
/** * Creates an instance that uses a <code>GenericParser</code> * @param theProcessor the <code>Processor</code> used to communicate * with the remote system */ public InitiatorImpl(Processor theProcessor) { myMetadataFields = new ArrayList<String>(20); myMetadataFields.add("MSH-18"); //add character set by default myParser = new GenericParser(); myProcessor = theProcessor; init(); }