001package org.hl7.fhir.r5.model; 002 003 004/* 005 Copyright (c) 2011+, HL7, Inc. 006 All rights reserved. 007 008 Redistribution and use in source and binary forms, with or without modification, \ 009 are permitted provided that the following conditions are met: 010 011 * Redistributions of source code must retain the above copyright notice, this \ 012 list of conditions and the following disclaimer. 013 * Redistributions in binary form must reproduce the above copyright notice, \ 014 this list of conditions and the following disclaimer in the documentation \ 015 and/or other materials provided with the distribution. 016 * Neither the name of HL7 nor the names of its contributors may be used to 017 endorse or promote products derived from this software without specific 018 prior written permission. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \ 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \ 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \ 023 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \ 024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \ 025 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \ 026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \ 027 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \ 028 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \ 029 POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032// Generated on Tue, Dec 28, 2021 07:16+1100 for FHIR v5.0.0-snapshot1 033 034import java.util.ArrayList; 035import java.util.Date; 036import java.util.List; 037import org.hl7.fhir.utilities.xhtml.NodeType; 038import org.hl7.fhir.utilities.xhtml.XhtmlNode; 039import org.hl7.fhir.utilities.Utilities; 040import org.hl7.fhir.r5.model.Enumerations.*; 041import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 042import org.hl7.fhir.exceptions.FHIRException; 043import org.hl7.fhir.instance.model.api.ICompositeType; 044import ca.uhn.fhir.model.api.annotation.Child; 045import ca.uhn.fhir.model.api.annotation.ChildOrder; 046import ca.uhn.fhir.model.api.annotation.DatatypeDef; 047import ca.uhn.fhir.model.api.annotation.Description; 048import ca.uhn.fhir.model.api.annotation.Block; 049 050import org.hl7.fhir.instance.model.api.INarrative; 051/** 052 * Base StructureDefinition for Narrative Type: A human-readable summary of the resource conveying the essential clinical and business information for the resource. 053 */ 054@DatatypeDef(name="Narrative") 055public class Narrative extends BaseNarrative implements INarrative { 056 057 public enum NarrativeStatus { 058 /** 059 * The contents of the narrative are entirely generated from the core elements in the content. 060 */ 061 GENERATED, 062 /** 063 * 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. 064 */ 065 EXTENSIONS, 066 /** 067 * 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. 068 */ 069 ADDITIONAL, 070 /** 071 * The contents of the narrative are some equivalent of \"No human-readable text provided in this case\". 072 */ 073 EMPTY, 074 /** 075 * added to help the parsers with the generic types 076 */ 077 NULL; 078 public static NarrativeStatus fromCode(String codeString) throws FHIRException { 079 if (codeString == null || "".equals(codeString)) 080 return null; 081 if ("generated".equals(codeString)) 082 return GENERATED; 083 if ("extensions".equals(codeString)) 084 return EXTENSIONS; 085 if ("additional".equals(codeString)) 086 return ADDITIONAL; 087 if ("empty".equals(codeString)) 088 return EMPTY; 089 if (Configuration.isAcceptInvalidEnums()) 090 return null; 091 else 092 throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'"); 093 } 094 public String toCode() { 095 switch (this) { 096 case GENERATED: return "generated"; 097 case EXTENSIONS: return "extensions"; 098 case ADDITIONAL: return "additional"; 099 case EMPTY: return "empty"; 100 default: return "?"; 101 } 102 } 103 public String getSystem() { 104 switch (this) { 105 case GENERATED: return "http://hl7.org/fhir/narrative-status"; 106 case EXTENSIONS: return "http://hl7.org/fhir/narrative-status"; 107 case ADDITIONAL: return "http://hl7.org/fhir/narrative-status"; 108 case EMPTY: return "http://hl7.org/fhir/narrative-status"; 109 default: return "?"; 110 } 111 } 112 public String getDefinition() { 113 switch (this) { 114 case GENERATED: return "The contents of the narrative are entirely generated from the core elements in the content."; 115 case EXTENSIONS: 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."; 116 case ADDITIONAL: 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."; 117 case EMPTY: return "The contents of the narrative are some equivalent of \"No human-readable text provided in this case\"."; 118 default: return "?"; 119 } 120 } 121 public String getDisplay() { 122 switch (this) { 123 case GENERATED: return "Generated"; 124 case EXTENSIONS: return "Extensions"; 125 case ADDITIONAL: return "Additional"; 126 case EMPTY: return "Empty"; 127 default: return "?"; 128 } 129 } 130 } 131 132 public static class NarrativeStatusEnumFactory implements EnumFactory<NarrativeStatus> { 133 public NarrativeStatus fromCode(String codeString) throws IllegalArgumentException { 134 if (codeString == null || "".equals(codeString)) 135 if (codeString == null || "".equals(codeString)) 136 return null; 137 if ("generated".equals(codeString)) 138 return NarrativeStatus.GENERATED; 139 if ("extensions".equals(codeString)) 140 return NarrativeStatus.EXTENSIONS; 141 if ("additional".equals(codeString)) 142 return NarrativeStatus.ADDITIONAL; 143 if ("empty".equals(codeString)) 144 return NarrativeStatus.EMPTY; 145 throw new IllegalArgumentException("Unknown NarrativeStatus code '"+codeString+"'"); 146 } 147 public Enumeration<NarrativeStatus> fromType(Base code) throws FHIRException { 148 if (code == null) 149 return null; 150 if (code.isEmpty()) 151 return new Enumeration<NarrativeStatus>(this); 152 String codeString = ((PrimitiveType) code).asStringValue(); 153 if (codeString == null || "".equals(codeString)) 154 return null; 155 if ("generated".equals(codeString)) 156 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.GENERATED); 157 if ("extensions".equals(codeString)) 158 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EXTENSIONS); 159 if ("additional".equals(codeString)) 160 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.ADDITIONAL); 161 if ("empty".equals(codeString)) 162 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EMPTY); 163 throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'"); 164 } 165 public String toCode(NarrativeStatus code) { 166 if (code == NarrativeStatus.GENERATED) 167 return "generated"; 168 if (code == NarrativeStatus.EXTENSIONS) 169 return "extensions"; 170 if (code == NarrativeStatus.ADDITIONAL) 171 return "additional"; 172 if (code == NarrativeStatus.EMPTY) 173 return "empty"; 174 return "?"; 175 } 176 public String toSystem(NarrativeStatus code) { 177 return code.getSystem(); 178 } 179 } 180 181 /** 182 * 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. 183 */ 184 @Child(name = "status", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=false) 185 @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." ) 186 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/narrative-status") 187 protected Enumeration<NarrativeStatus> status; 188 189 /** 190 * The actual narrative content, a stripped down version of XHTML. 191 */ 192 @Child(name = "div", type = {XhtmlType.class}, order=1, min=1, max=1, modifier=false, summary=false) 193 @Description(shortDefinition="Limited xhtml content", formalDefinition="The actual narrative content, a stripped down version of XHTML." ) 194 protected XhtmlNode div; 195 196 private static final long serialVersionUID = 1463852859L; 197 198 /** 199 * Constructor 200 */ 201 public Narrative() { 202 super(); 203 } 204 205 /** 206 * Constructor 207 */ 208 public Narrative(NarrativeStatus status, XhtmlNode div) { 209 super(); 210 this.setStatus(status); 211 this.setDiv(div); 212 } 213 214 /** 215 * @return {@link #status} (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.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value 216 */ 217 public Enumeration<NarrativeStatus> getStatusElement() { 218 if (this.status == null) 219 if (Configuration.errorOnAutoCreate()) 220 throw new Error("Attempt to auto-create Narrative.status"); 221 else if (Configuration.doAutoCreate()) 222 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); // bb 223 return this.status; 224 } 225 226 public boolean hasStatusElement() { 227 return this.status != null && !this.status.isEmpty(); 228 } 229 230 public boolean hasStatus() { 231 return this.status != null && !this.status.isEmpty(); 232 } 233 234 /** 235 * @param value {@link #status} (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.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value 236 */ 237 public Narrative setStatusElement(Enumeration<NarrativeStatus> value) { 238 this.status = value; 239 return this; 240 } 241 242 /** 243 * @return 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. 244 */ 245 public NarrativeStatus getStatus() { 246 return this.status == null ? null : this.status.getValue(); 247 } 248 249 /** 250 * @param value 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. 251 */ 252 public Narrative setStatus(NarrativeStatus value) { 253 if (this.status == null) 254 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); 255 this.status.setValue(value); 256 return this; 257 } 258 259 /** 260 * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.) 261 */ 262 public XhtmlNode getDiv() { 263 if (this.div == null) 264 if (Configuration.errorOnAutoCreate()) 265 throw new Error("Attempt to auto-create Narrative.div"); 266 else if (Configuration.doAutoCreate()) 267 this.div = new XhtmlNode(NodeType.Element, "div"); // cc.1 268 return this.div; 269 } 270 271 public boolean hasDiv() { 272 return this.div != null && !this.div.isEmpty(); 273 } 274 275 /** 276 * @param value {@link #div} (The actual narrative content, a stripped down version of XHTML.) 277 */ 278 public Narrative setDiv(XhtmlNode value) { 279 this.div = value; 280 return this; 281 } 282 283 protected void listChildren(List<Property> children) { 284 super.listChildren(children); 285 children.add(new Property("status", "code", "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.", 0, 1, status)); 286 } 287 288 @Override 289 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 290 switch (_hash) { 291 case -892481550: /*status*/ return new Property("status", "code", "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.", 0, 1, status); 292 default: return super.getNamedProperty(_hash, _name, _checkValid); 293 } 294 295 } 296 297 @Override 298 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 299 switch (hash) { 300 case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<NarrativeStatus> 301 case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div))}; // XhtmlNode 302 default: return super.getProperty(hash, name, checkValid); 303 } 304 305 } 306 307 @Override 308 public Base setProperty(int hash, String name, Base value) throws FHIRException { 309 switch (hash) { 310 case -892481550: // status 311 value = new NarrativeStatusEnumFactory().fromType(TypeConvertor.castToCode(value)); 312 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 313 return value; 314 case 99473: // div 315 this.div = TypeConvertor.castToXhtml(value); // XhtmlNode 316 return value; 317 default: return super.setProperty(hash, name, value); 318 } 319 320 } 321 322 @Override 323 public Base setProperty(String name, Base value) throws FHIRException { 324 if (name.equals("status")) { 325 value = new NarrativeStatusEnumFactory().fromType(TypeConvertor.castToCode(value)); 326 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 327 } else if (name.equals("div")) { 328 this.div = TypeConvertor.castToXhtml(value); // XhtmlNode 329 } else 330 return super.setProperty(name, value); 331 return value; 332 } 333 334 @Override 335 public Base makeProperty(int hash, String name) throws FHIRException { 336 switch (hash) { 337 case -892481550: return getStatusElement(); 338 case 99473: /*div*/ 339 if (div == null) 340 div = new XhtmlNode(NodeType.Element, "div"); 341 return new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div)); 342 default: return super.makeProperty(hash, name); 343 } 344 345 } 346 347 @Override 348 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 349 switch (hash) { 350 case -892481550: /*status*/ return new String[] {"code"}; 351 case 99473: /*div*/ return new String[] {"xhtml"}; 352 default: return super.getTypesForProperty(hash, name); 353 } 354 355 } 356 357 @Override 358 public Base addChild(String name) throws FHIRException { 359 if (name.equals("status")) { 360 throw new FHIRException("Cannot call addChild on a primitive type Narrative.status"); 361 } 362 else 363 return super.addChild(name); 364 } 365 366 public String fhirType() { 367 return "Narrative"; 368 369 } 370 371 public Narrative copy() { 372 Narrative dst = new Narrative(); 373 copyValues(dst); 374 return dst; 375 } 376 377 public void copyValues(Narrative dst) { 378 super.copyValues(dst); 379 dst.status = status == null ? null : status.copy(); 380 dst.div = div == null ? null : div.copy(); 381 } 382 383 protected Narrative typedCopy() { 384 return copy(); 385 } 386 387 @Override 388 public boolean equalsDeep(Base other_) { 389 if (!super.equalsDeep(other_)) 390 return false; 391 if (!(other_ instanceof Narrative)) 392 return false; 393 Narrative o = (Narrative) other_; 394 return compareDeep(status, o.status, true) && compareDeep(div, o.div, true); 395 } 396 397 @Override 398 public boolean equalsShallow(Base other_) { 399 if (!super.equalsShallow(other_)) 400 return false; 401 if (!(other_ instanceof Narrative)) 402 return false; 403 Narrative o = (Narrative) other_; 404 return compareValues(status, o.status, true); 405 } 406 407 public boolean isEmpty() { 408 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(status, div); 409 } 410 411 412} 413