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