001package org.hl7.fhir.dstu2.model;
002
003
004
005
006import java.math.BigDecimal;
007
008/*
009  Copyright (c) 2011+, HL7, Inc.
010  All rights reserved.
011  
012  Redistribution and use in source and binary forms, with or without modification, 
013  are permitted provided that the following conditions are met:
014  
015   * Redistributions of source code must retain the above copyright notice, this 
016     list of conditions and the following disclaimer.
017   * Redistributions in binary form must reproduce the above copyright notice, 
018     this list of conditions and the following disclaimer in the documentation 
019     and/or other materials provided with the distribution.
020   * Neither the name of HL7 nor the names of its contributors may be used to 
021     endorse or promote products derived from this software without specific 
022     prior written permission.
023  
024  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
025  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
026  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
027  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
028  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
029  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
030  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
031  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
032  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
033  POSSIBILITY OF SUCH DAMAGE.
034  
035*/
036
037// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.DatatypeDef;
042import ca.uhn.fhir.model.api.annotation.Description;
043import org.hl7.fhir.instance.model.api.ICompositeType;
044import org.hl7.fhir.exceptions.FHIRException;
045import org.hl7.fhir.utilities.Utilities;
046/**
047 * 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.
048 */
049@DatatypeDef(name="Quantity")
050public class Quantity extends Type implements ICompositeType {
051
052    public enum QuantityComparator {
053        /**
054         * The actual value is less than the given value.
055         */
056        LESS_THAN, 
057        /**
058         * The actual value is less than or equal to the given value.
059         */
060        LESS_OR_EQUAL, 
061        /**
062         * The actual value is greater than or equal to the given value.
063         */
064        GREATER_OR_EQUAL, 
065        /**
066         * The actual value is greater than the given value.
067         */
068        GREATER_THAN, 
069        /**
070         * added to help the parsers
071         */
072        NULL;
073        public static QuantityComparator fromCode(String codeString) throws FHIRException {
074            if (codeString == null || "".equals(codeString))
075                return null;
076        if ("<".equals(codeString))
077          return LESS_THAN;
078        if ("<=".equals(codeString))
079          return LESS_OR_EQUAL;
080        if (">=".equals(codeString))
081          return GREATER_OR_EQUAL;
082        if (">".equals(codeString))
083          return GREATER_THAN;
084        throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'");
085        }
086        public String toCode() {
087          switch (this) {
088            case LESS_THAN: return "<";
089            case LESS_OR_EQUAL: return "<=";
090            case GREATER_OR_EQUAL: return ">=";
091            case GREATER_THAN: return ">";
092            case NULL: return null;
093            default: return "?";
094          }
095        }
096        public String getSystem() {
097          switch (this) {
098            case LESS_THAN: return "http://hl7.org/fhir/quantity-comparator";
099            case LESS_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator";
100            case GREATER_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator";
101            case GREATER_THAN: return "http://hl7.org/fhir/quantity-comparator";
102            case NULL: return null;
103            default: return "?";
104          }
105        }
106        public String getDefinition() {
107          switch (this) {
108            case LESS_THAN: return "The actual value is less than the given value.";
109            case LESS_OR_EQUAL: return "The actual value is less than or equal to the given value.";
110            case GREATER_OR_EQUAL: return "The actual value is greater than or equal to the given value.";
111            case GREATER_THAN: return "The actual value is greater than the given value.";
112            case NULL: return null;
113            default: return "?";
114          }
115        }
116        public String getDisplay() {
117          switch (this) {
118            case LESS_THAN: return "Less than";
119            case LESS_OR_EQUAL: return "Less or Equal to";
120            case GREATER_OR_EQUAL: return "Greater or Equal to";
121            case GREATER_THAN: return "Greater than";
122            case NULL: return null;
123            default: return "?";
124          }
125        }
126    }
127
128  public static class QuantityComparatorEnumFactory implements EnumFactory<QuantityComparator> {
129    public QuantityComparator fromCode(String codeString) throws IllegalArgumentException {
130      if (codeString == null || "".equals(codeString))
131            if (codeString == null || "".equals(codeString))
132                return null;
133        if ("<".equals(codeString))
134          return QuantityComparator.LESS_THAN;
135        if ("<=".equals(codeString))
136          return QuantityComparator.LESS_OR_EQUAL;
137        if (">=".equals(codeString))
138          return QuantityComparator.GREATER_OR_EQUAL;
139        if (">".equals(codeString))
140          return QuantityComparator.GREATER_THAN;
141        throw new IllegalArgumentException("Unknown QuantityComparator code '"+codeString+"'");
142        }
143        public Enumeration<QuantityComparator> fromType(Base code) throws FHIRException {
144          if (code == null || code.isEmpty())
145            return null;
146          String codeString = ((PrimitiveType) code).asStringValue();
147          if (codeString == null || "".equals(codeString))
148            return null;
149        if ("<".equals(codeString))
150          return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_THAN);
151        if ("<=".equals(codeString))
152          return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_OR_EQUAL);
153        if (">=".equals(codeString))
154          return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_OR_EQUAL);
155        if (">".equals(codeString))
156          return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_THAN);
157        throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'");
158        }
159    public String toCode(QuantityComparator code) {
160      if (code == QuantityComparator.LESS_THAN)
161        return "<";
162      if (code == QuantityComparator.LESS_OR_EQUAL)
163        return "<=";
164      if (code == QuantityComparator.GREATER_OR_EQUAL)
165        return ">=";
166      if (code == QuantityComparator.GREATER_THAN)
167        return ">";
168      return "?";
169      }
170    }
171
172    /**
173     * The value of the measured amount. The value includes an implicit precision in the presentation of the value.
174     */
175    @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true)
176    @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." )
177    protected DecimalType value;
178
179    /**
180     * 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.
181     */
182    @Child(name = "comparator", type = {CodeType.class}, order=1, min=0, max=1, modifier=true, summary=true)
183    @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." )
184    protected Enumeration<QuantityComparator> comparator;
185
186    /**
187     * A human-readable form of the unit.
188     */
189    @Child(name = "unit", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=true)
190    @Description(shortDefinition="Unit representation", formalDefinition="A human-readable form of the unit." )
191    protected StringType unit;
192
193    /**
194     * The identification of the system that provides the coded form of the unit.
195     */
196    @Child(name = "system", type = {UriType.class}, order=3, min=0, max=1, modifier=false, summary=true)
197    @Description(shortDefinition="System that defines coded unit form", formalDefinition="The identification of the system that provides the coded form of the unit." )
198    protected UriType system;
199
200    /**
201     * A computer processable form of the unit in some unit representation system.
202     */
203    @Child(name = "code", type = {CodeType.class}, order=4, min=0, max=1, modifier=false, summary=true)
204    @Description(shortDefinition="Coded form of the unit", formalDefinition="A computer processable form of the unit in some unit representation system." )
205    protected CodeType code;
206
207    private static final long serialVersionUID = 1069574054L;
208
209  /*
210   * Constructor
211   */
212    public Quantity() {
213      super();
214    }
215
216    /**
217     * @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
218     */
219    public DecimalType getValueElement() { 
220      if (this.value == null)
221        if (Configuration.errorOnAutoCreate())
222          throw new Error("Attempt to auto-create Quantity.value");
223        else if (Configuration.doAutoCreate())
224          this.value = new DecimalType(); // bb
225      return this.value;
226    }
227
228    public boolean hasValueElement() { 
229      return this.value != null && !this.value.isEmpty();
230    }
231
232    public boolean hasValue() { 
233      return this.value != null && !this.value.isEmpty();
234    }
235
236    /**
237     * @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
238     */
239    public Quantity setValueElement(DecimalType value) { 
240      this.value = value;
241      return this;
242    }
243
244    /**
245     * @return The value of the measured amount. The value includes an implicit precision in the presentation of the value.
246     */
247    public BigDecimal getValue() { 
248      return this.value == null ? null : this.value.getValue();
249    }
250
251    /**
252     * @param value The value of the measured amount. The value includes an implicit precision in the presentation of the value.
253     */
254    public Quantity setValue(BigDecimal value) { 
255      if (value == null)
256        this.value = null;
257      else {
258        if (this.value == null)
259          this.value = new DecimalType();
260        this.value.setValue(value);
261      }
262      return this;
263    }
264
265    /**
266     * @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
267     */
268    public Enumeration<QuantityComparator> getComparatorElement() { 
269      if (this.comparator == null)
270        if (Configuration.errorOnAutoCreate())
271          throw new Error("Attempt to auto-create Quantity.comparator");
272        else if (Configuration.doAutoCreate())
273          this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory()); // bb
274      return this.comparator;
275    }
276
277    public boolean hasComparatorElement() { 
278      return this.comparator != null && !this.comparator.isEmpty();
279    }
280
281    public boolean hasComparator() { 
282      return this.comparator != null && !this.comparator.isEmpty();
283    }
284
285    /**
286     * @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
287     */
288    public Quantity setComparatorElement(Enumeration<QuantityComparator> value) { 
289      this.comparator = value;
290      return this;
291    }
292
293    /**
294     * @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.
295     */
296    public QuantityComparator getComparator() { 
297      return this.comparator == null ? null : this.comparator.getValue();
298    }
299
300    /**
301     * @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.
302     */
303    public Quantity setComparator(QuantityComparator value) { 
304      if (value == null)
305        this.comparator = null;
306      else {
307        if (this.comparator == null)
308          this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory());
309        this.comparator.setValue(value);
310      }
311      return this;
312    }
313
314    /**
315     * @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
316     */
317    public StringType getUnitElement() { 
318      if (this.unit == null)
319        if (Configuration.errorOnAutoCreate())
320          throw new Error("Attempt to auto-create Quantity.unit");
321        else if (Configuration.doAutoCreate())
322          this.unit = new StringType(); // bb
323      return this.unit;
324    }
325
326    public boolean hasUnitElement() { 
327      return this.unit != null && !this.unit.isEmpty();
328    }
329
330    public boolean hasUnit() { 
331      return this.unit != null && !this.unit.isEmpty();
332    }
333
334    /**
335     * @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
336     */
337    public Quantity setUnitElement(StringType value) { 
338      this.unit = value;
339      return this;
340    }
341
342    /**
343     * @return A human-readable form of the unit.
344     */
345    public String getUnit() { 
346      return this.unit == null ? null : this.unit.getValue();
347    }
348
349    /**
350     * @param value A human-readable form of the unit.
351     */
352    public Quantity setUnit(String value) { 
353      if (Utilities.noString(value))
354        this.unit = null;
355      else {
356        if (this.unit == null)
357          this.unit = new StringType();
358        this.unit.setValue(value);
359      }
360      return this;
361    }
362
363    /**
364     * @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
365     */
366    public UriType getSystemElement() { 
367      if (this.system == null)
368        if (Configuration.errorOnAutoCreate())
369          throw new Error("Attempt to auto-create Quantity.system");
370        else if (Configuration.doAutoCreate())
371          this.system = new UriType(); // bb
372      return this.system;
373    }
374
375    public boolean hasSystemElement() { 
376      return this.system != null && !this.system.isEmpty();
377    }
378
379    public boolean hasSystem() { 
380      return this.system != null && !this.system.isEmpty();
381    }
382
383    /**
384     * @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
385     */
386    public Quantity setSystemElement(UriType value) { 
387      this.system = value;
388      return this;
389    }
390
391    /**
392     * @return The identification of the system that provides the coded form of the unit.
393     */
394    public String getSystem() { 
395      return this.system == null ? null : this.system.getValue();
396    }
397
398    /**
399     * @param value The identification of the system that provides the coded form of the unit.
400     */
401    public Quantity setSystem(String value) { 
402      if (Utilities.noString(value))
403        this.system = null;
404      else {
405        if (this.system == null)
406          this.system = new UriType();
407        this.system.setValue(value);
408      }
409      return this;
410    }
411
412    /**
413     * @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
414     */
415    public CodeType getCodeElement() { 
416      if (this.code == null)
417        if (Configuration.errorOnAutoCreate())
418          throw new Error("Attempt to auto-create Quantity.code");
419        else if (Configuration.doAutoCreate())
420          this.code = new CodeType(); // bb
421      return this.code;
422    }
423
424    public boolean hasCodeElement() { 
425      return this.code != null && !this.code.isEmpty();
426    }
427
428    public boolean hasCode() { 
429      return this.code != null && !this.code.isEmpty();
430    }
431
432    /**
433     * @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
434     */
435    public Quantity setCodeElement(CodeType value) { 
436      this.code = value;
437      return this;
438    }
439
440    /**
441     * @return A computer processable form of the unit in some unit representation system.
442     */
443    public String getCode() { 
444      return this.code == null ? null : this.code.getValue();
445    }
446
447    /**
448     * @param value A computer processable form of the unit in some unit representation system.
449     */
450    public Quantity setCode(String value) { 
451      if (Utilities.noString(value))
452        this.code = null;
453      else {
454        if (this.code == null)
455          this.code = new CodeType();
456        this.code.setValue(value);
457      }
458      return this;
459    }
460
461      protected void listChildren(List<Property> childrenList) {
462        super.listChildren(childrenList);
463        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));
464        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));
465        childrenList.add(new Property("unit", "string", "A human-readable form of the unit.", 0, java.lang.Integer.MAX_VALUE, unit));
466        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));
467        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));
468      }
469
470      @Override
471      public void setProperty(String name, Base value) throws FHIRException {
472        if (name.equals("value"))
473          this.value = castToDecimal(value); // DecimalType
474        else if (name.equals("comparator"))
475          this.comparator = new QuantityComparatorEnumFactory().fromType(value); // Enumeration<QuantityComparator>
476        else if (name.equals("unit"))
477          this.unit = castToString(value); // StringType
478        else if (name.equals("system"))
479          this.system = castToUri(value); // UriType
480        else if (name.equals("code"))
481          this.code = castToCode(value); // CodeType
482        else
483          super.setProperty(name, value);
484      }
485
486      @Override
487      public Base addChild(String name) throws FHIRException {
488        if (name.equals("value")) {
489          throw new FHIRException("Cannot call addChild on a primitive type Quantity.value");
490        }
491        else if (name.equals("comparator")) {
492          throw new FHIRException("Cannot call addChild on a primitive type Quantity.comparator");
493        }
494        else if (name.equals("unit")) {
495          throw new FHIRException("Cannot call addChild on a primitive type Quantity.unit");
496        }
497        else if (name.equals("system")) {
498          throw new FHIRException("Cannot call addChild on a primitive type Quantity.system");
499        }
500        else if (name.equals("code")) {
501          throw new FHIRException("Cannot call addChild on a primitive type Quantity.code");
502        }
503        else
504          return super.addChild(name);
505      }
506
507  public String fhirType() {
508    return "Quantity";
509
510  }
511
512      public Quantity copy() {
513        Quantity dst = new Quantity();
514        copyValues(dst);
515        dst.value = value == null ? null : value.copy();
516        dst.comparator = comparator == null ? null : comparator.copy();
517        dst.unit = unit == null ? null : unit.copy();
518        dst.system = system == null ? null : system.copy();
519        dst.code = code == null ? null : code.copy();
520        return dst;
521      }
522
523      protected Quantity typedCopy() {
524        return copy();
525      }
526
527      @Override
528      public boolean equalsDeep(Base other) {
529        if (!super.equalsDeep(other))
530          return false;
531        if (!(other instanceof Quantity))
532          return false;
533        Quantity o = (Quantity) other;
534        return compareDeep(value, o.value, true) && compareDeep(comparator, o.comparator, true) && compareDeep(unit, o.unit, true)
535           && compareDeep(system, o.system, true) && compareDeep(code, o.code, true);
536      }
537
538      @Override
539      public boolean equalsShallow(Base other) {
540        if (!super.equalsShallow(other))
541          return false;
542        if (!(other instanceof Quantity))
543          return false;
544        Quantity o = (Quantity) other;
545        return compareValues(value, o.value, true) && compareValues(comparator, o.comparator, true) && compareValues(unit, o.unit, true)
546           && compareValues(system, o.system, true) && compareValues(code, o.code, true);
547      }
548
549      public boolean isEmpty() {
550        return super.isEmpty() && (value == null || value.isEmpty()) && (comparator == null || comparator.isEmpty())
551           && (unit == null || unit.isEmpty()) && (system == null || system.isEmpty()) && (code == null || code.isEmpty())
552          ;
553      }
554
555
556}