use of ca.uhn.hl7v2.protocol.Transportable in project pentaho-kettle by pentaho.
the class HL7MLLPAcknowledge method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
try {
String serverName = environmentSubstitute(server);
int portNumber = Integer.parseInt(environmentSubstitute(port));
String variable = environmentSubstitute(variableName);
MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
MLLPTransport transport = entry.getTransport();
//
synchronized (transport) {
String message = getVariable(variable);
// Parse the message and extract the acknowledge message.
//
Parser parser = new GenericParser();
ValidationContext validationContext = new NoValidation();
parser.setValidationContext(validationContext);
Message msg = parser.parse(message);
Message ack = msg.generateACK();
String ackMessage = ack.encode();
String APPNAME = "PDI4";
if (ack instanceof ca.uhn.hl7v2.model.v21.message.ACK) {
ca.uhn.hl7v2.model.v21.message.ACK mod = (ca.uhn.hl7v2.model.v21.message.ACK) ack;
mod.getMSH().getSENDINGAPPLICATION().setValue(APPNAME);
mod.getMSH().getSENDINGFACILITY().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v22.message.ACK) {
ca.uhn.hl7v2.model.v22.message.ACK mod = (ca.uhn.hl7v2.model.v22.message.ACK) ack;
mod.getMSH().getSendingApplication().setValue(APPNAME);
mod.getMSH().getSendingFacility().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v23.message.ACK) {
ca.uhn.hl7v2.model.v23.message.ACK mod = (ca.uhn.hl7v2.model.v23.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v231.message.ACK) {
ca.uhn.hl7v2.model.v231.message.ACK mod = (ca.uhn.hl7v2.model.v231.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v24.message.ACK) {
ca.uhn.hl7v2.model.v24.message.ACK mod = (ca.uhn.hl7v2.model.v24.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v25.message.ACK) {
ca.uhn.hl7v2.model.v25.message.ACK mod = (ca.uhn.hl7v2.model.v25.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v251.message.ACK) {
ca.uhn.hl7v2.model.v251.message.ACK mod = (ca.uhn.hl7v2.model.v251.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else if (ack instanceof ca.uhn.hl7v2.model.v26.message.ACK) {
ca.uhn.hl7v2.model.v26.message.ACK mod = (ca.uhn.hl7v2.model.v26.message.ACK) ack;
mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
ackMessage = mod.encode();
} else {
logError("This job entry does not support the HL7 dialect used. Found ACK class: " + ack.getClass().getName());
}
Transportable transportable = new TransportableImpl(ackMessage);
transport.doSend(transportable);
}
// All went well..
//
result.setNrErrors(0);
result.setResult(true);
} catch (Exception e) {
log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
result.setNrErrors(1);
result.setResult(false);
}
return result;
}
use of ca.uhn.hl7v2.protocol.Transportable in project pentaho-kettle by pentaho.
the class HL7MLLPInput method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
try {
String serverName = environmentSubstitute(server);
int portNumber = Integer.parseInt(environmentSubstitute(port));
String messageVariable = environmentSubstitute(messageVariableName);
String messageTypeVariable = environmentSubstitute(messageTypeVariableName);
String versionVariable = environmentSubstitute(versionVariableName);
MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
if (entry.getJobListener() != null) {
parentJob.addJobListener(entry.getJobListener());
}
MLLPTransport transport = entry.getTransport();
//
synchronized (transport) {
Transportable transportable = transport.doReceive();
String message = transportable.getMessage();
logDetailed("Received message: " + message);
parentJob.setVariable(messageVariable, message);
// Parse the message and extract the control ID.
//
Parser parser = new GenericParser();
ValidationContext validationContext = new NoValidation();
parser.setValidationContext(validationContext);
Message msg = parser.parse(message);
Structure structure = msg.get("MSH");
String messageType = null;
String version = msg.getVersion();
if (structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v21.segment.MSH) structure).getMESSAGETYPE().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v22.segment.MSH) structure).getMessageType().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v23.segment.MSH) structure).getMessageType().encode();
} else if (structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v231.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v24.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v25.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v251.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else if (structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH) {
messageType = ((ca.uhn.hl7v2.model.v26.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
} else {
logError("This job entry does not support the HL7 dialect used. Found MSH class: " + structure.getClass().getName());
}
if (!Utils.isEmpty(messageTypeVariable)) {
parentJob.setVariable(messageTypeVariable, messageType);
}
if (!Utils.isEmpty(versionVariable)) {
parentJob.setVariable(versionVariable, version);
}
}
// All went well..
//
result.setNrErrors(0);
result.setResult(true);
} catch (Exception e) {
log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
result.setNrErrors(1);
result.setResult(false);
}
return result;
}
Aggregations