001    /*
002     * This class is an auto-generated source file for a HAPI
003     * HL7 v2.x standard structure class.
004     *
005     * For more information, visit: http://hl7api.sourceforge.net/
006     */
007    
008    package ca.uhn.hl7v2.model.v24.message;
009    
010    import ca.uhn.hl7v2.model.v24.group.*;
011    import ca.uhn.hl7v2.model.v24.segment.*;
012    
013    import ca.uhn.log.HapiLogFactory;
014    import ca.uhn.hl7v2.HL7Exception;
015    import ca.uhn.hl7v2.parser.ModelClassFactory;
016    import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
017    import ca.uhn.hl7v2.model.AbstractMessage;
018    
019    /**
020     * <p>Represents a BAR_P02 message structure (see chapter 6). This structure contains the 
021     * following elements: </p>
022     * <ul>
023                     * <li>1: MSH (Message Header) <b> </b></li>
024                     * <li>2: EVN (Event Type) <b> </b></li>
025                     * <li>3: BAR_P02_PATIENT (a Group object) <b> repeating</b></li>
026     * </ul>
027     */
028    public class BAR_P02 extends AbstractMessage  {
029    
030        /**
031         * Creates a new BAR_P02 message with DefaultModelClassFactory. 
032         */ 
033        public BAR_P02() { 
034           this(new DefaultModelClassFactory());
035        }
036    
037        /** 
038         * Creates a new BAR_P02 message with custom ModelClassFactory.
039         */
040        public BAR_P02(ModelClassFactory factory) {
041           super(factory);
042           init(factory);
043        }
044    
045        private void init(ModelClassFactory factory) {
046           try {
047                              this.add(MSH.class, true, false);
048                              this.add(EVN.class, true, false);
049                              this.add(BAR_P02_PATIENT.class, true, true);
050           } catch(HL7Exception e) {
051              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error creating BAR_P02 - this is probably a bug in the source code generator.", e);
052           }
053        }
054    
055        /** 
056         * Returns "2.4"
057         */
058        public String getVersion() {
059           return "2.4";
060        }
061    
062    
063    
064        /**
065         * Returns
066         * MSH (Message Header) - creates it if necessary
067         */
068        public MSH getMSH() { 
069           MSH ret = null;
070           try {
071              ret = (MSH)this.get("MSH");
072           } catch(HL7Exception e) {
073              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
074              throw new RuntimeException(e);
075           }
076           return ret;
077        }
078    
079    
080    
081    
082        /**
083         * Returns
084         * EVN (Event Type) - creates it if necessary
085         */
086        public EVN getEVN() { 
087           EVN ret = null;
088           try {
089              ret = (EVN)this.get("EVN");
090           } catch(HL7Exception e) {
091              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
092              throw new RuntimeException(e);
093           }
094           return ret;
095        }
096    
097    
098    
099    
100        /**
101         * Returns
102         * the first repetition of 
103         * PATIENT (a Group object) - creates it if necessary
104         */
105        public BAR_P02_PATIENT getPATIENT() { 
106           BAR_P02_PATIENT ret = null;
107           try {
108              ret = (BAR_P02_PATIENT)this.get("PATIENT");
109           } catch(HL7Exception e) {
110              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
111              throw new RuntimeException(e);
112           }
113           return ret;
114        }
115    
116    
117        /**
118         * Returns a specific repetition of
119         * PATIENT (a Group object) - creates it if necessary
120         *
121         * @param rep The repetition index (0-indexed, i.e. the first repetition is at index 0)
122         * @throws HL7Exception if the repetition requested is more than one 
123         *     greater than the number of existing repetitions.
124         */
125        public BAR_P02_PATIENT getPATIENT(int rep) { 
126           BAR_P02_PATIENT ret = null;
127           try {
128              ret = (BAR_P02_PATIENT)this.get("PATIENT", rep);
129           } catch(HL7Exception e) {
130              HapiLogFactory.getHapiLog(this.getClass()).error("Unexpected error accessing data - this is probably a bug in the source code generator.", e);
131              throw new RuntimeException(e);
132           }
133           return ret;
134        }
135    
136        /** 
137         * Returns the number of existing repetitions of PATIENT 
138         */ 
139        public int getPATIENTReps() { 
140            int reps = -1; 
141            try { 
142                reps = this.getAll("PATIENT").length; 
143            } catch (HL7Exception e) { 
144                String message = "Unexpected error accessing data - this is probably a bug in the source code generator."; 
145                HapiLogFactory.getHapiLog(this.getClass()).error(message, e); 
146                throw new RuntimeException(message);
147            } 
148            return reps; 
149        } 
150    
151        /**
152         * Inserts a specific repetition of PATIENT (a Group object)
153         * @see AbstractGroup\#insertRepetition(Structure, int) 
154         */
155        public void insertPATIENT(BAR_P02_PATIENT structure, int rep) throws HL7Exception { 
156           super.insertRepetition( "PATIENT", structure, rep);
157        }
158    
159    
160        /**
161         * Inserts a specific repetition of PATIENT (a Group object)
162         * @see AbstractGroup\#insertRepetition(Structure, int) 
163         */
164        public BAR_P02_PATIENT insertPATIENT(int rep) throws HL7Exception { 
165           return (BAR_P02_PATIENT)super.insertRepetition("PATIENT", rep);
166        }
167    
168    
169        /**
170         * Removes a specific repetition of PATIENT (a Group object)
171         * @see AbstractGroup\#removeRepetition(String, int) 
172         */
173        public BAR_P02_PATIENT removePATIENT(int rep) throws HL7Exception { 
174           return (BAR_P02_PATIENT)super.removeRepetition("PATIENT", rep);
175        }
176    
177    
178    
179    }
180