use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class HL7Parse method doParse.
public List<Message> doParse(String filePath, TreeViewer messageViewerStep1, List<String> msgContentList, String startChar, String endChar) {
List<Message> messageList = new ArrayList<Message>();
String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
File file = Path.fromOSString(filePathNoQuotes).toFile();
if (file.exists()) {
msgContentList.clear();
ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
try {
array.setInnerContentFromFile(file);
//$NON-NLS-1$
TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
String hl7InputTem = null;
if (startChar != null) {
talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
}
if (endChar != null) {
talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
}
while ((hl7InputTem = talendHL7Reader.getMessage()) != null) {
msgContentList.add(hl7InputTem);
Message message = getHL7MessageInput(hl7InputTem);
messageList.add(message);
}
if (msgContentList == null || msgContentList.size() == 0) {
String msgText = new String(array.getInnerContent());
msgContentList.add(msgText);
Message message = getHL7MessageInput(msgText);
messageList.add(message);
}
messageViewerStep1.setInput(messageList.toArray());
} catch (IOException ex) {
ExceptionHandler.process(ex);
}
}
return messageList;
}
use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class HL7PublicUtil method getFirstLevelChild.
public List getFirstLevelChild(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(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);
}
}
}
}
} catch (HL7Exception e) {
e.printStackTrace();
}
}
}
return values;
}
use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class HL7PublicUtil method getHL7TreeNodes.
public List<HL7TreeNode> getHL7TreeNodes(List<Message> messageList) {
List<HL7TreeNode> list = new ArrayList<HL7TreeNode>();
if (messageList == null) {
return list;
}
for (Message message : messageList) {
HL7TreeNode root = initTreeRoot(message);
if (root instanceof Element) {
// root = ((Element) root).getElementChildren().get(0);
root.setParent(null);
list.add(root);
}
}
return list;
}
use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class TypeModel method getComponent.
private Type getComponent(Type type, int comp) {
Type ret = null;
if (Varies.class.isAssignableFrom(type.getClass())) {
Varies v = (Varies) type;
try {
if (comp > 1 && GenericPrimitive.class.isAssignableFrom(v.getData().getClass())) {
v.setData(new GenericComposite(v.getMessage()));
}
} catch (DataTypeException de) {
String message = "Unexpected exception copying data to generic composite: " + de.getMessage();
throw new Error(message);
}
ret = getComponent(v.getData(), comp);
} else {
if (Primitive.class.isAssignableFrom(type.getClass()) && comp == 1) {
ret = type;
} else if (GenericComposite.class.isAssignableFrom(type.getClass()) || (Composite.class.isAssignableFrom(type.getClass()) && comp <= numStandardComponents(type))) {
try {
ret = ((Composite) type).getComponent(comp - 1);
} catch (Exception e) {
throw new Error("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e);
}
} else {
ret = type.getExtraComponents().getComponent(comp - numStandardComponents(type) - 1);
}
}
return ret;
}
use of ca.uhn.hl7v2.model.Message in project tdi-studio-se by Talend.
the class ImportHL7StructureAction method treeNodeAdapt.
private List treeNodeAdapt() {
List<HL7TreeNode> treeData = new ArrayList<HL7TreeNode>();
FileDialog f = null;
if (hl7ui != null) {
f = new FileDialog(hl7ui.getHl7UIParent().getShell());
} else if (form != null) {
f = new FileDialog(form.getShell());
}
String file = f.open();
if (file == null) {
return treeData;
}
HL7Parse hl7Parse = new HL7Parse();
List<String> msgContentList = new ArrayList<String>();
List<Message> messageList = hl7Parse.doParse(file, "'\\u000b'", "'\\u001c'");
List<HL7TreeNode> nodeList = hl7Util.getHL7TreeNodes(messageList);
if (!nodeList.isEmpty()) {
HL7TreeNode hl7TreeNode = nodeList.get(0);
List<HL7FileNode> table = new ArrayList<HL7FileNode>();
if (hl7Connection != null) {
EList root = hl7Connection.getRoot();
root.clear();
if (hl7TreeNode != null) {
hl7Util.initNodeOrder(hl7TreeNode, orderMap);
hl7Util.tableLoader((Element) hl7TreeNode, "", root, hl7TreeNode.getDefaultValue(), orderMap);
}
table.addAll(root);
} else {
if (hl7TreeNode != null) {
hl7Util.initNodeOrder(hl7TreeNode, orderMap);
hl7Util.tableLoader((Element) hl7TreeNode, "", table, hl7TreeNode.getDefaultValue(), orderMap);
}
}
List<String> schemaList = new ArrayList<String>();
for (HL7FileNode node : table) {
String columnName = node.getRelatedColumn();
if (columnName.contains(":")) {
columnName = columnName.substring(0, columnName.indexOf(":"));
}
if (!schemaList.contains(columnName) && !"".equals(columnName)) {
schemaList.add(columnName);
}
}
initXmlTreeData(schemaList, table, treeData);
}
return treeData;
}
Aggregations