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