001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.ArrayList;
034import java.util.List;
035
036import org.hl7.fhir.exceptions.FHIRException;
037import org.hl7.fhir.instance.model.api.ICompositeType;
038import org.hl7.fhir.utilities.Utilities;
039
040import ca.uhn.fhir.model.api.annotation.*;
041/**
042 * A concept that may be defined by a formal reference to a terminology or ontology or may be provided by text.
043 */
044@DatatypeDef(name="CodeableConcept")
045public class CodeableConcept extends Type implements ICompositeType {
046
047    /**
048     * A reference to a code defined by a terminology system.
049     */
050    @Child(name = "coding", type = {Coding.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
051    @Description(shortDefinition="Code defined by a terminology system", formalDefinition="A reference to a code defined by a terminology system." )
052    protected List<Coding> coding;
053
054    /**
055     * 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.
056     */
057    @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
058    @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." )
059    protected StringType text;
060
061    private static final long serialVersionUID = 760353246L;
062
063  /*
064   * Constructor
065   */
066    public CodeableConcept() {
067      super();
068    }
069
070    /**
071     * @return {@link #coding} (A reference to a code defined by a terminology system.)
072     */
073    public List<Coding> getCoding() { 
074      if (this.coding == null)
075        this.coding = new ArrayList<Coding>();
076      return this.coding;
077    }
078
079    public boolean hasCoding() { 
080      if (this.coding == null)
081        return false;
082      for (Coding item : this.coding)
083        if (!item.isEmpty())
084          return true;
085      return false;
086    }
087
088    /**
089     * @return {@link #coding} (A reference to a code defined by a terminology system.)
090     */
091    // syntactic sugar
092    public Coding addCoding() { //3
093      Coding t = new Coding();
094      if (this.coding == null)
095        this.coding = new ArrayList<Coding>();
096      this.coding.add(t);
097      return t;
098    }
099
100    // syntactic sugar
101    public CodeableConcept addCoding(Coding t) { //3
102      if (t == null)
103        return this;
104      if (this.coding == null)
105        this.coding = new ArrayList<Coding>();
106      this.coding.add(t);
107      return this;
108    }
109
110    /**
111     * @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
112     */
113    public StringType getTextElement() { 
114      if (this.text == null)
115        if (Configuration.errorOnAutoCreate())
116          throw new Error("Attempt to auto-create CodeableConcept.text");
117        else if (Configuration.doAutoCreate())
118          this.text = new StringType(); // bb
119      return this.text;
120    }
121
122    public boolean hasTextElement() { 
123      return this.text != null && !this.text.isEmpty();
124    }
125
126    public boolean hasText() { 
127      return this.text != null && !this.text.isEmpty();
128    }
129
130    /**
131     * @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
132     */
133    public CodeableConcept setTextElement(StringType value) { 
134      this.text = value;
135      return this;
136    }
137
138    /**
139     * @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.
140     */
141    public String getText() { 
142      return this.text == null ? null : this.text.getValue();
143    }
144
145    /**
146     * @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.
147     */
148    public CodeableConcept setText(String value) { 
149      if (Utilities.noString(value))
150        this.text = null;
151      else {
152        if (this.text == null)
153          this.text = new StringType();
154        this.text.setValue(value);
155      }
156      return this;
157    }
158
159      protected void listChildren(List<Property> childrenList) {
160        super.listChildren(childrenList);
161        childrenList.add(new Property("coding", "Coding", "A reference to a code defined by a terminology system.", 0, java.lang.Integer.MAX_VALUE, coding));
162        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));
163      }
164
165      @Override
166      public void setProperty(String name, Base value) throws FHIRException {
167        if (name.equals("coding"))
168          this.getCoding().add(castToCoding(value));
169        else if (name.equals("text"))
170          this.text = castToString(value); // StringType
171        else
172          super.setProperty(name, value);
173      }
174
175      @Override
176      public Base addChild(String name) throws FHIRException {
177        if (name.equals("coding")) {
178          return addCoding();
179        }
180        else if (name.equals("text")) {
181          throw new FHIRException("Cannot call addChild on a primitive type CodeableConcept.text");
182        }
183        else
184          return super.addChild(name);
185      }
186
187  public String fhirType() {
188    return "CodeableConcept";
189
190  }
191
192      public CodeableConcept copy() {
193        CodeableConcept dst = new CodeableConcept();
194        copyValues(dst);
195        if (coding != null) {
196          dst.coding = new ArrayList<Coding>();
197          for (Coding i : coding)
198            dst.coding.add(i.copy());
199        };
200        dst.text = text == null ? null : text.copy();
201        return dst;
202      }
203
204      protected CodeableConcept typedCopy() {
205        return copy();
206      }
207
208      @Override
209      public boolean equalsDeep(Base other) {
210        if (!super.equalsDeep(other))
211          return false;
212        if (!(other instanceof CodeableConcept))
213          return false;
214        CodeableConcept o = (CodeableConcept) other;
215        return compareDeep(coding, o.coding, true) && compareDeep(text, o.text, true);
216      }
217
218      @Override
219      public boolean equalsShallow(Base other) {
220        if (!super.equalsShallow(other))
221          return false;
222        if (!(other instanceof CodeableConcept))
223          return false;
224        CodeableConcept o = (CodeableConcept) other;
225        return compareValues(text, o.text, true);
226      }
227
228      public boolean isEmpty() {
229        return super.isEmpty() && (coding == null || coding.isEmpty()) && (text == null || text.isEmpty())
230          ;
231      }
232
233
234}
235