001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.ChildOrder;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.DatatypeDef;
043import ca.uhn.fhir.model.api.annotation.Block;
044import org.hl7.fhir.instance.model.api.*;
045import org.hl7.fhir.exceptions.FHIRException;
046/**
047 * A  text note which also  contains information about who made the statement and when.
048 */
049@DatatypeDef(name="Annotation")
050public class Annotation extends Type implements ICompositeType {
051
052    /**
053     * The individual responsible for making the annotation.
054     */
055    @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class, Organization.class, StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
056    @Description(shortDefinition="Individual responsible for the annotation", formalDefinition="The individual responsible for making the annotation." )
057    protected Type author;
058
059    /**
060     * Indicates when this particular annotation was made.
061     */
062    @Child(name = "time", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @Description(shortDefinition="When the annotation was made", formalDefinition="Indicates when this particular annotation was made." )
064    protected DateTimeType time;
065
066    /**
067     * The text of the annotation in markdown format.
068     */
069    @Child(name = "text", type = {MarkdownType.class}, order=2, min=1, max=1, modifier=false, summary=true)
070    @Description(shortDefinition="The annotation  - text content (as markdown)", formalDefinition="The text of the annotation in markdown format." )
071    protected MarkdownType text;
072
073    private static final long serialVersionUID = 1324090545L;
074
075  /**
076   * Constructor
077   */
078    public Annotation() {
079      super();
080    }
081
082  /**
083   * Constructor
084   */
085    public Annotation(MarkdownType text) {
086      super();
087      this.text = text;
088    }
089
090    /**
091     * @return {@link #author} (The individual responsible for making the annotation.)
092     */
093    public Type getAuthor() { 
094      return this.author;
095    }
096
097    /**
098     * @return {@link #author} (The individual responsible for making the annotation.)
099     */
100    public Reference getAuthorReference() throws FHIRException { 
101      if (this.author == null)
102        this.author = new Reference();
103      if (!(this.author instanceof Reference))
104        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.author.getClass().getName()+" was encountered");
105      return (Reference) this.author;
106    }
107
108    public boolean hasAuthorReference() { 
109      return this != null && this.author instanceof Reference;
110    }
111
112    /**
113     * @return {@link #author} (The individual responsible for making the annotation.)
114     */
115    public StringType getAuthorStringType() throws FHIRException { 
116      if (this.author == null)
117        this.author = new StringType();
118      if (!(this.author instanceof StringType))
119        throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.author.getClass().getName()+" was encountered");
120      return (StringType) this.author;
121    }
122
123    public boolean hasAuthorStringType() { 
124      return this != null && this.author instanceof StringType;
125    }
126
127    public boolean hasAuthor() { 
128      return this.author != null && !this.author.isEmpty();
129    }
130
131    /**
132     * @param value {@link #author} (The individual responsible for making the annotation.)
133     */
134    public Annotation setAuthor(Type value) { 
135      if (value != null && !(value instanceof Reference || value instanceof StringType))
136        throw new Error("Not the right type for Annotation.author[x]: "+value.fhirType());
137      this.author = value;
138      return this;
139    }
140
141    /**
142     * @return {@link #time} (Indicates when this particular annotation was made.). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value
143     */
144    public DateTimeType getTimeElement() { 
145      if (this.time == null)
146        if (Configuration.errorOnAutoCreate())
147          throw new Error("Attempt to auto-create Annotation.time");
148        else if (Configuration.doAutoCreate())
149          this.time = new DateTimeType(); // bb
150      return this.time;
151    }
152
153    public boolean hasTimeElement() { 
154      return this.time != null && !this.time.isEmpty();
155    }
156
157    public boolean hasTime() { 
158      return this.time != null && !this.time.isEmpty();
159    }
160
161    /**
162     * @param value {@link #time} (Indicates when this particular annotation was made.). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value
163     */
164    public Annotation setTimeElement(DateTimeType value) { 
165      this.time = value;
166      return this;
167    }
168
169    /**
170     * @return Indicates when this particular annotation was made.
171     */
172    public Date getTime() { 
173      return this.time == null ? null : this.time.getValue();
174    }
175
176    /**
177     * @param value Indicates when this particular annotation was made.
178     */
179    public Annotation setTime(Date value) { 
180      if (value == null)
181        this.time = null;
182      else {
183        if (this.time == null)
184          this.time = new DateTimeType();
185        this.time.setValue(value);
186      }
187      return this;
188    }
189
190    /**
191     * @return {@link #text} (The text of the annotation in markdown format.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
192     */
193    public MarkdownType getTextElement() { 
194      if (this.text == null)
195        if (Configuration.errorOnAutoCreate())
196          throw new Error("Attempt to auto-create Annotation.text");
197        else if (Configuration.doAutoCreate())
198          this.text = new MarkdownType(); // bb
199      return this.text;
200    }
201
202    public boolean hasTextElement() { 
203      return this.text != null && !this.text.isEmpty();
204    }
205
206    public boolean hasText() { 
207      return this.text != null && !this.text.isEmpty();
208    }
209
210    /**
211     * @param value {@link #text} (The text of the annotation in markdown format.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
212     */
213    public Annotation setTextElement(MarkdownType value) { 
214      this.text = value;
215      return this;
216    }
217
218    /**
219     * @return The text of the annotation in markdown format.
220     */
221    public String getText() { 
222      return this.text == null ? null : this.text.getValue();
223    }
224
225    /**
226     * @param value The text of the annotation in markdown format.
227     */
228    public Annotation setText(String value) { 
229        if (this.text == null)
230          this.text = new MarkdownType();
231        this.text.setValue(value);
232      return this;
233    }
234
235      protected void listChildren(List<Property> children) {
236        super.listChildren(children);
237        children.add(new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author));
238        children.add(new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time));
239        children.add(new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text));
240      }
241
242      @Override
243      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
244        switch (_hash) {
245        case 1475597077: /*author[x]*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
246        case -1406328437: /*author*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
247        case 305515008: /*authorReference*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
248        case 290249084: /*authorString*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
249        case 3560141: /*time*/  return new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time);
250        case 3556653: /*text*/  return new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text);
251        default: return super.getNamedProperty(_hash, _name, _checkValid);
252        }
253
254      }
255
256      @Override
257      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
258        switch (hash) {
259        case -1406328437: /*author*/ return this.author == null ? new Base[0] : new Base[] {this.author}; // Type
260        case 3560141: /*time*/ return this.time == null ? new Base[0] : new Base[] {this.time}; // DateTimeType
261        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // MarkdownType
262        default: return super.getProperty(hash, name, checkValid);
263        }
264
265      }
266
267      @Override
268      public Base setProperty(int hash, String name, Base value) throws FHIRException {
269        switch (hash) {
270        case -1406328437: // author
271          this.author = castToType(value); // Type
272          return value;
273        case 3560141: // time
274          this.time = castToDateTime(value); // DateTimeType
275          return value;
276        case 3556653: // text
277          this.text = castToMarkdown(value); // MarkdownType
278          return value;
279        default: return super.setProperty(hash, name, value);
280        }
281
282      }
283
284      @Override
285      public Base setProperty(String name, Base value) throws FHIRException {
286        if (name.equals("author[x]")) {
287          this.author = castToType(value); // Type
288        } else if (name.equals("time")) {
289          this.time = castToDateTime(value); // DateTimeType
290        } else if (name.equals("text")) {
291          this.text = castToMarkdown(value); // MarkdownType
292        } else
293          return super.setProperty(name, value);
294        return value;
295      }
296
297      @Override
298      public Base makeProperty(int hash, String name) throws FHIRException {
299        switch (hash) {
300        case 1475597077:  return getAuthor(); 
301        case -1406328437:  return getAuthor(); 
302        case 3560141:  return getTimeElement();
303        case 3556653:  return getTextElement();
304        default: return super.makeProperty(hash, name);
305        }
306
307      }
308
309      @Override
310      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
311        switch (hash) {
312        case -1406328437: /*author*/ return new String[] {"Reference", "string"};
313        case 3560141: /*time*/ return new String[] {"dateTime"};
314        case 3556653: /*text*/ return new String[] {"markdown"};
315        default: return super.getTypesForProperty(hash, name);
316        }
317
318      }
319
320      @Override
321      public Base addChild(String name) throws FHIRException {
322        if (name.equals("authorReference")) {
323          this.author = new Reference();
324          return this.author;
325        }
326        else if (name.equals("authorString")) {
327          this.author = new StringType();
328          return this.author;
329        }
330        else if (name.equals("time")) {
331          throw new FHIRException("Cannot call addChild on a primitive type Annotation.time");
332        }
333        else if (name.equals("text")) {
334          throw new FHIRException("Cannot call addChild on a primitive type Annotation.text");
335        }
336        else
337          return super.addChild(name);
338      }
339
340  public String fhirType() {
341    return "Annotation";
342
343  }
344
345      public Annotation copy() {
346        Annotation dst = new Annotation();
347        copyValues(dst);
348        return dst;
349      }
350
351      public void copyValues(Annotation dst) {
352        super.copyValues(dst);
353        dst.author = author == null ? null : author.copy();
354        dst.time = time == null ? null : time.copy();
355        dst.text = text == null ? null : text.copy();
356      }
357
358      protected Annotation typedCopy() {
359        return copy();
360      }
361
362      @Override
363      public boolean equalsDeep(Base other_) {
364        if (!super.equalsDeep(other_))
365          return false;
366        if (!(other_ instanceof Annotation))
367          return false;
368        Annotation o = (Annotation) other_;
369        return compareDeep(author, o.author, true) && compareDeep(time, o.time, true) && compareDeep(text, o.text, true)
370          ;
371      }
372
373      @Override
374      public boolean equalsShallow(Base other_) {
375        if (!super.equalsShallow(other_))
376          return false;
377        if (!(other_ instanceof Annotation))
378          return false;
379        Annotation o = (Annotation) other_;
380        return compareValues(time, o.time, true) && compareValues(text, o.text, true);
381      }
382
383      public boolean isEmpty() {
384        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(author, time, text);
385      }
386
387
388}