Search in sources :

Example 1 with Type

use of ca.uhn.hl7v2.model.Type 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 2 with Type

use of ca.uhn.hl7v2.model.Type in project tdi-studio-se by Talend.

the class SegmentModel method generateDataTypes.

private void generateDataTypes() {
    int number = this.seg.numFields();
    ArrayList<TypeModel> datatypes = new ArrayList<TypeModel>();
    Method method = null;
    try {
        for (Method curMethod : seg.getClass().getDeclaredMethods()) {
            if (curMethod.getName().equals("createNewTypeWithoutReflection")) {
                method = curMethod;
                method.setAccessible(true);
                break;
            }
        }
        if (method != null) {
            // so add test of null in case this method doesn't exist, even if it should be in every subclass.
            for (int i = 0; i < number; i++) {
                Type type = (Type) method.invoke(seg, i);
                TypeModel tm = new TypeModel(type, seg, 0, i + 1);
                datatypes.add(tm);
            }
        }
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (method == null) {
        // but it means it won't get optional fields.
        try {
            int lastNotEmptyFiledIndex = 0;
            for (int i = 1; i < number; i++) {
                Type[] reps = seg.getField(i);
                if (reps.length > 0) {
                    lastNotEmptyFiledIndex = i;
                }
            }
            for (int i = 1; i <= lastNotEmptyFiledIndex; i++) {
                Type[] reps = seg.getField(i);
                if (reps.length > 0) {
                    for (int j = 0; j < reps.length; j++) {
                        TypeModel tm = new TypeModel(reps[j], seg, j, i);
                        datatypes.add(tm);
                    }
                } else {
                    // for empty column
                    TypeModel tm = new TypeModel(null, seg, 0, i);
                    datatypes.add(tm);
                }
            }
        } catch (HL7Exception e) {
            e.printStackTrace();
        }
    }
    this.types = datatypes.toArray(new TypeModel[0]);
}
Also used : Type(ca.uhn.hl7v2.model.Type) ArrayList(java.util.ArrayList) HL7Exception(ca.uhn.hl7v2.HL7Exception) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with Type

use of ca.uhn.hl7v2.model.Type in project tdi-studio-se by Talend.

the class TypeModel method getPrimitive.

public Primitive getPrimitive(Type type, int component, int subcomponent) {
    Type comp = getComponent(type, component);
    Type sub = getComponent(comp, subcomponent);
    return getPrimitive(sub);
}
Also used : Type(ca.uhn.hl7v2.model.Type)

Example 4 with Type

use of ca.uhn.hl7v2.model.Type in project tdi-studio-se by Talend.

the class HL7MessageTreeLabelProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (element instanceof Type) {
        Type datatype = (Type) element;
        return datatype.getName();
    }
    if (element instanceof IModel) {
        if (element instanceof TypeModel) {
            TypeModel tm = (TypeModel) element;
            allPrimitives.addAll(Arrays.asList(tm.getPrimitives()));
        }
        return ((IModel) element).getDisplayName();
    }
    // }
    if (element instanceof Group) {
        Group group = (Group) element;
        String groupName = group.getName();
        groupName = groupName.substring(groupName.lastIndexOf('.') + 1, groupName.length());
        return groupName;
    }
    if (element instanceof Structure) {
        Structure structure = (Structure) element;
        return structure.getName();
    }
    return null;
}
Also used : Group(ca.uhn.hl7v2.model.Group) Type(ca.uhn.hl7v2.model.Type) IModel(org.talend.designer.hl7.model.IModel) TypeModel(org.talend.designer.hl7.model.TypeModel) Structure(ca.uhn.hl7v2.model.Structure)

Example 5 with Type

use of ca.uhn.hl7v2.model.Type in project quickstarts by jboss-switchyard.

the class CamelServiceRoute method configure.

/**
     * The Camel route is configured via this method.  The from endpoint is required to be a SwitchYard service.
     */
public void configure() {
    DataFormat hl7 = new HL7DataFormat();
    from("switchyard://HL7Route").unmarshal(hl7).process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            String body = exchange.getIn().getBody(String.class);
            PipeParser pipeParser = new PipeParser();
            try {
                // Parse the HL7 message 
                ca.uhn.hl7v2.model.Message message = pipeParser.parse(body);
                if (message instanceof QRY_A19) {
                    // Print out some details from the QRD
                    QRD qrd = (QRD) message.get("QRD");
                    System.out.println("Query Date/Time : " + qrd.getQueryDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Query Format Code : " + qrd.getQueryFormatCode().getValue());
                    System.out.println("Query Priority : " + qrd.getQueryPriority().getValue());
                    System.out.println("Query ID : " + qrd.getQueryID().getValue());
                    System.out.println("Deferred Response Type : " + qrd.getDeferredResponseType().getValue());
                    System.out.println("Deferred Response Date/Time : " + qrd.getDeferredResponseDateTime().getTimeOfAnEvent().getValue());
                    System.out.println("Quantity Limited Request : " + qrd.getQuantityLimitedRequest().getQuantity().getValue());
                    System.out.println("Query Results Level : " + qrd.getQueryResultsLevel().getValue());
                    qrd.getQueryID();
                }
            } catch (Exception e) {
                throw e;
            }
            SwitchYardMessage out = new SwitchYardMessage();
            out.setBody(body);
            exchange.setOut(out);
        }
    });
}
Also used : QRD(ca.uhn.hl7v2.model.v24.segment.QRD) Processor(org.apache.camel.Processor) PipeParser(ca.uhn.hl7v2.parser.PipeParser) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) SwitchYardMessage(org.switchyard.common.camel.SwitchYardMessage) Exchange(org.apache.camel.Exchange) DataFormat(org.apache.camel.spi.DataFormat) HL7DataFormat(org.apache.camel.component.hl7.HL7DataFormat) QRY_A19(ca.uhn.hl7v2.model.v24.message.QRY_A19)

Aggregations

Type (ca.uhn.hl7v2.model.Type)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)2 GenericPrimitive (ca.uhn.hl7v2.model.GenericPrimitive)2 Primitive (ca.uhn.hl7v2.model.Primitive)2 ArrayList (java.util.ArrayList)2 Composite (ca.uhn.hl7v2.model.Composite)1 DataTypeException (ca.uhn.hl7v2.model.DataTypeException)1 GenericComposite (ca.uhn.hl7v2.model.GenericComposite)1 Group (ca.uhn.hl7v2.model.Group)1 Message (ca.uhn.hl7v2.model.Message)1 Structure (ca.uhn.hl7v2.model.Structure)1 Varies (ca.uhn.hl7v2.model.Varies)1 QRY_A19 (ca.uhn.hl7v2.model.v24.message.QRY_A19)1 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 HL7DataFormat (org.apache.camel.component.hl7.HL7DataFormat)1