001package org.hl7.fhir.r4.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
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 Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0
053import java.util.Date;
054import java.util.List;
055
056import org.hl7.fhir.exceptions.FHIRException;
057import org.hl7.fhir.instance.model.api.ICompositeType;
058
059import ca.uhn.fhir.model.api.annotation.Child;
060import ca.uhn.fhir.model.api.annotation.DatatypeDef;
061import ca.uhn.fhir.model.api.annotation.Description;
062/**
063 * A  text note which also  contains information about who made the statement and when.
064 */
065@DatatypeDef(name="Annotation")
066public class Annotation extends Type implements ICompositeType {
067
068    /**
069     * The individual responsible for making the annotation.
070     */
071    @Child(name = "author", type = {Practitioner.class, Patient.class, RelatedPerson.class, Organization.class, StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
072    @Description(shortDefinition="Individual responsible for the annotation", formalDefinition="The individual responsible for making the annotation." )
073    protected Type author;
074
075    /**
076     * Indicates when this particular annotation was made.
077     */
078    @Child(name = "time", type = {DateTimeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
079    @Description(shortDefinition="When the annotation was made", formalDefinition="Indicates when this particular annotation was made." )
080    protected DateTimeType time;
081
082    /**
083     * The text of the annotation in markdown format.
084     */
085    @Child(name = "text", type = {MarkdownType.class}, order=2, min=1, max=1, modifier=false, summary=true)
086    @Description(shortDefinition="The annotation  - text content (as markdown)", formalDefinition="The text of the annotation in markdown format." )
087    protected MarkdownType text;
088
089    private static final long serialVersionUID = 1324090545L;
090
091  /**
092   * Constructor
093   */
094    public Annotation() {
095      super();
096    }
097
098  /**
099   * Constructor
100   */
101    public Annotation(MarkdownType text) {
102      super();
103      this.text = text;
104    }
105
106    /**
107     * @return {@link #author} (The individual responsible for making the annotation.)
108     */
109    public Type getAuthor() { 
110      return this.author;
111    }
112
113    /**
114     * @return {@link #author} (The individual responsible for making the annotation.)
115     */
116    public Reference getAuthorReference() throws FHIRException { 
117      if (this.author == null)
118        this.author = new Reference();
119      if (!(this.author instanceof Reference))
120        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.author.getClass().getName()+" was encountered");
121      return (Reference) this.author;
122    }
123
124    public boolean hasAuthorReference() { 
125      return this != null && this.author instanceof Reference;
126    }
127
128    /**
129     * @return {@link #author} (The individual responsible for making the annotation.)
130     */
131    public StringType getAuthorStringType() throws FHIRException { 
132      if (this.author == null)
133        this.author = new StringType();
134      if (!(this.author instanceof StringType))
135        throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.author.getClass().getName()+" was encountered");
136      return (StringType) this.author;
137    }
138
139    public boolean hasAuthorStringType() { 
140      return this != null && this.author instanceof StringType;
141    }
142
143    public boolean hasAuthor() { 
144      return this.author != null && !this.author.isEmpty();
145    }
146
147    /**
148     * @param value {@link #author} (The individual responsible for making the annotation.)
149     */
150    public Annotation setAuthor(Type value) { 
151      if (value != null && !(value instanceof Reference || value instanceof StringType))
152        throw new Error("Not the right type for Annotation.author[x]: "+value.fhirType());
153      this.author = value;
154      return this;
155    }
156
157    /**
158     * @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
159     */
160    public DateTimeType getTimeElement() { 
161      if (this.time == null)
162        if (Configuration.errorOnAutoCreate())
163          throw new Error("Attempt to auto-create Annotation.time");
164        else if (Configuration.doAutoCreate())
165          this.time = new DateTimeType(); // bb
166      return this.time;
167    }
168
169    public boolean hasTimeElement() { 
170      return this.time != null && !this.time.isEmpty();
171    }
172
173    public boolean hasTime() { 
174      return this.time != null && !this.time.isEmpty();
175    }
176
177    /**
178     * @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
179     */
180    public Annotation setTimeElement(DateTimeType value) { 
181      this.time = value;
182      return this;
183    }
184
185    /**
186     * @return Indicates when this particular annotation was made.
187     */
188    public Date getTime() { 
189      return this.time == null ? null : this.time.getValue();
190    }
191
192    /**
193     * @param value Indicates when this particular annotation was made.
194     */
195    public Annotation setTime(Date value) { 
196      if (value == null)
197        this.time = null;
198      else {
199        if (this.time == null)
200          this.time = new DateTimeType();
201        this.time.setValue(value);
202      }
203      return this;
204    }
205
206    /**
207     * @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
208     */
209    public MarkdownType getTextElement() { 
210      if (this.text == null)
211        if (Configuration.errorOnAutoCreate())
212          throw new Error("Attempt to auto-create Annotation.text");
213        else if (Configuration.doAutoCreate())
214          this.text = new MarkdownType(); // bb
215      return this.text;
216    }
217
218    public boolean hasTextElement() { 
219      return this.text != null && !this.text.isEmpty();
220    }
221
222    public boolean hasText() { 
223      return this.text != null && !this.text.isEmpty();
224    }
225
226    /**
227     * @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
228     */
229    public Annotation setTextElement(MarkdownType value) { 
230      this.text = value;
231      return this;
232    }
233
234    /**
235     * @return The text of the annotation in markdown format.
236     */
237    public String getText() { 
238      return this.text == null ? null : this.text.getValue();
239    }
240
241    /**
242     * @param value The text of the annotation in markdown format.
243     */
244    public Annotation setText(String value) { 
245        if (this.text == null)
246          this.text = new MarkdownType();
247        this.text.setValue(value);
248      return this;
249    }
250
251      protected void listChildren(List<Property> children) {
252        super.listChildren(children);
253        children.add(new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author));
254        children.add(new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time));
255        children.add(new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text));
256      }
257
258      @Override
259      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
260        switch (_hash) {
261        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);
262        case -1406328437: /*author*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
263        case 305515008: /*authorReference*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
264        case 290249084: /*authorString*/  return new Property("author[x]", "Reference(Practitioner|Patient|RelatedPerson|Organization)|string", "The individual responsible for making the annotation.", 0, 1, author);
265        case 3560141: /*time*/  return new Property("time", "dateTime", "Indicates when this particular annotation was made.", 0, 1, time);
266        case 3556653: /*text*/  return new Property("text", "markdown", "The text of the annotation in markdown format.", 0, 1, text);
267        default: return super.getNamedProperty(_hash, _name, _checkValid);
268        }
269
270      }
271
272      @Override
273      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
274        switch (hash) {
275        case -1406328437: /*author*/ return this.author == null ? new Base[0] : new Base[] {this.author}; // Type
276        case 3560141: /*time*/ return this.time == null ? new Base[0] : new Base[] {this.time}; // DateTimeType
277        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // MarkdownType
278        default: return super.getProperty(hash, name, checkValid);
279        }
280
281      }
282
283      @Override
284      public Base setProperty(int hash, String name, Base value) throws FHIRException {
285        switch (hash) {
286        case -1406328437: // author
287          this.author = castToType(value); // Type
288          return value;
289        case 3560141: // time
290          this.time = castToDateTime(value); // DateTimeType
291          return value;
292        case 3556653: // text
293          this.text = castToMarkdown(value); // MarkdownType
294          return value;
295        default: return super.setProperty(hash, name, value);
296        }
297
298      }
299
300      @Override
301      public Base setProperty(String name, Base value) throws FHIRException {
302        if (name.equals("author[x]")) {
303          this.author = castToType(value); // Type
304        } else if (name.equals("time")) {
305          this.time = castToDateTime(value); // DateTimeType
306        } else if (name.equals("text")) {
307          this.text = castToMarkdown(value); // MarkdownType
308        } else
309          return super.setProperty(name, value);
310        return value;
311      }
312
313      @Override
314      public Base makeProperty(int hash, String name) throws FHIRException {
315        switch (hash) {
316        case 1475597077:  return getAuthor(); 
317        case -1406328437:  return getAuthor(); 
318        case 3560141:  return getTimeElement();
319        case 3556653:  return getTextElement();
320        default: return super.makeProperty(hash, name);
321        }
322
323      }
324
325      @Override
326      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
327        switch (hash) {
328        case -1406328437: /*author*/ return new String[] {"Reference", "string"};
329        case 3560141: /*time*/ return new String[] {"dateTime"};
330        case 3556653: /*text*/ return new String[] {"markdown"};
331        default: return super.getTypesForProperty(hash, name);
332        }
333
334      }
335
336      @Override
337      public Base addChild(String name) throws FHIRException {
338        if (name.equals("authorReference")) {
339          this.author = new Reference();
340          return this.author;
341        }
342        else if (name.equals("authorString")) {
343          this.author = new StringType();
344          return this.author;
345        }
346        else if (name.equals("time")) {
347          throw new FHIRException("Cannot call addChild on a primitive type Annotation.time");
348        }
349        else if (name.equals("text")) {
350          throw new FHIRException("Cannot call addChild on a primitive type Annotation.text");
351        }
352        else
353          return super.addChild(name);
354      }
355
356  public String fhirType() {
357    return "Annotation";
358
359  }
360
361      public Annotation copy() {
362        Annotation dst = new Annotation();
363        copyValues(dst);
364        dst.author = author == null ? null : author.copy();
365        dst.time = time == null ? null : time.copy();
366        dst.text = text == null ? null : text.copy();
367        return dst;
368      }
369
370      protected Annotation typedCopy() {
371        return copy();
372      }
373
374      @Override
375      public boolean equalsDeep(Base other_) {
376        if (!super.equalsDeep(other_))
377          return false;
378        if (!(other_ instanceof Annotation))
379          return false;
380        Annotation o = (Annotation) other_;
381        return compareDeep(author, o.author, true) && compareDeep(time, o.time, true) && compareDeep(text, o.text, true)
382          ;
383      }
384
385      @Override
386      public boolean equalsShallow(Base other_) {
387        if (!super.equalsShallow(other_))
388          return false;
389        if (!(other_ instanceof Annotation))
390          return false;
391        Annotation o = (Annotation) other_;
392        return compareValues(time, o.time, true) && compareValues(text, o.text, true);
393      }
394
395      public boolean isEmpty() {
396        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(author, time, text);
397      }
398
399
400}
401