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