Created
June 21, 2012 18:14
-
-
Save rahulsom/2967508 to your computer and use it in GitHub Desktop.
HL7 Demuxer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes([ | |
@Grab('ca.uhn.hapi:hapi-base:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v26:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v251:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v25:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v24:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v231:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v23:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v22:1.2'), | |
@Grab('ca.uhn.hapi:hapi-structures-v21:1.2') | |
]) | |
import ca.uhn.hl7v2.llp.* | |
import ca.uhn.hl7v2.app.* | |
import ca.uhn.hl7v2.parser.PipeParser | |
import ca.uhn.hl7v2.model.Message | |
import ca.uhn.hl7v2.util.Terser | |
/* | |
* Settings | |
*/ | |
int port = 8099 | |
String deciderField = '/.PID-3-4-1' | |
def routes = [ | |
new Route(value: 'FOO', /*host: 'localhost', */port: 8002), | |
new Route(value: 'BAR', /*host: 'localhost', */port: 8888) | |
] | |
/* | |
* Fan out setup | |
*/ | |
class Route { | |
String value | |
String host = 'localhost' | |
int port | |
} | |
/* | |
* Server setup | |
*/ | |
def s = new SimpleServer(port, LowerLayerProtocol.makeLLP(), new PipeParser()) | |
def hub = ConnectionHub.instance | |
def h = new Application() { | |
Message processMessage(Message inMessage) { | |
def t = new Terser(inMessage) | |
def route = routes.find {it.value == t.get(deciderField)} | |
if (route) { | |
def connection = hub.attach(route.host, route.port, new PipeParser(), MinLowerLayerProtocol) | |
connection.initiator.sendAndReceive(inMessage) | |
} else { | |
null | |
} | |
} | |
boolean canProcess(Message inMessage) { | |
return true | |
} | |
} | |
s.registerApplication('*', '*', h) | |
s.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment