Search in sources :

Example 1 with PrimitiveModel

use of org.talend.designer.hl7.model.PrimitiveModel in project tdi-studio-se by Talend.

the class HL7PublicUtil method getChildren.

public Set getChildren(Object parentElement) {
    // List values = new ArrayList();
    Set values = new HashSet();
    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 (getChildren(childReps[j]).size() > 0) {
                            values.addAll(getChildren(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 (getChildren(sModel).size() > 0) {
                                values.addAll(getChildren(sModel));
                            }
                            if (!allSegmentsForMessage.contains(sModel)) {
                                allSegmentsForMessage.add(sModel);
                            }
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values;
    }
    if (parentElement instanceof Segment) {
        values.clear();
        Segment segment = (Segment) parentElement;
        SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
        TypeModel[] models = sm.getTypes();
        for (TypeModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    }
    if (parentElement instanceof SegmentModel) {
        SegmentModel sm = (SegmentModel) parentElement;
        TypeModel[] models = sm.getTypes();
        for (TypeModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    }
    if (parentElement instanceof TypeModel) {
        TypeModel tm = (TypeModel) parentElement;
        PrimitiveModel[] models = tm.getPrimitives();
        for (PrimitiveModel model : models) {
            values.add(model);
            if (getChildren(model).size() > 0) {
                values.addAll(getChildren(model));
            }
        }
        return values;
    // 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);
                            if (getChildren(sm).size() > 0) {
                                values.addAll(getChildren(sm));
                            }
                        }
                    } else {
                        values.add(childReps[j]);
                        if (getChildren(childReps[j]).size() > 0) {
                            values.addAll(getChildren(childReps[j]));
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values;
    }
    return values;
}
Also used : Group(ca.uhn.hl7v2.model.Group) Set(java.util.Set) HashSet(java.util.HashSet) Message(ca.uhn.hl7v2.model.Message) TypeModel(org.talend.designer.hl7.model.TypeModel) PrimitiveModel(org.talend.designer.hl7.model.PrimitiveModel) Segment(ca.uhn.hl7v2.model.Segment) HL7Exception(ca.uhn.hl7v2.HL7Exception) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel) HashSet(java.util.HashSet)

Example 2 with PrimitiveModel

use of org.talend.designer.hl7.model.PrimitiveModel in project tdi-studio-se by Talend.

the class HL7UI method initLinkersByPrimitiveModels.

protected void initLinkersByPrimitiveModels(List<PrimitiveModel> pms) {
    TableItem[] tableItems = this.linker.getTarget().getItems();
    TreeItem[] treeItems = this.linker.getSource().getItems();
    TreeItem sourceItem = null;
    String sourceItemName = "";
    Object targetItemData = null;
    List<linkMapPropertis> allLinkProp = new ArrayList<linkMapPropertis>();
    for (PrimitiveModel pm : pms) {
        for (TableItem ti : tableItems) {
            Object data = ti.getData();
            MetadataColumn column = (MetadataColumn) data;
            if (column.getOriginalField().equals(pm.getDisplayName())) {
                sourceItemName = pm.getDisplayName();
                sourceItem = findSourceItem(sourceItemName, treeItems);
                targetItemData = ti.getData();
                linkMapPropertis linkProp = new linkMapPropertis(sourceItem, targetItemData);
                allLinkProp.add(linkProp);
            }
        }
    }
    for (linkMapPropertis linkProp : allLinkProp) {
        linker.addLinks(linkProp.getSource(), linkProp.getSource().getData(), this.linker.getTarget(), linkProp.getTargetData());
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) PrimitiveModel(org.talend.designer.hl7.model.PrimitiveModel)

Aggregations

PrimitiveModel (org.talend.designer.hl7.model.PrimitiveModel)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1 Group (ca.uhn.hl7v2.model.Group)1 Message (ca.uhn.hl7v2.model.Message)1 Segment (ca.uhn.hl7v2.model.Segment)1 Structure (ca.uhn.hl7v2.model.Structure)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TableItem (org.eclipse.swt.widgets.TableItem)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 SegmentModel (org.talend.designer.hl7.model.SegmentModel)1 TypeModel (org.talend.designer.hl7.model.TypeModel)1