001package org.hl7.fhir.r4.model; 002 003 004 005/* 006 Copyright (c) 2011+, HL7, Inc. 007 All rights reserved. 008 009 Redistribution and use in source and binary forms, with or without modification, 010 are permitted provided that the following conditions are met: 011 012 * Redistributions of source code must retain the above copyright notice, this 013 list of conditions and the following disclaimer. 014 * Redistributions in binary form must reproduce the above copyright notice, 015 this list of conditions and the following disclaimer in the documentation 016 and/or other materials provided with the distribution. 017 * Neither the name of HL7 nor the names of its contributors may be used to 018 endorse or promote products derived from this software without specific 019 prior written permission. 020 021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 024 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 026 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 027 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 030 POSSIBILITY OF SUCH DAMAGE. 031 032*/ 033 034 035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1 036 037import java.util.*; 038 039import ca.uhn.fhir.model.api.annotation.Child; 040import ca.uhn.fhir.model.api.annotation.ChildOrder; 041import ca.uhn.fhir.model.api.annotation.Description; 042import ca.uhn.fhir.model.api.annotation.DatatypeDef; 043import ca.uhn.fhir.model.api.annotation.Block; 044import org.hl7.fhir.instance.model.api.*; 045import org.hl7.fhir.exceptions.FHIRException; 046/** 047 * 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). 048 */ 049@DatatypeDef(name="UsageContext") 050public class UsageContext extends Type implements ICompositeType { 051 052 /** 053 * A code that identifies the type of context being specified by this usage context. 054 */ 055 @Child(name = "code", type = {Coding.class}, order=0, min=1, max=1, modifier=false, summary=true) 056 @Description(shortDefinition="Type of context being specified", formalDefinition="A code that identifies the type of context being specified by this usage context." ) 057 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/usage-context-type") 058 protected Coding code; 059 060 /** 061 * A value that defines the context specified in this context of use. The interpretation of the value is defined by the code. 062 */ 063 @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) 064 @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." ) 065 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/use-context") 066 protected Type value; 067 068 private static final long serialVersionUID = -1092486508L; 069 070 /** 071 * Constructor 072 */ 073 public UsageContext() { 074 super(); 075 } 076 077 /** 078 * Constructor 079 */ 080 public UsageContext(Coding code, Type value) { 081 super(); 082 this.code = code; 083 this.value = value; 084 } 085 086 /** 087 * @return {@link #code} (A code that identifies the type of context being specified by this usage context.) 088 */ 089 public Coding getCode() { 090 if (this.code == null) 091 if (Configuration.errorOnAutoCreate()) 092 throw new Error("Attempt to auto-create UsageContext.code"); 093 else if (Configuration.doAutoCreate()) 094 this.code = new Coding(); // cc 095 return this.code; 096 } 097 098 public boolean hasCode() { 099 return this.code != null && !this.code.isEmpty(); 100 } 101 102 /** 103 * @param value {@link #code} (A code that identifies the type of context being specified by this usage context.) 104 */ 105 public UsageContext setCode(Coding value) { 106 this.code = value; 107 return this; 108 } 109 110 /** 111 * @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.) 112 */ 113 public Type getValue() { 114 return this.value; 115 } 116 117 /** 118 * @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.) 119 */ 120 public CodeableConcept getValueCodeableConcept() throws FHIRException { 121 if (this.value == null) 122 this.value = new CodeableConcept(); 123 if (!(this.value instanceof CodeableConcept)) 124 throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered"); 125 return (CodeableConcept) this.value; 126 } 127 128 public boolean hasValueCodeableConcept() { 129 return this != null && this.value instanceof CodeableConcept; 130 } 131 132 /** 133 * @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.) 134 */ 135 public Quantity getValueQuantity() throws FHIRException { 136 if (this.value == null) 137 this.value = new Quantity(); 138 if (!(this.value instanceof Quantity)) 139 throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered"); 140 return (Quantity) this.value; 141 } 142 143 public boolean hasValueQuantity() { 144 return this != null && this.value instanceof Quantity; 145 } 146 147 /** 148 * @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.) 149 */ 150 public Range getValueRange() throws FHIRException { 151 if (this.value == null) 152 this.value = new Range(); 153 if (!(this.value instanceof Range)) 154 throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered"); 155 return (Range) this.value; 156 } 157 158 public boolean hasValueRange() { 159 return this != null && this.value instanceof Range; 160 } 161 162 /** 163 * @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.) 164 */ 165 public Reference getValueReference() throws FHIRException { 166 if (this.value == null) 167 this.value = new Reference(); 168 if (!(this.value instanceof Reference)) 169 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.value.getClass().getName()+" was encountered"); 170 return (Reference) this.value; 171 } 172 173 public boolean hasValueReference() { 174 return this != null && this.value instanceof Reference; 175 } 176 177 public boolean hasValue() { 178 return this.value != null && !this.value.isEmpty(); 179 } 180 181 /** 182 * @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.) 183 */ 184 public UsageContext setValue(Type value) { 185 if (value != null && !(value instanceof CodeableConcept || value instanceof Quantity || value instanceof Range || value instanceof Reference)) 186 throw new Error("Not the right type for UsageContext.value[x]: "+value.fhirType()); 187 this.value = value; 188 return this; 189 } 190 191 protected void listChildren(List<Property> children) { 192 super.listChildren(children); 193 children.add(new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, 1, code)); 194 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)); 195 } 196 197 @Override 198 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 199 switch (_hash) { 200 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); 201 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); 202 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); 203 case 924902896: /*valueCodeableConcept*/ 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); 204 case -2029823716: /*valueQuantity*/ 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); 205 case 2030761548: /*valueRange*/ 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); 206 case 1755241690: /*valueReference*/ 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); 207 default: return super.getNamedProperty(_hash, _name, _checkValid); 208 } 209 210 } 211 212 @Override 213 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 214 switch (hash) { 215 case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // Coding 216 case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // Type 217 default: return super.getProperty(hash, name, checkValid); 218 } 219 220 } 221 222 @Override 223 public Base setProperty(int hash, String name, Base value) throws FHIRException { 224 switch (hash) { 225 case 3059181: // code 226 this.code = castToCoding(value); // Coding 227 return value; 228 case 111972721: // value 229 this.value = castToType(value); // Type 230 return value; 231 default: return super.setProperty(hash, name, value); 232 } 233 234 } 235 236 @Override 237 public Base setProperty(String name, Base value) throws FHIRException { 238 if (name.equals("code")) { 239 this.code = castToCoding(value); // Coding 240 } else if (name.equals("value[x]")) { 241 this.value = castToType(value); // Type 242 } else 243 return super.setProperty(name, value); 244 return value; 245 } 246 247 @Override 248 public Base makeProperty(int hash, String name) throws FHIRException { 249 switch (hash) { 250 case 3059181: return getCode(); 251 case -1410166417: return getValue(); 252 case 111972721: return getValue(); 253 default: return super.makeProperty(hash, name); 254 } 255 256 } 257 258 @Override 259 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 260 switch (hash) { 261 case 3059181: /*code*/ return new String[] {"Coding"}; 262 case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range", "Reference"}; 263 default: return super.getTypesForProperty(hash, name); 264 } 265 266 } 267 268 @Override 269 public Base addChild(String name) throws FHIRException { 270 if (name.equals("code")) { 271 this.code = new Coding(); 272 return this.code; 273 } 274 else if (name.equals("valueCodeableConcept")) { 275 this.value = new CodeableConcept(); 276 return this.value; 277 } 278 else if (name.equals("valueQuantity")) { 279 this.value = new Quantity(); 280 return this.value; 281 } 282 else if (name.equals("valueRange")) { 283 this.value = new Range(); 284 return this.value; 285 } 286 else if (name.equals("valueReference")) { 287 this.value = new Reference(); 288 return this.value; 289 } 290 else 291 return super.addChild(name); 292 } 293 294 public String fhirType() { 295 return "UsageContext"; 296 297 } 298 299 public UsageContext copy() { 300 UsageContext dst = new UsageContext(); 301 copyValues(dst); 302 return dst; 303 } 304 305 public void copyValues(UsageContext dst) { 306 super.copyValues(dst); 307 dst.code = code == null ? null : code.copy(); 308 dst.value = value == null ? null : value.copy(); 309 } 310 311 protected UsageContext typedCopy() { 312 return copy(); 313 } 314 315 @Override 316 public boolean equalsDeep(Base other_) { 317 if (!super.equalsDeep(other_)) 318 return false; 319 if (!(other_ instanceof UsageContext)) 320 return false; 321 UsageContext o = (UsageContext) other_; 322 return compareDeep(code, o.code, true) && compareDeep(value, o.value, true); 323 } 324 325 @Override 326 public boolean equalsShallow(Base other_) { 327 if (!super.equalsShallow(other_)) 328 return false; 329 if (!(other_ instanceof UsageContext)) 330 return false; 331 UsageContext o = (UsageContext) other_; 332 return true; 333 } 334 335 public boolean isEmpty() { 336 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value); 337 } 338 339 340}