001package org.hl7.fhir.dstu2.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.dstu2 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/* 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 053// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 054import java.util.Date; 055import java.util.List; 056 057import ca.uhn.fhir.model.api.annotation.Child; 058import ca.uhn.fhir.model.api.annotation.DatatypeDef; 059import ca.uhn.fhir.model.api.annotation.Description; 060import org.hl7.fhir.instance.model.api.ICompositeType; 061import org.hl7.fhir.exceptions.FHIRException; 062/** 063 * A time period defined by a start and end date and optionally time. 064 */ 065@DatatypeDef(name="Period") 066public class Period extends Type implements ICompositeType { 067 068 /** 069 * The start of the period. The boundary is inclusive. 070 */ 071 @Child(name = "start", type = {DateTimeType.class}, order=0, min=0, max=1, modifier=false, summary=true) 072 @Description(shortDefinition="Starting time with inclusive boundary", formalDefinition="The start of the period. The boundary is inclusive." ) 073 protected DateTimeType start; 074 075 /** 076 * 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. 077 */ 078 @Child(name = "end", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true) 079 @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." ) 080 protected DateTimeType end; 081 082 private static final long serialVersionUID = 649791751L; 083 084 /* 085 * Constructor 086 */ 087 public Period() { 088 super(); 089 } 090 091 /** 092 * @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 093 */ 094 public DateTimeType getStartElement() { 095 if (this.start == null) 096 if (Configuration.errorOnAutoCreate()) 097 throw new Error("Attempt to auto-create Period.start"); 098 else if (Configuration.doAutoCreate()) 099 this.start = new DateTimeType(); // bb 100 return this.start; 101 } 102 103 public boolean hasStartElement() { 104 return this.start != null && !this.start.isEmpty(); 105 } 106 107 public boolean hasStart() { 108 return this.start != null && !this.start.isEmpty(); 109 } 110 111 /** 112 * @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 113 */ 114 public Period setStartElement(DateTimeType value) { 115 this.start = value; 116 return this; 117 } 118 119 /** 120 * @return The start of the period. The boundary is inclusive. 121 */ 122 public Date getStart() { 123 return this.start == null ? null : this.start.getValue(); 124 } 125 126 /** 127 * @param value The start of the period. The boundary is inclusive. 128 */ 129 public Period setStart(Date value) { 130 if (value == null) 131 this.start = null; 132 else { 133 if (this.start == null) 134 this.start = new DateTimeType(); 135 this.start.setValue(value); 136 } 137 return this; 138 } 139 140 /** 141 * @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 142 */ 143 public DateTimeType getEndElement() { 144 if (this.end == null) 145 if (Configuration.errorOnAutoCreate()) 146 throw new Error("Attempt to auto-create Period.end"); 147 else if (Configuration.doAutoCreate()) 148 this.end = new DateTimeType(); // bb 149 return this.end; 150 } 151 152 public boolean hasEndElement() { 153 return this.end != null && !this.end.isEmpty(); 154 } 155 156 public boolean hasEnd() { 157 return this.end != null && !this.end.isEmpty(); 158 } 159 160 /** 161 * @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 162 */ 163 public Period setEndElement(DateTimeType value) { 164 this.end = value; 165 return this; 166 } 167 168 /** 169 * @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. 170 */ 171 public Date getEnd() { 172 return this.end == null ? null : this.end.getValue(); 173 } 174 175 /** 176 * @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. 177 */ 178 public Period setEnd(Date value) { 179 if (value == null) 180 this.end = null; 181 else { 182 if (this.end == null) 183 this.end = new DateTimeType(); 184 this.end.setValue(value); 185 } 186 return this; 187 } 188 189 protected void listChildren(List<Property> childrenList) { 190 super.listChildren(childrenList); 191 childrenList.add(new Property("start", "dateTime", "The start of the period. The boundary is inclusive.", 0, java.lang.Integer.MAX_VALUE, start)); 192 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)); 193 } 194 195 @Override 196 public void setProperty(String name, Base value) throws FHIRException { 197 if (name.equals("start")) 198 this.start = castToDateTime(value); // DateTimeType 199 else if (name.equals("end")) 200 this.end = castToDateTime(value); // DateTimeType 201 else 202 super.setProperty(name, value); 203 } 204 205 @Override 206 public Base addChild(String name) throws FHIRException { 207 if (name.equals("start")) { 208 throw new FHIRException("Cannot call addChild on a primitive type Period.start"); 209 } 210 else if (name.equals("end")) { 211 throw new FHIRException("Cannot call addChild on a primitive type Period.end"); 212 } 213 else 214 return super.addChild(name); 215 } 216 217 public String fhirType() { 218 return "Period"; 219 220 } 221 222 public Period copy() { 223 Period dst = new Period(); 224 copyValues(dst); 225 dst.start = start == null ? null : start.copy(); 226 dst.end = end == null ? null : end.copy(); 227 return dst; 228 } 229 230 protected Period typedCopy() { 231 return copy(); 232 } 233 234 @Override 235 public boolean equalsDeep(Base other) { 236 if (!super.equalsDeep(other)) 237 return false; 238 if (!(other instanceof Period)) 239 return false; 240 Period o = (Period) other; 241 return compareDeep(start, o.start, true) && compareDeep(end, o.end, true); 242 } 243 244 @Override 245 public boolean equalsShallow(Base other) { 246 if (!super.equalsShallow(other)) 247 return false; 248 if (!(other instanceof Period)) 249 return false; 250 Period o = (Period) other; 251 return compareValues(start, o.start, true) && compareValues(end, o.end, true); 252 } 253 254 public boolean isEmpty() { 255 return super.isEmpty() && (start == null || start.isEmpty()) && (end == null || end.isEmpty()) 256 ; 257 } 258 259 260} 261