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 Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1 033import java.util.List; 034 035import org.hl7.fhir.exceptions.FHIRException; 036import org.hl7.fhir.instance.model.api.INarrative; 037import org.hl7.fhir.utilities.xhtml.NodeType; 038import org.hl7.fhir.utilities.xhtml.XhtmlNode; 039 040import ca.uhn.fhir.model.api.annotation.Child; 041import ca.uhn.fhir.model.api.annotation.DatatypeDef; 042import ca.uhn.fhir.model.api.annotation.Description; 043 044/** 045 * A human-readable summary of the resource conveying the essential clinical and 046 * business information for the resource. 047 */ 048@DatatypeDef(name = "Narrative") 049public class Narrative extends BaseNarrative implements INarrative { 050 051 public enum NarrativeStatus { 052 /** 053 * The contents of the narrative are entirely generated from the core elements 054 * in the content. 055 */ 056 GENERATED, 057 /** 058 * The contents of the narrative are entirely generated from the core elements 059 * in the content and some of the content is generated from extensions. The 060 * narrative SHALL reflect the impact of all modifier extensions. 061 */ 062 EXTENSIONS, 063 /** 064 * The contents of the narrative may contain additional information not found in 065 * the structured data. Note that there is no computable way to determine what 066 * the extra information is, other than by human inspection. 067 */ 068 ADDITIONAL, 069 /** 070 * The contents of the narrative are some equivalent of "No human-readable text 071 * provided in this case". 072 */ 073 EMPTY, 074 /** 075 * added to help the parsers with the generic types 076 */ 077 NULL; 078 079 public static NarrativeStatus fromCode(String codeString) throws FHIRException { 080 if (codeString == null || "".equals(codeString)) 081 return null; 082 if ("generated".equals(codeString)) 083 return GENERATED; 084 if ("extensions".equals(codeString)) 085 return EXTENSIONS; 086 if ("additional".equals(codeString)) 087 return ADDITIONAL; 088 if ("empty".equals(codeString)) 089 return EMPTY; 090 if (Configuration.isAcceptInvalidEnums()) 091 return null; 092 else 093 throw new FHIRException("Unknown NarrativeStatus code '" + codeString + "'"); 094 } 095 096 public String toCode() { 097 switch (this) { 098 case GENERATED: 099 return "generated"; 100 case EXTENSIONS: 101 return "extensions"; 102 case ADDITIONAL: 103 return "additional"; 104 case EMPTY: 105 return "empty"; 106 case NULL: 107 return null; 108 default: 109 return "?"; 110 } 111 } 112 113 public String getSystem() { 114 switch (this) { 115 case GENERATED: 116 return "http://hl7.org/fhir/narrative-status"; 117 case EXTENSIONS: 118 return "http://hl7.org/fhir/narrative-status"; 119 case ADDITIONAL: 120 return "http://hl7.org/fhir/narrative-status"; 121 case EMPTY: 122 return "http://hl7.org/fhir/narrative-status"; 123 case NULL: 124 return null; 125 default: 126 return "?"; 127 } 128 } 129 130 public String getDefinition() { 131 switch (this) { 132 case GENERATED: 133 return "The contents of the narrative are entirely generated from the core elements in the content."; 134 case EXTENSIONS: 135 return "The contents of the narrative are entirely generated from the core elements in the content and some of the content is generated from extensions. The narrative SHALL reflect the impact of all modifier extensions."; 136 case ADDITIONAL: 137 return "The contents of the narrative may contain additional information not found in the structured data. Note that there is no computable way to determine what the extra information is, other than by human inspection."; 138 case EMPTY: 139 return "The contents of the narrative are some equivalent of \"No human-readable text provided in this case\"."; 140 case NULL: 141 return null; 142 default: 143 return "?"; 144 } 145 } 146 147 public String getDisplay() { 148 switch (this) { 149 case GENERATED: 150 return "Generated"; 151 case EXTENSIONS: 152 return "Extensions"; 153 case ADDITIONAL: 154 return "Additional"; 155 case EMPTY: 156 return "Empty"; 157 case NULL: 158 return null; 159 default: 160 return "?"; 161 } 162 } 163 } 164 165 public static class NarrativeStatusEnumFactory implements EnumFactory<NarrativeStatus> { 166 public NarrativeStatus fromCode(String codeString) throws IllegalArgumentException { 167 if (codeString == null || "".equals(codeString)) 168 if (codeString == null || "".equals(codeString)) 169 return null; 170 if ("generated".equals(codeString)) 171 return NarrativeStatus.GENERATED; 172 if ("extensions".equals(codeString)) 173 return NarrativeStatus.EXTENSIONS; 174 if ("additional".equals(codeString)) 175 return NarrativeStatus.ADDITIONAL; 176 if ("empty".equals(codeString)) 177 return NarrativeStatus.EMPTY; 178 throw new IllegalArgumentException("Unknown NarrativeStatus code '" + codeString + "'"); 179 } 180 181 public Enumeration<NarrativeStatus> fromType(PrimitiveType<?> code) throws FHIRException { 182 if (code == null) 183 return null; 184 if (code.isEmpty()) 185 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.NULL, code); 186 String codeString = code.asStringValue(); 187 if (codeString == null || "".equals(codeString)) 188 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.NULL, code); 189 if ("generated".equals(codeString)) 190 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.GENERATED, code); 191 if ("extensions".equals(codeString)) 192 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EXTENSIONS, code); 193 if ("additional".equals(codeString)) 194 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.ADDITIONAL, code); 195 if ("empty".equals(codeString)) 196 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EMPTY, code); 197 throw new FHIRException("Unknown NarrativeStatus code '" + codeString + "'"); 198 } 199 200 public String toCode(NarrativeStatus code) { 201 if (code == NarrativeStatus.GENERATED) 202 return "generated"; 203 if (code == NarrativeStatus.EXTENSIONS) 204 return "extensions"; 205 if (code == NarrativeStatus.ADDITIONAL) 206 return "additional"; 207 if (code == NarrativeStatus.EMPTY) 208 return "empty"; 209 return "?"; 210 } 211 212 public String toSystem(NarrativeStatus code) { 213 return code.getSystem(); 214 } 215 } 216 217 /** 218 * The status of the narrative - whether it's entirely generated (from just the 219 * defined data or the extensions too), or whether a human authored it and it 220 * may contain additional data. 221 */ 222 @Child(name = "status", type = { CodeType.class }, order = 0, min = 1, max = 1, modifier = false, summary = false) 223 @Description(shortDefinition = "generated | extensions | additional | empty", formalDefinition = "The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data.") 224 @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/narrative-status") 225 protected Enumeration<NarrativeStatus> status; 226 227 /** 228 * The actual narrative content, a stripped down version of XHTML. 229 */ 230 @Child(name = "div", type = {}, order = 1, min = 1, max = 1, modifier = false, summary = false) 231 @Description(shortDefinition = "Limited xhtml content", formalDefinition = "The actual narrative content, a stripped down version of XHTML.") 232 protected XhtmlNode div; 233 234 private static final long serialVersionUID = 1463852859L; 235 236 /** 237 * Constructor 238 */ 239 public Narrative() { 240 super(); 241 } 242 243 /** 244 * Constructor 245 */ 246 public Narrative(Enumeration<NarrativeStatus> status, XhtmlNode div) { 247 super(); 248 this.status = status; 249 this.div = div; 250 } 251 252 /** 253 * @return {@link #status} (The status of the narrative - whether it's entirely 254 * generated (from just the defined data or the extensions too), or 255 * whether a human authored it and it may contain additional data.). 256 * This is the underlying object with id, value and extensions. The 257 * accessor "getStatus" gives direct access to the value 258 */ 259 public Enumeration<NarrativeStatus> getStatusElement() { 260 if (this.status == null) 261 if (Configuration.errorOnAutoCreate()) 262 throw new Error("Attempt to auto-create Narrative.status"); 263 else if (Configuration.doAutoCreate()) 264 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); // bb 265 return this.status; 266 } 267 268 public boolean hasStatusElement() { 269 return this.status != null && !this.status.isEmpty(); 270 } 271 272 public boolean hasStatus() { 273 return this.status != null && !this.status.isEmpty(); 274 } 275 276 /** 277 * @param value {@link #status} (The status of the narrative - whether it's 278 * entirely generated (from just the defined data or the extensions 279 * too), or whether a human authored it and it may contain 280 * additional data.). This is the underlying object with id, value 281 * and extensions. The accessor "getStatus" gives direct access to 282 * the value 283 */ 284 public Narrative setStatusElement(Enumeration<NarrativeStatus> value) { 285 this.status = value; 286 return this; 287 } 288 289 /** 290 * @return The status of the narrative - whether it's entirely generated (from 291 * just the defined data or the extensions too), or whether a human 292 * authored it and it may contain additional data. 293 */ 294 public NarrativeStatus getStatus() { 295 return this.status == null ? null : this.status.getValue(); 296 } 297 298 /** 299 * @param value The status of the narrative - whether it's entirely generated 300 * (from just the defined data or the extensions too), or whether a 301 * human authored it and it may contain additional data. 302 */ 303 public Narrative setStatus(NarrativeStatus value) { 304 if (this.status == null) 305 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); 306 this.status.setValue(value); 307 return this; 308 } 309 310 /** 311 * @return {@link #div} (The actual narrative content, a stripped down version 312 * of XHTML.) 313 */ 314 public XhtmlNode getDiv() { 315 if (this.div == null) 316 if (Configuration.errorOnAutoCreate()) 317 throw new Error("Attempt to auto-create Narrative.div"); 318 else if (Configuration.doAutoCreate()) 319 this.div = new XhtmlNode(NodeType.Element, "div"); // cc 320 return this.div; 321 } 322 323 public boolean hasDiv() { 324 return this.div != null && !this.div.isEmpty(); 325 } 326 327 /** 328 * @param value {@link #div} (The actual narrative content, a stripped down 329 * version of XHTML.) 330 */ 331 public Narrative setDiv(XhtmlNode value) { 332 this.div = value; 333 return this; 334 } 335 336 protected void listChildren(List<Property> children) { 337 super.listChildren(children); 338 children.add(new Property("status", "code", 339 "The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data.", 340 0, 1, status)); 341 } 342 343 @Override 344 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 345 switch (_hash) { 346 case -892481550: 347 /* status */ return new Property("status", "code", 348 "The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data.", 349 0, 1, status); 350 default: 351 return super.getNamedProperty(_hash, _name, _checkValid); 352 } 353 354 } 355 356 @Override 357 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 358 switch (hash) { 359 case -892481550: 360 /* status */ return this.status == null ? new Base[0] : new Base[] { this.status }; // Enumeration<NarrativeStatus> 361 case 99473: 362 /* div */ return this.div == null ? new Base[0] 363 : new Base[] { new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div)) }; // XhtmlNode 364 default: 365 return super.getProperty(hash, name, checkValid); 366 } 367 368 } 369 370 @Override 371 public Base setProperty(int hash, String name, Base value) throws FHIRException { 372 switch (hash) { 373 case -892481550: // status 374 value = new NarrativeStatusEnumFactory().fromType(castToCode(value)); 375 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 376 return value; 377 case 99473: // div 378 this.div = castToXhtml(value); // XhtmlNode 379 return value; 380 default: 381 return super.setProperty(hash, name, value); 382 } 383 384 } 385 386 @Override 387 public Base setProperty(String name, Base value) throws FHIRException { 388 if (name.equals("status")) { 389 value = new NarrativeStatusEnumFactory().fromType(castToCode(value)); 390 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 391 } else if (name.equals("div")) { 392 this.div = castToXhtml(value); // XhtmlNode 393 } else 394 return super.setProperty(name, value); 395 return value; 396 } 397 398 @Override 399 public Base makeProperty(int hash, String name) throws FHIRException { 400 switch (hash) { 401 case -892481550: 402 return getStatusElement(); 403 case 99473: /* div */ 404 if (div == null) 405 div = new XhtmlNode(NodeType.Element, "div"); 406 return new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div)); 407 default: 408 return super.makeProperty(hash, name); 409 } 410 411 } 412 413 @Override 414 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 415 switch (hash) { 416 case -892481550: 417 /* status */ return new String[] { "code" }; 418 case 99473: 419 /* div */ return new String[] { "xhtml" }; 420 default: 421 return super.getTypesForProperty(hash, name); 422 } 423 424 } 425 426 @Override 427 public Base addChild(String name) throws FHIRException { 428 if (name.equals("status")) { 429 throw new FHIRException("Cannot call addChild on a singleton property Narrative.status"); 430 } else 431 return super.addChild(name); 432 } 433 434 public String fhirType() { 435 return "Narrative"; 436 437 } 438 439 public Narrative copy() { 440 Narrative dst = new Narrative(); 441 copyValues(dst); 442 return dst; 443 } 444 445 public void copyValues(Narrative dst) { 446 super.copyValues(dst); 447 dst.status = status == null ? null : status.copy(); 448 dst.div = div == null ? null : div.copy(); 449 } 450 451 protected Narrative typedCopy() { 452 return copy(); 453 } 454 455 @Override 456 public boolean equalsDeep(Base other_) { 457 if (!super.equalsDeep(other_)) 458 return false; 459 if (!(other_ instanceof Narrative)) 460 return false; 461 Narrative o = (Narrative) other_; 462 return compareDeep(status, o.status, true) && compareDeep(div, o.div, true); 463 } 464 465 @Override 466 public boolean equalsShallow(Base other_) { 467 if (!super.equalsShallow(other_)) 468 return false; 469 if (!(other_ instanceof Narrative)) 470 return false; 471 Narrative o = (Narrative) other_; 472 return compareValues(status, o.status, true); 473 } 474 475 public boolean isEmpty() { 476 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(status, div); 477 } 478 479}