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