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, Sep 13, 2018 09:04-0400 for FHIR v3.5.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}, 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        return null;
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        return null;
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        return null;
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    public boolean hasValue() { 
160      return this.value != null && !this.value.isEmpty();
161    }
162
163    /**
164     * @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.)
165     */
166    public UsageContext setValue(Type value) { 
167      if (value != null && !(value instanceof CodeableConcept || value instanceof Quantity || value instanceof Range))
168        throw new Error("Not the right type for UsageContext.value[x]: "+value.fhirType());
169      this.value = value;
170      return this;
171    }
172
173      protected void listChildren(List<Property> children) {
174        super.listChildren(children);
175        children.add(new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, 1, code));
176        children.add(new Property("value[x]", "CodeableConcept|Quantity|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));
177      }
178
179      @Override
180      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
181        switch (_hash) {
182        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);
183        case -1410166417: /*value[x]*/  return new Property("value[x]", "CodeableConcept|Quantity|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);
184        case 111972721: /*value*/  return new Property("value[x]", "CodeableConcept|Quantity|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);
185        case 924902896: /*valueCodeableConcept*/  return new Property("value[x]", "CodeableConcept|Quantity|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);
186        case -2029823716: /*valueQuantity*/  return new Property("value[x]", "CodeableConcept|Quantity|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);
187        case 2030761548: /*valueRange*/  return new Property("value[x]", "CodeableConcept|Quantity|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);
188        default: return super.getNamedProperty(_hash, _name, _checkValid);
189        }
190
191      }
192
193      @Override
194      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
195        switch (hash) {
196        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // Coding
197        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // Type
198        default: return super.getProperty(hash, name, checkValid);
199        }
200
201      }
202
203      @Override
204      public Base setProperty(int hash, String name, Base value) throws FHIRException {
205        switch (hash) {
206        case 3059181: // code
207          this.code = castToCoding(value); // Coding
208          return value;
209        case 111972721: // value
210          this.value = castToType(value); // Type
211          return value;
212        default: return super.setProperty(hash, name, value);
213        }
214
215      }
216
217      @Override
218      public Base setProperty(String name, Base value) throws FHIRException {
219        if (name.equals("code")) {
220          this.code = castToCoding(value); // Coding
221        } else if (name.equals("value[x]")) {
222          this.value = castToType(value); // Type
223        } else
224          return super.setProperty(name, value);
225        return value;
226      }
227
228      @Override
229      public Base makeProperty(int hash, String name) throws FHIRException {
230        switch (hash) {
231        case 3059181:  return getCode(); 
232        case -1410166417:  return getValue(); 
233        case 111972721:  return getValue(); 
234        default: return super.makeProperty(hash, name);
235        }
236
237      }
238
239      @Override
240      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
241        switch (hash) {
242        case 3059181: /*code*/ return new String[] {"Coding"};
243        case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range"};
244        default: return super.getTypesForProperty(hash, name);
245        }
246
247      }
248
249      @Override
250      public Base addChild(String name) throws FHIRException {
251        if (name.equals("code")) {
252          this.code = new Coding();
253          return this.code;
254        }
255        else if (name.equals("valueCodeableConcept")) {
256          this.value = new CodeableConcept();
257          return this.value;
258        }
259        else if (name.equals("valueQuantity")) {
260          this.value = new Quantity();
261          return this.value;
262        }
263        else if (name.equals("valueRange")) {
264          this.value = new Range();
265          return this.value;
266        }
267        else
268          return super.addChild(name);
269      }
270
271  public String fhirType() {
272    return "UsageContext";
273
274  }
275
276      public UsageContext copy() {
277        UsageContext dst = new UsageContext();
278        copyValues(dst);
279        dst.code = code == null ? null : code.copy();
280        dst.value = value == null ? null : value.copy();
281        return dst;
282      }
283
284      protected UsageContext typedCopy() {
285        return copy();
286      }
287
288      @Override
289      public boolean equalsDeep(Base other_) {
290        if (!super.equalsDeep(other_))
291          return false;
292        if (!(other_ instanceof UsageContext))
293          return false;
294        UsageContext o = (UsageContext) other_;
295        return compareDeep(code, o.code, true) && compareDeep(value, o.value, true);
296      }
297
298      @Override
299      public boolean equalsShallow(Base other_) {
300        if (!super.equalsShallow(other_))
301          return false;
302        if (!(other_ instanceof UsageContext))
303          return false;
304        UsageContext o = (UsageContext) other_;
305        return true;
306      }
307
308      public boolean isEmpty() {
309        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value);
310      }
311
312
313}
314