Search in sources :

Example 1 with DataTypeException

use of ca.uhn.hl7v2.model.DataTypeException 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 DataTypeException

use of ca.uhn.hl7v2.model.DataTypeException in project openmrs-core by openmrs.

the class ORUR01Handler method getDatetime.

/**
 * Return a java date object for the given TS
 *
 * @param ts TS to parse
 * @return date object or null
 * @throws HL7Exception
 */
private Date getDatetime(TS ts) throws HL7Exception {
    Date datetime = null;
    DTM value = ts.getTime();
    if (value.getYear() == 0 || value.getValue() == null) {
        return null;
    }
    try {
        datetime = getDate(value.getYear(), value.getMonth(), value.getDay(), value.getHour(), value.getMinute(), value.getSecond());
    } catch (DataTypeException e) {
    }
    return datetime;
}
Also used : DataTypeException(ca.uhn.hl7v2.model.DataTypeException) DTM(ca.uhn.hl7v2.model.v25.datatype.DTM) Date(java.util.Date)

Aggregations

DataTypeException (ca.uhn.hl7v2.model.DataTypeException)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1 Composite (ca.uhn.hl7v2.model.Composite)1 GenericComposite (ca.uhn.hl7v2.model.GenericComposite)1 GenericPrimitive (ca.uhn.hl7v2.model.GenericPrimitive)1 Primitive (ca.uhn.hl7v2.model.Primitive)1 Type (ca.uhn.hl7v2.model.Type)1 Varies (ca.uhn.hl7v2.model.Varies)1 DTM (ca.uhn.hl7v2.model.v25.datatype.DTM)1 Date (java.util.Date)1