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