001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 08:38+1000 for FHIR v3.0.1 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.xhtml.XhtmlComposer; 037import org.hl7.fhir.utilities.xhtml.XhtmlNode; 038 039import org.hl7.fhir.utilities.Utilities; 040import ca.uhn.fhir.model.api.annotation.Child; 041import ca.uhn.fhir.model.api.annotation.ChildOrder; 042import ca.uhn.fhir.model.api.annotation.Description; 043import ca.uhn.fhir.model.api.annotation.DatatypeDef; 044import ca.uhn.fhir.model.api.annotation.Block; 045import org.hl7.fhir.instance.model.api.*; 046import org.hl7.fhir.exceptions.FHIRException; 047/** 048 * A human-readable formatted text, including images. 049 */ 050@DatatypeDef(name="Narrative") 051public class Narrative extends BaseNarrative implements INarrative { 052 053 public enum NarrativeStatus { 054 /** 055 * The contents of the narrative are entirely generated from the structured data in the content. 056 */ 057 GENERATED, 058 /** 059 * The contents of the narrative are entirely generated from the structured data in the content and some of the content is generated from extensions 060 */ 061 EXTENSIONS, 062 /** 063 * 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 064 */ 065 ADDITIONAL, 066 /** 067 * The contents of the narrative are some equivalent of "No human-readable text provided in this case" 068 */ 069 EMPTY, 070 /** 071 * added to help the parsers with the generic types 072 */ 073 NULL; 074 public static NarrativeStatus fromCode(String codeString) throws FHIRException { 075 if (codeString == null || "".equals(codeString)) 076 return null; 077 if ("generated".equals(codeString)) 078 return GENERATED; 079 if ("extensions".equals(codeString)) 080 return EXTENSIONS; 081 if ("additional".equals(codeString)) 082 return ADDITIONAL; 083 if ("empty".equals(codeString)) 084 return EMPTY; 085 if (Configuration.isAcceptInvalidEnums()) 086 return null; 087 else 088 throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'"); 089 } 090 public String toCode() { 091 switch (this) { 092 case GENERATED: return "generated"; 093 case EXTENSIONS: return "extensions"; 094 case ADDITIONAL: return "additional"; 095 case EMPTY: return "empty"; 096 default: return "?"; 097 } 098 } 099 public String getSystem() { 100 switch (this) { 101 case GENERATED: return "http://hl7.org/fhir/narrative-status"; 102 case EXTENSIONS: return "http://hl7.org/fhir/narrative-status"; 103 case ADDITIONAL: return "http://hl7.org/fhir/narrative-status"; 104 case EMPTY: return "http://hl7.org/fhir/narrative-status"; 105 default: return "?"; 106 } 107 } 108 public String getDefinition() { 109 switch (this) { 110 case GENERATED: return "The contents of the narrative are entirely generated from the structured data in the content."; 111 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"; 112 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"; 113 case EMPTY: return "The contents of the narrative are some equivalent of \"No human-readable text provided in this case\""; 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 default: return "?"; 124 } 125 } 126 } 127 128 public static class NarrativeStatusEnumFactory implements EnumFactory<NarrativeStatus> { 129 public NarrativeStatus fromCode(String codeString) throws IllegalArgumentException { 130 if (codeString == null || "".equals(codeString)) 131 if (codeString == null || "".equals(codeString)) 132 return null; 133 if ("generated".equals(codeString)) 134 return NarrativeStatus.GENERATED; 135 if ("extensions".equals(codeString)) 136 return NarrativeStatus.EXTENSIONS; 137 if ("additional".equals(codeString)) 138 return NarrativeStatus.ADDITIONAL; 139 if ("empty".equals(codeString)) 140 return NarrativeStatus.EMPTY; 141 throw new IllegalArgumentException("Unknown NarrativeStatus code '"+codeString+"'"); 142 } 143 public Enumeration<NarrativeStatus> fromType(Base code) throws FHIRException { 144 if (code == null) 145 return null; 146 if (code.isEmpty()) 147 return new Enumeration<NarrativeStatus>(this); 148 String codeString = ((PrimitiveType) code).asStringValue(); 149 if (codeString == null || "".equals(codeString)) 150 return null; 151 if ("generated".equals(codeString)) 152 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.GENERATED); 153 if ("extensions".equals(codeString)) 154 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EXTENSIONS); 155 if ("additional".equals(codeString)) 156 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.ADDITIONAL); 157 if ("empty".equals(codeString)) 158 return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EMPTY); 159 throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'"); 160 } 161 public String toCode(NarrativeStatus code) { 162 if (code == NarrativeStatus.GENERATED) 163 return "generated"; 164 if (code == NarrativeStatus.EXTENSIONS) 165 return "extensions"; 166 if (code == NarrativeStatus.ADDITIONAL) 167 return "additional"; 168 if (code == NarrativeStatus.EMPTY) 169 return "empty"; 170 return "?"; 171 } 172 public String toSystem(NarrativeStatus code) { 173 return code.getSystem(); 174 } 175 } 176 177 /** 178 * 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. 179 */ 180 @Child(name = "status", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=false) 181 @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." ) 182 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/narrative-status") 183 protected Enumeration<NarrativeStatus> status; 184 185 /** 186 * The actual narrative content, a stripped down version of XHTML. 187 */ 188 @Child(name = "div", type = {}, order=1, min=1, max=1, modifier=false, summary=false) 189 @Description(shortDefinition="Limited xhtml content", formalDefinition="The actual narrative content, a stripped down version of XHTML." ) 190 protected XhtmlNode div; 191 192 private static final long serialVersionUID = 1463852859L; 193 194 /** 195 * Constructor 196 */ 197 public Narrative() { 198 super(); 199 } 200 201 /** 202 * Constructor 203 */ 204 public Narrative(Enumeration<NarrativeStatus> status, XhtmlNode div) { 205 super(); 206 this.status = status; 207 this.div = div; 208 } 209 210 /** 211 * @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 212 */ 213 public Enumeration<NarrativeStatus> getStatusElement() { 214 if (this.status == null) 215 if (Configuration.errorOnAutoCreate()) 216 throw new Error("Attempt to auto-create Narrative.status"); 217 else if (Configuration.doAutoCreate()) 218 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); // bb 219 return this.status; 220 } 221 222 public boolean hasStatusElement() { 223 return this.status != null && !this.status.isEmpty(); 224 } 225 226 public boolean hasStatus() { 227 return this.status != null && !this.status.isEmpty(); 228 } 229 230 /** 231 * @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 232 */ 233 public Narrative setStatusElement(Enumeration<NarrativeStatus> value) { 234 this.status = value; 235 return this; 236 } 237 238 /** 239 * @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. 240 */ 241 public NarrativeStatus getStatus() { 242 return this.status == null ? null : this.status.getValue(); 243 } 244 245 /** 246 * @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. 247 */ 248 public Narrative setStatus(NarrativeStatus value) { 249 if (this.status == null) 250 this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); 251 this.status.setValue(value); 252 return this; 253 } 254 255 /** 256 * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.) 257 */ 258 public XhtmlNode getDiv() { 259 if (this.div == null) 260 if (Configuration.errorOnAutoCreate()) 261 throw new Error("Attempt to auto-create Narrative.div"); 262 else if (Configuration.doAutoCreate()) 263 this.div = new XhtmlNode(); // cc 264 return this.div; 265 } 266 267 public boolean hasDiv() { 268 return this.div != null && !this.div.isEmpty(); 269 } 270 271 /** 272 * @param value {@link #div} (The actual narrative content, a stripped down version of XHTML.) 273 */ 274 public Narrative setDiv(XhtmlNode value) { 275 this.div = value; 276 return this; 277 } 278 279 protected void listChildren(List<Property> childrenList) { 280 super.listChildren(childrenList); 281 childrenList.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, java.lang.Integer.MAX_VALUE, status)); 282 } 283 284 @Override 285 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 286 switch (hash) { 287 case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<NarrativeStatus> 288 case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(XhtmlComposer.XML).composeEx(this.div))}; // XhtmlNode 289 default: return super.getProperty(hash, name, checkValid); 290 } 291 292 } 293 294 @Override 295 public Base setProperty(int hash, String name, Base value) throws FHIRException { 296 switch (hash) { 297 case -892481550: // status 298 value = new NarrativeStatusEnumFactory().fromType(castToCode(value)); 299 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 300 return value; 301 case 99473: // div 302 this.div = castToXhtml(value); // XhtmlNode 303 return value; 304 default: return super.setProperty(hash, name, value); 305 } 306 307 } 308 309 @Override 310 public Base setProperty(String name, Base value) throws FHIRException { 311 if (name.equals("status")) { 312 value = new NarrativeStatusEnumFactory().fromType(castToCode(value)); 313 this.status = (Enumeration) value; // Enumeration<NarrativeStatus> 314 } else if (name.equals("div")) { 315 this.div = castToXhtml(value); // XhtmlNode 316 } else 317 return super.setProperty(name, value); 318 return value; 319 } 320 321 @Override 322 public Base makeProperty(int hash, String name) throws FHIRException { 323 switch (hash) { 324 case -892481550: return getStatusElement(); 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 -892481550: /*status*/ return new String[] {"code"}; 334 case 99473: /*div*/ return new String[] {"xhtml"}; 335 default: return super.getTypesForProperty(hash, name); 336 } 337 338 } 339 340 @Override 341 public Base addChild(String name) throws FHIRException { 342 if (name.equals("status")) { 343 throw new FHIRException("Cannot call addChild on a primitive type Narrative.status"); 344 } 345 else 346 return super.addChild(name); 347 } 348 349 public String fhirType() { 350 return "Narrative"; 351 352 } 353 354 public Narrative copy() { 355 Narrative dst = new Narrative(); 356 copyValues(dst); 357 dst.status = status == null ? null : status.copy(); 358 dst.div = div == null ? null : div.copy(); 359 return dst; 360 } 361 362 protected Narrative typedCopy() { 363 return copy(); 364 } 365 366 @Override 367 public boolean equalsDeep(Base other) { 368 if (!super.equalsDeep(other)) 369 return false; 370 if (!(other instanceof Narrative)) 371 return false; 372 Narrative o = (Narrative) other; 373 return compareDeep(status, o.status, true) && compareDeep(div, o.div, true); 374 } 375 376 @Override 377 public boolean equalsShallow(Base other) { 378 if (!super.equalsShallow(other)) 379 return false; 380 if (!(other instanceof Narrative)) 381 return false; 382 Narrative o = (Narrative) other; 383 return compareValues(status, o.status, true); 384 } 385 386 public boolean isEmpty() { 387 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(status, div); 388 } 389 390 391} 392