001package org.hl7.fhir.dstu2016may.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
036import java.util.ArrayList;
037import java.util.List;
038
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.instance.model.api.ICompositeType;
041import org.hl7.fhir.utilities.Utilities;
042
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.DatatypeDef;
045import ca.uhn.fhir.model.api.annotation.Description;
046/**
047 * A concept that may be defined by a formal reference to a terminology or ontology or may be provided by text.
048 */
049@DatatypeDef(name="CodeableConcept")
050public class CodeableConcept extends Type implements ICompositeType {
051
052    /**
053     * A reference to a code defined by a terminology system.
054     */
055    @Child(name = "coding", type = {Coding.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
056    @Description(shortDefinition="Code defined by a terminology system", formalDefinition="A reference to a code defined by a terminology system." )
057    protected List<Coding> coding;
058
059    /**
060     * 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.
061     */
062    @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @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." )
064    protected StringType text;
065
066    private static final long serialVersionUID = 760353246L;
067
068  /**
069   * Constructor
070   */
071    public CodeableConcept() {
072      super();
073    }
074
075    /**
076     * @return {@link #coding} (A reference to a code defined by a terminology system.)
077     */
078    public List<Coding> getCoding() { 
079      if (this.coding == null)
080        this.coding = new ArrayList<Coding>();
081      return this.coding;
082    }
083
084    public boolean hasCoding() { 
085      if (this.coding == null)
086        return false;
087      for (Coding item : this.coding)
088        if (!item.isEmpty())
089          return true;
090      return false;
091    }
092
093    /**
094     * @return {@link #coding} (A reference to a code defined by a terminology system.)
095     */
096    // syntactic sugar
097    public Coding addCoding() { //3
098      Coding t = new Coding();
099      if (this.coding == null)
100        this.coding = new ArrayList<Coding>();
101      this.coding.add(t);
102      return t;
103    }
104
105    // syntactic sugar
106    public CodeableConcept addCoding(Coding t) { //3
107      if (t == null)
108        return this;
109      if (this.coding == null)
110        this.coding = new ArrayList<Coding>();
111      this.coding.add(t);
112      return this;
113    }
114
115    /**
116     * @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
117     */
118    public StringType getTextElement() { 
119      if (this.text == null)
120        if (Configuration.errorOnAutoCreate())
121          throw new Error("Attempt to auto-create CodeableConcept.text");
122        else if (Configuration.doAutoCreate())
123          this.text = new StringType(); // bb
124      return this.text;
125    }
126
127    public boolean hasTextElement() { 
128      return this.text != null && !this.text.isEmpty();
129    }
130
131    public boolean hasText() { 
132      return this.text != null && !this.text.isEmpty();
133    }
134
135    /**
136     * @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
137     */
138    public CodeableConcept setTextElement(StringType value) { 
139      this.text = value;
140      return this;
141    }
142
143    /**
144     * @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.
145     */
146    public String getText() { 
147      return this.text == null ? null : this.text.getValue();
148    }
149
150    /**
151     * @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.
152     */
153    public CodeableConcept setText(String value) { 
154      if (Utilities.noString(value))
155        this.text = null;
156      else {
157        if (this.text == null)
158          this.text = new StringType();
159        this.text.setValue(value);
160      }
161      return this;
162    }
163
164      protected void listChildren(List<Property> childrenList) {
165        super.listChildren(childrenList);
166        childrenList.add(new Property("coding", "Coding", "A reference to a code defined by a terminology system.", 0, java.lang.Integer.MAX_VALUE, coding));
167        childrenList.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, java.lang.Integer.MAX_VALUE, text));
168      }
169
170      @Override
171      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
172        switch (hash) {
173        case -1355086998: /*coding*/ return this.coding == null ? new Base[0] : this.coding.toArray(new Base[this.coding.size()]); // Coding
174        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
175        default: return super.getProperty(hash, name, checkValid);
176        }
177
178      }
179
180      @Override
181      public void setProperty(int hash, String name, Base value) throws FHIRException {
182        switch (hash) {
183        case -1355086998: // coding
184          this.getCoding().add(castToCoding(value)); // Coding
185          break;
186        case 3556653: // text
187          this.text = castToString(value); // StringType
188          break;
189        default: super.setProperty(hash, name, value);
190        }
191
192      }
193
194      @Override
195      public void setProperty(String name, Base value) throws FHIRException {
196        if (name.equals("coding"))
197          this.getCoding().add(castToCoding(value));
198        else if (name.equals("text"))
199          this.text = castToString(value); // StringType
200        else
201          super.setProperty(name, value);
202      }
203
204      @Override
205      public Base makeProperty(int hash, String name) throws FHIRException {
206        switch (hash) {
207        case -1355086998:  return addCoding(); // Coding
208        case 3556653: throw new FHIRException("Cannot make property text as it is not a complex type"); // StringType
209        default: return super.makeProperty(hash, name);
210        }
211
212      }
213
214      @Override
215      public Base addChild(String name) throws FHIRException {
216        if (name.equals("coding")) {
217          return addCoding();
218        }
219        else if (name.equals("text")) {
220          throw new FHIRException("Cannot call addChild on a primitive type CodeableConcept.text");
221        }
222        else
223          return super.addChild(name);
224      }
225
226  public String fhirType() {
227    return "CodeableConcept";
228
229  }
230
231      public CodeableConcept copy() {
232        CodeableConcept dst = new CodeableConcept();
233        copyValues(dst);
234        if (coding != null) {
235          dst.coding = new ArrayList<Coding>();
236          for (Coding i : coding)
237            dst.coding.add(i.copy());
238        };
239        dst.text = text == null ? null : text.copy();
240        return dst;
241      }
242
243      protected CodeableConcept typedCopy() {
244        return copy();
245      }
246
247      @Override
248      public boolean equalsDeep(Base other) {
249        if (!super.equalsDeep(other))
250          return false;
251        if (!(other instanceof CodeableConcept))
252          return false;
253        CodeableConcept o = (CodeableConcept) other;
254        return compareDeep(coding, o.coding, true) && compareDeep(text, o.text, true);
255      }
256
257      @Override
258      public boolean equalsShallow(Base other) {
259        if (!super.equalsShallow(other))
260          return false;
261        if (!(other instanceof CodeableConcept))
262          return false;
263        CodeableConcept o = (CodeableConcept) other;
264        return compareValues(text, o.text, true);
265      }
266
267      public boolean isEmpty() {
268        return super.isEmpty() && (coding == null || coding.isEmpty()) && (text == null || text.isEmpty())
269          ;
270      }
271
272
273}