001package org.hl7.fhir.r5.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r5 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 Copyright (c) 2011+, HL7, Inc. 025 All rights reserved. 026 027 Redistribution and use in source and binary forms, with or without modification, 028 are permitted provided that the following conditions are met: 029 030 * Redistributions of source code must retain the above copyright notice, this 031 list of conditions and the following disclaimer. 032 * Redistributions in binary form must reproduce the above copyright notice, 033 this list of conditions and the following disclaimer in the documentation 034 and/or other materials provided with the distribution. 035 * Neither the name of HL7 nor the names of its contributors may be used to 036 endorse or promote products derived from this software without specific 037 prior written permission. 038 039 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 040 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 041 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 042 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 043 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 045 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 046 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 047 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 048 POSSIBILITY OF SUCH DAMAGE. 049 050*/ 051 052// Generated on Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0 053import java.util.ArrayList; 054import java.util.Date; 055import java.util.List; 056import org.hl7.fhir.exceptions.FHIRException; 057import org.hl7.fhir.instance.model.api.ICompositeType; 058 059import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 060import ca.uhn.fhir.model.api.annotation.Child; 061import ca.uhn.fhir.model.api.annotation.ChildOrder; 062import ca.uhn.fhir.model.api.annotation.DatatypeDef; 063import ca.uhn.fhir.model.api.annotation.Description; 064import ca.uhn.fhir.model.api.annotation.Block; 065/** 066 * A text note which also contains information about who made the statement and when. 067 */ 068@DatatypeDef(name="Annotation") 069public class Annotation extends Type implements ICompositeType { 070 071 /** 072 * The individual responsible for making the annotation. 073 */ 074 @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class, Organization.class, StringType.class}, order=0, min=0, max=1, modifier=false, summary=true) 075 @Description(shortDefinition="Individual responsible for the annotation", formalDefinition="The individual responsible for making the annotation." ) 076 protected Type author; 077 078 /** 079 * Indicates when this particular annotation was made. 080 */ 081 @Child(name = "time", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true) 082 @Description(shortDefinition="When the annotation was made", formalDefinition="Indicates when this particular annotation was made." ) 083 protected DateTimeType time; 084 085 /** 086 * The text of the annotation in markdown format. 087 */ 088 @Child(name = "text", type = {MarkdownType.class}, order=2, min=1, max=1, modifier=false, summary=true) 089 @Description(shortDefinition="The annotation - text content (as markdown)", formalDefinition="The text of the annotation in markdown format." ) 090 protected MarkdownType text; 091 092 private static final long serialVersionUID = 1324090545L; 093 094 /** 095 * Constructor 096 */ 097 public Annotation() { 098 super(); 099 } 100 101 /** 102 * Constructor 103 */ 104 public Annotation(MarkdownType text) { 105 super(); 106 this.text = text; 107 } 108 109 /** 110 * @return {@link #author} (The individual responsible for making the annotation.) 111 */ 112 public Type getAuthor() { 113 return this.author; 114 } 115 116 /** 117 * @return {@link #author} (The individual responsible for making the annotation.) 118 */ 119 public Reference getAuthorReference() throws FHIRException { 120 if (this.author == null) 121 this.author = new Reference(); 122 if (!(this.author instanceof Reference)) 123 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.author.getClass().getName()+" was encountered"); 124 return (Reference) this.author; 125 } 126 127 public boolean hasAuthorReference() { 128 return this != null && this.author instanceof Reference; 129 } 130 131 /** 132 * @return {@link #author} (The individual responsible for making the annotation.) 133 */ 134 public StringType getAuthorStringType() throws FHIRException { 135 if (this.author == null) 136 this.author = new StringType(); 137 if (!(this.author instanceof StringType)) 138 throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.author.getClass().getName()+" was encountered"); 139 return (StringType) this.author; 140 } 141 142 public boolean hasAuthorStringType() { 143 return this != null && this.author instanceof StringType; 144 } 145 146 public boolean hasAuthor() { 147 return this.author != null && !this.author.isEmpty(); 148 } 149 150 /** 151 * @param value {@link #author} (The individual responsible for making the annotation.) 152 */ 153 public Annotation setAuthor(Type value) { 154 if (value != null && !(value instanceof Reference || value instanceof StringType)) 155 throw new Error("Not the right type for Annotation.author[x]: "+value.fhirType()); 156 this.author = value; 157 return this; 158 } 159 160 /** 161 * @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 162 */ 163 public DateTimeType getTimeElement() { 164 if (this.time == null) 165 if (Configuration.errorOnAutoCreate()) 166 throw new Error("Attempt to auto-create Annotation.time"); 167 else if (Configuration.doAutoCreate()) 168 this.time = new DateTimeType(); // bb 169 return this.time; 170 } 171 172 public boolean hasTimeElement() { 173 return this.time != null && !this.time.isEmpty(); 174 } 175 176 public boolean hasTime() { 177 return this.time != null && !this.time.isEmpty(); 178 } 179 180 /** 181 * @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 182 */ 183 public Annotation setTimeElement(DateTimeType value) { 184 this.time = value; 185 return this; 186 } 187 188 /** 189 * @return Indicates when this particular annotation was made. 190 */ 191 public Date getTime() { 192 return this.time == null ? null : this.time.getValue(); 193 } 194 195 /** 196 * @param value Indicates when this particular annotation was made. 197 */ 198 public Annotation setTime(Date value) { 199 if (value == null) 200 this.time = null; 201 else { 202 if (this.time == null) 203 this.time = new DateTimeType(); 204 this.time.setValue(value); 205 } 206 return this; 207 } 208 209 /** 210 * @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 211 */ 212 public MarkdownType getTextElement() { 213 if (this.text == null) 214 if (Configuration.errorOnAutoCreate()) 215 throw new Error("Attempt to auto-create Annotation.text"); 216 else if (Configuration.doAutoCreate()) 217 this.text = new MarkdownType(); // bb 218 return this.text; 219 } 220 221 public boolean hasTextElement() { 222 return this.text != null && !this.text.isEmpty(); 223 } 224 225 public boolean hasText() { 226 return this.text != null && !this.text.isEmpty(); 227 } 228 229 /** 230 * @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 231 */ 232 public Annotation setTextElement(MarkdownType value) { 233 this.text = value; 234 return this; 235 } 236 237 /** 238 * @return The text of the annotation in markdown format. 239 */ 240 public String getText() { 241 return this.text == null ? null : this.text.getValue(); 242 } 243 244 /** 245 * @param value The text of the annotation in markdown format. 246 */ 247 public Annotation setText(String value) { 248 if (this.text == null) 249 this.text = new MarkdownType(); 250 this.text.setValue(value); 251 return this; 252 } 253 254 protected void listChildren(List<Property> children) { 255 super.listChildren(children); 256 children.add(new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author)); 257 children.add(new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time)); 258 children.add(new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text)); 259 } 260 261 @Override 262 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 263 switch (_hash) { 264 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); 265 case -1406328437: /*author*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author); 266 case 305515008: /*authorReference*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author); 267 case 290249084: /*authorString*/ return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author); 268 case 3560141: /*time*/ return new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time); 269 case 3556653: /*text*/ return new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text); 270 default: return super.getNamedProperty(_hash, _name, _checkValid); 271 } 272 273 } 274 275 @Override 276 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 277 switch (hash) { 278 case -1406328437: /*author*/ return this.author == null ? new Base[0] : new Base[] {this.author}; // Type 279 case 3560141: /*time*/ return this.time == null ? new Base[0] : new Base[] {this.time}; // DateTimeType 280 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // MarkdownType 281 default: return super.getProperty(hash, name, checkValid); 282 } 283 284 } 285 286 @Override 287 public Base setProperty(int hash, String name, Base value) throws FHIRException { 288 switch (hash) { 289 case -1406328437: // author 290 this.author = castToType(value); // Type 291 return value; 292 case 3560141: // time 293 this.time = castToDateTime(value); // DateTimeType 294 return value; 295 case 3556653: // text 296 this.text = castToMarkdown(value); // MarkdownType 297 return value; 298 default: return super.setProperty(hash, name, value); 299 } 300 301 } 302 303 @Override 304 public Base setProperty(String name, Base value) throws FHIRException { 305 if (name.equals("author[x]")) { 306 this.author = castToType(value); // Type 307 } else if (name.equals("time")) { 308 this.time = castToDateTime(value); // DateTimeType 309 } else if (name.equals("text")) { 310 this.text = castToMarkdown(value); // MarkdownType 311 } else 312 return super.setProperty(name, value); 313 return value; 314 } 315 316 @Override 317 public Base makeProperty(int hash, String name) throws FHIRException { 318 switch (hash) { 319 case 1475597077: return getAuthor(); 320 case -1406328437: return getAuthor(); 321 case 3560141: return getTimeElement(); 322 case 3556653: return getTextElement(); 323 default: return super.makeProperty(hash, name); 324 } 325 326 } 327 328 @Override 329 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 330 switch (hash) { 331 case -1406328437: /*author*/ return new String[] {"Reference", "string"}; 332 case 3560141: /*time*/ return new String[] {"dateTime"}; 333 case 3556653: /*text*/ return new String[] {"markdown"}; 334 default: return super.getTypesForProperty(hash, name); 335 } 336 337 } 338 339 @Override 340 public Base addChild(String name) throws FHIRException { 341 if (name.equals("authorReference")) { 342 this.author = new Reference(); 343 return this.author; 344 } 345 else if (name.equals("authorString")) { 346 this.author = new StringType(); 347 return this.author; 348 } 349 else if (name.equals("time")) { 350 throw new FHIRException("Cannot call addChild on a primitive type Annotation.time"); 351 } 352 else if (name.equals("text")) { 353 throw new FHIRException("Cannot call addChild on a primitive type Annotation.text"); 354 } 355 else 356 return super.addChild(name); 357 } 358 359 public String fhirType() { 360 return "Annotation"; 361 362 } 363 364 public Annotation copy() { 365 Annotation dst = new Annotation(); 366 copyValues(dst); 367 return dst; 368 } 369 370 public void copyValues(Annotation dst) { 371 super.copyValues(dst); 372 dst.author = author == null ? null : author.copy(); 373 dst.time = time == null ? null : time.copy(); 374 dst.text = text == null ? null : text.copy(); 375 } 376 377 protected Annotation typedCopy() { 378 return copy(); 379 } 380 381 @Override 382 public boolean equalsDeep(Base other_) { 383 if (!super.equalsDeep(other_)) 384 return false; 385 if (!(other_ instanceof Annotation)) 386 return false; 387 Annotation o = (Annotation) other_; 388 return compareDeep(author, o.author, true) && compareDeep(time, o.time, true) && compareDeep(text, o.text, true) 389 ; 390 } 391 392 @Override 393 public boolean equalsShallow(Base other_) { 394 if (!super.equalsShallow(other_)) 395 return false; 396 if (!(other_ instanceof Annotation)) 397 return false; 398 Annotation o = (Annotation) other_; 399 return compareValues(time, o.time, true) && compareValues(text, o.text, true); 400 } 401 402 public boolean isEmpty() { 403 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(author, time, text); 404 } 405 406 407} 408