001package org.hl7.fhir.r4.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
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.List;
054
055import org.hl7.fhir.exceptions.FHIRException;
056import org.hl7.fhir.instance.model.api.ICompositeType;
057
058import ca.uhn.fhir.model.api.annotation.Child;
059import ca.uhn.fhir.model.api.annotation.DatatypeDef;
060import ca.uhn.fhir.model.api.annotation.Description;
061/**
062 * 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).
063 */
064@DatatypeDef(name="UsageContext")
065public class UsageContext extends Type implements ICompositeType {
066
067    /**
068     * A code that identifies the type of context being specified by this usage context.
069     */
070    @Child(name = "code", type = {Coding.class}, order=0, min=1, max=1, modifier=false, summary=true)
071    @Description(shortDefinition="Type of context being specified", formalDefinition="A code that identifies the type of context being specified by this usage context." )
072    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/usage-context-type")
073    protected Coding code;
074
075    /**
076     * A value that defines the context specified in this context of use. The interpretation of the value is defined by the code.
077     */
078    @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)
079    @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." )
080    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/use-context")
081    protected Type value;
082
083    private static final long serialVersionUID = -1092486508L;
084
085  /**
086   * Constructor
087   */
088    public UsageContext() {
089      super();
090    }
091
092  /**
093   * Constructor
094   */
095    public UsageContext(Coding code, Type value) {
096      super();
097      this.code = code;
098      this.value = value;
099    }
100
101    /**
102     * @return {@link #code} (A code that identifies the type of context being specified by this usage context.)
103     */
104    public Coding getCode() { 
105      if (this.code == null)
106        if (Configuration.errorOnAutoCreate())
107          throw new Error("Attempt to auto-create UsageContext.code");
108        else if (Configuration.doAutoCreate())
109          this.code = new Coding(); // cc
110      return this.code;
111    }
112
113    public boolean hasCode() { 
114      return this.code != null && !this.code.isEmpty();
115    }
116
117    /**
118     * @param value {@link #code} (A code that identifies the type of context being specified by this usage context.)
119     */
120    public UsageContext setCode(Coding value) { 
121      this.code = value;
122      return this;
123    }
124
125    /**
126     * @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.)
127     */
128    public Type getValue() { 
129      return this.value;
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 CodeableConcept getValueCodeableConcept() throws FHIRException { 
136      if (this.value == null)
137        this.value = new CodeableConcept();
138      if (!(this.value instanceof CodeableConcept))
139        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered");
140      return (CodeableConcept) this.value;
141    }
142
143    public boolean hasValueCodeableConcept() { 
144      return this != null && this.value instanceof CodeableConcept;
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 Quantity getValueQuantity() throws FHIRException { 
151      if (this.value == null)
152        this.value = new Quantity();
153      if (!(this.value instanceof Quantity))
154        throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered");
155      return (Quantity) this.value;
156    }
157
158    public boolean hasValueQuantity() { 
159      return this != null && this.value instanceof Quantity;
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 Range getValueRange() throws FHIRException { 
166      if (this.value == null)
167        this.value = new Range();
168      if (!(this.value instanceof Range))
169        throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered");
170      return (Range) this.value;
171    }
172
173    public boolean hasValueRange() { 
174      return this != null && this.value instanceof Range;
175    }
176
177    /**
178     * @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.)
179     */
180    public Reference getValueReference() throws FHIRException { 
181      if (this.value == null)
182        this.value = new Reference();
183      if (!(this.value instanceof Reference))
184        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.value.getClass().getName()+" was encountered");
185      return (Reference) this.value;
186    }
187
188    public boolean hasValueReference() { 
189      return this != null && this.value instanceof Reference;
190    }
191
192    public boolean hasValue() { 
193      return this.value != null && !this.value.isEmpty();
194    }
195
196    /**
197     * @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.)
198     */
199    public UsageContext setValue(Type value) { 
200      if (value != null && !(value instanceof CodeableConcept || value instanceof Quantity || value instanceof Range || value instanceof Reference))
201        throw new Error("Not the right type for UsageContext.value[x]: "+value.fhirType());
202      this.value = value;
203      return this;
204    }
205
206      protected void listChildren(List<Property> children) {
207        super.listChildren(children);
208        children.add(new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, 1, code));
209        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));
210      }
211
212      @Override
213      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
214        switch (_hash) {
215        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);
216        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);
217        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);
218        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);
219        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);
220        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);
221        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);
222        default: return super.getNamedProperty(_hash, _name, _checkValid);
223        }
224
225      }
226
227      @Override
228      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
229        switch (hash) {
230        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // Coding
231        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // Type
232        default: return super.getProperty(hash, name, checkValid);
233        }
234
235      }
236
237      @Override
238      public Base setProperty(int hash, String name, Base value) throws FHIRException {
239        switch (hash) {
240        case 3059181: // code
241          this.code = castToCoding(value); // Coding
242          return value;
243        case 111972721: // value
244          this.value = castToType(value); // Type
245          return value;
246        default: return super.setProperty(hash, name, value);
247        }
248
249      }
250
251      @Override
252      public Base setProperty(String name, Base value) throws FHIRException {
253        if (name.equals("code")) {
254          this.code = castToCoding(value); // Coding
255        } else if (name.equals("value[x]")) {
256          this.value = castToType(value); // Type
257        } else
258          return super.setProperty(name, value);
259        return value;
260      }
261
262      @Override
263      public Base makeProperty(int hash, String name) throws FHIRException {
264        switch (hash) {
265        case 3059181:  return getCode(); 
266        case -1410166417:  return getValue(); 
267        case 111972721:  return getValue(); 
268        default: return super.makeProperty(hash, name);
269        }
270
271      }
272
273      @Override
274      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
275        switch (hash) {
276        case 3059181: /*code*/ return new String[] {"Coding"};
277        case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range", "Reference"};
278        default: return super.getTypesForProperty(hash, name);
279        }
280
281      }
282
283      @Override
284      public Base addChild(String name) throws FHIRException {
285        if (name.equals("code")) {
286          this.code = new Coding();
287          return this.code;
288        }
289        else if (name.equals("valueCodeableConcept")) {
290          this.value = new CodeableConcept();
291          return this.value;
292        }
293        else if (name.equals("valueQuantity")) {
294          this.value = new Quantity();
295          return this.value;
296        }
297        else if (name.equals("valueRange")) {
298          this.value = new Range();
299          return this.value;
300        }
301        else if (name.equals("valueReference")) {
302          this.value = new Reference();
303          return this.value;
304        }
305        else
306          return super.addChild(name);
307      }
308
309  public String fhirType() {
310    return "UsageContext";
311
312  }
313
314      public UsageContext copy() {
315        UsageContext dst = new UsageContext();
316        copyValues(dst);
317        dst.code = code == null ? null : code.copy();
318        dst.value = value == null ? null : value.copy();
319        return dst;
320      }
321
322      protected UsageContext typedCopy() {
323        return copy();
324      }
325
326      @Override
327      public boolean equalsDeep(Base other_) {
328        if (!super.equalsDeep(other_))
329          return false;
330        if (!(other_ instanceof UsageContext))
331          return false;
332        UsageContext o = (UsageContext) other_;
333        return compareDeep(code, o.code, true) && compareDeep(value, o.value, true);
334      }
335
336      @Override
337      public boolean equalsShallow(Base other_) {
338        if (!super.equalsShallow(other_))
339          return false;
340        if (!(other_ instanceof UsageContext))
341          return false;
342        UsageContext o = (UsageContext) other_;
343        return true;
344      }
345
346      public boolean isEmpty() {
347        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value);
348      }
349
350
351}
352