use of ca.uhn.hl7v2.model.Structure 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;
}
use of ca.uhn.hl7v2.model.Structure in project pentaho-kettle by pentaho.
the class HL7KettleParser method parseStructure.
private static void parseStructure(List<HL7Value> values, Message message, Terser terser, Structure structure, String structureNumber) throws Exception {
Map<String, List<String>> nameMap = NamesUtil.getInstance().getMap();
if (structure instanceof Segment) {
Segment segment = (Segment) structure;
String[] names = segment.getNames();
for (int n = 1; n <= segment.numFields(); n++) {
Type[] types = segment.getField(n);
for (int t = 0; t < types.length; t++) {
int nrComponents = Terser.numComponents(types[t]);
for (int c = 1; c <= nrComponents; c++) {
int nrSub = Terser.numSubComponents(types[t], c);
for (int sc = 1; sc <= nrSub; sc++) {
String string = Terser.get(segment, n, t, c, sc);
// Primitive primitive = Terser.getPrimitive(types[t], c, sc);
String description = "?";
List<String> list = nameMap.get(types[t].getName());
if (list != null && c - 1 < list.size()) {
description = list.get(c - 1);
}
Group group = structure.getParent();
Group rootGroup = structure.getMessage();
String coordinates = n + "." + (t + 1) + "." + c + "." + sc;
HL7Value value = new HL7Value(message.getVersion(), rootGroup.getName(), group.getName(), structure.getName(), structureNumber, names[n - 1], coordinates, types[t].getName(), description, string);
values.add(value);
}
}
}
}
} else if (structure instanceof Group) {
Group group = (Group) structure;
String[] names = group.getNames();
for (int n = 1; n <= names.length; n++) {
String name = names[n - 1];
Structure subStructure = group.get(name);
parseStructure(values, message, terser, subStructure, structureNumber + "." + n);
}
} else {
throw new Exception("oops, not handled yet!");
}
}
use of ca.uhn.hl7v2.model.Structure in project streamsx.health by IBMStreams.
the class HapiMessageHandler method processMessage.
@Override
public Message processMessage(Message theMessage, Map<String, Object> arg1) throws ReceivingApplicationException, HL7Exception {
server.messageArrived(theMessage);
Message ack;
try {
// Always use the default parser to generate an ack
// HAPI seems to get into trouble if the ADT_AXX superstructure
// is used.
// Internally, when it tries to generate an ack message
// the super structure setting in the model class factory causes the ADT_AXX message
// to get created instead of the ACK getting created. This is to override the model
// class factory so that the proper class can be generated.
theMessage.setParser(ackParser);
ack = theMessage.generateACK();
return ack;
} catch (IOException e) {
TRACE.log(TraceLevel.ERROR, "Unable to generate ack message", e);
}
return theMessage;
}
use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.
the class HL7MessageTreeContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
List values = new ArrayList();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
}
if (childReps[j] instanceof Group) {
values.add((Group) childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values.toArray();
}
if (parentElement instanceof Segment) {
values.clear();
Segment segment = (Segment) parentElement;
SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
return sm.getTypes();
}
if (parentElement instanceof SegmentModel) {
SegmentModel sm = (SegmentModel) parentElement;
return sm.getTypes();
}
if (parentElement instanceof TypeModel) {
TypeModel tm = (TypeModel) parentElement;
return tm.getPrimitives();
}
if (parentElement instanceof Group) {
values.clear();
Group group = (Group) parentElement;
String[] childNames = group.getNames();
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = group.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Segment) {
SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
if (sm.getTypes() != null && sm.getTypes().length > 0) {
values.add(sm);
}
} else {
values.add(childReps[j]);
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values.toArray();
}
return new Object[0];
}
use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.
the class HL7PublicUtil method getChildList.
public Object[] getChildList(Object parentElement) {
List values = new ArrayList();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
}
if (childReps[j] instanceof Group) {
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
if (allSegmentFromGroup.size() > 0) {
values.addAll(Arrays.asList(allSegmentFromGroup.toArray(new SegmentModel[0])));
}
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values.toArray();
}
if (parentElement instanceof Segment) {
values.clear();
Segment segment = (Segment) parentElement;
SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
return sm.getTypes();
}
if (parentElement instanceof SegmentModel) {
SegmentModel sm = (SegmentModel) parentElement;
return sm.getTypes();
}
if (parentElement instanceof TypeModel) {
TypeModel tm = (TypeModel) parentElement;
return tm.getPrimitives();
}
if (parentElement instanceof Group) {
values.clear();
Group group = (Group) parentElement;
String[] childNames = group.getNames();
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = group.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Segment) {
SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
if (sm.getTypes() != null && sm.getTypes().length > 0) {
values.add(sm);
}
} else {
values.add(childReps[j]);
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values.toArray();
}
return new Object[0];
}
Aggregations