001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import ca.uhn.fhir.model.api.annotation.Child;
037import ca.uhn.fhir.model.api.annotation.ChildOrder;
038import ca.uhn.fhir.model.api.annotation.Description;
039import ca.uhn.fhir.model.api.annotation.DatatypeDef;
040import ca.uhn.fhir.model.api.annotation.Block;
041import org.hl7.fhir.instance.model.api.*;
042import org.hl7.fhir.exceptions.FHIRException;
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> childrenList) {
197        super.listChildren(childrenList);
198        childrenList.add(new Property("start", "dateTime", "The start of the period. The boundary is inclusive.", 0, java.lang.Integer.MAX_VALUE, start));
199        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));
200      }
201
202      @Override
203      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
204        switch (hash) {
205        case 109757538: /*start*/ return this.start == null ? new Base[0] : new Base[] {this.start}; // DateTimeType
206        case 100571: /*end*/ return this.end == null ? new Base[0] : new Base[] {this.end}; // DateTimeType
207        default: return super.getProperty(hash, name, checkValid);
208        }
209
210      }
211
212      @Override
213      public Base setProperty(int hash, String name, Base value) throws FHIRException {
214        switch (hash) {
215        case 109757538: // start
216          this.start = castToDateTime(value); // DateTimeType
217          return value;
218        case 100571: // end
219          this.end = castToDateTime(value); // DateTimeType
220          return value;
221        default: return super.setProperty(hash, name, value);
222        }
223
224      }
225
226      @Override
227      public Base setProperty(String name, Base value) throws FHIRException {
228        if (name.equals("start")) {
229          this.start = castToDateTime(value); // DateTimeType
230        } else if (name.equals("end")) {
231          this.end = castToDateTime(value); // DateTimeType
232        } else
233          return super.setProperty(name, value);
234        return value;
235      }
236
237      @Override
238      public Base makeProperty(int hash, String name) throws FHIRException {
239        switch (hash) {
240        case 109757538:  return getStartElement();
241        case 100571:  return getEndElement();
242        default: return super.makeProperty(hash, name);
243        }
244
245      }
246
247      @Override
248      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
249        switch (hash) {
250        case 109757538: /*start*/ return new String[] {"dateTime"};
251        case 100571: /*end*/ return new String[] {"dateTime"};
252        default: return super.getTypesForProperty(hash, name);
253        }
254
255      }
256
257      @Override
258      public Base addChild(String name) throws FHIRException {
259        if (name.equals("start")) {
260          throw new FHIRException("Cannot call addChild on a primitive type Period.start");
261        }
262        else if (name.equals("end")) {
263          throw new FHIRException("Cannot call addChild on a primitive type Period.end");
264        }
265        else
266          return super.addChild(name);
267      }
268
269  public String fhirType() {
270    return "Period";
271
272  }
273
274      public Period copy() {
275        Period dst = new Period();
276        copyValues(dst);
277        dst.start = start == null ? null : start.copy();
278        dst.end = end == null ? null : end.copy();
279        return dst;
280      }
281
282      protected Period typedCopy() {
283        return copy();
284      }
285
286      @Override
287      public boolean equalsDeep(Base other) {
288        if (!super.equalsDeep(other))
289          return false;
290        if (!(other instanceof Period))
291          return false;
292        Period o = (Period) other;
293        return compareDeep(start, o.start, true) && compareDeep(end, o.end, true);
294      }
295
296      @Override
297      public boolean equalsShallow(Base other) {
298        if (!super.equalsShallow(other))
299          return false;
300        if (!(other instanceof Period))
301          return false;
302        Period o = (Period) other;
303        return compareValues(start, o.start, true) && compareValues(end, o.end, true);
304      }
305
306      public boolean isEmpty() {
307        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(start, end);
308      }
309
310
311}
312