// make ACK of correct version
Class<? extends Message> clazz = null;
try {
Message inbound = inboundHeader.getMessage();
Parser p = inbound.getParser();
ModelClassFactory mcf = p != null ? p.getFactory() : new DefaultModelClassFactory();
String version = inbound.getVersion();
if (version == null)
version = "2.4"; // TODO: This should be set dynamically based on available HL7 version
clazz = mcf.getMessageClass("ACK", version, false);
Message out = clazz.newInstance();
Terser terser = new Terser(out);
// populate outbound MSH using data from inbound message ...
Segment outHeader = (Segment) out.get("MSH");