/**
The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is "PID.java".  Description:
"Represents an HL7 PID message segment"

The Initial Developer of the Original Code is University Health Network. Copyright (C)
2002.  All Rights Reserved.

Contributor(s): ______________________________________.

Alternatively, the contents of this file may be used under the terms of the
GNU General Public License (the  “GPL”), in which case the provisions of the GPL are
applicable instead of those above.  If you wish to allow use of your version of this
file only under the terms of the GPL and not to allow others to use your version
of this file under the MPL, indicate your decision by deleting  the provisions above
and replace  them with the notice and other provisions required by the GPL License.
If you do not delete the provisions above, a recipient may use your version of
this file under either the MPL or the GPL.

*/

package eclrs.lab.fileprocess.hl7.hl723.hapi.segment;

import ca.uhn.hl7v2.model.*;
import ca.uhn.hl7v2.model.v23.datatype.*;
import ca.uhn.log.HapiLogFactory;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.parser.ModelClassFactory;

/**
 * Represents an HL7 ZLR segment (Lab Reporting for Public Health,
 * as defined in Health Level Seven Specifications for
 * Electronic Laboratory-Based Reporting of
 * Public Health Information, Centers for Disease Control and Prevention,
 * October 1, 1997).
 * This segment has the following fields:<p>
 * ZLR-1: Ordering Provider’s Address (XAD)<br>
 * ZLR-2: Ordering Facility Name (XON)<br>
 * ZLR-3: Ordering Facility Address (XAD)<br>
 * ZLR-4: Ordering Facility Phone (XPN)<br>
 * ZLR-5: Patient’s Age (SN)<br> 
 * ZLR-6: Next of Kin/Assoc. Party Name (XPN)<br>
 * ZLR-7: Next of Kin/Assoc. Party Relationship (CE)<br> 
 * ZLR-8: Next of Kin/Assoc. Party Address (XAD)<br>
 * ZLR-9: Next of Kin/Assoc. Party Phone (XPN)
 */
public class ZLR extends AbstractSegment  {

  /**
   * Creates a ZLR (Z-Segment for Lab Reporting)
   * segment object that belongs to the given
   * Group.
   */
  public ZLR(Group parent, ModelClassFactory factory) {
    super(parent, factory);
    try {
       this.add(XAD.class, false, 1, 106, null);
       this.add(XON.class, false, 1, 90, null);
       this.add(XAD.class, false, 1, 106, null);
       this.add(XTN.class, false, 1, 40, null);
       this.add(SN.class, false, 1, 20, null);
       this.add(XPN.class, false, 1, 48, null);
       this.add(CE.class, false, 1, 40, null);
       this.add(XAD.class, false, 1, 106, null);
       this.add(XTN.class, false, 1, 40, null);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Can't instantiate " + this.getClass().getName(), he);
    }
  }

   /**
   * Returns Ordering Provider Address (ZLR-1)
   */
  public XAD getOrderingProviderAddress() {
    XAD ret = null;
    try {
        Type t = this.getField(1, 0);
        ret = (XAD)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

   /**
   * Returns Facility Name (ZLR-2)
   */
  public XON getFacilityName() {
    XON ret = null;
    try {
        Type t = this.getField(2, 0);
        ret = (XON)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

  /**
   * Returns Facility Address (ZLR-3)
   */
  public XAD getFacilityAddress() {
    XAD ret = null;
    try {
        Type t = this.getField(3, 0);
        ret = (XAD)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

  /**
   * Returns Facility Phone Number (ZLR-4)
   */
  public XTN getFacilityPhoneNumber() {
    XTN ret = null;
    try {
        Type t = this.getField(4, 0);
        ret = (XTN)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

  public SN getPatientAge() {
      SN ret = null;
      try {
          Type t = this.getField(5, 0);
          ret = (SN)t;
      } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
      } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }
    return ret;
  }

   /**
   * Returns Next Of Kin Name (ZLR-6).
   */
  public XPN getNextOfKinName()  {
    XPN ret = null;
    try {
        Type t = this.getField(6, 0);
        ret = (XPN)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

   /**
   * Returns Relationship Code (ZLR-7).
   */
  public CE getRelationshipCode()  {
    CE ret = null;
    try {
        Type t = this.getField(7, 0);
        ret = (CE)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

   /**
   * Returns Next of Kin Address (ZLR-8)
   */
  public XAD getNextOfKinAddress() {
    XAD ret = null;
    try {
        Type t = this.getField(8, 0);
        ret = (XAD)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

  /**
   * Returns Facility Phone Number (ZLR-9)
   */
  public XTN getNextOfKinPhoneNumber() {
    XTN ret = null;
    try {
        Type t = this.getField(9, 0);
        ret = (XTN)t;
    } catch (ClassCastException cce) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", cce);
    } catch (HL7Exception he) {
        HapiLogFactory.getHapiLog(this.getClass()).error(
        "Unexpected problem obtaining field value.  This is a bug.", he);
    }

    return ret;
  }

}