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