@Override public UnparsedHL7Message onMessage(HL7Application hl7App, Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { HL7MessageListener listener = listeners.get(msg.msh().getMessageType()); if (listener == null) { listener = listeners.get("*"); if (listener == null) return super.onMessage(hl7App, conn, s, msg); } return listener.onMessage(hl7App, conn, s, msg); }
private UnparsedHL7Message onMessage(UnparsedHL7Message msg) throws Exception { if (storageDir != null) storeToFile(msg.data(), new File( new File(storageDir, msg.msh().getMessageType()), msg.msh().getField(9, "_NULL_"))); return new UnparsedHL7Message(tpls == null ? HL7Message.makeACK(msg.msh(), HL7Exception.AA, null).getBytes(null) : xslt(msg)); }
private UnparsedHL7Message onMessage(UnparsedHL7Message msg) throws Exception { if (storageDir != null) storeToFile(msg.data(), new File( new File(storageDir, msg.msh().getMessageType()), msg.msh().getField(9, "_NULL_"))); return new UnparsedHL7Message(tpls == null ? HL7Message.makeACK(msg.msh(), HL7Exception.AA, null).getBytes(null) : xslt(msg)); }
private byte[] xslt(UnparsedHL7Message msg) throws Exception { String charsetName = HL7Charset.toCharsetName(msg.msh().getField(17, charset)); ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler th = factory.newTransformerHandler(tpls); Transformer t = th.getTransformer(); t.setParameter("MessageControlID", HL7Segment.nextMessageControlID()); t.setParameter("DateTimeOfMessage", HL7Segment.timeStamp(new Date())); if (xsltParams != null) for (int i = 1; i < xsltParams.length; i++, i++) t.setParameter(xsltParams[i-1], xsltParams[i]); th.setResult(new SAXResult(new HL7ContentHandler( new OutputStreamWriter(out, charsetName)))); new HL7Parser(th).parse(new InputStreamReader( new ByteArrayInputStream(msg.data()), charsetName)); return out.toByteArray(); }
private byte[] xslt(UnparsedHL7Message msg) throws Exception { String charsetName = HL7Charset.toCharsetName(msg.msh().getField(17, charset)); ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler th = factory.newTransformerHandler(tpls); Transformer t = th.getTransformer(); t.setParameter("MessageControlID", HL7Segment.nextMessageControlID()); t.setParameter("DateTimeOfMessage", HL7Segment.timeStamp(new Date())); if (xsltParams != null) for (int i = 1; i < xsltParams.length; i++, i++) t.setParameter(xsltParams[i-1], xsltParams[i]); th.setResult(new SAXResult(new HL7ContentHandler( new OutputStreamWriter(out, charsetName)))); new HL7Parser(th).parse(new InputStreamReader( new ByteArrayInputStream(msg.data()), charsetName)); return out.toByteArray(); }
@Override public UnparsedHL7Message onMessage(HL7Application hl7App, Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { try { return HL7Rcv.this.onMessage(msg); } catch (Exception e) { throw new HL7Exception( new ERRSegment(msg.msh()).setUserMessage(e.getMessage()), e); } } };
@Override public UnparsedHL7Message onMessage(HL7Application hl7App, Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { return new UnparsedHL7Message( HL7Message.makeACK(msg.msh(), HL7Exception.AA, null).getBytes(null)); } }
@Override public UnparsedHL7Message onMessage(HL7Application hl7App, Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { try { return HL7Rcv.this.onMessage(msg); } catch (Exception e) { throw new HL7Exception( new ERRSegment(msg.msh()).setUserMessage(e.getMessage()), e); } } };
UnparsedHL7Message onMessage(Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { HL7Application hl7App = getHL7Application(msg.msh().getReceivingApplicationWithFacility(), true); if (hl7App == null) throw new HL7Exception( new ERRSegment(msg.msh()) .setHL7ErrorCode(ERRSegment.TableValueNotFound) .setErrorLocation(ERRSegment.UnknownReceivingApplication) .setUserMessage("Receiving Application not recognized")); return hl7App.onMessage(conn, s, msg); }
UnparsedHL7Message onMessage(Connection conn, Socket s, UnparsedHL7Message msg) throws HL7Exception { HL7Segment msh = msg.msh(); if (!(isInstalled() && conns.contains(conn))) throw new HL7Exception( new ERRSegment(msh) .setHL7ErrorCode(ERRSegment.TableValueNotFound) .setErrorLocation(ERRSegment.UnknownReceivingApplication) .setUserMessage("Receiving Application not recognized")); if (!(acceptedSendingApplications.isEmpty() || acceptedSendingApplications.contains(msh.getSendingApplicationWithFacility()))) throw new HL7Exception( new ERRSegment(msh) .setHL7ErrorCode(ERRSegment.TableValueNotFound) .setErrorLocation(ERRSegment.UnknownSendingApplication) .setUserMessage("Sending Application not recognized")); String messageType = msh.getMessageType(); if (!(acceptedMessageTypes.contains("*") || acceptedMessageTypes.contains(messageType))) throw new HL7Exception( new ERRSegment(msh) .setHL7ErrorCode(unsupportedMessageTypeOrEventCode(messageType.substring(0,3))) .setUserMessage("Message Type not supported")); HL7MessageListener listener = getHL7MessageListener(); if (listener == null) throw new HL7Exception(new ERRSegment(msh) .setHL7ErrorCode(ERRSegment.ApplicationInternalError) .setUserMessage("No HL7 Message Listener configured")); return listener.onMessage(this, conn, s, msg); }
public void run() { try { s.setSoTimeout(conn.getIdleTimeout()); MLLPConnection mllp = new MLLPConnection(s); byte[] data; while ((data = mllp.readMessage()) != null) { HL7ConnectionMonitor monitor = hl7dev.getHL7ConnectionMonitor(); UnparsedHL7Message msg = new UnparsedHL7Message(data); if (monitor != null) monitor.onMessageReceived(conn, s, msg); UnparsedHL7Message rsp; try { rsp = hl7dev.onMessage(conn, s, msg); if (monitor != null) monitor.onMessageProcessed(conn, s, msg, rsp, null); } catch (HL7Exception e) { rsp = new UnparsedHL7Message( HL7Message.makeACK(msg.msh(), e).getBytes(null)); if (monitor != null) monitor.onMessageProcessed(conn, s, msg, rsp, e); } mllp.writeMessage(rsp.data()); } } catch (IOException e) { LOG.warn("Exception on accepted connection {}:", s, e); } finally { conn.close(s); } } }