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