private void reconfigureHL7Applications(HL7DeviceExtension from) { hl7apps.keySet().retainAll(from.hl7apps.keySet()); for (HL7Application src : from.hl7apps.values()) { HL7Application hl7app = hl7apps.get(src.getApplicationName()); if (hl7app == null) addHL7Application(hl7app = new HL7Application(src.getApplicationName())); hl7app.reconfigure(src); } } }
@Override protected void markForUnregister(Device prev, Device device, List<String> dns) { HL7DeviceExtension prevHL7Ext = prev.getDeviceExtension(HL7DeviceExtension.class); if (prevHL7Ext == null) return; HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); for (String name : prevHL7Ext.getHL7ApplicationNames()) { if (!name.equals("*") && (hl7Ext == null || hl7Ext.getHL7Application(name) == null)) dns.add(hl7appDN(name, appNamesRegistryDN)); } }
public HL7Application getHL7Application(String name, boolean matchOtherAppNames) { HL7Application app = hl7apps.get(name); if (app == null) app = hl7apps.get("*"); if (app == null && matchOtherAppNames) for (HL7Application app1 : getHL7Applications()) if (app1.isOtherApplicationName(name)) return app1; return app; }
public void setApplicationName(String name) { if (name.isEmpty()) throw new IllegalArgumentException("name cannot be empty"); HL7DeviceExtension ext = device != null ? device.getDeviceExtension(HL7DeviceExtension.class) : null; if (ext != null) ext.removeHL7Application(this.name); this.name = name; if (ext != null) ext.addHL7Application(this); }
@Override protected void loadChilds(Device device, String deviceDN) throws NamingException, ConfigurationException { NamingEnumeration<SearchResult> ne = config.search(deviceDN, "(objectclass=hl7Application)"); try { if (!ne.hasMore()) return; HL7DeviceExtension hl7Ext = new HL7DeviceExtension(); device.addDeviceExtension(hl7Ext); do { hl7Ext.addHL7Application( loadHL7Application(ne.next(), deviceDN, device)); } while (ne.hasMore()); } finally { LdapUtils.safeClose(ne); } }
@Override protected void mergeChilds(ConfigurationChanges diffs, Device prev, Device device, String deviceDN) throws NamingException { HL7DeviceExtension prevHL7Ext = prev.getDeviceExtension(HL7DeviceExtension.class); HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); if (prevHL7Ext != null) for (String appName : prevHL7Ext.getHL7ApplicationNames()) { if (hl7Ext == null || !hl7Ext.containsHL7Application(appName)) { config.destroySubcontextWithChilds(hl7appDN(appName, deviceDN)); ConfigurationChanges.addModifiedObject(diffs, hl7appDN(appName, deviceDN), ConfigurationChanges.ChangeType.D); } } if (hl7Ext == null) return; for (HL7Application hl7app : hl7Ext.getHL7Applications()) { String appName = hl7app.getApplicationName(); if (prevHL7Ext == null || !prevHL7Ext.containsHL7Application(appName)) { store(diffs, hl7app, deviceDN); } else merge(diffs, prevHL7Ext.getHL7Application(appName), hl7app, deviceDN); } }
@Override public HL7Application findHL7Application(String name) throws ConfigurationException { Device device = config.findDevice( "(&(objectclass=hl7Application)(hl7ApplicationName=" + name + "))", name); HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); return hl7Ext.getHL7Application(name); }
@Override public boolean loadDeviceExtension(Device device, JsonReader reader, ConfigurationDelegate config) throws ConfigurationException { if (!reader.getString().equals("hl7Application")) return false; HL7DeviceExtension ext = new HL7DeviceExtension(); loadFrom(ext, reader, device, config); device.addDeviceExtension(ext); return true; }
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); } } }
@Override protected void register(Device device, List<String> dns) throws ConfigurationException { HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); if (hl7Ext == null) return; for (String name : hl7Ext.getHL7ApplicationNames()) { if (!name.equals("*")) dns.add(registerHL7App(name)); } }
public HL7Connection(HL7Application hl7Application, MLLPConnection mllpConnection) { this.hl7Application = hl7Application; this.mllpConnection = mllpConnection; this.monitor = hl7Application.getDevice() .getDeviceExtensionNotNull(HL7DeviceExtension.class) .getHL7ConnectionMonitor(); }
@Override public HL7Application findHL7Application(String name) throws ConfigurationException { String pathForDeviceName = DicomPath.DeviceNameByHL7AppName.set("hl7AppName", name).path(); try { Iterator search = lowLevelConfig.search(pathForDeviceName); String deviceName = (String) search.next(); Device device = findDevice(deviceName); return device.getDeviceExtension(HL7DeviceExtension.class).getHL7Application(name); } catch (NoSuchElementException e) { throw new ConfigurationException("HL7 app with name '" + name + "' not found", e); } catch (Exception e) { throw new ConfigurationException("Error while searching for HL7 app with name '" + name + "'", e); } }
@Override public boolean loadDeviceExtension(Device device, JsonReader reader, ConfigurationDelegate config) throws ConfigurationException { if (!reader.getString().equals("hl7Application")) return false; HL7DeviceExtension ext = new HL7DeviceExtension(); loadFrom(ext, reader, device, config); device.addDeviceExtension(ext); return true; }
public HL7Rcv() throws IOException { conn.setProtocol(Protocol.HL7); device.addDeviceExtension(hl7Ext); device.addConnection(conn); hl7Ext.addHL7Application(hl7App); hl7App.setAcceptedMessageTypes("*"); hl7App.addConnection(conn); hl7App.setHL7MessageListener(handler); }
@Override protected void storeChilds(ConfigurationChanges diffs, String deviceDN, Device device) throws NamingException { HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); if (hl7Ext == null) return; for (HL7Application hl7App : hl7Ext.getHL7Applications()) store(diffs, hl7App, deviceDN); }
@Override protected void registerDiff(Device prev, Device device, List<String> dns) throws ConfigurationException { HL7DeviceExtension prevHL7Ext = prev.getDeviceExtension(HL7DeviceExtension.class); if (prevHL7Ext == null) { register(device, dns); return; } HL7DeviceExtension hl7Ext = device.getDeviceExtension(HL7DeviceExtension.class); if (hl7Ext == null) return; for (String name : hl7Ext.getHL7ApplicationNames()) { if (!name.equals("*") && prevHL7Ext.getHL7Application(name) == null) dns.add(registerHL7App(name)); } }
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); }
public HL7Rcv() throws IOException { conn.setProtocol(Protocol.HL7); device.addDeviceExtension(hl7Ext); device.addConnection(conn); hl7Ext.addHL7Application(hl7App); hl7App.setAcceptedMessageTypes("*"); hl7App.addConnection(conn); hl7App.setHL7MessageListener(handler); }
@Override protected void storeTo(Device device, JsonWriter writer) { HL7DeviceExtension ext = device.getDeviceExtension(HL7DeviceExtension.class); if (ext == null) return; writer.writeStartArray("hl7Application"); for (HL7Application hl7App : ext.getHL7Applications()) writeTo(device, hl7App, writer); writer.writeEnd(); }
private void loadFrom(HL7DeviceExtension ext, JsonReader reader, Device device, ConfigurationDelegate config) throws ConfigurationException { List<Connection> conns = device.listConnections(); reader.next(); reader.expect(JsonParser.Event.START_ARRAY); while (reader.next() == JsonParser.Event.START_OBJECT) { HL7Application hl7App = new HL7Application(); loadFrom(hl7App, reader, device, conns, config); reader.expect(JsonParser.Event.END_OBJECT); ext.addHL7Application(hl7App); } reader.expect(JsonParser.Event.END_ARRAY); }