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