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