/**
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 "ORU_R01_ORDER_OBSERVATION.java".  Description: 
"Represents the ORU_R01_ORDER_OBSERVATION Group" 

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 ca.uhn.hl7v2.model.v23.group;

import ca.uhn.hl7v2.parser.ModelClassFactory;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.log.HapiLogFactory;
import ca.uhn.hl7v2.model.v23.segment.*;

import ca.uhn.hl7v2.model.*;

import eclrs.lab.fileprocess.hl7.hl723.hapi.segment.ZLR;

/**
 * <p>Represents the ORU_R01_ORDER_OBSERVATION Group.
 * A Group is an ordered collection of message 
 * segments that can repeat together or be optionally in/excluded together.
 * This group was modified by adding an optional ZLR segment after the OBR.
 * The ZLR segment was specified by the CDC to add fields of interest to
 * Public Health to the HL7 version 2.3 ORU_R01 message for electronic
 * reporting of legally reportable conditions.
 * This Group contains the following elements: </p>
 * 0: ORC (Common order segment) <b>optional </b><br>
 * 1: OBR (Observation request segment) <b></b><br>
 * 2: ZLR (Extension segment("Z") for <b>L</b>ab <b>R</b>eporting)<b>optional><br>
 * 3: NTE (Notes and comments segment) <b>optional repeating</b><br>
 * 4: ORU_R01_OBSERVATION (a Group object) <b>repeating</b><br>
 * 5: CTI (Clinical Trial Identification) <b>optional repeating</b><br>
 */
public class ORU_R01_ORDER_OBSERVATION extends AbstractGroup {

    /** 
     * Creates a new ORU_R01_ORDER_OBSERVATION Group.
     */
    public ORU_R01_ORDER_OBSERVATION(Group parent, ModelClassFactory factory) {
       super(parent, factory);
       try {
          this.add(ORC.class, false, false);
          this.add(OBR.class, true, false);
          // Added for ECLRS 3/22/2005
          // See getZLR method added below
          this.add(ZLR.class, false, false);
          // End of addition 3/22/2005
          this.add(NTE.class, false, true);
          this.add(ORU_R01_OBSERVATION.class, true, true);
          this.add(CTI.class, false, true);
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating ORU_R01_ORDER_OBSERVATION - this is probably a bug in the source code generator.", e);
       }
    }

    /**
     * Returns ORC (Common order segment) - creates it if necessary
     */
    public ORC getORC() { 
       ORC ret = null;
       try {
          ret = (ORC)this.get("ORC");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
          throw new RuntimeException(e);
       }
       return ret;
    }

    /**
     * Returns OBR (Observation request segment) - creates it if necessary
     */
    public OBR getOBR() { 
       OBR ret = null;
       try {
          ret = (OBR)this.get("OBR");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
          throw new RuntimeException(e);
       }
       return ret;
    }

    // Added for ECLRS 3/22/2005
    /**
     * Returns ZLR (Extension segment for Lab Reporting) - 
     * creates it if necessary
     */
    public ZLR getZLR() { 
       ZLR ret = null;
       try {
          ret = (ZLR)this.get("ZLR");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
       }
       return ret;
    }
    // End of addition 3/22/2005
    
    /**
     * Returns  first repetition of NTE (Notes and comments segment) - creates it if necessary
     */
    public NTE getNTE() { 
       NTE ret = null;
       try {
          ret = (NTE)this.get("NTE");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
          throw new RuntimeException(e);
       }
       return ret;
    }

    /**
     * Returns a specific repetition of NTE
     * (Notes and comments segment) - creates it if necessary
     * throws HL7Exception if the repetition requested is more than one 
     *     greater than the number of existing repetitions.
     */
    public NTE getNTE(int rep) throws HL7Exception { 
       return (NTE)this.get("NTE", rep);
    }

    /** 
     * Returns the number of existing repetitions of NTE 
     */ 
    public int getNTEReps() { 
        int reps = -1; 
        try { 
            reps = this.getAll("NTE").length; 
        } catch (HL7Exception e) { 
            String message = "Unexpected error accessing data - this is probably a bug in the source code generator."; 
            HapiLogFactory.getHapiLog(this.getClass()).error(message, e); 
            throw new RuntimeException(message);
        } 
        return reps; 
    } 

    /**
     * Returns  first repetition of ORU_R01_OBSERVATION (a Group object) - creates it if necessary
     */
    public ORU_R01_OBSERVATION getOBSERVATION() { 
       ORU_R01_OBSERVATION ret = null;
       try {
          ret = (ORU_R01_OBSERVATION)this.get("OBSERVATION");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
          throw new RuntimeException(e);
       }
       return ret;
    }

    /**
     * Returns a specific repetition of ORU_R01_OBSERVATION
     * (a Group object) - creates it if necessary
     * throws HL7Exception if the repetition requested is more than one 
     *     greater than the number of existing repetitions.
     */
    public ORU_R01_OBSERVATION getOBSERVATION(int rep) throws HL7Exception { 
       return (ORU_R01_OBSERVATION)this.get("OBSERVATION", rep);
    }

    /** 
     * Returns the number of existing repetitions of ORU_R01_OBSERVATION 
     */ 
    public int getOBSERVATIONReps() { 
        int reps = -1; 
        try { 
            reps = this.getAll("OBSERVATION").length; 
        } catch (HL7Exception e) { 
            String message = "Unexpected error accessing data - this is probably a bug in the source code generator."; 
            HapiLogFactory.getHapiLog(this.getClass()).error(message, e); 
            throw new RuntimeException(message);
        } 
        return reps; 
    } 

    /**
     * Returns  first repetition of CTI (Clinical Trial Identification) - creates it if necessary
     */
    public CTI getCTI() { 
       CTI ret = null;
       try {
          ret = (CTI)this.get("CTI");
       } catch(HL7Exception e) {
          HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
          throw new RuntimeException(e);
       }
       return ret;
    }

    /**
     * Returns a specific repetition of CTI
     * (Clinical Trial Identification) - creates it if necessary
     * throws HL7Exception if the repetition requested is more than one 
     *     greater than the number of existing repetitions.
     */
    public CTI getCTI(int rep) throws HL7Exception { 
       return (CTI)this.get("CTI", rep);
    }

    /** 
     * Returns the number of existing repetitions of CTI 
     */ 
    public int getCTIReps() { 
        int reps = -1; 
        try { 
            reps = this.getAll("CTI").length; 
        } catch (HL7Exception e) { 
            String message = "Unexpected error accessing data - this is probably a bug in the source code generator."; 
            HapiLogFactory.getHapiLog(this.getClass()).error(message, e); 
            throw new RuntimeException(message);
        } 
        return reps; 
    } 

}
