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