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