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