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