Search in sources :

Example 31 with Message

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;
}
Also used : Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) ByteArray(org.talend.core.model.properties.ByteArray) IOException(java.io.IOException) File(java.io.File)

Example 32 with Message

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;
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) HL7Exception(ca.uhn.hl7v2.HL7Exception) ArrayList(java.util.ArrayList) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel) Segment(ca.uhn.hl7v2.model.Segment)

Example 33 with Message

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;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Example 34 with Message

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;
}
Also used : Type(ca.uhn.hl7v2.model.Type) Primitive(ca.uhn.hl7v2.model.Primitive) GenericPrimitive(ca.uhn.hl7v2.model.GenericPrimitive) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) GenericComposite(ca.uhn.hl7v2.model.GenericComposite) Composite(ca.uhn.hl7v2.model.Composite) GenericComposite(ca.uhn.hl7v2.model.GenericComposite) GenericPrimitive(ca.uhn.hl7v2.model.GenericPrimitive) Varies(ca.uhn.hl7v2.model.Varies) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 35 with Message

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;
}
Also used : EList(org.eclipse.emf.common.util.EList) Message(ca.uhn.hl7v2.model.Message) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) FileDialog(org.eclipse.swt.widgets.FileDialog) HL7Parse(org.talend.designer.hl7.ui.header.HL7Parse)

Aggregations

Message (ca.uhn.hl7v2.model.Message)44 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)19 Test (org.junit.Test)19 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)18 MSH (ca.uhn.hl7v2.model.v24.segment.MSH)13 ArrayList (java.util.ArrayList)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 ADR_A19 (ca.uhn.hl7v2.model.v24.message.ADR_A19)9 MSA (ca.uhn.hl7v2.model.v24.segment.MSA)9 ADT_A01 (ca.uhn.hl7v2.model.v24.message.ADT_A01)7 PID (ca.uhn.hl7v2.model.v24.segment.PID)7 Exchange (org.apache.camel.Exchange)7 Processor (org.apache.camel.Processor)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 Structure (ca.uhn.hl7v2.model.Structure)5 IOException (java.io.IOException)5 Group (ca.uhn.hl7v2.model.Group)4 Segment (ca.uhn.hl7v2.model.Segment)4 File (java.io.File)4 SegmentModel (org.talend.designer.hl7.model.SegmentModel)4