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