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