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