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