001package org.hl7.fhir.r4.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 6, 2018 17:51-0400 for FHIR v3.4.0
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * A concept that may be defined by a formal reference to a terminology or ontology or may be provided by text.
046 */
047@DatatypeDef(name="CodeableConcept")
048public class CodeableConcept extends Type implements ICompositeType {
049
050    /**
051     * A reference to a code defined by a terminology system.
052     */
053    @Child(name = "coding", type = {Coding.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
054    @Description(shortDefinition="Code defined by a terminology system", formalDefinition="A reference to a code defined by a terminology system." )
055    protected List<Coding> coding;
056
057    /**
058     * A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.
059     */
060    @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
061    @Description(shortDefinition="Plain text representation of the concept", formalDefinition="A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user." )
062    protected StringType text;
063
064    private static final long serialVersionUID = 760353246L;
065
066  /**
067   * Constructor
068   */
069    public CodeableConcept() {
070      super();
071    }
072
073    /**
074     * @return {@link #coding} (A reference to a code defined by a terminology system.)
075     */
076    public List<Coding> getCoding() { 
077      if (this.coding == null)
078        this.coding = new ArrayList<Coding>();
079      return this.coding;
080    }
081
082    /**
083     * @return Returns a reference to <code>this</code> for easy method chaining
084     */
085    public CodeableConcept setCoding(List<Coding> theCoding) { 
086      this.coding = theCoding;
087      return this;
088    }
089
090    public boolean hasCoding() { 
091      if (this.coding == null)
092        return false;
093      for (Coding item : this.coding)
094        if (!item.isEmpty())
095          return true;
096      return false;
097    }
098
099    public Coding addCoding() { //3
100      Coding t = new Coding();
101      if (this.coding == null)
102        this.coding = new ArrayList<Coding>();
103      this.coding.add(t);
104      return t;
105    }
106
107    public CodeableConcept addCoding(Coding t) { //3
108      if (t == null)
109        return this;
110      if (this.coding == null)
111        this.coding = new ArrayList<Coding>();
112      this.coding.add(t);
113      return this;
114    }
115
116    /**
117     * @return The first repetition of repeating field {@link #coding}, creating it if it does not already exist
118     */
119    public Coding getCodingFirstRep() { 
120      if (getCoding().isEmpty()) {
121        addCoding();
122      }
123      return getCoding().get(0);
124    }
125
126    /**
127     * @return {@link #text} (A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
128     */
129    public StringType getTextElement() { 
130      if (this.text == null)
131        if (Configuration.errorOnAutoCreate())
132          throw new Error("Attempt to auto-create CodeableConcept.text");
133        else if (Configuration.doAutoCreate())
134          this.text = new StringType(); // bb
135      return this.text;
136    }
137
138    public boolean hasTextElement() { 
139      return this.text != null && !this.text.isEmpty();
140    }
141
142    public boolean hasText() { 
143      return this.text != null && !this.text.isEmpty();
144    }
145
146    /**
147     * @param value {@link #text} (A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
148     */
149    public CodeableConcept setTextElement(StringType value) { 
150      this.text = value;
151      return this;
152    }
153
154    /**
155     * @return A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.
156     */
157    public String getText() { 
158      return this.text == null ? null : this.text.getValue();
159    }
160
161    /**
162     * @param value A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.
163     */
164    public CodeableConcept setText(String value) { 
165      if (Utilities.noString(value))
166        this.text = null;
167      else {
168        if (this.text == null)
169          this.text = new StringType();
170        this.text.setValue(value);
171      }
172      return this;
173    }
174
175      protected void listChildren(List<Property> children) {
176        super.listChildren(children);
177        children.add(new Property("coding", "Coding", "A reference to a code defined by a terminology system.", 0, java.lang.Integer.MAX_VALUE, coding));
178        children.add(new Property("text", "string", "A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.", 0, 1, text));
179      }
180
181      @Override
182      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
183        switch (_hash) {
184        case -1355086998: /*coding*/  return new Property("coding", "Coding", "A reference to a code defined by a terminology system.", 0, java.lang.Integer.MAX_VALUE, coding);
185        case 3556653: /*text*/  return new Property("text", "string", "A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.", 0, 1, text);
186        default: return super.getNamedProperty(_hash, _name, _checkValid);
187        }
188
189      }
190
191      @Override
192      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
193        switch (hash) {
194        case -1355086998: /*coding*/ return this.coding == null ? new Base[0] : this.coding.toArray(new Base[this.coding.size()]); // Coding
195        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
196        default: return super.getProperty(hash, name, checkValid);
197        }
198
199      }
200
201      @Override
202      public Base setProperty(int hash, String name, Base value) throws FHIRException {
203        switch (hash) {
204        case -1355086998: // coding
205          this.getCoding().add(castToCoding(value)); // Coding
206          return value;
207        case 3556653: // text
208          this.text = castToString(value); // StringType
209          return value;
210        default: return super.setProperty(hash, name, value);
211        }
212
213      }
214
215      @Override
216      public Base setProperty(String name, Base value) throws FHIRException {
217        if (name.equals("coding")) {
218          this.getCoding().add(castToCoding(value));
219        } else if (name.equals("text")) {
220          this.text = castToString(value); // StringType
221        } else
222          return super.setProperty(name, value);
223        return value;
224      }
225
226      @Override
227      public Base makeProperty(int hash, String name) throws FHIRException {
228        switch (hash) {
229        case -1355086998:  return addCoding(); 
230        case 3556653:  return getTextElement();
231        default: return super.makeProperty(hash, name);
232        }
233
234      }
235
236      @Override
237      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
238        switch (hash) {
239        case -1355086998: /*coding*/ return new String[] {"Coding"};
240        case 3556653: /*text*/ return new String[] {"string"};
241        default: return super.getTypesForProperty(hash, name);
242        }
243
244      }
245
246      @Override
247      public Base addChild(String name) throws FHIRException {
248        if (name.equals("coding")) {
249          return addCoding();
250        }
251        else if (name.equals("text")) {
252          throw new FHIRException("Cannot call addChild on a primitive type CodeableConcept.text");
253        }
254        else
255          return super.addChild(name);
256      }
257
258  public String fhirType() {
259    return "CodeableConcept";
260
261  }
262
263      public CodeableConcept copy() {
264        CodeableConcept dst = new CodeableConcept();
265        copyValues(dst);
266        if (coding != null) {
267          dst.coding = new ArrayList<Coding>();
268          for (Coding i : coding)
269            dst.coding.add(i.copy());
270        };
271        dst.text = text == null ? null : text.copy();
272        return dst;
273      }
274
275      protected CodeableConcept typedCopy() {
276        return copy();
277      }
278
279      @Override
280      public boolean equalsDeep(Base other_) {
281        if (!super.equalsDeep(other_))
282          return false;
283        if (!(other_ instanceof CodeableConcept))
284          return false;
285        CodeableConcept o = (CodeableConcept) other_;
286        return compareDeep(coding, o.coding, true) && compareDeep(text, o.text, true);
287      }
288
289      @Override
290      public boolean equalsShallow(Base other_) {
291        if (!super.equalsShallow(other_))
292          return false;
293        if (!(other_ instanceof CodeableConcept))
294          return false;
295        CodeableConcept o = (CodeableConcept) other_;
296        return compareValues(text, o.text, true);
297      }
298
299      public boolean isEmpty() {
300        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(coding, text);
301      }
302
303
304}
305