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