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