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 Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
033import java.util.List;
034
035import org.hl7.fhir.exceptions.FHIRException;
036import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
037import org.hl7.fhir.instance.model.api.ICompositeType;
038import org.hl7.fhir.utilities.Utilities;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.DatatypeDef;
043import ca.uhn.fhir.model.api.annotation.Description;
044
045/**
046 * Chemical substances are a single substance type whose primary defining
047 * element is the molecular structure. Chemical substances shall be defined on
048 * the basis of their complete covalent molecular structure; the presence of a
049 * salt (counter-ion) and/or solvates (water, alcohols) is also captured.
050 * Purity, grade, physical form or particle size are not taken into account in
051 * the definition of a chemical substance or in the assignment of a Substance
052 * ID.
053 */
054@DatatypeDef(name = "SubstanceAmount")
055public class SubstanceAmount extends BackboneType implements ICompositeType {
056
057  @Block()
058  public static class SubstanceAmountReferenceRangeComponent extends Element implements IBaseDatatypeElement {
059    /**
060     * Lower limit possible or expected.
061     */
062    @Child(name = "lowLimit", type = { Quantity.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
063    @Description(shortDefinition = "Lower limit possible or expected", formalDefinition = "Lower limit possible or expected.")
064    protected Quantity lowLimit;
065
066    /**
067     * Upper limit possible or expected.
068     */
069    @Child(name = "highLimit", type = { Quantity.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
070    @Description(shortDefinition = "Upper limit possible or expected", formalDefinition = "Upper limit possible or expected.")
071    protected Quantity highLimit;
072
073    private static final long serialVersionUID = -193230412L;
074
075    /**
076     * Constructor
077     */
078    public SubstanceAmountReferenceRangeComponent() {
079      super();
080    }
081
082    /**
083     * @return {@link #lowLimit} (Lower limit possible or expected.)
084     */
085    public Quantity getLowLimit() {
086      if (this.lowLimit == null)
087        if (Configuration.errorOnAutoCreate())
088          throw new Error("Attempt to auto-create SubstanceAmountReferenceRangeComponent.lowLimit");
089        else if (Configuration.doAutoCreate())
090          this.lowLimit = new Quantity(); // cc
091      return this.lowLimit;
092    }
093
094    public boolean hasLowLimit() {
095      return this.lowLimit != null && !this.lowLimit.isEmpty();
096    }
097
098    /**
099     * @param value {@link #lowLimit} (Lower limit possible or expected.)
100     */
101    public SubstanceAmountReferenceRangeComponent setLowLimit(Quantity value) {
102      this.lowLimit = value;
103      return this;
104    }
105
106    /**
107     * @return {@link #highLimit} (Upper limit possible or expected.)
108     */
109    public Quantity getHighLimit() {
110      if (this.highLimit == null)
111        if (Configuration.errorOnAutoCreate())
112          throw new Error("Attempt to auto-create SubstanceAmountReferenceRangeComponent.highLimit");
113        else if (Configuration.doAutoCreate())
114          this.highLimit = new Quantity(); // cc
115      return this.highLimit;
116    }
117
118    public boolean hasHighLimit() {
119      return this.highLimit != null && !this.highLimit.isEmpty();
120    }
121
122    /**
123     * @param value {@link #highLimit} (Upper limit possible or expected.)
124     */
125    public SubstanceAmountReferenceRangeComponent setHighLimit(Quantity value) {
126      this.highLimit = value;
127      return this;
128    }
129
130    protected void listChildren(List<Property> children) {
131      super.listChildren(children);
132      children.add(new Property("lowLimit", "Quantity", "Lower limit possible or expected.", 0, 1, lowLimit));
133      children.add(new Property("highLimit", "Quantity", "Upper limit possible or expected.", 0, 1, highLimit));
134    }
135
136    @Override
137    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
138      switch (_hash) {
139      case -1841058617:
140        /* lowLimit */ return new Property("lowLimit", "Quantity", "Lower limit possible or expected.", 0, 1, lowLimit);
141      case -710757575:
142        /* highLimit */ return new Property("highLimit", "Quantity", "Upper limit possible or expected.", 0, 1,
143            highLimit);
144      default:
145        return super.getNamedProperty(_hash, _name, _checkValid);
146      }
147
148    }
149
150    @Override
151    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
152      switch (hash) {
153      case -1841058617:
154        /* lowLimit */ return this.lowLimit == null ? new Base[0] : new Base[] { this.lowLimit }; // Quantity
155      case -710757575:
156        /* highLimit */ return this.highLimit == null ? new Base[0] : new Base[] { this.highLimit }; // Quantity
157      default:
158        return super.getProperty(hash, name, checkValid);
159      }
160
161    }
162
163    @Override
164    public Base setProperty(int hash, String name, Base value) throws FHIRException {
165      switch (hash) {
166      case -1841058617: // lowLimit
167        this.lowLimit = castToQuantity(value); // Quantity
168        return value;
169      case -710757575: // highLimit
170        this.highLimit = castToQuantity(value); // Quantity
171        return value;
172      default:
173        return super.setProperty(hash, name, value);
174      }
175
176    }
177
178    @Override
179    public Base setProperty(String name, Base value) throws FHIRException {
180      if (name.equals("lowLimit")) {
181        this.lowLimit = castToQuantity(value); // Quantity
182      } else if (name.equals("highLimit")) {
183        this.highLimit = castToQuantity(value); // Quantity
184      } else
185        return super.setProperty(name, value);
186      return value;
187    }
188
189    @Override
190    public Base makeProperty(int hash, String name) throws FHIRException {
191      switch (hash) {
192      case -1841058617:
193        return getLowLimit();
194      case -710757575:
195        return getHighLimit();
196      default:
197        return super.makeProperty(hash, name);
198      }
199
200    }
201
202    @Override
203    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
204      switch (hash) {
205      case -1841058617:
206        /* lowLimit */ return new String[] { "Quantity" };
207      case -710757575:
208        /* highLimit */ return new String[] { "Quantity" };
209      default:
210        return super.getTypesForProperty(hash, name);
211      }
212
213    }
214
215    @Override
216    public Base addChild(String name) throws FHIRException {
217      if (name.equals("lowLimit")) {
218        this.lowLimit = new Quantity();
219        return this.lowLimit;
220      } else if (name.equals("highLimit")) {
221        this.highLimit = new Quantity();
222        return this.highLimit;
223      } else
224        return super.addChild(name);
225    }
226
227    public SubstanceAmountReferenceRangeComponent copy() {
228      SubstanceAmountReferenceRangeComponent dst = new SubstanceAmountReferenceRangeComponent();
229      copyValues(dst);
230      return dst;
231    }
232
233    public void copyValues(SubstanceAmountReferenceRangeComponent dst) {
234      super.copyValues(dst);
235      dst.lowLimit = lowLimit == null ? null : lowLimit.copy();
236      dst.highLimit = highLimit == null ? null : highLimit.copy();
237    }
238
239    @Override
240    public boolean equalsDeep(Base other_) {
241      if (!super.equalsDeep(other_))
242        return false;
243      if (!(other_ instanceof SubstanceAmountReferenceRangeComponent))
244        return false;
245      SubstanceAmountReferenceRangeComponent o = (SubstanceAmountReferenceRangeComponent) other_;
246      return compareDeep(lowLimit, o.lowLimit, true) && compareDeep(highLimit, o.highLimit, true);
247    }
248
249    @Override
250    public boolean equalsShallow(Base other_) {
251      if (!super.equalsShallow(other_))
252        return false;
253      if (!(other_ instanceof SubstanceAmountReferenceRangeComponent))
254        return false;
255      SubstanceAmountReferenceRangeComponent o = (SubstanceAmountReferenceRangeComponent) other_;
256      return true;
257    }
258
259    public boolean isEmpty() {
260      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(lowLimit, highLimit);
261    }
262
263    public String fhirType() {
264      return "SubstanceAmount.referenceRange";
265
266    }
267
268  }
269
270  /**
271   * Used to capture quantitative values for a variety of elements. If only limits
272   * are given, the arithmetic mean would be the average. If only a single
273   * definite value for a given element is given, it would be captured in this
274   * field.
275   */
276  @Child(name = "amount", type = { Quantity.class, Range.class,
277      StringType.class }, order = 0, min = 0, max = 1, modifier = false, summary = true)
278  @Description(shortDefinition = "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field", formalDefinition = "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.")
279  protected Type amount;
280
281  /**
282   * Most elements that require a quantitative value will also have a field called
283   * amount type. Amount type should always be specified because the actual value
284   * of the amount is often dependent on it. EXAMPLE: In capturing the actual
285   * relative amounts of substances or molecular fragments it is essential to
286   * indicate whether the amount refers to a mole ratio or weight ratio. For any
287   * given element an effort should be made to use same the amount type for all
288   * related definitional elements.
289   */
290  @Child(name = "amountType", type = {
291      CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
292  @Description(shortDefinition = "Most elements that require a quantitative value will also have a field called amount type. Amount type should always be specified because the actual value of the amount is often dependent on it. EXAMPLE: In capturing the actual relative amounts of substances or molecular fragments it is essential to indicate whether the amount refers to a mole ratio or weight ratio. For any given element an effort should be made to use same the amount type for all related definitional elements", formalDefinition = "Most elements that require a quantitative value will also have a field called amount type. Amount type should always be specified because the actual value of the amount is often dependent on it. EXAMPLE: In capturing the actual relative amounts of substances or molecular fragments it is essential to indicate whether the amount refers to a mole ratio or weight ratio. For any given element an effort should be made to use same the amount type for all related definitional elements.")
293  protected CodeableConcept amountType;
294
295  /**
296   * A textual comment on a numeric value.
297   */
298  @Child(name = "amountText", type = {
299      StringType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
300  @Description(shortDefinition = "A textual comment on a numeric value", formalDefinition = "A textual comment on a numeric value.")
301  protected StringType amountText;
302
303  /**
304   * Reference range of possible or expected values.
305   */
306  @Child(name = "referenceRange", type = {}, order = 3, min = 0, max = 1, modifier = false, summary = true)
307  @Description(shortDefinition = "Reference range of possible or expected values", formalDefinition = "Reference range of possible or expected values.")
308  protected SubstanceAmountReferenceRangeComponent referenceRange;
309
310  private static final long serialVersionUID = -174997548L;
311
312  /**
313   * Constructor
314   */
315  public SubstanceAmount() {
316    super();
317  }
318
319  /**
320   * @return {@link #amount} (Used to capture quantitative values for a variety of
321   *         elements. If only limits are given, the arithmetic mean would be the
322   *         average. If only a single definite value for a given element is
323   *         given, it would be captured in this field.)
324   */
325  public Type getAmount() {
326    return this.amount;
327  }
328
329  /**
330   * @return {@link #amount} (Used to capture quantitative values for a variety of
331   *         elements. If only limits are given, the arithmetic mean would be the
332   *         average. If only a single definite value for a given element is
333   *         given, it would be captured in this field.)
334   */
335  public Quantity getAmountQuantity() throws FHIRException {
336    if (this.amount == null)
337      this.amount = new Quantity();
338    if (!(this.amount instanceof Quantity))
339      throw new FHIRException("Type mismatch: the type Quantity was expected, but " + this.amount.getClass().getName()
340          + " was encountered");
341    return (Quantity) this.amount;
342  }
343
344  public boolean hasAmountQuantity() {
345    return this != null && this.amount instanceof Quantity;
346  }
347
348  /**
349   * @return {@link #amount} (Used to capture quantitative values for a variety of
350   *         elements. If only limits are given, the arithmetic mean would be the
351   *         average. If only a single definite value for a given element is
352   *         given, it would be captured in this field.)
353   */
354  public Range getAmountRange() throws FHIRException {
355    if (this.amount == null)
356      this.amount = new Range();
357    if (!(this.amount instanceof Range))
358      throw new FHIRException(
359          "Type mismatch: the type Range was expected, but " + this.amount.getClass().getName() + " was encountered");
360    return (Range) this.amount;
361  }
362
363  public boolean hasAmountRange() {
364    return this != null && this.amount instanceof Range;
365  }
366
367  /**
368   * @return {@link #amount} (Used to capture quantitative values for a variety of
369   *         elements. If only limits are given, the arithmetic mean would be the
370   *         average. If only a single definite value for a given element is
371   *         given, it would be captured in this field.)
372   */
373  public StringType getAmountStringType() throws FHIRException {
374    if (this.amount == null)
375      this.amount = new StringType();
376    if (!(this.amount instanceof StringType))
377      throw new FHIRException("Type mismatch: the type StringType was expected, but " + this.amount.getClass().getName()
378          + " was encountered");
379    return (StringType) this.amount;
380  }
381
382  public boolean hasAmountStringType() {
383    return this != null && this.amount instanceof StringType;
384  }
385
386  public boolean hasAmount() {
387    return this.amount != null && !this.amount.isEmpty();
388  }
389
390  /**
391   * @param value {@link #amount} (Used to capture quantitative values for a
392   *              variety of elements. If only limits are given, the arithmetic
393   *              mean would be the average. If only a single definite value for a
394   *              given element is given, it would be captured in this field.)
395   */
396  public SubstanceAmount setAmount(Type value) {
397    if (value != null && !(value instanceof Quantity || value instanceof Range || value instanceof StringType))
398      throw new Error("Not the right type for SubstanceAmount.amount[x]: " + value.fhirType());
399    this.amount = value;
400    return this;
401  }
402
403  /**
404   * @return {@link #amountType} (Most elements that require a quantitative value
405   *         will also have a field called amount type. Amount type should always
406   *         be specified because the actual value of the amount is often
407   *         dependent on it. EXAMPLE: In capturing the actual relative amounts of
408   *         substances or molecular fragments it is essential to indicate whether
409   *         the amount refers to a mole ratio or weight ratio. For any given
410   *         element an effort should be made to use same the amount type for all
411   *         related definitional elements.)
412   */
413  public CodeableConcept getAmountType() {
414    if (this.amountType == null)
415      if (Configuration.errorOnAutoCreate())
416        throw new Error("Attempt to auto-create SubstanceAmount.amountType");
417      else if (Configuration.doAutoCreate())
418        this.amountType = new CodeableConcept(); // cc
419    return this.amountType;
420  }
421
422  public boolean hasAmountType() {
423    return this.amountType != null && !this.amountType.isEmpty();
424  }
425
426  /**
427   * @param value {@link #amountType} (Most elements that require a quantitative
428   *              value will also have a field called amount type. Amount type
429   *              should always be specified because the actual value of the
430   *              amount is often dependent on it. EXAMPLE: In capturing the
431   *              actual relative amounts of substances or molecular fragments it
432   *              is essential to indicate whether the amount refers to a mole
433   *              ratio or weight ratio. For any given element an effort should be
434   *              made to use same the amount type for all related definitional
435   *              elements.)
436   */
437  public SubstanceAmount setAmountType(CodeableConcept value) {
438    this.amountType = value;
439    return this;
440  }
441
442  /**
443   * @return {@link #amountText} (A textual comment on a numeric value.). This is
444   *         the underlying object with id, value and extensions. The accessor
445   *         "getAmountText" gives direct access to the value
446   */
447  public StringType getAmountTextElement() {
448    if (this.amountText == null)
449      if (Configuration.errorOnAutoCreate())
450        throw new Error("Attempt to auto-create SubstanceAmount.amountText");
451      else if (Configuration.doAutoCreate())
452        this.amountText = new StringType(); // bb
453    return this.amountText;
454  }
455
456  public boolean hasAmountTextElement() {
457    return this.amountText != null && !this.amountText.isEmpty();
458  }
459
460  public boolean hasAmountText() {
461    return this.amountText != null && !this.amountText.isEmpty();
462  }
463
464  /**
465   * @param value {@link #amountText} (A textual comment on a numeric value.).
466   *              This is the underlying object with id, value and extensions. The
467   *              accessor "getAmountText" gives direct access to the value
468   */
469  public SubstanceAmount setAmountTextElement(StringType value) {
470    this.amountText = value;
471    return this;
472  }
473
474  /**
475   * @return A textual comment on a numeric value.
476   */
477  public String getAmountText() {
478    return this.amountText == null ? null : this.amountText.getValue();
479  }
480
481  /**
482   * @param value A textual comment on a numeric value.
483   */
484  public SubstanceAmount setAmountText(String value) {
485    if (Utilities.noString(value))
486      this.amountText = null;
487    else {
488      if (this.amountText == null)
489        this.amountText = new StringType();
490      this.amountText.setValue(value);
491    }
492    return this;
493  }
494
495  /**
496   * @return {@link #referenceRange} (Reference range of possible or expected
497   *         values.)
498   */
499  public SubstanceAmountReferenceRangeComponent getReferenceRange() {
500    if (this.referenceRange == null)
501      if (Configuration.errorOnAutoCreate())
502        throw new Error("Attempt to auto-create SubstanceAmount.referenceRange");
503      else if (Configuration.doAutoCreate())
504        this.referenceRange = new SubstanceAmountReferenceRangeComponent(); // cc
505    return this.referenceRange;
506  }
507
508  public boolean hasReferenceRange() {
509    return this.referenceRange != null && !this.referenceRange.isEmpty();
510  }
511
512  /**
513   * @param value {@link #referenceRange} (Reference range of possible or expected
514   *              values.)
515   */
516  public SubstanceAmount setReferenceRange(SubstanceAmountReferenceRangeComponent value) {
517    this.referenceRange = value;
518    return this;
519  }
520
521  protected void listChildren(List<Property> children) {
522    super.listChildren(children);
523    children.add(new Property("amount[x]", "Quantity|Range|string",
524        "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
525        0, 1, amount));
526    children.add(new Property("amountType", "CodeableConcept",
527        "Most elements that require a quantitative value will also have a field called amount type. Amount type should always be specified because the actual value of the amount is often dependent on it. EXAMPLE: In capturing the actual relative amounts of substances or molecular fragments it is essential to indicate whether the amount refers to a mole ratio or weight ratio. For any given element an effort should be made to use same the amount type for all related definitional elements.",
528        0, 1, amountType));
529    children.add(new Property("amountText", "string", "A textual comment on a numeric value.", 0, 1, amountText));
530    children.add(
531        new Property("referenceRange", "", "Reference range of possible or expected values.", 0, 1, referenceRange));
532  }
533
534  @Override
535  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
536    switch (_hash) {
537    case 646780200:
538      /* amount[x] */ return new Property("amount[x]", "Quantity|Range|string",
539          "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
540          0, 1, amount);
541    case -1413853096:
542      /* amount */ return new Property("amount[x]", "Quantity|Range|string",
543          "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
544          0, 1, amount);
545    case 1664303363:
546      /* amountQuantity */ return new Property("amount[x]", "Quantity|Range|string",
547          "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
548          0, 1, amount);
549    case -1223462971:
550      /* amountRange */ return new Property("amount[x]", "Quantity|Range|string",
551          "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
552          0, 1, amount);
553    case 773651081:
554      /* amountString */ return new Property("amount[x]", "Quantity|Range|string",
555          "Used to capture quantitative values for a variety of elements. If only limits are given, the arithmetic mean would be the average. If only a single definite value for a given element is given, it would be captured in this field.",
556          0, 1, amount);
557    case -1424857166:
558      /* amountType */ return new Property("amountType", "CodeableConcept",
559          "Most elements that require a quantitative value will also have a field called amount type. Amount type should always be specified because the actual value of the amount is often dependent on it. EXAMPLE: In capturing the actual relative amounts of substances or molecular fragments it is essential to indicate whether the amount refers to a mole ratio or weight ratio. For any given element an effort should be made to use same the amount type for all related definitional elements.",
560          0, 1, amountType);
561    case -1424876123:
562      /* amountText */ return new Property("amountText", "string", "A textual comment on a numeric value.", 0, 1,
563          amountText);
564    case -1912545102:
565      /* referenceRange */ return new Property("referenceRange", "", "Reference range of possible or expected values.",
566          0, 1, referenceRange);
567    default:
568      return super.getNamedProperty(_hash, _name, _checkValid);
569    }
570
571  }
572
573  @Override
574  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
575    switch (hash) {
576    case -1413853096:
577      /* amount */ return this.amount == null ? new Base[0] : new Base[] { this.amount }; // Type
578    case -1424857166:
579      /* amountType */ return this.amountType == null ? new Base[0] : new Base[] { this.amountType }; // CodeableConcept
580    case -1424876123:
581      /* amountText */ return this.amountText == null ? new Base[0] : new Base[] { this.amountText }; // StringType
582    case -1912545102:
583      /* referenceRange */ return this.referenceRange == null ? new Base[0] : new Base[] { this.referenceRange }; // SubstanceAmountReferenceRangeComponent
584    default:
585      return super.getProperty(hash, name, checkValid);
586    }
587
588  }
589
590  @Override
591  public Base setProperty(int hash, String name, Base value) throws FHIRException {
592    switch (hash) {
593    case -1413853096: // amount
594      this.amount = castToType(value); // Type
595      return value;
596    case -1424857166: // amountType
597      this.amountType = castToCodeableConcept(value); // CodeableConcept
598      return value;
599    case -1424876123: // amountText
600      this.amountText = castToString(value); // StringType
601      return value;
602    case -1912545102: // referenceRange
603      this.referenceRange = (SubstanceAmountReferenceRangeComponent) value; // SubstanceAmountReferenceRangeComponent
604      return value;
605    default:
606      return super.setProperty(hash, name, value);
607    }
608
609  }
610
611  @Override
612  public Base setProperty(String name, Base value) throws FHIRException {
613    if (name.equals("amount[x]")) {
614      this.amount = castToType(value); // Type
615    } else if (name.equals("amountType")) {
616      this.amountType = castToCodeableConcept(value); // CodeableConcept
617    } else if (name.equals("amountText")) {
618      this.amountText = castToString(value); // StringType
619    } else if (name.equals("referenceRange")) {
620      this.referenceRange = (SubstanceAmountReferenceRangeComponent) value; // SubstanceAmountReferenceRangeComponent
621    } else
622      return super.setProperty(name, value);
623    return value;
624  }
625
626  @Override
627  public Base makeProperty(int hash, String name) throws FHIRException {
628    switch (hash) {
629    case 646780200:
630      return getAmount();
631    case -1413853096:
632      return getAmount();
633    case -1424857166:
634      return getAmountType();
635    case -1424876123:
636      return getAmountTextElement();
637    case -1912545102:
638      return getReferenceRange();
639    default:
640      return super.makeProperty(hash, name);
641    }
642
643  }
644
645  @Override
646  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
647    switch (hash) {
648    case -1413853096:
649      /* amount */ return new String[] { "Quantity", "Range", "string" };
650    case -1424857166:
651      /* amountType */ return new String[] { "CodeableConcept" };
652    case -1424876123:
653      /* amountText */ return new String[] { "string" };
654    case -1912545102:
655      /* referenceRange */ return new String[] {};
656    default:
657      return super.getTypesForProperty(hash, name);
658    }
659
660  }
661
662  @Override
663  public Base addChild(String name) throws FHIRException {
664    if (name.equals("amountQuantity")) {
665      this.amount = new Quantity();
666      return this.amount;
667    } else if (name.equals("amountRange")) {
668      this.amount = new Range();
669      return this.amount;
670    } else if (name.equals("amountString")) {
671      this.amount = new StringType();
672      return this.amount;
673    } else if (name.equals("amountType")) {
674      this.amountType = new CodeableConcept();
675      return this.amountType;
676    } else if (name.equals("amountText")) {
677      throw new FHIRException("Cannot call addChild on a singleton property SubstanceAmount.amountText");
678    } else if (name.equals("referenceRange")) {
679      this.referenceRange = new SubstanceAmountReferenceRangeComponent();
680      return this.referenceRange;
681    } else
682      return super.addChild(name);
683  }
684
685  public String fhirType() {
686    return "SubstanceAmount";
687
688  }
689
690  public SubstanceAmount copy() {
691    SubstanceAmount dst = new SubstanceAmount();
692    copyValues(dst);
693    return dst;
694  }
695
696  public void copyValues(SubstanceAmount dst) {
697    super.copyValues(dst);
698    dst.amount = amount == null ? null : amount.copy();
699    dst.amountType = amountType == null ? null : amountType.copy();
700    dst.amountText = amountText == null ? null : amountText.copy();
701    dst.referenceRange = referenceRange == null ? null : referenceRange.copy();
702  }
703
704  protected SubstanceAmount typedCopy() {
705    return copy();
706  }
707
708  @Override
709  public boolean equalsDeep(Base other_) {
710    if (!super.equalsDeep(other_))
711      return false;
712    if (!(other_ instanceof SubstanceAmount))
713      return false;
714    SubstanceAmount o = (SubstanceAmount) other_;
715    return compareDeep(amount, o.amount, true) && compareDeep(amountType, o.amountType, true)
716        && compareDeep(amountText, o.amountText, true) && compareDeep(referenceRange, o.referenceRange, true);
717  }
718
719  @Override
720  public boolean equalsShallow(Base other_) {
721    if (!super.equalsShallow(other_))
722      return false;
723    if (!(other_ instanceof SubstanceAmount))
724      return false;
725    SubstanceAmount o = (SubstanceAmount) other_;
726    return compareValues(amountText, o.amountText, true);
727  }
728
729  public boolean isEmpty() {
730    return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(amount, amountType, amountText, referenceRange);
731  }
732
733}