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 void removeChild(String name, Base value) throws FHIRException {
250        if (name.equals("code")) {
251          this.code = null;
252        } else if (name.equals("value[x]")) {
253          this.value = null;
254        } else
255          super.removeChild(name, value);
256        
257      }
258
259      @Override
260      public Base makeProperty(int hash, String name) throws FHIRException {
261        switch (hash) {
262        case 3059181:  return getCode();
263        case -1410166417:  return getValue();
264        case 111972721:  return getValue();
265        default: return super.makeProperty(hash, name);
266        }
267
268      }
269
270      @Override
271      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
272        switch (hash) {
273        case 3059181: /*code*/ return new String[] {"Coding"};
274        case 111972721: /*value*/ return new String[] {"CodeableConcept", "Quantity", "Range", "Reference"};
275        default: return super.getTypesForProperty(hash, name);
276        }
277
278      }
279
280      @Override
281      public Base addChild(String name) throws FHIRException {
282        if (name.equals("code")) {
283          this.code = new Coding();
284          return this.code;
285        }
286        else if (name.equals("valueCodeableConcept")) {
287          this.value = new CodeableConcept();
288          return this.value;
289        }
290        else if (name.equals("valueQuantity")) {
291          this.value = new Quantity();
292          return this.value;
293        }
294        else if (name.equals("valueRange")) {
295          this.value = new Range();
296          return this.value;
297        }
298        else if (name.equals("valueReference")) {
299          this.value = new Reference();
300          return this.value;
301        }
302        else
303          return super.addChild(name);
304      }
305
306  public String fhirType() {
307    return "UsageContext";
308
309  }
310
311      public UsageContext copy() {
312        UsageContext dst = new UsageContext();
313        copyValues(dst);
314        return dst;
315      }
316
317      public void copyValues(UsageContext dst) {
318        super.copyValues(dst);
319        dst.code = code == null ? null : code.copy();
320        dst.value = value == null ? null : value.copy();
321      }
322
323      protected UsageContext typedCopy() {
324        return copy();
325      }
326
327      @Override
328      public boolean equalsDeep(Base other_) {
329        if (!super.equalsDeep(other_))
330          return false;
331        if (!(other_ instanceof UsageContext))
332          return false;
333        UsageContext o = (UsageContext) other_;
334        return compareDeep(code, o.code, true) && compareDeep(value, o.value, true);
335      }
336
337      @Override
338      public boolean equalsShallow(Base other_) {
339        if (!super.equalsShallow(other_))
340          return false;
341        if (!(other_ instanceof UsageContext))
342          return false;
343        UsageContext o = (UsageContext) other_;
344        return true;
345      }
346
347      public boolean isEmpty() {
348        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(code, value);
349      }
350
351
352}
353