/**
 * St. Josefs Hospital Wisbaden GmbH
 * 
 * @author Ismet Celebi
 * @date 23.03.2011
 * @package de.joho.portal.hapi.costum.v24.segment
 * @file ZBE.java
 */
package de.joho.portal.hapi.costum.v24.segment;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.AbstractSegment;
import ca.uhn.hl7v2.model.Group;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Type;
import ca.uhn.hl7v2.model.v24.datatype.EI;
import ca.uhn.hl7v2.model.v24.datatype.ST;
import ca.uhn.hl7v2.model.v24.datatype.TS;
import ca.uhn.hl7v2.parser.ModelClassFactory;

/**
 * 
 * <p>
 * Represents an HL7 ZBE message segment. This segment has the following fields:
 * </p>
 * <ul>
 * <li>ZBE-1: TransferID from the KIS (EI)</li>
 * <li>ZBE-2: Start - Date/Time of Transfer (TS)</li>
 * <li>ZBE-3: Housing Functional Unit (TS)</li>
 * <li>ZBE-4: Action code of Message (ST)</li>
 * </ul>
 * <p>
 * The get...() methods return data from individual fields.
 * </p>
 */
public class ZBE extends AbstractSegment
{

    /**
     * Generated serialVersionUID
     */
    private static final long serialVersionUID = -2738323557840035918L;

    public ZBE(Group parent, ModelClassFactory factory)
    {
        super(parent, factory);
        Message message = getMessage();
        try {
            this.add(EI.class, false, 0, 250, new Object[] { message });
            this.add(TS.class, false, 0, 250, new Object[] { message });
            this.add(TS.class, false, 0, 250, new Object[] { message });
            this.add(ST.class, false, 0, 250, new Object[] { message });
        } catch (HL7Exception he) {
            he.printStackTrace();
        }
    }

    /**
     * Returns TransferID from the KIS (ZBE-1).
     */
    public EI getTransferID()
    {
        EI ret = null;
        try {
            Type t = this.getField(1, 0);
            ret = (EI) t;
        } catch (ClassCastException cce) {
            cce.printStackTrace();
            throw new RuntimeException(cce);
        } catch (HL7Exception he) {
            he.printStackTrace();
            throw new RuntimeException(he);
        }
        return ret;
    }

    /**
     * Returns Start - Date/Time of Transfer (ZBE-2).
     */
    public TS getTransferStartTime()
    {
        TS ret = null;
        try {
            Type t = this.getField(2, 0);
            ret = (TS) t;
        } catch (ClassCastException cce) {
            cce.printStackTrace();
            throw new RuntimeException(cce);
        } catch (HL7Exception he) {
            he.printStackTrace();
            throw new RuntimeException(he);
        }
        return ret;
    }

    /**
     * Returns End - Date/Time of Transfer (ZBE-3).
     */
    public TS getTransferEndTime()
    {
        TS ret = null;
        try {
            Type t = this.getField(3, 0);
            ret = (TS) t;
        } catch (ClassCastException cce) {
            cce.printStackTrace();
            throw new RuntimeException(cce);
        } catch (HL7Exception he) {
            he.printStackTrace();
            throw new RuntimeException(he);
        }
        return ret;
    }

    /**
     * Returns Action code of Message such as INSER; UPDATE; ERROR; (ZBE-4).
     */
    public ST getActionCode()
    {
        ST ret = null;
        try {
            Type t = this.getField(4, 0);
            ret = (ST) t;
        } catch (ClassCastException cce) {
            cce.printStackTrace();
            throw new RuntimeException(cce);
        } catch (HL7Exception he) {
            he.printStackTrace();
            throw new RuntimeException(he);
        }
        return ret;
    }
}
