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