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