001package org.hl7.fhir.r5.model;
002
003
004/*
005 * #%L
006 * org.hl7.fhir.r5
007 * %%
008 * Copyright (C) 2014 - 2019 Health Level 7
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the \"License\");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 * 
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 * 
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an \"AS IS\" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * #L%
022 */
023
024/*
025  Copyright (c) 2011+, HL7, Inc.
026  All rights reserved.
027  
028  Redistribution and use in source and binary forms, with or without modification, \
029  are permitted provided that the following conditions are met:
030  
031   * Redistributions of source code must retain the above copyright notice, this \
032     list of conditions and the following disclaimer.
033   * Redistributions in binary form must reproduce the above copyright notice, \
034     this list of conditions and the following disclaimer in the documentation \
035     and/or other materials provided with the distribution.
036   * Neither the name of HL7 nor the names of its contributors may be used to 
037     endorse or promote products derived from this software without specific 
038     prior written permission.
039  
040  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
041  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
042  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
043  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
044  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
045  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
046  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
047  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
048  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
049  POSSIBILITY OF SUCH DAMAGE.
050  */
051
052// Generated on Tue, Dec 31, 2019 12:12+1100 for FHIR vcurrent
053
054import java.util.ArrayList;
055import java.util.Date;
056import java.util.List;
057import org.hl7.fhir.utilities.Utilities;
058import org.hl7.fhir.r5.model.Enumerations.*;
059import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
060import org.hl7.fhir.exceptions.FHIRException;
061import org.hl7.fhir.instance.model.api.ICompositeType;
062import ca.uhn.fhir.model.api.annotation.Child;
063import ca.uhn.fhir.model.api.annotation.ChildOrder;
064import ca.uhn.fhir.model.api.annotation.DatatypeDef;
065import ca.uhn.fhir.model.api.annotation.Description;
066import ca.uhn.fhir.model.api.annotation.Block;
067
068/**
069 * Base StructureDefinition for CodeableConcept Type: A concept that may be defined by a formal reference to a terminology or ontology or may be provided by text.
070 */
071@DatatypeDef(name="CodeableConcept")
072public class CodeableConcept extends DataType implements ICompositeType {
073
074    /**
075     * A reference to a code defined by a terminology system.
076     */
077    @Child(name = "coding", type = {Coding.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
078    @Description(shortDefinition="Code defined by a terminology system", formalDefinition="A reference to a code defined by a terminology system." )
079    protected List<Coding> coding;
080
081    /**
082     * 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.
083     */
084    @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
085    @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." )
086    protected StringType text;
087
088    private static final long serialVersionUID = 760353246L;
089
090  /**
091   * Constructor
092   */
093    public CodeableConcept() {
094      super();
095    }
096
097    /**
098     * @return {@link #coding} (A reference to a code defined by a terminology system.)
099     */
100    public List<Coding> getCoding() { 
101      if (this.coding == null)
102        this.coding = new ArrayList<Coding>();
103      return this.coding;
104    }
105
106    /**
107     * @return Returns a reference to <code>this</code> for easy method chaining
108     */
109    public CodeableConcept setCoding(List<Coding> theCoding) { 
110      this.coding = theCoding;
111      return this;
112    }
113
114    public boolean hasCoding() { 
115      if (this.coding == null)
116        return false;
117      for (Coding item : this.coding)
118        if (!item.isEmpty())
119          return true;
120      return false;
121    }
122
123    public Coding addCoding() { //3
124      Coding t = new Coding();
125      if (this.coding == null)
126        this.coding = new ArrayList<Coding>();
127      this.coding.add(t);
128      return t;
129    }
130
131    public CodeableConcept addCoding(Coding t) { //3
132      if (t == null)
133        return this;
134      if (this.coding == null)
135        this.coding = new ArrayList<Coding>();
136      this.coding.add(t);
137      return this;
138    }
139
140    /**
141     * @return The first repetition of repeating field {@link #coding}, creating it if it does not already exist {3}
142     */
143    public Coding getCodingFirstRep() { 
144      if (getCoding().isEmpty()) {
145        addCoding();
146      }
147      return getCoding().get(0);
148    }
149
150    /**
151     * @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
152     */
153    public StringType getTextElement() { 
154      if (this.text == null)
155        if (Configuration.errorOnAutoCreate())
156          throw new Error("Attempt to auto-create CodeableConcept.text");
157        else if (Configuration.doAutoCreate())
158          this.text = new StringType(); // bb
159      return this.text;
160    }
161
162    public boolean hasTextElement() { 
163      return this.text != null && !this.text.isEmpty();
164    }
165
166    public boolean hasText() { 
167      return this.text != null && !this.text.isEmpty();
168    }
169
170    /**
171     * @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
172     */
173    public CodeableConcept setTextElement(StringType value) { 
174      this.text = value;
175      return this;
176    }
177
178    /**
179     * @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.
180     */
181    public String getText() { 
182      return this.text == null ? null : this.text.getValue();
183    }
184
185    /**
186     * @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.
187     */
188    public CodeableConcept setText(String value) { 
189      if (Utilities.noString(value))
190        this.text = null;
191      else {
192        if (this.text == null)
193          this.text = new StringType();
194        this.text.setValue(value);
195      }
196      return this;
197    }
198
199      protected void listChildren(List<Property> children) {
200        super.listChildren(children);
201        children.add(new Property("coding", "Coding", "A reference to a code defined by a terminology system.", 0, java.lang.Integer.MAX_VALUE, coding));
202        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));
203      }
204
205      @Override
206      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
207        switch (_hash) {
208        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);
209        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);
210        default: return super.getNamedProperty(_hash, _name, _checkValid);
211        }
212
213      }
214
215      @Override
216      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
217        switch (hash) {
218        case -1355086998: /*coding*/ return this.coding == null ? new Base[0] : this.coding.toArray(new Base[this.coding.size()]); // Coding
219        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
220        default: return super.getProperty(hash, name, checkValid);
221        }
222
223      }
224
225      @Override
226      public Base setProperty(int hash, String name, Base value) throws FHIRException {
227        switch (hash) {
228        case -1355086998: // coding
229          this.getCoding().add(TypeConvertor.castToCoding(value)); // Coding
230          return value;
231        case 3556653: // text
232          this.text = TypeConvertor.castToString(value); // StringType
233          return value;
234        default: return super.setProperty(hash, name, value);
235        }
236
237      }
238
239      @Override
240      public Base setProperty(String name, Base value) throws FHIRException {
241        if (name.equals("coding")) {
242          this.getCoding().add(TypeConvertor.castToCoding(value));
243        } else if (name.equals("text")) {
244          this.text = TypeConvertor.castToString(value); // StringType
245        } else
246          return super.setProperty(name, value);
247        return value;
248      }
249
250      @Override
251      public Base makeProperty(int hash, String name) throws FHIRException {
252        switch (hash) {
253        case -1355086998:  return addCoding(); 
254        case 3556653:  return getTextElement();
255        default: return super.makeProperty(hash, name);
256        }
257
258      }
259
260      @Override
261      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
262        switch (hash) {
263        case -1355086998: /*coding*/ return new String[] {"Coding"};
264        case 3556653: /*text*/ return new String[] {"string"};
265        default: return super.getTypesForProperty(hash, name);
266        }
267
268      }
269
270      @Override
271      public Base addChild(String name) throws FHIRException {
272        if (name.equals("coding")) {
273          return addCoding();
274        }
275        else if (name.equals("text")) {
276          throw new FHIRException("Cannot call addChild on a primitive type CodeableConcept.text");
277        }
278        else
279          return super.addChild(name);
280      }
281
282  public String fhirType() {
283    return "CodeableConcept";
284
285  }
286
287      public CodeableConcept copy() {
288        CodeableConcept dst = new CodeableConcept();
289        copyValues(dst);
290        return dst;
291      }
292
293      public void copyValues(CodeableConcept dst) {
294        super.copyValues(dst);
295        if (coding != null) {
296          dst.coding = new ArrayList<Coding>();
297          for (Coding i : coding)
298            dst.coding.add(i.copy());
299        };
300        dst.text = text == null ? null : text.copy();
301      }
302
303      protected CodeableConcept typedCopy() {
304        return copy();
305      }
306
307      @Override
308      public boolean equalsDeep(Base other_) {
309        if (!super.equalsDeep(other_))
310          return false;
311        if (!(other_ instanceof CodeableConcept))
312          return false;
313        CodeableConcept o = (CodeableConcept) other_;
314        return compareDeep(coding, o.coding, true) && compareDeep(text, o.text, true);
315      }
316
317      @Override
318      public boolean equalsShallow(Base other_) {
319        if (!super.equalsShallow(other_))
320          return false;
321        if (!(other_ instanceof CodeableConcept))
322          return false;
323        CodeableConcept o = (CodeableConcept) other_;
324        return compareValues(text, o.text, true);
325      }
326
327      public boolean isEmpty() {
328        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(coding, text);
329      }
330
331// Manual code (from Configuration.txt)t:
332 
333  public boolean hasCoding(String system, String code) {
334    for (Coding c : getCoding()) {
335      if (system.equals(c.getSystem()) && code.equals(c.getCode()))
336        return true;
337    }
338    return false;
339  } 
340
341  public CodeableConcept(Coding code) {
342    super();
343    addCoding(code);
344  }
345  
346  
347
348// end addition
349
350}
351