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