001package org.hl7.fhir.dstu2016may.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
033import java.util.Date;
034import java.util.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.instance.model.api.ICompositeType;
038
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Description;
042/**
043 * A time period defined by a start and end date and optionally time.
044 */
045@DatatypeDef(name="Period")
046public class Period extends Type implements ICompositeType {
047
048    /**
049     * The start of the period. The boundary is inclusive.
050     */
051    @Child(name = "start", type = {DateTimeType.class}, order=0, min=0, max=1, modifier=false, summary=true)
052    @Description(shortDefinition="Starting time with inclusive boundary", formalDefinition="The start of the period. The boundary is inclusive." )
053    protected DateTimeType start;
054
055    /**
056     * The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.
057     */
058    @Child(name = "end", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
059    @Description(shortDefinition="End time with inclusive boundary, if not ongoing", formalDefinition="The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time." )
060    protected DateTimeType end;
061
062    private static final long serialVersionUID = 649791751L;
063
064  /**
065   * Constructor
066   */
067    public Period() {
068      super();
069    }
070
071    /**
072     * @return {@link #start} (The start of the period. The boundary is inclusive.). This is the underlying object with id, value and extensions. The accessor "getStart" gives direct access to the value
073     */
074    public DateTimeType getStartElement() { 
075      if (this.start == null)
076        if (Configuration.errorOnAutoCreate())
077          throw new Error("Attempt to auto-create Period.start");
078        else if (Configuration.doAutoCreate())
079          this.start = new DateTimeType(); // bb
080      return this.start;
081    }
082
083    public boolean hasStartElement() { 
084      return this.start != null && !this.start.isEmpty();
085    }
086
087    public boolean hasStart() { 
088      return this.start != null && !this.start.isEmpty();
089    }
090
091    /**
092     * @param value {@link #start} (The start of the period. The boundary is inclusive.). This is the underlying object with id, value and extensions. The accessor "getStart" gives direct access to the value
093     */
094    public Period setStartElement(DateTimeType value) { 
095      this.start = value;
096      return this;
097    }
098
099    /**
100     * @return The start of the period. The boundary is inclusive.
101     */
102    public Date getStart() { 
103      return this.start == null ? null : this.start.getValue();
104    }
105
106    /**
107     * @param value The start of the period. The boundary is inclusive.
108     */
109    public Period setStart(Date value) { 
110      if (value == null)
111        this.start = null;
112      else {
113        if (this.start == null)
114          this.start = new DateTimeType();
115        this.start.setValue(value);
116      }
117      return this;
118    }
119
120    /**
121     * @return {@link #end} (The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.). This is the underlying object with id, value and extensions. The accessor "getEnd" gives direct access to the value
122     */
123    public DateTimeType getEndElement() { 
124      if (this.end == null)
125        if (Configuration.errorOnAutoCreate())
126          throw new Error("Attempt to auto-create Period.end");
127        else if (Configuration.doAutoCreate())
128          this.end = new DateTimeType(); // bb
129      return this.end;
130    }
131
132    public boolean hasEndElement() { 
133      return this.end != null && !this.end.isEmpty();
134    }
135
136    public boolean hasEnd() { 
137      return this.end != null && !this.end.isEmpty();
138    }
139
140    /**
141     * @param value {@link #end} (The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.). This is the underlying object with id, value and extensions. The accessor "getEnd" gives direct access to the value
142     */
143    public Period setEndElement(DateTimeType value) { 
144      this.end = value;
145      return this;
146    }
147
148    /**
149     * @return The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.
150     */
151    public Date getEnd() { 
152      return this.end == null ? null : this.end.getValue();
153    }
154
155    /**
156     * @param value The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.
157     */
158    public Period setEnd(Date value) { 
159      if (value == null)
160        this.end = null;
161      else {
162        if (this.end == null)
163          this.end = new DateTimeType();
164        this.end.setValue(value);
165      }
166      return this;
167    }
168
169   /**
170   * Sets the value for <b>start</b> ()
171   *
172     * <p>
173     * <b>Definition:</b>
174     * The start of the period. The boundary is inclusive.
175     * </p> 
176   */
177  public Period setStart( Date theDate,  TemporalPrecisionEnum thePrecision) {
178    start = new DateTimeType(theDate, thePrecision); 
179    return this; 
180  }
181
182   /**
183   * Sets the value for <b>end</b> ()
184   *
185     * <p>
186     * <b>Definition:</b>
187     * The end of the period. The boundary is inclusive.
188     * </p> 
189   */
190  public Period setEnd( Date theDate,  TemporalPrecisionEnum thePrecision) {
191    end = new DateTimeType(theDate, thePrecision); 
192    return this; 
193  }
194
195      protected void listChildren(List<Property> childrenList) {
196        super.listChildren(childrenList);
197        childrenList.add(new Property("start", "dateTime", "The start of the period. The boundary is inclusive.", 0, java.lang.Integer.MAX_VALUE, start));
198        childrenList.add(new Property("end", "dateTime", "The end of the period. If the end of the period is missing, it means that the period is ongoing. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.", 0, java.lang.Integer.MAX_VALUE, end));
199      }
200
201      @Override
202      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
203        switch (hash) {
204        case 109757538: /*start*/ return this.start == null ? new Base[0] : new Base[] {this.start}; // DateTimeType
205        case 100571: /*end*/ return this.end == null ? new Base[0] : new Base[] {this.end}; // DateTimeType
206        default: return super.getProperty(hash, name, checkValid);
207        }
208
209      }
210
211      @Override
212      public void setProperty(int hash, String name, Base value) throws FHIRException {
213        switch (hash) {
214        case 109757538: // start
215          this.start = castToDateTime(value); // DateTimeType
216          break;
217        case 100571: // end
218          this.end = castToDateTime(value); // DateTimeType
219          break;
220        default: super.setProperty(hash, name, value);
221        }
222
223      }
224
225      @Override
226      public void setProperty(String name, Base value) throws FHIRException {
227        if (name.equals("start"))
228          this.start = castToDateTime(value); // DateTimeType
229        else if (name.equals("end"))
230          this.end = castToDateTime(value); // DateTimeType
231        else
232          super.setProperty(name, value);
233      }
234
235      @Override
236      public Base makeProperty(int hash, String name) throws FHIRException {
237        switch (hash) {
238        case 109757538: throw new FHIRException("Cannot make property start as it is not a complex type"); // DateTimeType
239        case 100571: throw new FHIRException("Cannot make property end as it is not a complex type"); // DateTimeType
240        default: return super.makeProperty(hash, name);
241        }
242
243      }
244
245      @Override
246      public Base addChild(String name) throws FHIRException {
247        if (name.equals("start")) {
248          throw new FHIRException("Cannot call addChild on a primitive type Period.start");
249        }
250        else if (name.equals("end")) {
251          throw new FHIRException("Cannot call addChild on a primitive type Period.end");
252        }
253        else
254          return super.addChild(name);
255      }
256
257  public String fhirType() {
258    return "Period";
259
260  }
261
262      public Period copy() {
263        Period dst = new Period();
264        copyValues(dst);
265        dst.start = start == null ? null : start.copy();
266        dst.end = end == null ? null : end.copy();
267        return dst;
268      }
269
270      protected Period typedCopy() {
271        return copy();
272      }
273
274      @Override
275      public boolean equalsDeep(Base other) {
276        if (!super.equalsDeep(other))
277          return false;
278        if (!(other instanceof Period))
279          return false;
280        Period o = (Period) other;
281        return compareDeep(start, o.start, true) && compareDeep(end, o.end, true);
282      }
283
284      @Override
285      public boolean equalsShallow(Base other) {
286        if (!super.equalsShallow(other))
287          return false;
288        if (!(other instanceof Period))
289          return false;
290        Period o = (Period) other;
291        return compareValues(start, o.start, true) && compareValues(end, o.end, true);
292      }
293
294      public boolean isEmpty() {
295        return super.isEmpty() && (start == null || start.isEmpty()) && (end == null || end.isEmpty())
296          ;
297      }
298
299
300}
301