001package org.hl7.fhir.r4.model;
002
003import java.math.BigDecimal;
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
035import java.util.List;
036
037import org.hl7.fhir.exceptions.FHIRException;
038import org.hl7.fhir.instance.model.api.ICompositeType;
039import org.hl7.fhir.utilities.Utilities;
040
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 * A measured amount (or an amount that can potentially be measured). Note that
047 * measured amounts include amounts that are not precisely quantified, including
048 * amounts involving arbitrary units and floating currencies.
049 */
050@DatatypeDef(name = "Quantity")
051public class Quantity extends Type implements ICompositeType, ICoding {
052
053  public enum QuantityComparator {
054    /**
055     * The actual value is less than the given value.
056     */
057    LESS_THAN,
058    /**
059     * The actual value is less than or equal to the given value.
060     */
061    LESS_OR_EQUAL,
062    /**
063     * The actual value is greater than or equal to the given value.
064     */
065    GREATER_OR_EQUAL,
066    /**
067     * The actual value is greater than the given value.
068     */
069    GREATER_THAN,
070    /**
071     * added to help the parsers with the generic types
072     */
073    NULL;
074
075    public static QuantityComparator fromCode(String codeString) throws FHIRException {
076      if (codeString == null || "".equals(codeString))
077        return null;
078      if ("<".equals(codeString))
079        return LESS_THAN;
080      if ("<=".equals(codeString))
081        return LESS_OR_EQUAL;
082      if (">=".equals(codeString))
083        return GREATER_OR_EQUAL;
084      if (">".equals(codeString))
085        return GREATER_THAN;
086      if (Configuration.isAcceptInvalidEnums())
087        return null;
088      else
089        throw new FHIRException("Unknown QuantityComparator code '" + codeString + "'");
090    }
091
092    public String toCode() {
093      switch (this) {
094      case LESS_THAN:
095        return "<";
096      case LESS_OR_EQUAL:
097        return "<=";
098      case GREATER_OR_EQUAL:
099        return ">=";
100      case GREATER_THAN:
101        return ">";
102      case NULL:
103        return null;
104      default:
105        return "?";
106      }
107    }
108
109    public String getSystem() {
110      switch (this) {
111      case LESS_THAN:
112        return "http://hl7.org/fhir/quantity-comparator";
113      case LESS_OR_EQUAL:
114        return "http://hl7.org/fhir/quantity-comparator";
115      case GREATER_OR_EQUAL:
116        return "http://hl7.org/fhir/quantity-comparator";
117      case GREATER_THAN:
118        return "http://hl7.org/fhir/quantity-comparator";
119      case NULL:
120        return null;
121      default:
122        return "?";
123      }
124    }
125
126    public String getDefinition() {
127      switch (this) {
128      case LESS_THAN:
129        return "The actual value is less than the given value.";
130      case LESS_OR_EQUAL:
131        return "The actual value is less than or equal to the given value.";
132      case GREATER_OR_EQUAL:
133        return "The actual value is greater than or equal to the given value.";
134      case GREATER_THAN:
135        return "The actual value is greater than the given value.";
136      case NULL:
137        return null;
138      default:
139        return "?";
140      }
141    }
142
143    public String getDisplay() {
144      switch (this) {
145      case LESS_THAN:
146        return "Less than";
147      case LESS_OR_EQUAL:
148        return "Less or Equal to";
149      case GREATER_OR_EQUAL:
150        return "Greater or Equal to";
151      case GREATER_THAN:
152        return "Greater than";
153      case NULL:
154        return null;
155      default:
156        return "?";
157      }
158    }
159  }
160
161  public static class QuantityComparatorEnumFactory implements EnumFactory<QuantityComparator> {
162    public QuantityComparator fromCode(String codeString) throws IllegalArgumentException {
163      if (codeString == null || "".equals(codeString))
164        if (codeString == null || "".equals(codeString))
165          return null;
166      if ("<".equals(codeString))
167        return QuantityComparator.LESS_THAN;
168      if ("<=".equals(codeString))
169        return QuantityComparator.LESS_OR_EQUAL;
170      if (">=".equals(codeString))
171        return QuantityComparator.GREATER_OR_EQUAL;
172      if (">".equals(codeString))
173        return QuantityComparator.GREATER_THAN;
174      throw new IllegalArgumentException("Unknown QuantityComparator code '" + codeString + "'");
175    }
176
177    public Enumeration<QuantityComparator> fromType(PrimitiveType<?> code) throws FHIRException {
178      if (code == null)
179        return null;
180      if (code.isEmpty())
181        return new Enumeration<QuantityComparator>(this, QuantityComparator.NULL, code);
182      String codeString = code.asStringValue();
183      if (codeString == null || "".equals(codeString))
184        return new Enumeration<QuantityComparator>(this, QuantityComparator.NULL, code);
185      if ("<".equals(codeString))
186        return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_THAN, code);
187      if ("<=".equals(codeString))
188        return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_OR_EQUAL, code);
189      if (">=".equals(codeString))
190        return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_OR_EQUAL, code);
191      if (">".equals(codeString))
192        return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_THAN, code);
193      throw new FHIRException("Unknown QuantityComparator code '" + codeString + "'");
194    }
195
196    public String toCode(QuantityComparator code) {
197      if (code == QuantityComparator.LESS_THAN)
198        return "<";
199      if (code == QuantityComparator.LESS_OR_EQUAL)
200        return "<=";
201      if (code == QuantityComparator.GREATER_OR_EQUAL)
202        return ">=";
203      if (code == QuantityComparator.GREATER_THAN)
204        return ">";
205      return "?";
206    }
207
208    public String toSystem(QuantityComparator code) {
209      return code.getSystem();
210    }
211  }
212
213  /**
214   * The value of the measured amount. The value includes an implicit precision in
215   * the presentation of the value.
216   */
217  @Child(name = "value", type = { DecimalType.class }, order = 0, min = 0, max = 1, modifier = false, summary = true)
218  @Description(shortDefinition = "Numerical value (with implicit precision)", formalDefinition = "The value of the measured amount. The value includes an implicit precision in the presentation of the value.")
219  protected DecimalType value;
220
221  /**
222   * How the value should be understood and represented - whether the actual value
223   * is greater or less than the stated value due to measurement issues; e.g. if
224   * the comparator is "<" , then the real value is < stated value.
225   */
226  @Child(name = "comparator", type = { CodeType.class }, order = 1, min = 0, max = 1, modifier = true, summary = true)
227  @Description(shortDefinition = "< | <= | >= | > - how to understand the value", formalDefinition = "How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is \"<\" , then the real value is < stated value.")
228  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/quantity-comparator")
229  protected Enumeration<QuantityComparator> comparator;
230
231  /**
232   * A human-readable form of the unit.
233   */
234  @Child(name = "unit", type = { StringType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
235  @Description(shortDefinition = "Unit representation", formalDefinition = "A human-readable form of the unit.")
236  protected StringType unit;
237
238  /**
239   * The identification of the system that provides the coded form of the unit.
240   */
241  @Child(name = "system", type = { UriType.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
242  @Description(shortDefinition = "System that defines coded unit form", formalDefinition = "The identification of the system that provides the coded form of the unit.")
243  protected UriType system;
244
245  /**
246   * A computer processable form of the unit in some unit representation system.
247   */
248  @Child(name = "code", type = { CodeType.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
249  @Description(shortDefinition = "Coded form of the unit", formalDefinition = "A computer processable form of the unit in some unit representation system.")
250  protected CodeType code;
251
252  private static final long serialVersionUID = 1069574054L;
253
254  /**
255   * Constructor
256   */
257  public Quantity() {
258    super();
259  }
260
261  /**
262   * Convenience constructor
263   * 
264   * @param theValue The {@link #setValue(double) value}
265   */
266  public Quantity(double theValue) {
267    setValue(theValue);
268  }
269
270  /**
271   * Convenience constructor
272   * 
273   * @param theValue The {@link #setValue(long) value}
274   */
275  public Quantity(long theValue) {
276    setValue(theValue);
277  }
278
279  /**
280   * Convenience constructor
281   * 
282   * @param theComparator The {@link #setComparator(QuantityComparator)
283   *                      comparator}
284   * @param theValue      The {@link #setValue(BigDecimal) value}
285   * @param theSystem     The {@link #setSystem(String)} (the code system for the
286   *                      units}
287   * @param theCode       The {@link #setCode(String)} (the code for the units}
288   * @param theUnit       The {@link #setUnit(String)} (the human readable display
289   *                      name for the units}
290   */
291  public Quantity(QuantityComparator theComparator, double theValue, String theSystem, String theCode, String theUnit) {
292    setValue(theValue);
293    setComparator(theComparator);
294    setSystem(theSystem);
295    setCode(theCode);
296    setUnit(theUnit);
297  }
298
299  /**
300   * Convenience constructor
301   * 
302   * @param theComparator The {@link #setComparator(QuantityComparator)
303   *                      comparator}
304   * @param theValue      The {@link #setValue(BigDecimal) value}
305   * @param theSystem     The {@link #setSystem(String)} (the code system for the
306   *                      units}
307   * @param theCode       The {@link #setCode(String)} (the code for the units}
308   * @param theUnit       The {@link #setUnit(String)} (the human readable display
309   *                      name for the units}
310   */
311  public Quantity(QuantityComparator theComparator, long theValue, String theSystem, String theCode, String theUnit) {
312    setValue(theValue);
313    setComparator(theComparator);
314    setSystem(theSystem);
315    setCode(theCode);
316    setUnit(theUnit);
317  }
318
319  /**
320   * @return {@link #value} (The value of the measured amount. The value includes
321   *         an implicit precision in the presentation of the value.). This is the
322   *         underlying object with id, value and extensions. The accessor
323   *         "getValue" gives direct access to the value
324   */
325  public DecimalType getValueElement() {
326    if (this.value == null)
327      if (Configuration.errorOnAutoCreate())
328        throw new Error("Attempt to auto-create Quantity.value");
329      else if (Configuration.doAutoCreate())
330        this.value = new DecimalType(); // bb
331    return this.value;
332  }
333
334  public boolean hasValueElement() {
335    return this.value != null && !this.value.isEmpty();
336  }
337
338  public boolean hasValue() {
339    return this.value != null && !this.value.isEmpty();
340  }
341
342  /**
343   * @param value {@link #value} (The value of the measured amount. The value
344   *              includes an implicit precision in the presentation of the
345   *              value.). This is the underlying object with id, value and
346   *              extensions. The accessor "getValue" gives direct access to the
347   *              value
348   */
349  public Quantity setValueElement(DecimalType value) {
350    this.value = value;
351    return this;
352  }
353
354  /**
355   * @return The value of the measured amount. The value includes an implicit
356   *         precision in the presentation of the value.
357   */
358  public BigDecimal getValue() {
359    return this.value == null ? null : this.value.getValue();
360  }
361
362  /**
363   * @param value The value of the measured amount. The value includes an implicit
364   *              precision in the presentation of the value.
365   */
366  public Quantity setValue(BigDecimal value) {
367    if (value == null)
368      this.value = null;
369    else {
370      if (this.value == null)
371        this.value = new DecimalType();
372      this.value.setValue(value);
373    }
374    return this;
375  }
376
377  /**
378   * @param value The value of the measured amount. The value includes an implicit
379   *              precision in the presentation of the value.
380   */
381  public Quantity setValue(long value) {
382    this.value = new DecimalType();
383    this.value.setValue(value);
384    return this;
385  }
386
387  /**
388   * @param value The value of the measured amount. The value includes an implicit
389   *              precision in the presentation of the value.
390   */
391  public Quantity setValue(double value) {
392    this.value = new DecimalType();
393    this.value.setValue(value);
394    return this;
395  }
396
397  /**
398   * @return {@link #comparator} (How the value should be understood and
399   *         represented - whether the actual value is greater or less than the
400   *         stated value due to measurement issues; e.g. if the comparator is "<"
401   *         , then the real value is < stated value.). This is the underlying
402   *         object with id, value and extensions. The accessor "getComparator"
403   *         gives direct access to the value
404   */
405  public Enumeration<QuantityComparator> getComparatorElement() {
406    if (this.comparator == null)
407      if (Configuration.errorOnAutoCreate())
408        throw new Error("Attempt to auto-create Quantity.comparator");
409      else if (Configuration.doAutoCreate())
410        this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory()); // bb
411    return this.comparator;
412  }
413
414  public boolean hasComparatorElement() {
415    return this.comparator != null && !this.comparator.isEmpty();
416  }
417
418  public boolean hasComparator() {
419    return this.comparator != null && !this.comparator.isEmpty();
420  }
421
422  /**
423   * @param value {@link #comparator} (How the value should be understood and
424   *              represented - whether the actual value is greater or less than
425   *              the stated value due to measurement issues; e.g. if the
426   *              comparator is "<" , then the real value is < stated value.).
427   *              This is the underlying object with id, value and extensions. The
428   *              accessor "getComparator" gives direct access to the value
429   */
430  public Quantity setComparatorElement(Enumeration<QuantityComparator> value) {
431    this.comparator = value;
432    return this;
433  }
434
435  /**
436   * @return How the value should be understood and represented - whether the
437   *         actual value is greater or less than the stated value due to
438   *         measurement issues; e.g. if the comparator is "<" , then the real
439   *         value is < stated value.
440   */
441  public QuantityComparator getComparator() {
442    return this.comparator == null ? null : this.comparator.getValue();
443  }
444
445  /**
446   * @param value How the value should be understood and represented - whether the
447   *              actual value is greater or less than the stated value due to
448   *              measurement issues; e.g. if the comparator is "<" , then the
449   *              real value is < stated value.
450   */
451  public Quantity setComparator(QuantityComparator value) {
452    if (value == null)
453      this.comparator = null;
454    else {
455      if (this.comparator == null)
456        this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory());
457      this.comparator.setValue(value);
458    }
459    return this;
460  }
461
462  /**
463   * @return {@link #unit} (A human-readable form of the unit.). This is the
464   *         underlying object with id, value and extensions. The accessor
465   *         "getUnit" gives direct access to the value
466   */
467  public StringType getUnitElement() {
468    if (this.unit == null)
469      if (Configuration.errorOnAutoCreate())
470        throw new Error("Attempt to auto-create Quantity.unit");
471      else if (Configuration.doAutoCreate())
472        this.unit = new StringType(); // bb
473    return this.unit;
474  }
475
476  public boolean hasUnitElement() {
477    return this.unit != null && !this.unit.isEmpty();
478  }
479
480  public boolean hasUnit() {
481    return this.unit != null && !this.unit.isEmpty();
482  }
483
484  /**
485   * @param value {@link #unit} (A human-readable form of the unit.). This is the
486   *              underlying object with id, value and extensions. The accessor
487   *              "getUnit" gives direct access to the value
488   */
489  public Quantity setUnitElement(StringType value) {
490    this.unit = value;
491    return this;
492  }
493
494  /**
495   * @return A human-readable form of the unit.
496   */
497  public String getUnit() {
498    return this.unit == null ? null : this.unit.getValue();
499  }
500
501  /**
502   * @param value A human-readable form of the unit.
503   */
504  public Quantity setUnit(String value) {
505    if (Utilities.noString(value))
506      this.unit = null;
507    else {
508      if (this.unit == null)
509        this.unit = new StringType();
510      this.unit.setValue(value);
511    }
512    return this;
513  }
514
515  /**
516   * @return {@link #system} (The identification of the system that provides the
517   *         coded form of the unit.). This is the underlying object with id,
518   *         value and extensions. The accessor "getSystem" gives direct access to
519   *         the value
520   */
521  public UriType getSystemElement() {
522    if (this.system == null)
523      if (Configuration.errorOnAutoCreate())
524        throw new Error("Attempt to auto-create Quantity.system");
525      else if (Configuration.doAutoCreate())
526        this.system = new UriType(); // bb
527    return this.system;
528  }
529
530  public boolean hasSystemElement() {
531    return this.system != null && !this.system.isEmpty();
532  }
533
534  public boolean hasSystem() {
535    return this.system != null && !this.system.isEmpty();
536  }
537
538  /**
539   * @param value {@link #system} (The identification of the system that provides
540   *              the coded form of the unit.). This is the underlying object with
541   *              id, value and extensions. The accessor "getSystem" gives direct
542   *              access to the value
543   */
544  public Quantity setSystemElement(UriType value) {
545    this.system = value;
546    return this;
547  }
548
549  /**
550   * @return The identification of the system that provides the coded form of the
551   *         unit.
552   */
553  public String getSystem() {
554    return this.system == null ? null : this.system.getValue();
555  }
556
557  /**
558   * @param value The identification of the system that provides the coded form of
559   *              the unit.
560   */
561  public Quantity setSystem(String value) {
562    if (Utilities.noString(value))
563      this.system = null;
564    else {
565      if (this.system == null)
566        this.system = new UriType();
567      this.system.setValue(value);
568    }
569    return this;
570  }
571
572  /**
573   * @return {@link #code} (A computer processable form of the unit in some unit
574   *         representation system.). This is the underlying object with id, value
575   *         and extensions. The accessor "getCode" gives direct access to the
576   *         value
577   */
578  public CodeType getCodeElement() {
579    if (this.code == null)
580      if (Configuration.errorOnAutoCreate())
581        throw new Error("Attempt to auto-create Quantity.code");
582      else if (Configuration.doAutoCreate())
583        this.code = new CodeType(); // bb
584    return this.code;
585  }
586
587  public boolean hasCodeElement() {
588    return this.code != null && !this.code.isEmpty();
589  }
590
591  public boolean hasCode() {
592    return this.code != null && !this.code.isEmpty();
593  }
594
595  /**
596   * @param value {@link #code} (A computer processable form of the unit in some
597   *              unit representation system.). This is the underlying object with
598   *              id, value and extensions. The accessor "getCode" gives direct
599   *              access to the value
600   */
601  public Quantity setCodeElement(CodeType value) {
602    this.code = value;
603    return this;
604  }
605
606  /**
607   * @return A computer processable form of the unit in some unit representation
608   *         system.
609   */
610  public String getCode() {
611    return this.code == null ? null : this.code.getValue();
612  }
613
614  /**
615   * @param value A computer processable form of the unit in some unit
616   *              representation system.
617   */
618  public Quantity setCode(String value) {
619    if (Utilities.noString(value))
620      this.code = null;
621    else {
622      if (this.code == null)
623        this.code = new CodeType();
624      this.code.setValue(value);
625    }
626    return this;
627  }
628
629  protected void listChildren(List<Property> children) {
630    super.listChildren(children);
631    children.add(new Property("value", "decimal",
632        "The value of the measured amount. The value includes an implicit precision in the presentation of the value.",
633        0, 1, value));
634    children.add(new Property("comparator", "code",
635        "How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is \"<\" , then the real value is < stated value.",
636        0, 1, comparator));
637    children.add(new Property("unit", "string", "A human-readable form of the unit.", 0, 1, unit));
638    children.add(new Property("system", "uri",
639        "The identification of the system that provides the coded form of the unit.", 0, 1, system));
640    children.add(new Property("code", "code",
641        "A computer processable form of the unit in some unit representation system.", 0, 1, code));
642  }
643
644  @Override
645  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
646    switch (_hash) {
647    case 111972721:
648      /* value */ return new Property("value", "decimal",
649          "The value of the measured amount. The value includes an implicit precision in the presentation of the value.",
650          0, 1, value);
651    case -844673834:
652      /* comparator */ return new Property("comparator", "code",
653          "How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is \"<\" , then the real value is < stated value.",
654          0, 1, comparator);
655    case 3594628:
656      /* unit */ return new Property("unit", "string", "A human-readable form of the unit.", 0, 1, unit);
657    case -887328209:
658      /* system */ return new Property("system", "uri",
659          "The identification of the system that provides the coded form of the unit.", 0, 1, system);
660    case 3059181:
661      /* code */ return new Property("code", "code",
662          "A computer processable form of the unit in some unit representation system.", 0, 1, code);
663    default:
664      return super.getNamedProperty(_hash, _name, _checkValid);
665    }
666
667  }
668
669  @Override
670  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
671    switch (hash) {
672    case 111972721:
673      /* value */ return this.value == null ? new Base[0] : new Base[] { this.value }; // DecimalType
674    case -844673834:
675      /* comparator */ return this.comparator == null ? new Base[0] : new Base[] { this.comparator }; // Enumeration<QuantityComparator>
676    case 3594628:
677      /* unit */ return this.unit == null ? new Base[0] : new Base[] { this.unit }; // StringType
678    case -887328209:
679      /* system */ return this.system == null ? new Base[0] : new Base[] { this.system }; // UriType
680    case 3059181:
681      /* code */ return this.code == null ? new Base[0] : new Base[] { this.code }; // CodeType
682    default:
683      return super.getProperty(hash, name, checkValid);
684    }
685
686  }
687
688  @Override
689  public Base setProperty(int hash, String name, Base value) throws FHIRException {
690    switch (hash) {
691    case 111972721: // value
692      this.value = castToDecimal(value); // DecimalType
693      return value;
694    case -844673834: // comparator
695      value = new QuantityComparatorEnumFactory().fromType(castToCode(value));
696      this.comparator = (Enumeration) value; // Enumeration<QuantityComparator>
697      return value;
698    case 3594628: // unit
699      this.unit = castToString(value); // StringType
700      return value;
701    case -887328209: // system
702      this.system = castToUri(value); // UriType
703      return value;
704    case 3059181: // code
705      this.code = castToCode(value); // CodeType
706      return value;
707    default:
708      return super.setProperty(hash, name, value);
709    }
710
711  }
712
713  @Override
714  public Base setProperty(String name, Base value) throws FHIRException {
715    if (name.equals("value")) {
716      this.value = castToDecimal(value); // DecimalType
717    } else if (name.equals("comparator")) {
718      value = new QuantityComparatorEnumFactory().fromType(castToCode(value));
719      this.comparator = (Enumeration) value; // Enumeration<QuantityComparator>
720    } else if (name.equals("unit")) {
721      this.unit = castToString(value); // StringType
722    } else if (name.equals("system")) {
723      this.system = castToUri(value); // UriType
724    } else if (name.equals("code")) {
725      this.code = castToCode(value); // CodeType
726    } else
727      return super.setProperty(name, value);
728    return value;
729  }
730
731  @Override
732  public Base makeProperty(int hash, String name) throws FHIRException {
733    switch (hash) {
734    case 111972721:
735      return getValueElement();
736    case -844673834:
737      return getComparatorElement();
738    case 3594628:
739      return getUnitElement();
740    case -887328209:
741      return getSystemElement();
742    case 3059181:
743      return getCodeElement();
744    default:
745      return super.makeProperty(hash, name);
746    }
747
748  }
749
750  @Override
751  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
752    switch (hash) {
753    case 111972721:
754      /* value */ return new String[] { "decimal" };
755    case -844673834:
756      /* comparator */ return new String[] { "code" };
757    case 3594628:
758      /* unit */ return new String[] { "string" };
759    case -887328209:
760      /* system */ return new String[] { "uri" };
761    case 3059181:
762      /* code */ return new String[] { "code" };
763    default:
764      return super.getTypesForProperty(hash, name);
765    }
766
767  }
768
769  @Override
770  public Base addChild(String name) throws FHIRException {
771    if (name.equals("value")) {
772      throw new FHIRException("Cannot call addChild on a singleton property Quantity.value");
773    } else if (name.equals("comparator")) {
774      throw new FHIRException("Cannot call addChild on a singleton property Quantity.comparator");
775    } else if (name.equals("unit")) {
776      throw new FHIRException("Cannot call addChild on a singleton property Quantity.unit");
777    } else if (name.equals("system")) {
778      throw new FHIRException("Cannot call addChild on a singleton property Quantity.system");
779    } else if (name.equals("code")) {
780      throw new FHIRException("Cannot call addChild on a singleton property Quantity.code");
781    } else
782      return super.addChild(name);
783  }
784
785  public String fhirType() {
786    return "Quantity";
787
788  }
789
790  public Quantity copy() {
791    Quantity dst = new Quantity();
792    copyValues(dst);
793    return dst;
794  }
795
796  public void copyValues(Quantity dst) {
797    super.copyValues(dst);
798    dst.value = value == null ? null : value.copy();
799    dst.comparator = comparator == null ? null : comparator.copy();
800    dst.unit = unit == null ? null : unit.copy();
801    dst.system = system == null ? null : system.copy();
802    dst.code = code == null ? null : code.copy();
803  }
804
805  protected Quantity typedCopy() {
806    return copy();
807  }
808
809  @Override
810  public boolean equalsDeep(Base other_) {
811    if (!super.equalsDeep(other_))
812      return false;
813    if (!(other_ instanceof Quantity))
814      return false;
815    Quantity o = (Quantity) other_;
816    return compareDeep(value, o.value, true) && compareDeep(comparator, o.comparator, true)
817        && compareDeep(unit, o.unit, true) && compareDeep(system, o.system, true) && compareDeep(code, o.code, true);
818  }
819
820  @Override
821  public boolean equalsShallow(Base other_) {
822    if (!super.equalsShallow(other_))
823      return false;
824    if (!(other_ instanceof Quantity))
825      return false;
826    Quantity o = (Quantity) other_;
827    return compareValues(value, o.value, true) && compareValues(comparator, o.comparator, true)
828        && compareValues(unit, o.unit, true) && compareValues(system, o.system, true)
829        && compareValues(code, o.code, true);
830  }
831
832  public boolean isEmpty() {
833    return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(value, comparator, unit, system, code);
834  }
835
836// added from java-adornments.txt:
837
838  @Override
839  public String getVersion() {
840    return null;
841  }
842
843  @Override
844  public boolean hasVersion() {
845    return false;
846  }
847
848  @Override
849  public boolean supportsVersion() {
850    return false;
851  }
852
853  @Override
854  public String getDisplay() {
855    return null;
856  }
857
858  @Override
859  public boolean hasDisplay() {
860    return false;
861  }
862
863  @Override
864  public boolean supportsDisplay() {
865    return false;
866  }
867
868  public static Quantity fromUcum(String v, String code) {
869    Quantity res = new Quantity();
870    res.setValue(new BigDecimal(v));
871    res.setSystem("http://unitsofmeasure.org");
872    res.setCode(code);
873    return res;
874  }
875
876// end addition
877
878}