001package org.hl7.fhir.dstu2.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu2
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/*
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
053// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
054import java.util.List;
055
056import ca.uhn.fhir.model.api.annotation.Child;
057import ca.uhn.fhir.model.api.annotation.DatatypeDef;
058import ca.uhn.fhir.model.api.annotation.Description;
059import org.hl7.fhir.instance.model.api.INarrative;
060import org.hl7.fhir.exceptions.FHIRException;
061import org.hl7.fhir.utilities.xhtml.XhtmlNode;
062/**
063 * A human-readable formatted text, including images.
064 */
065@DatatypeDef(name="Narrative")
066public class Narrative extends BaseNarrative implements INarrative {
067
068    public enum NarrativeStatus {
069        /**
070         * The contents of the narrative are entirely generated from the structured data in the content.
071         */
072        GENERATED, 
073        /**
074         * The contents of the narrative are entirely generated from the structured data in the content and some of the content is generated from extensions
075         */
076        EXTENSIONS, 
077        /**
078         * The contents of the narrative contain additional information not found in the structured data
079         */
080        ADDITIONAL, 
081        /**
082         * The contents of the narrative are some equivalent of "No human-readable text provided in this case"
083         */
084        EMPTY, 
085        /**
086         * added to help the parsers
087         */
088        NULL;
089        public static NarrativeStatus fromCode(String codeString) throws FHIRException {
090            if (codeString == null || "".equals(codeString))
091                return null;
092        if ("generated".equals(codeString))
093          return GENERATED;
094        if ("extensions".equals(codeString))
095          return EXTENSIONS;
096        if ("additional".equals(codeString))
097          return ADDITIONAL;
098        if ("empty".equals(codeString))
099          return EMPTY;
100        throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'");
101        }
102        public String toCode() {
103          switch (this) {
104            case GENERATED: return "generated";
105            case EXTENSIONS: return "extensions";
106            case ADDITIONAL: return "additional";
107            case EMPTY: return "empty";
108            default: return "?";
109          }
110        }
111        public String getSystem() {
112          switch (this) {
113            case GENERATED: return "http://hl7.org/fhir/narrative-status";
114            case EXTENSIONS: return "http://hl7.org/fhir/narrative-status";
115            case ADDITIONAL: return "http://hl7.org/fhir/narrative-status";
116            case EMPTY: return "http://hl7.org/fhir/narrative-status";
117            default: return "?";
118          }
119        }
120        public String getDefinition() {
121          switch (this) {
122            case GENERATED: return "The contents of the narrative are entirely generated from the structured data in the content.";
123            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";
124            case ADDITIONAL: return "The contents of the narrative contain additional information not found in the structured data";
125            case EMPTY: return "The contents of the narrative are some equivalent of \"No human-readable text provided in this case\"";
126            default: return "?";
127          }
128        }
129        public String getDisplay() {
130          switch (this) {
131            case GENERATED: return "Generated";
132            case EXTENSIONS: return "Extensions";
133            case ADDITIONAL: return "Additional";
134            case EMPTY: return "Empty";
135            default: return "?";
136          }
137        }
138    }
139
140  public static class NarrativeStatusEnumFactory implements EnumFactory<NarrativeStatus> {
141    public NarrativeStatus fromCode(String codeString) throws IllegalArgumentException {
142      if (codeString == null || "".equals(codeString))
143            if (codeString == null || "".equals(codeString))
144                return null;
145        if ("generated".equals(codeString))
146          return NarrativeStatus.GENERATED;
147        if ("extensions".equals(codeString))
148          return NarrativeStatus.EXTENSIONS;
149        if ("additional".equals(codeString))
150          return NarrativeStatus.ADDITIONAL;
151        if ("empty".equals(codeString))
152          return NarrativeStatus.EMPTY;
153        throw new IllegalArgumentException("Unknown NarrativeStatus code '"+codeString+"'");
154        }
155        public Enumeration<NarrativeStatus> fromType(Base code) throws FHIRException {
156          if (code == null || code.isEmpty())
157            return null;
158          String codeString = ((PrimitiveType) code).asStringValue();
159          if (codeString == null || "".equals(codeString))
160            return null;
161        if ("generated".equals(codeString))
162          return new Enumeration<NarrativeStatus>(this, NarrativeStatus.GENERATED);
163        if ("extensions".equals(codeString))
164          return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EXTENSIONS);
165        if ("additional".equals(codeString))
166          return new Enumeration<NarrativeStatus>(this, NarrativeStatus.ADDITIONAL);
167        if ("empty".equals(codeString))
168          return new Enumeration<NarrativeStatus>(this, NarrativeStatus.EMPTY);
169        throw new FHIRException("Unknown NarrativeStatus code '"+codeString+"'");
170        }
171    public String toCode(NarrativeStatus code) {
172      if (code == NarrativeStatus.GENERATED)
173        return "generated";
174      if (code == NarrativeStatus.EXTENSIONS)
175        return "extensions";
176      if (code == NarrativeStatus.ADDITIONAL)
177        return "additional";
178      if (code == NarrativeStatus.EMPTY)
179        return "empty";
180      return "?";
181      }
182    }
183
184    /**
185     * 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.
186     */
187    @Child(name = "status", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=false)
188    @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." )
189    protected Enumeration<NarrativeStatus> status;
190
191    /**
192     * The actual narrative content, a stripped down version of XHTML.
193     */
194    @Child(name = "div", type = {}, order=1, min=1, max=1, modifier=false, summary=false)
195    @Description(shortDefinition="Limited xhtml content", formalDefinition="The actual narrative content, a stripped down version of XHTML." )
196    protected XhtmlNode div;
197
198    private static final long serialVersionUID = 1463852859L;
199
200  /*
201   * Constructor
202   */
203    public Narrative() {
204      super();
205    }
206
207  /*
208   * Constructor
209   */
210    public Narrative(Enumeration<NarrativeStatus> status, XhtmlNode div) {
211      super();
212      this.status = status;
213      this.div = div;
214    }
215
216    /**
217     * @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
218     */
219    public Enumeration<NarrativeStatus> getStatusElement() { 
220      if (this.status == null)
221        if (Configuration.errorOnAutoCreate())
222          throw new Error("Attempt to auto-create Narrative.status");
223        else if (Configuration.doAutoCreate())
224          this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory()); // bb
225      return this.status;
226    }
227
228    public boolean hasStatusElement() { 
229      return this.status != null && !this.status.isEmpty();
230    }
231
232    public boolean hasStatus() { 
233      return this.status != null && !this.status.isEmpty();
234    }
235
236    /**
237     * @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
238     */
239    public Narrative setStatusElement(Enumeration<NarrativeStatus> value) { 
240      this.status = value;
241      return this;
242    }
243
244    /**
245     * @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.
246     */
247    public NarrativeStatus getStatus() { 
248      return this.status == null ? null : this.status.getValue();
249    }
250
251    /**
252     * @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.
253     */
254    public Narrative setStatus(NarrativeStatus value) { 
255        if (this.status == null)
256          this.status = new Enumeration<NarrativeStatus>(new NarrativeStatusEnumFactory());
257        this.status.setValue(value);
258      return this;
259    }
260
261    /**
262     * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.)
263     */
264    public XhtmlNode getDiv() { 
265      if (this.div == null)
266        if (Configuration.errorOnAutoCreate())
267          throw new Error("Attempt to auto-create Narrative.div");
268        else if (Configuration.doAutoCreate())
269          this.div = new XhtmlNode(); // cc
270      return this.div;
271    }
272
273    public boolean hasDiv() { 
274      return this.div != null && !this.div.isEmpty();
275    }
276
277    /**
278     * @param value {@link #div} (The actual narrative content, a stripped down version of XHTML.)
279     */
280    public Narrative setDiv(XhtmlNode value) { 
281      this.div = value;
282      return this;
283    }
284
285      protected void listChildren(List<Property> childrenList) {
286        super.listChildren(childrenList);
287        childrenList.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, java.lang.Integer.MAX_VALUE, status));
288      }
289
290      @Override
291      public void setProperty(String name, Base value) throws FHIRException {
292        if (name.equals("status"))
293          this.status = new NarrativeStatusEnumFactory().fromType(value); // Enumeration<NarrativeStatus>
294        else
295          super.setProperty(name, value);
296      }
297
298      @Override
299      public Base addChild(String name) throws FHIRException {
300        if (name.equals("status")) {
301          throw new FHIRException("Cannot call addChild on a primitive type Narrative.status");
302        }
303        else
304          return super.addChild(name);
305      }
306
307  public String fhirType() {
308    return "Narrative";
309
310  }
311
312      public Narrative copy() {
313        Narrative dst = new Narrative();
314        copyValues(dst);
315        dst.status = status == null ? null : status.copy();
316        dst.div = div == null ? null : div.copy();
317        return dst;
318      }
319
320      protected Narrative typedCopy() {
321        return copy();
322      }
323
324      @Override
325      public boolean equalsDeep(Base other) {
326        if (!super.equalsDeep(other))
327          return false;
328        if (!(other instanceof Narrative))
329          return false;
330        Narrative o = (Narrative) other;
331        return compareDeep(status, o.status, true) && compareDeep(div, o.div, true);
332      }
333
334      @Override
335      public boolean equalsShallow(Base other) {
336        if (!super.equalsShallow(other))
337          return false;
338        if (!(other instanceof Narrative))
339          return false;
340        Narrative o = (Narrative) other;
341        return compareValues(status, o.status, true);
342      }
343
344      public boolean isEmpty() {
345        return super.isEmpty() && (status == null || status.isEmpty()) && (div == null || div.isEmpty())
346          ;
347      }
348
349
350}
351