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