001package org.hl7.fhir.r4.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 Sun, May 6, 2018 17:51-0400 for FHIR v3.4.0 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.Utilities; 037import ca.uhn.fhir.model.api.annotation.Child; 038import ca.uhn.fhir.model.api.annotation.ChildOrder; 039import ca.uhn.fhir.model.api.annotation.Description; 040import ca.uhn.fhir.model.api.annotation.DatatypeDef; 041import ca.uhn.fhir.model.api.annotation.Block; 042import org.hl7.fhir.instance.model.api.*; 043import org.hl7.fhir.exceptions.FHIRException; 044/** 045 * A text note which also contains information about who made the statement and when. 046 */ 047@DatatypeDef(name="Annotation") 048public class Annotation extends Type implements ICompositeType { 049 050 /** 051 * The individual responsible for making the annotation. 052 */ 053 @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class, StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 054 @Description(shortDefinition="Individual responsible for the annotation", formalDefinition="The individual responsible for making the annotation." ) 055 protected Type author; 056 057 /** 058 * Indicates when this particular annotation was made. 059 */ 060 @Child(name = "time", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true) 061 @Description(shortDefinition="When the annotation was made", formalDefinition="Indicates when this particular annotation was made." ) 062 protected DateTimeType time; 063 064 /** 065 * The text of the annotation. 066 */ 067 @Child(name = "text", type = {StringType.class}, order=2, min=1, max=1, modifier=false, summary=true) 068 @Description(shortDefinition="The annotation - text content", formalDefinition="The text of the annotation." ) 069 protected StringType text; 070 071 private static final long serialVersionUID = -575590381L; 072 073 /** 074 * Constructor 075 */ 076 public Annotation() { 077 super(); 078 } 079 080 /** 081 * Constructor 082 */ 083 public Annotation(StringType text) { 084 super(); 085 this.text = text; 086 } 087 088 /** 089 * @return {@link #author} (The individual responsible for making the annotation.) 090 */ 091 public Type getAuthor() { 092 return this.author; 093 } 094 095 /** 096 * @return {@link #author} (The individual responsible for making the annotation.) 097 */ 098 public Reference getAuthorReference() throws FHIRException { 099 if (this.author == null) 100 return null; 101 if (!(this.author instanceof Reference)) 102 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.author.getClass().getName()+" was encountered"); 103 return (Reference) this.author; 104 } 105 106 public boolean hasAuthorReference() { 107 return this != null && this.author instanceof Reference; 108 } 109 110 /** 111 * @return {@link #author} (The individual responsible for making the annotation.) 112 */ 113 public StringType getAuthorStringType() throws FHIRException { 114 if (this.author == null) 115 return null; 116 if (!(this.author instanceof StringType)) 117 throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.author.getClass().getName()+" was encountered"); 118 return (StringType) this.author; 119 } 120 121 public boolean hasAuthorStringType() { 122 return this != null && this.author instanceof StringType; 123 } 124 125 public boolean hasAuthor() { 126 return this.author != null && !this.author.isEmpty(); 127 } 128 129 /** 130 * @param value {@link #author} (The individual responsible for making the annotation.) 131 */ 132 public Annotation setAuthor(Type value) { 133 if (value != null && !(value instanceof Reference || value instanceof StringType)) 134 throw new Error("Not the right type for Annotation.author[x]: "+value.fhirType()); 135 this.author = value; 136 return this; 137 } 138 139 /** 140 * @return {@link #time} (Indicates when this particular annotation was made.). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value 141 */ 142 public DateTimeType getTimeElement() { 143 if (this.time == null) 144 if (Configuration.errorOnAutoCreate()) 145 throw new Error("Attempt to auto-create Annotation.time"); 146 else if (Configuration.doAutoCreate()) 147 this.time = new DateTimeType(); // bb 148 return this.time; 149 } 150 151 public boolean hasTimeElement() { 152 return this.time != null && !this.time.isEmpty(); 153 } 154 155 public boolean hasTime() { 156 return this.time != null && !this.time.isEmpty(); 157 } 158 159 /** 160 * @param value {@link #time} (Indicates when this particular annotation was made.). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value 161 */ 162 public Annotation setTimeElement(DateTimeType value) { 163 this.time = value; 164 return this; 165 } 166 167 /** 168 * @return Indicates when this particular annotation was made. 169 */ 170 public Date getTime() { 171 return this.time == null ? null : this.time.getValue(); 172 } 173 174 /** 175 * @param value Indicates when this particular annotation was made. 176 */ 177 public Annotation setTime(Date value) { 178 if (value == null) 179 this.time = null; 180 else { 181 if (this.time == null) 182 this.time = new DateTimeType(); 183 this.time.setValue(value); 184 } 185 return this; 186 } 187 188 /** 189 * @return {@link #text} (The text of the annotation.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value 190 */ 191 public StringType getTextElement() { 192 if (this.text == null) 193 if (Configuration.errorOnAutoCreate()) 194 throw new Error("Attempt to auto-create Annotation.text"); 195 else if (Configuration.doAutoCreate()) 196 this.text = new StringType(); // bb 197 return this.text; 198 } 199 200 public boolean hasTextElement() { 201 return this.text != null && !this.text.isEmpty(); 202 } 203 204 public boolean hasText() { 205 return this.text != null && !this.text.isEmpty(); 206 } 207 208 /** 209 * @param value {@link #text} (The text of the annotation.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value 210 */ 211 public Annotation setTextElement(StringType value) { 212 this.text = value; 213 return this; 214 } 215 216 /** 217 * @return The text of the annotation. 218 */ 219 public String getText() { 220 return this.text == null ? null : this.text.getValue(); 221 } 222 223 /** 224 * @param value The text of the annotation. 225 */ 226 public Annotation setText(String value) { 227 if (this.text == null) 228 this.text = new StringType(); 229 this.text.setValue(value); 230 return this; 231 } 232 233 protected void listChildren(List<Property> children) { 234 super.listChildren(children); 235 children.add(new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, 1, author)); 236 children.add(new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time)); 237 children.add(new Property("text", "string", "The text of the annotation.", 0, 1, text)); 238 } 239 240 @Override 241 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 242 switch (_hash) { 243 case 1475597077: /*author[x]*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, 1, author); 244 case -1406328437: /*author*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, 1, author); 245 case 305515008: /*authorReference*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, 1, author); 246 case 290249084: /*authorString*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, 1, author); 247 case 3560141: /*time*/ return new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time); 248 case 3556653: /*text*/ return new Property("text", "string", "The text of the annotation.", 0, 1, text); 249 default: return super.getNamedProperty(_hash, _name, _checkValid); 250 } 251 252 } 253 254 @Override 255 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 256 switch (hash) { 257 case -1406328437: /*author*/ return this.author == null ? new Base[0] : new Base[] {this.author}; // Type 258 case 3560141: /*time*/ return this.time == null ? new Base[0] : new Base[] {this.time}; // DateTimeType 259 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType 260 default: return super.getProperty(hash, name, checkValid); 261 } 262 263 } 264 265 @Override 266 public Base setProperty(int hash, String name, Base value) throws FHIRException { 267 switch (hash) { 268 case -1406328437: // author 269 this.author = castToType(value); // Type 270 return value; 271 case 3560141: // time 272 this.time = castToDateTime(value); // DateTimeType 273 return value; 274 case 3556653: // text 275 this.text = castToString(value); // StringType 276 return value; 277 default: return super.setProperty(hash, name, value); 278 } 279 280 } 281 282 @Override 283 public Base setProperty(String name, Base value) throws FHIRException { 284 if (name.equals("author[x]")) { 285 this.author = castToType(value); // Type 286 } else if (name.equals("time")) { 287 this.time = castToDateTime(value); // DateTimeType 288 } else if (name.equals("text")) { 289 this.text = castToString(value); // StringType 290 } else 291 return super.setProperty(name, value); 292 return value; 293 } 294 295 @Override 296 public Base makeProperty(int hash, String name) throws FHIRException { 297 switch (hash) { 298 case 1475597077: return getAuthor(); 299 case -1406328437: return getAuthor(); 300 case 3560141: return getTimeElement(); 301 case 3556653: return getTextElement(); 302 default: return super.makeProperty(hash, name); 303 } 304 305 } 306 307 @Override 308 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 309 switch (hash) { 310 case -1406328437: /*author*/ return new String[] {"Reference", "string"}; 311 case 3560141: /*time*/ return new String[] {"dateTime"}; 312 case 3556653: /*text*/ return new String[] {"string"}; 313 default: return super.getTypesForProperty(hash, name); 314 } 315 316 } 317 318 @Override 319 public Base addChild(String name) throws FHIRException { 320 if (name.equals("authorReference")) { 321 this.author = new Reference(); 322 return this.author; 323 } 324 else if (name.equals("authorString")) { 325 this.author = new StringType(); 326 return this.author; 327 } 328 else if (name.equals("time")) { 329 throw new FHIRException("Cannot call addChild on a primitive type Annotation.time"); 330 } 331 else if (name.equals("text")) { 332 throw new FHIRException("Cannot call addChild on a primitive type Annotation.text"); 333 } 334 else 335 return super.addChild(name); 336 } 337 338 public String fhirType() { 339 return "Annotation"; 340 341 } 342 343 public Annotation copy() { 344 Annotation dst = new Annotation(); 345 copyValues(dst); 346 dst.author = author == null ? null : author.copy(); 347 dst.time = time == null ? null : time.copy(); 348 dst.text = text == null ? null : text.copy(); 349 return dst; 350 } 351 352 protected Annotation typedCopy() { 353 return copy(); 354 } 355 356 @Override 357 public boolean equalsDeep(Base other_) { 358 if (!super.equalsDeep(other_)) 359 return false; 360 if (!(other_ instanceof Annotation)) 361 return false; 362 Annotation o = (Annotation) other_; 363 return compareDeep(author, o.author, true) && compareDeep(time, o.time, true) && compareDeep(text, o.text, true) 364 ; 365 } 366 367 @Override 368 public boolean equalsShallow(Base other_) { 369 if (!super.equalsShallow(other_)) 370 return false; 371 if (!(other_ instanceof Annotation)) 372 return false; 373 Annotation o = (Annotation) other_; 374 return compareValues(time, o.time, true) && compareValues(text, o.text, true); 375 } 376 377 public boolean isEmpty() { 378 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(author, time, text); 379 } 380 381 382} 383