001package org.hl7.fhir.r4.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 6, 2018 17:51-0400 for FHIR v3.4.0
033
034import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
035import ca.uhn.fhir.model.api.annotation.Child;
036import ca.uhn.fhir.model.api.annotation.DatatypeDef;
037import ca.uhn.fhir.model.api.annotation.Description;
038import org.hl7.fhir.exceptions.FHIRException;
039import org.hl7.fhir.instance.model.api.ICompositeType;
040
041import java.util.Date;
042import java.util.List;
043/**
044 * A time period defined by a start and end date and optionally time.
045 */
046@DatatypeDef(name="Period")
047public class Period extends Type implements ICompositeType {
048
049    /**
050     * The start of the period. The boundary is inclusive.
051     */
052    @Child(name = "start", type = {DateTimeType.class}, order=0, min=0, max=1, modifier=false, summary=true)
053    @Description(shortDefinition="Starting time with inclusive boundary", formalDefinition="The start of the period. The boundary is inclusive." )
054    protected DateTimeType start;
055
056    /**
057     * 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.
058     */
059    @Child(name = "end", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
060    @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." )
061    protected DateTimeType end;
062
063    private static final long serialVersionUID = 649791751L;
064
065  /**
066   * Constructor
067   */
068    public Period() {
069      super();
070    }
071
072    /**
073     * @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
074     */
075    public DateTimeType getStartElement() { 
076      if (this.start == null)
077        if (Configuration.errorOnAutoCreate())
078          throw new Error("Attempt to auto-create Period.start");
079        else if (Configuration.doAutoCreate())
080          this.start = new DateTimeType(); // bb
081      return this.start;
082    }
083
084    public boolean hasStartElement() { 
085      return this.start != null && !this.start.isEmpty();
086    }
087
088    public boolean hasStart() { 
089      return this.start != null && !this.start.isEmpty();
090    }
091
092    /**
093     * @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
094     */
095    public Period setStartElement(DateTimeType value) { 
096      this.start = value;
097      return this;
098    }
099
100    /**
101     * @return The start of the period. The boundary is inclusive.
102     */
103    public Date getStart() { 
104      return this.start == null ? null : this.start.getValue();
105    }
106
107    /**
108     * @param value The start of the period. The boundary is inclusive.
109     */
110    public Period setStart(Date value) { 
111      if (value == null)
112        this.start = null;
113      else {
114        if (this.start == null)
115          this.start = new DateTimeType();
116        this.start.setValue(value);
117      }
118      return this;
119    }
120
121    /**
122     * @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
123     */
124    public DateTimeType getEndElement() { 
125      if (this.end == null)
126        if (Configuration.errorOnAutoCreate())
127          throw new Error("Attempt to auto-create Period.end");
128        else if (Configuration.doAutoCreate())
129          this.end = new DateTimeType(); // bb
130      return this.end;
131    }
132
133    public boolean hasEndElement() { 
134      return this.end != null && !this.end.isEmpty();
135    }
136
137    public boolean hasEnd() { 
138      return this.end != null && !this.end.isEmpty();
139    }
140
141    /**
142     * @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
143     */
144    public Period setEndElement(DateTimeType value) { 
145      this.end = value;
146      return this;
147    }
148
149    /**
150     * @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.
151     */
152    public Date getEnd() { 
153      return this.end == null ? null : this.end.getValue();
154    }
155
156    /**
157     * @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.
158     */
159    public Period setEnd(Date value) { 
160      if (value == null)
161        this.end = null;
162      else {
163        if (this.end == null)
164          this.end = new DateTimeType();
165        this.end.setValue(value);
166      }
167      return this;
168    }
169
170   /**
171   * Sets the value for <b>start</b> ()
172   *
173     * <p>
174     * <b>Definition:</b>
175     * The start of the period. The boundary is inclusive.
176     * </p> 
177   */
178  public Period setStart( Date theDate,  TemporalPrecisionEnum thePrecision) {
179    start = new DateTimeType(theDate, thePrecision); 
180    return this; 
181  }
182
183   /**
184   * Sets the value for <b>end</b> ()
185   *
186     * <p>
187     * <b>Definition:</b>
188     * The end of the period. The boundary is inclusive.
189     * </p> 
190   */
191  public Period setEnd( Date theDate,  TemporalPrecisionEnum thePrecision) {
192    end = new DateTimeType(theDate, thePrecision); 
193    return this; 
194  }
195
196      protected void listChildren(List<Property> children) {
197        super.listChildren(children);
198        children.add(new Property("start", "dateTime", "The start of the period. The boundary is inclusive.", 0, 1, start));
199        children.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, 1, end));
200      }
201
202      @Override
203      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
204        switch (_hash) {
205        case 109757538: /*start*/  return new Property("start", "dateTime", "The start of the period. The boundary is inclusive.", 0, 1, start);
206        case 100571: /*end*/  return 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, 1, end);
207        default: return super.getNamedProperty(_hash, _name, _checkValid);
208        }
209
210      }
211
212      @Override
213      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
214        switch (hash) {
215        case 109757538: /*start*/ return this.start == null ? new Base[0] : new Base[] {this.start}; // DateTimeType
216        case 100571: /*end*/ return this.end == null ? new Base[0] : new Base[] {this.end}; // DateTimeType
217        default: return super.getProperty(hash, name, checkValid);
218        }
219
220      }
221
222      @Override
223      public Base setProperty(int hash, String name, Base value) throws FHIRException {
224        switch (hash) {
225        case 109757538: // start
226          this.start = castToDateTime(value); // DateTimeType
227          return value;
228        case 100571: // end
229          this.end = castToDateTime(value); // DateTimeType
230          return value;
231        default: return super.setProperty(hash, name, value);
232        }
233
234      }
235
236      @Override
237      public Base setProperty(String name, Base value) throws FHIRException {
238        if (name.equals("start")) {
239          this.start = castToDateTime(value); // DateTimeType
240        } else if (name.equals("end")) {
241          this.end = castToDateTime(value); // DateTimeType
242        } else
243          return super.setProperty(name, value);
244        return value;
245      }
246
247      @Override
248      public Base makeProperty(int hash, String name) throws FHIRException {
249        switch (hash) {
250        case 109757538:  return getStartElement();
251        case 100571:  return getEndElement();
252        default: return super.makeProperty(hash, name);
253        }
254
255      }
256
257      @Override
258      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
259        switch (hash) {
260        case 109757538: /*start*/ return new String[] {"dateTime"};
261        case 100571: /*end*/ return new String[] {"dateTime"};
262        default: return super.getTypesForProperty(hash, name);
263        }
264
265      }
266
267      @Override
268      public Base addChild(String name) throws FHIRException {
269        if (name.equals("start")) {
270          throw new FHIRException("Cannot call addChild on a primitive type Period.start");
271        }
272        else if (name.equals("end")) {
273          throw new FHIRException("Cannot call addChild on a primitive type Period.end");
274        }
275        else
276          return super.addChild(name);
277      }
278
279  public String fhirType() {
280    return "Period";
281
282  }
283
284      public Period copy() {
285        Period dst = new Period();
286        copyValues(dst);
287        dst.start = start == null ? null : start.copy();
288        dst.end = end == null ? null : end.copy();
289        return dst;
290      }
291
292      protected Period typedCopy() {
293        return copy();
294      }
295
296      @Override
297      public boolean equalsDeep(Base other_) {
298        if (!super.equalsDeep(other_))
299          return false;
300        if (!(other_ instanceof Period))
301          return false;
302        Period o = (Period) other_;
303        return compareDeep(start, o.start, true) && compareDeep(end, o.end, true);
304      }
305
306      @Override
307      public boolean equalsShallow(Base other_) {
308        if (!super.equalsShallow(other_))
309          return false;
310        if (!(other_ instanceof Period))
311          return false;
312        Period o = (Period) other_;
313        return compareValues(start, o.start, true) && compareValues(end, o.end, true);
314      }
315
316      public boolean isEmpty() {
317        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(start, end);
318      }
319
320
321}
322