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