001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
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 instanceof CodeableConcept))
119        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.value.getClass().getName()+" was encountered");
120      return (CodeableConcept) this.value;
121    }
122
123    public boolean hasValueCodeableConcept() { 
124      return this.value instanceof CodeableConcept;
125    }
126
127    /**
128     * @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.)
129     */
130    public Quantity getValueQuantity() throws FHIRException { 
131      if (!(this.value instanceof Quantity))
132        throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered");
133      return (Quantity) this.value;
134    }
135
136    public boolean hasValueQuantity() { 
137      return this.value instanceof Quantity;
138    }
139
140    /**
141     * @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.)
142     */
143    public Range getValueRange() throws FHIRException { 
144      if (!(this.value instanceof Range))
145        throw new FHIRException("Type mismatch: the type Range was expected, but "+this.value.getClass().getName()+" was encountered");
146      return (Range) this.value;
147    }
148
149    public boolean hasValueRange() { 
150      return this.value instanceof Range;
151    }
152
153    public boolean hasValue() { 
154      return this.value != null && !this.value.isEmpty();
155    }
156
157    /**
158     * @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.)
159     */
160    public UsageContext setValue(Type value) { 
161      this.value = value;
162      return this;
163    }
164
165      protected void listChildren(List<Property> childrenList) {
166        super.listChildren(childrenList);
167        childrenList.add(new Property("code", "Coding", "A code that identifies the type of context being specified by this usage context.", 0, java.lang.Integer.MAX_VALUE, code));
168        childrenList.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, java.lang.Integer.MAX_VALUE, value));
169      }
170
171      @Override
172      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
173        switch (hash) {
174        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // Coding
175        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // Type
176        default: return super.getProperty(hash, name, checkValid);
177        }
178
179      }
180
181      @Override
182      public Base setProperty(int hash, String name, Base value) throws FHIRException {
183        switch (hash) {
184        case 3059181: // code
185          this.code = castToCoding(value); // Coding
186          return value;
187        case 111972721: // value
188          this.value = castToType(value); // Type
189          return value;
190        default: return super.setProperty(hash, name, value);
191        }
192
193      }
194
195      @Override
196      public Base setProperty(String name, Base value) throws FHIRException {
197        if (name.equals("code")) {
198          this.code = castToCoding(value); // Coding
199        } else if (name.equals("value[x]")) {
200          this.value = castToType(value); // Type
201        } else
202          return super.setProperty(name, value);
203        return value;
204      }
205
206      @Override
207      public Base makeProperty(int hash, String name) throws FHIRException {
208        switch (hash) {
209        case 3059181:  return getCode(); 
210        case -1410166417:  return getValue(); 
211        case 111972721:  return getValue(); 
212        default: return super.makeProperty(hash, name);
213        }
214
215      }
216
217      @Override
218      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
219        switch (hash) {
220        case 3059181: /*code*/ return new String[] {"Coding"};
221        case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range"};
222        default: return super.getTypesForProperty(hash, name);
223        }
224
225      }
226
227      @Override
228      public Base addChild(String name) throws FHIRException {
229        if (name.equals("code")) {
230          this.code = new Coding();
231          return this.code;
232        }
233        else if (name.equals("valueCodeableConcept")) {
234          this.value = new CodeableConcept();
235          return this.value;
236        }
237        else if (name.equals("valueQuantity")) {
238          this.value = new Quantity();
239          return this.value;
240        }
241        else if (name.equals("valueRange")) {
242          this.value = new Range();
243          return this.value;
244        }
245        else
246          return super.addChild(name);
247      }
248
249  public String fhirType() {
250    return "UsageContext";
251
252  }
253
254      public UsageContext copy() {
255        UsageContext dst = new UsageContext();
256        copyValues(dst);
257        dst.code = code == null ? null : code.copy();
258        dst.value = value == null ? null : value.copy();
259        return dst;
260      }
261
262      protected UsageContext typedCopy() {
263        return copy();
264      }
265
266      @Override
267      public boolean equalsDeep(Base other) {
268        if (!super.equalsDeep(other))
269          return false;
270        if (!(other instanceof UsageContext))
271          return false;
272        UsageContext o = (UsageContext) other;
273        return compareDeep(code, o.code, true) && compareDeep(value, o.value, true);
274      }
275
276      @Override
277      public boolean equalsShallow(Base other) {
278        if (!super.equalsShallow(other))
279          return false;
280        if (!(other instanceof UsageContext))
281          return false;
282        UsageContext o = (UsageContext) other;
283        return true;
284      }
285
286      public boolean isEmpty() {
287        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value);
288      }
289
290
291}
292