001package org.hl7.fhir.r5.model; 002 003 004/* 005 * #%L 006 * org.hl7.fhir.r5 007 * %% 008 * Copyright (C) 2014 - 2019 Health Level 7 009 * %% 010 * Licensed under the Apache License, Version 2.0 (the \"License\"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an \"AS IS\" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * #L% 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// Generated on Tue, Dec 31, 2019 12:12+1100 for FHIR vcurrent 053 054import java.util.ArrayList; 055import java.util.Date; 056import java.util.List; 057import org.hl7.fhir.r5.model.Enumerations.*; 058import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 059import org.hl7.fhir.exceptions.FHIRException; 060import org.hl7.fhir.instance.model.api.ICompositeType; 061import ca.uhn.fhir.model.api.annotation.Child; 062import ca.uhn.fhir.model.api.annotation.ChildOrder; 063import ca.uhn.fhir.model.api.annotation.DatatypeDef; 064import ca.uhn.fhir.model.api.annotation.Description; 065import ca.uhn.fhir.model.api.annotation.Block; 066 067/** 068 * Base StructureDefinition for UsageContext Type: Specifies clinical/business/etc. metadata that can be used to retrieve, index and/or categorize an artifact. This metadata can either be specific to the applicable population (e.g., age category, DRG) or the specific context of care (e.g., venue, care setting, provider of care). 069 */ 070@DatatypeDef(name="UsageContext") 071public class UsageContext extends DataType implements ICompositeType { 072 073 /** 074 * A code that identifies the type of context being specified by this usage context. 075 */ 076 @Child(name = "code", type = {Coding.class}, order=0, min=1, max=1, modifier=false, summary=true) 077 @Description(shortDefinition="Type of context being specified", formalDefinition="A code that identifies the type of context being specified by this usage context." ) 078 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/usage-context-type") 079 protected Coding code; 080 081 /** 082 * A value that defines the context specified in this context of use. The interpretation of the value is defined by the code. 083 */ 084 @Child(name = "value", type = {CodeableConcept.class, Quantity.class, Range.class, PlanDefinition.class, ResearchStudy.class, InsurancePlan.class, HealthcareService.class, Group.class, Location.class, Organization.class}, order=1, min=1, max=1, modifier=false, summary=true) 085 @Description(shortDefinition="Value that defines the context", formalDefinition="A value that defines the context specified in this context of use. The interpretation of the value is defined by the code." ) 086 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/use-context") 087 protected DataType value; 088 089 private static final long serialVersionUID = -1546390646L; 090 091 /** 092 * Constructor 093 */ 094 public UsageContext() { 095 super(); 096 } 097 098 /** 099 * Constructor 100 */ 101 public UsageContext(Coding code, DataType value) { 102 super(); 103 this.setCode(code); 104 this.setValue(value); 105 } 106 107 /** 108 * @return {@link #code} (A code that identifies the type of context being specified by this usage context.) 109 */ 110 public Coding getCode() { 111 if (this.code == null) 112 if (Configuration.errorOnAutoCreate()) 113 throw new Error("Attempt to auto-create UsageContext.code"); 114 else if (Configuration.doAutoCreate()) 115 this.code = new Coding(); // cc 116 return this.code; 117 } 118 119 public boolean hasCode() { 120 return this.code != null && !this.code.isEmpty(); 121 } 122 123 /** 124 * @param value {@link #code} (A code that identifies the type of context being specified by this usage context.) 125 */ 126 public UsageContext setCode(Coding value) { 127 this.code = value; 128 return this; 129 } 130 131 /** 132 * @return {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 133 */ 134 public DataType getValue() { 135 return this.value; 136 } 137 138 /** 139 * @return {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 140 */ 141 public CodeableConcept getValueCodeableConcept() throws FHIRException { 142 if (this.value == null) 143 this.value = new CodeableConcept(); 144 if (!(this.value instanceof CodeableConcept)) 145 throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered"); 146 return (CodeableConcept) this.value; 147 } 148 149 public boolean hasValueCodeableConcept() { 150 return this != null && this.value instanceof CodeableConcept; 151 } 152 153 /** 154 * @return {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 155 */ 156 public Quantity getValueQuantity() throws FHIRException { 157 if (this.value == null) 158 this.value = new Quantity(); 159 if (!(this.value instanceof Quantity)) 160 throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered"); 161 return (Quantity) this.value; 162 } 163 164 public boolean hasValueQuantity() { 165 return this != null && this.value instanceof Quantity; 166 } 167 168 /** 169 * @return {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 170 */ 171 public Range getValueRange() throws FHIRException { 172 if (this.value == null) 173 this.value = new Range(); 174 if (!(this.value instanceof Range)) 175 throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered"); 176 return (Range) this.value; 177 } 178 179 public boolean hasValueRange() { 180 return this != null && this.value instanceof Range; 181 } 182 183 /** 184 * @return {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 185 */ 186 public Reference getValueReference() throws FHIRException { 187 if (this.value == null) 188 this.value = new Reference(); 189 if (!(this.value instanceof Reference)) 190 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.value.getClass().getName()+" was encountered"); 191 return (Reference) this.value; 192 } 193 194 public boolean hasValueReference() { 195 return this != null && this.value instanceof Reference; 196 } 197 198 public boolean hasValue() { 199 return this.value != null && !this.value.isEmpty(); 200 } 201 202 /** 203 * @param value {@link #value} (A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.) 204 */ 205 public UsageContext setValue(DataType value) { 206 if (value != null && !(value instanceof CodeableConcept || value instanceof Quantity || value instanceof Range || value instanceof Reference)) 207 throw new Error("Not the right type for UsageContext.value[x]: "+value.fhirType()); 208 this.value = value; 209 return this; 210 } 211 212 protected void listChildren(List<Property> children) { 213 super.listChildren(children); 214 children.add(new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, 1, code)); 215 children.add(new Property("value[x]", "CodeableConcept|Quantity|Range|Reference(PlanDefinition|ResearchStudy|InsurancePlan|HealthcareService|Group|Location|Organization)", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value)); 216 } 217 218 @Override 219 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 220 switch (_hash) { 221 case 3059181: /*code*/ return new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, 1, code); 222 case -1410166417: /*value[x]*/ return new Property("value[x]", "CodeableConcept|Quantity|Range|Reference(PlanDefinition|ResearchStudy|InsurancePlan|HealthcareService|Group|Location|Organization)", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 223 case 111972721: /*value*/ return new Property("value[x]", "CodeableConcept|Quantity|Range|Reference(PlanDefinition|ResearchStudy|InsurancePlan|HealthcareService|Group|Location|Organization)", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 224 case 924902896: /*valueCodeableConcept*/ return new Property("value[x]", "CodeableConcept", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 225 case -2029823716: /*valueQuantity*/ return new Property("value[x]", "Quantity", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 226 case 2030761548: /*valueRange*/ return new Property("value[x]", "Range", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 227 case 1755241690: /*valueReference*/ return new Property("value[x]", "Reference(PlanDefinition|ResearchStudy|InsurancePlan|HealthcareService|Group|Location|Organization)", "A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.", 0, 1, value); 228 default: return super.getNamedProperty(_hash, _name, _checkValid); 229 } 230 231 } 232 233 @Override 234 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 235 switch (hash) { 236 case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // Coding 237 case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // DataType 238 default: return super.getProperty(hash, name, checkValid); 239 } 240 241 } 242 243 @Override 244 public Base setProperty(int hash, String name, Base value) throws FHIRException { 245 switch (hash) { 246 case 3059181: // code 247 this.code = TypeConvertor.castToCoding(value); // Coding 248 return value; 249 case 111972721: // value 250 this.value = TypeConvertor.castToType(value); // DataType 251 return value; 252 default: return super.setProperty(hash, name, value); 253 } 254 255 } 256 257 @Override 258 public Base setProperty(String name, Base value) throws FHIRException { 259 if (name.equals("code")) { 260 this.code = TypeConvertor.castToCoding(value); // Coding 261 } else if (name.equals("value[x]")) { 262 this.value = TypeConvertor.castToType(value); // DataType 263 } else 264 return super.setProperty(name, value); 265 return value; 266 } 267 268 @Override 269 public Base makeProperty(int hash, String name) throws FHIRException { 270 switch (hash) { 271 case 3059181: return getCode(); 272 case -1410166417: return getValue(); 273 case 111972721: return getValue(); 274 default: return super.makeProperty(hash, name); 275 } 276 277 } 278 279 @Override 280 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 281 switch (hash) { 282 case 3059181: /*code*/ return new String[] {"Coding"}; 283 case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range", "Reference"}; 284 default: return super.getTypesForProperty(hash, name); 285 } 286 287 } 288 289 @Override 290 public Base addChild(String name) throws FHIRException { 291 if (name.equals("code")) { 292 this.code = new Coding(); 293 return this.code; 294 } 295 else if (name.equals("valueCodeableConcept")) { 296 this.value = new CodeableConcept(); 297 return this.value; 298 } 299 else if (name.equals("valueQuantity")) { 300 this.value = new Quantity(); 301 return this.value; 302 } 303 else if (name.equals("valueRange")) { 304 this.value = new Range(); 305 return this.value; 306 } 307 else if (name.equals("valueReference")) { 308 this.value = new Reference(); 309 return this.value; 310 } 311 else 312 return super.addChild(name); 313 } 314 315 public String fhirType() { 316 return "UsageContext"; 317 318 } 319 320 public UsageContext copy() { 321 UsageContext dst = new UsageContext(); 322 copyValues(dst); 323 return dst; 324 } 325 326 public void copyValues(UsageContext dst) { 327 super.copyValues(dst); 328 dst.code = code == null ? null : code.copy(); 329 dst.value = value == null ? null : value.copy(); 330 } 331 332 protected UsageContext typedCopy() { 333 return copy(); 334 } 335 336 @Override 337 public boolean equalsDeep(Base other_) { 338 if (!super.equalsDeep(other_)) 339 return false; 340 if (!(other_ instanceof UsageContext)) 341 return false; 342 UsageContext o = (UsageContext) other_; 343 return compareDeep(code, o.code, true) && compareDeep(value, o.value, true); 344 } 345 346 @Override 347 public boolean equalsShallow(Base other_) { 348 if (!super.equalsShallow(other_)) 349 return false; 350 if (!(other_ instanceof UsageContext)) 351 return false; 352 UsageContext o = (UsageContext) other_; 353 return true; 354 } 355 356 public boolean isEmpty() { 357 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value); 358 } 359 360 361} 362