Search in sources :

Example 21 with Segment

use of ca.uhn.hl7v2.model.Segment 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];
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) TypeModel(org.talend.designer.hl7.model.TypeModel) Segment(ca.uhn.hl7v2.model.Segment) 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)

Example 22 with Segment

use of ca.uhn.hl7v2.model.Segment 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];
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) TypeModel(org.talend.designer.hl7.model.TypeModel) Segment(ca.uhn.hl7v2.model.Segment) 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)

Aggregations

MSH (ca.uhn.hl7v2.model.v24.segment.MSH)14 ADR_A19 (ca.uhn.hl7v2.model.v24.message.ADR_A19)10 MSA (ca.uhn.hl7v2.model.v24.segment.MSA)10 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)10 ADT_A01 (ca.uhn.hl7v2.model.v24.message.ADT_A01)8 PID (ca.uhn.hl7v2.model.v24.segment.PID)8 HL7Exception (ca.uhn.hl7v2.HL7Exception)4 Group (ca.uhn.hl7v2.model.Group)4 Message (ca.uhn.hl7v2.model.Message)4 Segment (ca.uhn.hl7v2.model.Segment)4 Structure (ca.uhn.hl7v2.model.Structure)4 SegmentModel (org.talend.designer.hl7.model.SegmentModel)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TypeModel (org.talend.designer.hl7.model.TypeModel)3 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PrimitiveModel (org.talend.designer.hl7.model.PrimitiveModel)1