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