001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
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.*;
042/**
043 * A measured amount (or an amount that can potentially be measured). Note that measured amounts include amounts that are not precisely quantified, including amounts involving arbitrary units and floating currencies.
044 */
045@DatatypeDef(name="Quantity")
046public class Quantity extends Type implements ICompositeType {
047
048    public enum QuantityComparator {
049        /**
050         * The actual value is less than the given value.
051         */
052        LESS_THAN, 
053        /**
054         * The actual value is less than or equal to the given value.
055         */
056        LESS_OR_EQUAL, 
057        /**
058         * The actual value is greater than or equal to the given value.
059         */
060        GREATER_OR_EQUAL, 
061        /**
062         * The actual value is greater than the given value.
063         */
064        GREATER_THAN, 
065        /**
066         * added to help the parsers
067         */
068        NULL;
069        public static QuantityComparator fromCode(String codeString) throws FHIRException {
070            if (codeString == null || "".equals(codeString))
071                return null;
072        if ("<".equals(codeString))
073          return LESS_THAN;
074        if ("<=".equals(codeString))
075          return LESS_OR_EQUAL;
076        if (">=".equals(codeString))
077          return GREATER_OR_EQUAL;
078        if (">".equals(codeString))
079          return GREATER_THAN;
080        throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'");
081        }
082        public String toCode() {
083          switch (this) {
084            case LESS_THAN: return "<";
085            case LESS_OR_EQUAL: return "<=";
086            case GREATER_OR_EQUAL: return ">=";
087            case GREATER_THAN: return ">";
088            default: return "?";
089          }
090        }
091        public String getSystem() {
092          switch (this) {
093            case LESS_THAN: return "http://hl7.org/fhir/quantity-comparator";
094            case LESS_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator";
095            case GREATER_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator";
096            case GREATER_THAN: return "http://hl7.org/fhir/quantity-comparator";
097            default: return "?";
098          }
099        }
100        public String getDefinition() {
101          switch (this) {
102            case LESS_THAN: return "The actual value is less than the given value.";
103            case LESS_OR_EQUAL: return "The actual value is less than or equal to the given value.";
104            case GREATER_OR_EQUAL: return "The actual value is greater than or equal to the given value.";
105            case GREATER_THAN: return "The actual value is greater than the given value.";
106            default: return "?";
107          }
108        }
109        public String getDisplay() {
110          switch (this) {
111            case LESS_THAN: return "Less than";
112            case LESS_OR_EQUAL: return "Less or Equal to";
113            case GREATER_OR_EQUAL: return "Greater or Equal to";
114            case GREATER_THAN: return "Greater than";
115            default: return "?";
116          }
117        }
118    }
119
120  public static class QuantityComparatorEnumFactory implements EnumFactory<QuantityComparator> {
121    public QuantityComparator fromCode(String codeString) throws IllegalArgumentException {
122      if (codeString == null || "".equals(codeString))
123            if (codeString == null || "".equals(codeString))
124                return null;
125        if ("<".equals(codeString))
126          return QuantityComparator.LESS_THAN;
127        if ("<=".equals(codeString))
128          return QuantityComparator.LESS_OR_EQUAL;
129        if (">=".equals(codeString))
130          return QuantityComparator.GREATER_OR_EQUAL;
131        if (">".equals(codeString))
132          return QuantityComparator.GREATER_THAN;
133        throw new IllegalArgumentException("Unknown QuantityComparator code '"+codeString+"'");
134        }
135        public Enumeration<QuantityComparator> fromType(Base code) throws FHIRException {
136          if (code == null || code.isEmpty())
137            return null;
138          String codeString = ((PrimitiveType) code).asStringValue();
139          if (codeString == null || "".equals(codeString))
140            return null;
141        if ("<".equals(codeString))
142          return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_THAN);
143        if ("<=".equals(codeString))
144          return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_OR_EQUAL);
145        if (">=".equals(codeString))
146          return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_OR_EQUAL);
147        if (">".equals(codeString))
148          return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_THAN);
149        throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'");
150        }
151    public String toCode(QuantityComparator code) {
152      if (code == QuantityComparator.LESS_THAN)
153        return "<";
154      if (code == QuantityComparator.LESS_OR_EQUAL)
155        return "<=";
156      if (code == QuantityComparator.GREATER_OR_EQUAL)
157        return ">=";
158      if (code == QuantityComparator.GREATER_THAN)
159        return ">";
160      return "?";
161      }
162    }
163
164    /**
165     * The value of the measured amount. The value includes an implicit precision in the presentation of the value.
166     */
167    @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true)
168    @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." )
169    protected DecimalType value;
170
171    /**
172     * 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.
173     */
174    @Child(name = "comparator", type = {CodeType.class}, order=1, min=0, max=1, modifier=true, summary=true)
175    @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." )
176    protected Enumeration<QuantityComparator> comparator;
177
178    /**
179     * A human-readable form of the unit.
180     */
181    @Child(name = "unit", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=true)
182    @Description(shortDefinition="Unit representation", formalDefinition="A human-readable form of the unit." )
183    protected StringType unit;
184
185    /**
186     * The identification of the system that provides the coded form of the unit.
187     */
188    @Child(name = "system", type = {UriType.class}, order=3, min=0, max=1, modifier=false, summary=true)
189    @Description(shortDefinition="System that defines coded unit form", formalDefinition="The identification of the system that provides the coded form of the unit." )
190    protected UriType system;
191
192    /**
193     * A computer processable form of the unit in some unit representation system.
194     */
195    @Child(name = "code", type = {CodeType.class}, order=4, min=0, max=1, modifier=false, summary=true)
196    @Description(shortDefinition="Coded form of the unit", formalDefinition="A computer processable form of the unit in some unit representation system." )
197    protected CodeType code;
198
199    private static final long serialVersionUID = 1069574054L;
200
201  /*
202   * Constructor
203   */
204    public Quantity() {
205      super();
206    }
207
208    /**
209     * @return {@link #value} (The value of the measured amount. The value includes an implicit precision in the presentation of the value.). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value
210     */
211    public DecimalType getValueElement() { 
212      if (this.value == null)
213        if (Configuration.errorOnAutoCreate())
214          throw new Error("Attempt to auto-create Quantity.value");
215        else if (Configuration.doAutoCreate())
216          this.value = new DecimalType(); // bb
217      return this.value;
218    }
219
220    public boolean hasValueElement() { 
221      return this.value != null && !this.value.isEmpty();
222    }
223
224    public boolean hasValue() { 
225      return this.value != null && !this.value.isEmpty();
226    }
227
228    /**
229     * @param value {@link #value} (The value of the measured amount. The value includes an implicit precision in the presentation of the value.). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value
230     */
231    public Quantity setValueElement(DecimalType value) { 
232      this.value = value;
233      return this;
234    }
235
236    /**
237     * @return The value of the measured amount. The value includes an implicit precision in the presentation of the value.
238     */
239    public BigDecimal getValue() { 
240      return this.value == null ? null : this.value.getValue();
241    }
242
243    /**
244     * @param value The value of the measured amount. The value includes an implicit precision in the presentation of the value.
245     */
246    public Quantity setValue(BigDecimal value) { 
247      if (value == null)
248        this.value = null;
249      else {
250        if (this.value == null)
251          this.value = new DecimalType();
252        this.value.setValue(value);
253      }
254      return this;
255    }
256
257    /**
258     * @return {@link #comparator} (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.). This is the underlying object with id, value and extensions. The accessor "getComparator" gives direct access to the value
259     */
260    public Enumeration<QuantityComparator> getComparatorElement() { 
261      if (this.comparator == null)
262        if (Configuration.errorOnAutoCreate())
263          throw new Error("Attempt to auto-create Quantity.comparator");
264        else if (Configuration.doAutoCreate())
265          this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory()); // bb
266      return this.comparator;
267    }
268
269    public boolean hasComparatorElement() { 
270      return this.comparator != null && !this.comparator.isEmpty();
271    }
272
273    public boolean hasComparator() { 
274      return this.comparator != null && !this.comparator.isEmpty();
275    }
276
277    /**
278     * @param value {@link #comparator} (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.). This is the underlying object with id, value and extensions. The accessor "getComparator" gives direct access to the value
279     */
280    public Quantity setComparatorElement(Enumeration<QuantityComparator> value) { 
281      this.comparator = value;
282      return this;
283    }
284
285    /**
286     * @return 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.
287     */
288    public QuantityComparator getComparator() { 
289      return this.comparator == null ? null : this.comparator.getValue();
290    }
291
292    /**
293     * @param value 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.
294     */
295    public Quantity setComparator(QuantityComparator value) { 
296      if (value == null)
297        this.comparator = null;
298      else {
299        if (this.comparator == null)
300          this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory());
301        this.comparator.setValue(value);
302      }
303      return this;
304    }
305
306    /**
307     * @return {@link #unit} (A human-readable form of the unit.). This is the underlying object with id, value and extensions. The accessor "getUnit" gives direct access to the value
308     */
309    public StringType getUnitElement() { 
310      if (this.unit == null)
311        if (Configuration.errorOnAutoCreate())
312          throw new Error("Attempt to auto-create Quantity.unit");
313        else if (Configuration.doAutoCreate())
314          this.unit = new StringType(); // bb
315      return this.unit;
316    }
317
318    public boolean hasUnitElement() { 
319      return this.unit != null && !this.unit.isEmpty();
320    }
321
322    public boolean hasUnit() { 
323      return this.unit != null && !this.unit.isEmpty();
324    }
325
326    /**
327     * @param value {@link #unit} (A human-readable form of the unit.). This is the underlying object with id, value and extensions. The accessor "getUnit" gives direct access to the value
328     */
329    public Quantity setUnitElement(StringType value) { 
330      this.unit = value;
331      return this;
332    }
333
334    /**
335     * @return A human-readable form of the unit.
336     */
337    public String getUnit() { 
338      return this.unit == null ? null : this.unit.getValue();
339    }
340
341    /**
342     * @param value A human-readable form of the unit.
343     */
344    public Quantity setUnit(String value) { 
345      if (Utilities.noString(value))
346        this.unit = null;
347      else {
348        if (this.unit == null)
349          this.unit = new StringType();
350        this.unit.setValue(value);
351      }
352      return this;
353    }
354
355    /**
356     * @return {@link #system} (The identification of the system that provides the coded form of the unit.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value
357     */
358    public UriType getSystemElement() { 
359      if (this.system == null)
360        if (Configuration.errorOnAutoCreate())
361          throw new Error("Attempt to auto-create Quantity.system");
362        else if (Configuration.doAutoCreate())
363          this.system = new UriType(); // bb
364      return this.system;
365    }
366
367    public boolean hasSystemElement() { 
368      return this.system != null && !this.system.isEmpty();
369    }
370
371    public boolean hasSystem() { 
372      return this.system != null && !this.system.isEmpty();
373    }
374
375    /**
376     * @param value {@link #system} (The identification of the system that provides the coded form of the unit.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value
377     */
378    public Quantity setSystemElement(UriType value) { 
379      this.system = value;
380      return this;
381    }
382
383    /**
384     * @return The identification of the system that provides the coded form of the unit.
385     */
386    public String getSystem() { 
387      return this.system == null ? null : this.system.getValue();
388    }
389
390    /**
391     * @param value The identification of the system that provides the coded form of the unit.
392     */
393    public Quantity setSystem(String value) { 
394      if (Utilities.noString(value))
395        this.system = null;
396      else {
397        if (this.system == null)
398          this.system = new UriType();
399        this.system.setValue(value);
400      }
401      return this;
402    }
403
404    /**
405     * @return {@link #code} (A computer processable form of the unit in some unit representation system.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value
406     */
407    public CodeType getCodeElement() { 
408      if (this.code == null)
409        if (Configuration.errorOnAutoCreate())
410          throw new Error("Attempt to auto-create Quantity.code");
411        else if (Configuration.doAutoCreate())
412          this.code = new CodeType(); // bb
413      return this.code;
414    }
415
416    public boolean hasCodeElement() { 
417      return this.code != null && !this.code.isEmpty();
418    }
419
420    public boolean hasCode() { 
421      return this.code != null && !this.code.isEmpty();
422    }
423
424    /**
425     * @param value {@link #code} (A computer processable form of the unit in some unit representation system.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value
426     */
427    public Quantity setCodeElement(CodeType value) { 
428      this.code = value;
429      return this;
430    }
431
432    /**
433     * @return A computer processable form of the unit in some unit representation system.
434     */
435    public String getCode() { 
436      return this.code == null ? null : this.code.getValue();
437    }
438
439    /**
440     * @param value A computer processable form of the unit in some unit representation system.
441     */
442    public Quantity setCode(String value) { 
443      if (Utilities.noString(value))
444        this.code = null;
445      else {
446        if (this.code == null)
447          this.code = new CodeType();
448        this.code.setValue(value);
449      }
450      return this;
451    }
452
453      protected void listChildren(List<Property> childrenList) {
454        super.listChildren(childrenList);
455        childrenList.add(new Property("value", "decimal", "The value of the measured amount. The value includes an implicit precision in the presentation of the value.", 0, java.lang.Integer.MAX_VALUE, value));
456        childrenList.add(new Property("comparator", "code", "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.", 0, java.lang.Integer.MAX_VALUE, comparator));
457        childrenList.add(new Property("unit", "string", "A human-readable form of the unit.", 0, java.lang.Integer.MAX_VALUE, unit));
458        childrenList.add(new Property("system", "uri", "The identification of the system that provides the coded form of the unit.", 0, java.lang.Integer.MAX_VALUE, system));
459        childrenList.add(new Property("code", "code", "A computer processable form of the unit in some unit representation system.", 0, java.lang.Integer.MAX_VALUE, code));
460      }
461
462      @Override
463      public void setProperty(String name, Base value) throws FHIRException {
464        if (name.equals("value"))
465          this.value = castToDecimal(value); // DecimalType
466        else if (name.equals("comparator"))
467          this.comparator = new QuantityComparatorEnumFactory().fromType(value); // Enumeration<QuantityComparator>
468        else if (name.equals("unit"))
469          this.unit = castToString(value); // StringType
470        else if (name.equals("system"))
471          this.system = castToUri(value); // UriType
472        else if (name.equals("code"))
473          this.code = castToCode(value); // CodeType
474        else
475          super.setProperty(name, value);
476      }
477
478      @Override
479      public Base addChild(String name) throws FHIRException {
480        if (name.equals("value")) {
481          throw new FHIRException("Cannot call addChild on a primitive type Quantity.value");
482        }
483        else if (name.equals("comparator")) {
484          throw new FHIRException("Cannot call addChild on a primitive type Quantity.comparator");
485        }
486        else if (name.equals("unit")) {
487          throw new FHIRException("Cannot call addChild on a primitive type Quantity.unit");
488        }
489        else if (name.equals("system")) {
490          throw new FHIRException("Cannot call addChild on a primitive type Quantity.system");
491        }
492        else if (name.equals("code")) {
493          throw new FHIRException("Cannot call addChild on a primitive type Quantity.code");
494        }
495        else
496          return super.addChild(name);
497      }
498
499  public String fhirType() {
500    return "Quantity";
501
502  }
503
504      public Quantity copy() {
505        Quantity dst = new Quantity();
506        copyValues(dst);
507        dst.value = value == null ? null : value.copy();
508        dst.comparator = comparator == null ? null : comparator.copy();
509        dst.unit = unit == null ? null : unit.copy();
510        dst.system = system == null ? null : system.copy();
511        dst.code = code == null ? null : code.copy();
512        return dst;
513      }
514
515      protected Quantity typedCopy() {
516        return copy();
517      }
518
519      @Override
520      public boolean equalsDeep(Base other) {
521        if (!super.equalsDeep(other))
522          return false;
523        if (!(other instanceof Quantity))
524          return false;
525        Quantity o = (Quantity) other;
526        return compareDeep(value, o.value, true) && compareDeep(comparator, o.comparator, true) && compareDeep(unit, o.unit, true)
527           && compareDeep(system, o.system, true) && compareDeep(code, o.code, true);
528      }
529
530      @Override
531      public boolean equalsShallow(Base other) {
532        if (!super.equalsShallow(other))
533          return false;
534        if (!(other instanceof Quantity))
535          return false;
536        Quantity o = (Quantity) other;
537        return compareValues(value, o.value, true) && compareValues(comparator, o.comparator, true) && compareValues(unit, o.unit, true)
538           && compareValues(system, o.system, true) && compareValues(code, o.code, true);
539      }
540
541      public boolean isEmpty() {
542        return super.isEmpty() && (value == null || value.isEmpty()) && (comparator == null || comparator.isEmpty())
543           && (unit == null || unit.isEmpty()) && (system == null || system.isEmpty()) && (code == null || code.isEmpty())
544          ;
545      }
546
547
548}
549