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