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