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