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