001package org.hl7.fhir.instance.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.Date;
034import java.util.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.instance.model.api.ICompositeType;
038
039import ca.uhn.fhir.model.api.annotation.*;
040/**
041 * A  text note which also  contains information about who made the statement and when.
042 */
043@DatatypeDef(name="Annotation")
044public class Annotation extends Type implements ICompositeType {
045
046    /**
047     * The individual responsible for making the annotation.
048     */
049    @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class, StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
050    @Description(shortDefinition="Individual responsible for the annotation", formalDefinition="The individual responsible for making the annotation." )
051    protected Type author;
052
053    /**
054     * Indicates when this particular annotation was made.
055     */
056    @Child(name = "time", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
057    @Description(shortDefinition="When the annotation was made", formalDefinition="Indicates when this particular annotation was made." )
058    protected DateTimeType time;
059
060    /**
061     * The text of the annotation.
062     */
063    @Child(name = "text", type = {StringType.class}, order=2, min=1, max=1, modifier=false, summary=true)
064    @Description(shortDefinition="The annotation  - text content", formalDefinition="The text of the annotation." )
065    protected StringType text;
066
067    private static final long serialVersionUID = -575590381L;
068
069  /*
070   * Constructor
071   */
072    public Annotation() {
073      super();
074    }
075
076  /*
077   * Constructor
078   */
079    public Annotation(StringType text) {
080      super();
081      this.text = text;
082    }
083
084    /**
085     * @return {@link #author} (The individual responsible for making the annotation.)
086     */
087    public Type getAuthor() { 
088      return this.author;
089    }
090
091    /**
092     * @return {@link #author} (The individual responsible for making the annotation.)
093     */
094    public Reference getAuthorReference() throws FHIRException { 
095      if (!(this.author instanceof Reference))
096        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.author.getClass().getName()+" was encountered");
097      return (Reference) this.author;
098    }
099
100    public boolean hasAuthorReference() { 
101      return this.author instanceof Reference;
102    }
103
104    /**
105     * @return {@link #author} (The individual responsible for making the annotation.)
106     */
107    public StringType getAuthorStringType() throws FHIRException { 
108      if (!(this.author instanceof StringType))
109        throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.author.getClass().getName()+" was encountered");
110      return (StringType) this.author;
111    }
112
113    public boolean hasAuthorStringType() { 
114      return this.author instanceof StringType;
115    }
116
117    public boolean hasAuthor() { 
118      return this.author != null && !this.author.isEmpty();
119    }
120
121    /**
122     * @param value {@link #author} (The individual responsible for making the annotation.)
123     */
124    public Annotation setAuthor(Type value) { 
125      this.author = value;
126      return this;
127    }
128
129    /**
130     * @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
131     */
132    public DateTimeType getTimeElement() { 
133      if (this.time == null)
134        if (Configuration.errorOnAutoCreate())
135          throw new Error("Attempt to auto-create Annotation.time");
136        else if (Configuration.doAutoCreate())
137          this.time = new DateTimeType(); // bb
138      return this.time;
139    }
140
141    public boolean hasTimeElement() { 
142      return this.time != null && !this.time.isEmpty();
143    }
144
145    public boolean hasTime() { 
146      return this.time != null && !this.time.isEmpty();
147    }
148
149    /**
150     * @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
151     */
152    public Annotation setTimeElement(DateTimeType value) { 
153      this.time = value;
154      return this;
155    }
156
157    /**
158     * @return Indicates when this particular annotation was made.
159     */
160    public Date getTime() { 
161      return this.time == null ? null : this.time.getValue();
162    }
163
164    /**
165     * @param value Indicates when this particular annotation was made.
166     */
167    public Annotation setTime(Date value) { 
168      if (value == null)
169        this.time = null;
170      else {
171        if (this.time == null)
172          this.time = new DateTimeType();
173        this.time.setValue(value);
174      }
175      return this;
176    }
177
178    /**
179     * @return {@link #text} (The text of the annotation.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
180     */
181    public StringType getTextElement() { 
182      if (this.text == null)
183        if (Configuration.errorOnAutoCreate())
184          throw new Error("Attempt to auto-create Annotation.text");
185        else if (Configuration.doAutoCreate())
186          this.text = new StringType(); // bb
187      return this.text;
188    }
189
190    public boolean hasTextElement() { 
191      return this.text != null && !this.text.isEmpty();
192    }
193
194    public boolean hasText() { 
195      return this.text != null && !this.text.isEmpty();
196    }
197
198    /**
199     * @param value {@link #text} (The text of the annotation.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
200     */
201    public Annotation setTextElement(StringType value) { 
202      this.text = value;
203      return this;
204    }
205
206    /**
207     * @return The text of the annotation.
208     */
209    public String getText() { 
210      return this.text == null ? null : this.text.getValue();
211    }
212
213    /**
214     * @param value The text of the annotation.
215     */
216    public Annotation setText(String value) { 
217        if (this.text == null)
218          this.text = new StringType();
219        this.text.setValue(value);
220      return this;
221    }
222
223      protected void listChildren(List<Property> childrenList) {
224        super.listChildren(childrenList);
225        childrenList.add(new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson)|string", "The individual responsible for making the annotation.", 0, java.lang.Integer.MAX_VALUE, author));
226        childrenList.add(new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, java.lang.Integer.MAX_VALUE, time));
227        childrenList.add(new Property("text", "string", "The text of the annotation.", 0, java.lang.Integer.MAX_VALUE, text));
228      }
229
230      @Override
231      public void setProperty(String name, Base value) throws FHIRException {
232        if (name.equals("author[x]"))
233          this.author = (Type) value; // Type
234        else if (name.equals("time"))
235          this.time = castToDateTime(value); // DateTimeType
236        else if (name.equals("text"))
237          this.text = castToString(value); // StringType
238        else
239          super.setProperty(name, value);
240      }
241
242      @Override
243      public Base addChild(String name) throws FHIRException {
244        if (name.equals("authorReference")) {
245          this.author = new Reference();
246          return this.author;
247        }
248        else if (name.equals("authorString")) {
249          this.author = new StringType();
250          return this.author;
251        }
252        else if (name.equals("time")) {
253          throw new FHIRException("Cannot call addChild on a primitive type Annotation.time");
254        }
255        else if (name.equals("text")) {
256          throw new FHIRException("Cannot call addChild on a primitive type Annotation.text");
257        }
258        else
259          return super.addChild(name);
260      }
261
262  public String fhirType() {
263    return "Annotation";
264
265  }
266
267      public Annotation copy() {
268        Annotation dst = new Annotation();
269        copyValues(dst);
270        dst.author = author == null ? null : author.copy();
271        dst.time = time == null ? null : time.copy();
272        dst.text = text == null ? null : text.copy();
273        return dst;
274      }
275
276      protected Annotation typedCopy() {
277        return copy();
278      }
279
280      @Override
281      public boolean equalsDeep(Base other) {
282        if (!super.equalsDeep(other))
283          return false;
284        if (!(other instanceof Annotation))
285          return false;
286        Annotation o = (Annotation) other;
287        return compareDeep(author, o.author, true) && compareDeep(time, o.time, true) && compareDeep(text, o.text, true)
288          ;
289      }
290
291      @Override
292      public boolean equalsShallow(Base other) {
293        if (!super.equalsShallow(other))
294          return false;
295        if (!(other instanceof Annotation))
296          return false;
297        Annotation o = (Annotation) other;
298        return compareValues(time, o.time, true) && compareValues(text, o.text, true);
299      }
300
301      public boolean isEmpty() {
302        return super.isEmpty() && (author == null || author.isEmpty()) && (time == null || time.isEmpty())
303           && (text == null || text.isEmpty());
304      }
305
306
307}
308