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