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