public static HL7Message parse(byte[] b, String defCharset) { return parse(b, b.length, defCharset); }
public void query(String pid, String[] domains) throws IOException { HL7Message qbp = HL7Message.makePixQuery(pid, domains); HL7Segment msh = qbp.get(0); msh.setSendingApplicationWithFacility(sendingApplication); msh.setReceivingApplicationWithFacility(receivingApplication); msh.setField(17, charset); mllp.writeMessage(qbp.getBytes(charset)); if (mllp.readMessage() == null) throw new IOException("Connection closed by receiver"); } }
public static HL7Message parse(byte[] b, int size, String defCharset) { ParsePosition pos = new ParsePosition(0); HL7Message msg = new HL7Message(); HL7Segment seg = HL7Segment.parseMSH(b, size, pos); char fieldSeparator = seg.getFieldSeparator(); String encodingCharacters = seg.getEncodingCharacters(); String charsetName = HL7Charset.toCharsetName(seg.getField(17, defCharset)); msg.add(seg); while ((seg = HL7Segment.parse( b, size, pos, fieldSeparator, encodingCharacters, charsetName)) != null) msg.add(seg); msg.trimToSize(); return msg; }
public static HL7Message makePixQuery(String pid, String... domains) { HL7Segment msh = HL7Segment.makeMSH(); msh.setField(8, "QBP^Q23^QBP_Q21"); HL7Segment qpd = new HL7Segment(5); qpd.setField(0, "QPD"); qpd.setField(1, "IHE PIX Query"); qpd.setField(2, "QRY" + msh.getField(9, "")); qpd.setField(3, pid); qpd.setField(4, HL7Segment.concat(domains, '~')); HL7Segment rcp = new HL7Segment(8); rcp.setField(0, "RCP"); rcp.setField(1, "I"); HL7Message qbp = new HL7Message(3); qbp.add(msh); qbp.add(qpd); qbp.add(rcp); return qbp; }
@Override public String toString() { return toString('\r'); }
public String toString(char segdelim) { int len = size(); for (HL7Segment seg : this) { int segSize = seg.size(); len += segSize - 1; for (int i = 0; i < segSize; i++) { String s = seg.getField(i, null); if (s != null) len += s.length(); } } char[] cs = new char[len]; int off = 0; for (HL7Segment seg : this) { char delim = seg.getFieldSeparator(); int segSize = seg.size(); for (int i = 0; i < segSize; i++) { String s = seg.getField(i, null); if (s != null) { int l = s.length(); s.getChars(0, l, cs, off); off += l; } cs[off++] = delim; } cs[off-1] = segdelim; } return new String(cs); }
public void query(String pid, String[] domains) throws IOException { HL7Message qbp = HL7Message.makePixQuery(pid, domains); HL7Segment msh = qbp.get(0); msh.setSendingApplicationWithFacility(sendingApplication); msh.setReceivingApplicationWithFacility(receivingApplication); msh.setField(17, charset); mllp.writeMessage(qbp.getBytes(charset)); if (mllp.readMessage() == null) throw new IOException("Connection closed by receiver"); } }
public static HL7Message makeACK(HL7Segment msh, String ackCode, String text) { int size = msh.size(); HL7Segment ackmsh = HL7Segment.makeMSH(size, msh.getFieldSeparator(), msh.getEncodingCharacters()); ackmsh.setField(2, msh.getField(4, null)); ackmsh.setField(3, msh.getField(5, null)); ackmsh.setField(4, msh.getField(2, null)); ackmsh.setField(5, msh.getField(3, null)); ackmsh.setField(8, "ACK^" + msh.getMessageType().substring(4,7) + "^ACK"); for (int i = 10; i < size; i++) ackmsh.setField(i, msh.getField(i, null)); HL7Segment msa = new HL7Segment(4, msh.getFieldSeparator(), msh.getEncodingCharacters()); msa.setField(0, "MSA"); msa.setField(1, ackCode); msa.setField(2, msh.getMessageControlID()); msa.setField(3, text != null && text.length() > 80 ? text.substring(0, 80) : text); HL7Message ack = new HL7Message(2); ack.add(ackmsh); ack.add(msa); return ack; }
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)); }
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); } } }