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