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