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