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