001package org.hl7.fhir.r5.openehr;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import java.math.*;
038import org.hl7.fhir.utilities.Utilities;
039import org.hl7.fhir.r5.openehr.Enumerations.*;
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.r5.model.*;
042import org.hl7.fhir.instance.model.api.ICompositeType;
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.ChildOrder;
045import ca.uhn.fhir.model.api.annotation.DatatypeDef;
046import ca.uhn.fhir.model.api.annotation.Description;
047import ca.uhn.fhir.model.api.annotation.Block;
048
049/**
050 * Countable quantities. Used for countable types such as pregnancies and steps (taken by a physiotherapy patient), number of cigarettes smoked in a day.
051 */
052@DatatypeDef(name="DV_PROPORTION")
053public class DV_PROPORTION extends DV_AMOUNT implements ICompositeType {
054
055    /**
056     * Numerator of ratio.
057     */
058    @Child(name = "numerator", type = {DecimalType.class}, order=0, min=1, max=1, modifier=false, summary=false)
059    @Description(shortDefinition="Numerator of ratio", formalDefinition="Numerator of ratio." )
060    protected DecimalType numerator;
061
062    /**
063     * Denominator of ratio.
064     */
065    @Child(name = "denominator", type = {DecimalType.class}, order=1, min=1, max=1, modifier=false, summary=false)
066    @Description(shortDefinition="Denominator of ratio", formalDefinition="Denominator of ratio." )
067    protected DecimalType denominator;
068
069    /**
070     * Indicates semantic type of proportion, including percent, unitary etc.
071     */
072    @Child(name = "type", type = {CodeType.class}, order=2, min=1, max=1, modifier=false, summary=false)
073    @Description(shortDefinition="Indicates semantic type of proportion, including percent, unitary etc", formalDefinition="Indicates semantic type of proportion, including percent, unitary etc." )
074    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="https://specifications.openehr.org/fhir/valueset-proportion_kind")
075    protected CodeType type;
076
077    /**
078     * Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.
079     */
080    @Child(name = "precision", type = {IntegerType.class}, order=3, min=0, max=1, modifier=false, summary=false)
081    @Description(shortDefinition="Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places", formalDefinition="Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places." )
082    protected IntegerType precision;
083
084    private static final long serialVersionUID = 398780922L;
085
086  /**
087   * Constructor
088   */
089    public DV_PROPORTION() {
090      super();
091    }
092
093  /**
094   * Constructor
095   */
096    public DV_PROPORTION(BigDecimal numerator, BigDecimal denominator, String type) {
097      super();
098      this.setNumerator(numerator);
099      this.setDenominator(denominator);
100      this.setType(type);
101    }
102
103    /**
104     * @return {@link #numerator} (Numerator of ratio.). This is the underlying object with id, value and extensions. The accessor "getNumerator" gives direct access to the value
105     */
106    public DecimalType getNumeratorElement() { 
107      if (this.numerator == null)
108        if (Configuration.errorOnAutoCreate())
109          throw new Error("Attempt to auto-create DV_PROPORTION.numerator");
110        else if (Configuration.doAutoCreate())
111          this.numerator = new DecimalType(); // bb
112      return this.numerator;
113    }
114
115    public boolean hasNumeratorElement() { 
116      return this.numerator != null && !this.numerator.isEmpty();
117    }
118
119    public boolean hasNumerator() { 
120      return this.numerator != null && !this.numerator.isEmpty();
121    }
122
123    /**
124     * @param value {@link #numerator} (Numerator of ratio.). This is the underlying object with id, value and extensions. The accessor "getNumerator" gives direct access to the value
125     */
126    public DV_PROPORTION setNumeratorElement(DecimalType value) { 
127      this.numerator = value;
128      return this;
129    }
130
131    /**
132     * @return Numerator of ratio.
133     */
134    public BigDecimal getNumerator() { 
135      return this.numerator == null ? null : this.numerator.getValue();
136    }
137
138    /**
139     * @param value Numerator of ratio.
140     */
141    public DV_PROPORTION setNumerator(BigDecimal value) { 
142        if (this.numerator == null)
143          this.numerator = new DecimalType();
144        this.numerator.setValue(value);
145      return this;
146    }
147
148    /**
149     * @param value Numerator of ratio.
150     */
151    public DV_PROPORTION setNumerator(long value) { 
152          this.numerator = new DecimalType();
153        this.numerator.setValue(value);
154      return this;
155    }
156
157    /**
158     * @param value Numerator of ratio.
159     */
160    public DV_PROPORTION setNumerator(double value) { 
161          this.numerator = new DecimalType();
162        this.numerator.setValue(value);
163      return this;
164    }
165
166    /**
167     * @return {@link #denominator} (Denominator of ratio.). This is the underlying object with id, value and extensions. The accessor "getDenominator" gives direct access to the value
168     */
169    public DecimalType getDenominatorElement() { 
170      if (this.denominator == null)
171        if (Configuration.errorOnAutoCreate())
172          throw new Error("Attempt to auto-create DV_PROPORTION.denominator");
173        else if (Configuration.doAutoCreate())
174          this.denominator = new DecimalType(); // bb
175      return this.denominator;
176    }
177
178    public boolean hasDenominatorElement() { 
179      return this.denominator != null && !this.denominator.isEmpty();
180    }
181
182    public boolean hasDenominator() { 
183      return this.denominator != null && !this.denominator.isEmpty();
184    }
185
186    /**
187     * @param value {@link #denominator} (Denominator of ratio.). This is the underlying object with id, value and extensions. The accessor "getDenominator" gives direct access to the value
188     */
189    public DV_PROPORTION setDenominatorElement(DecimalType value) { 
190      this.denominator = value;
191      return this;
192    }
193
194    /**
195     * @return Denominator of ratio.
196     */
197    public BigDecimal getDenominator() { 
198      return this.denominator == null ? null : this.denominator.getValue();
199    }
200
201    /**
202     * @param value Denominator of ratio.
203     */
204    public DV_PROPORTION setDenominator(BigDecimal value) { 
205        if (this.denominator == null)
206          this.denominator = new DecimalType();
207        this.denominator.setValue(value);
208      return this;
209    }
210
211    /**
212     * @param value Denominator of ratio.
213     */
214    public DV_PROPORTION setDenominator(long value) { 
215          this.denominator = new DecimalType();
216        this.denominator.setValue(value);
217      return this;
218    }
219
220    /**
221     * @param value Denominator of ratio.
222     */
223    public DV_PROPORTION setDenominator(double value) { 
224          this.denominator = new DecimalType();
225        this.denominator.setValue(value);
226      return this;
227    }
228
229    /**
230     * @return {@link #type} (Indicates semantic type of proportion, including percent, unitary etc.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
231     */
232    public CodeType getTypeElement() { 
233      if (this.type == null)
234        if (Configuration.errorOnAutoCreate())
235          throw new Error("Attempt to auto-create DV_PROPORTION.type");
236        else if (Configuration.doAutoCreate())
237          this.type = new CodeType(); // bb
238      return this.type;
239    }
240
241    public boolean hasTypeElement() { 
242      return this.type != null && !this.type.isEmpty();
243    }
244
245    public boolean hasType() { 
246      return this.type != null && !this.type.isEmpty();
247    }
248
249    /**
250     * @param value {@link #type} (Indicates semantic type of proportion, including percent, unitary etc.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
251     */
252    public DV_PROPORTION setTypeElement(CodeType value) { 
253      this.type = value;
254      return this;
255    }
256
257    /**
258     * @return Indicates semantic type of proportion, including percent, unitary etc.
259     */
260    public String getType() { 
261      return this.type == null ? null : this.type.getValue();
262    }
263
264    /**
265     * @param value Indicates semantic type of proportion, including percent, unitary etc.
266     */
267    public DV_PROPORTION setType(String value) { 
268        if (this.type == null)
269          this.type = new CodeType();
270        this.type.setValue(value);
271      return this;
272    }
273
274    /**
275     * @return {@link #precision} (Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.). This is the underlying object with id, value and extensions. The accessor "getPrecision" gives direct access to the value
276     */
277    public IntegerType getPrecisionElement() { 
278      if (this.precision == null)
279        if (Configuration.errorOnAutoCreate())
280          throw new Error("Attempt to auto-create DV_PROPORTION.precision");
281        else if (Configuration.doAutoCreate())
282          this.precision = new IntegerType(); // bb
283      return this.precision;
284    }
285
286    public boolean hasPrecisionElement() { 
287      return this.precision != null && !this.precision.isEmpty();
288    }
289
290    public boolean hasPrecision() { 
291      return this.precision != null && !this.precision.isEmpty();
292    }
293
294    /**
295     * @param value {@link #precision} (Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.). This is the underlying object with id, value and extensions. The accessor "getPrecision" gives direct access to the value
296     */
297    public DV_PROPORTION setPrecisionElement(IntegerType value) { 
298      this.precision = value;
299      return this;
300    }
301
302    /**
303     * @return Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.
304     */
305    public int getPrecision() { 
306      return this.precision == null || this.precision.isEmpty() ? 0 : this.precision.getValue();
307    }
308
309    /**
310     * @param value Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.
311     */
312    public DV_PROPORTION setPrecision(int value) { 
313        if (this.precision == null)
314          this.precision = new IntegerType();
315        this.precision.setValue(value);
316      return this;
317    }
318
319      protected void listChildren(List<Property> children) {
320        super.listChildren(children);
321        children.add(new Property("numerator", "decimal", "Numerator of ratio.", 0, 1, numerator));
322        children.add(new Property("denominator", "decimal", "Denominator of ratio.", 0, 1, denominator));
323        children.add(new Property("type", "code", "Indicates semantic type of proportion, including percent, unitary etc.", 0, 1, type));
324        children.add(new Property("precision", "integer", "Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.", 0, 1, precision));
325      }
326
327      @Override
328      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
329        switch (_hash) {
330        case 1747334793: /*numerator*/  return new Property("numerator", "decimal", "Numerator of ratio.", 0, 1, numerator);
331        case -1983274394: /*denominator*/  return new Property("denominator", "decimal", "Denominator of ratio.", 0, 1, denominator);
332        case 3575610: /*type*/  return new Property("type", "code", "Indicates semantic type of proportion, including percent, unitary etc.", 0, 1, type);
333        case -1376177026: /*precision*/  return new Property("precision", "integer", "Precision to which the numerator and denominator values of the proportion are expressed, in terms of number of decimal places. The value 0 implies an integral quantity. The value -1 implies no limit, i.e. any number of decimal places.", 0, 1, precision);
334        default: return super.getNamedProperty(_hash, _name, _checkValid);
335        }
336
337      }
338
339      @Override
340      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
341        switch (hash) {
342        case 1747334793: /*numerator*/ return this.numerator == null ? new Base[0] : new Base[] {this.numerator}; // DecimalType
343        case -1983274394: /*denominator*/ return this.denominator == null ? new Base[0] : new Base[] {this.denominator}; // DecimalType
344        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // CodeType
345        case -1376177026: /*precision*/ return this.precision == null ? new Base[0] : new Base[] {this.precision}; // IntegerType
346        default: return super.getProperty(hash, name, checkValid);
347        }
348
349      }
350
351      @Override
352      public Base setProperty(int hash, String name, Base value) throws FHIRException {
353        switch (hash) {
354        case 1747334793: // numerator
355          this.numerator = TypeConvertor.castToDecimal(value); // DecimalType
356          return value;
357        case -1983274394: // denominator
358          this.denominator = TypeConvertor.castToDecimal(value); // DecimalType
359          return value;
360        case 3575610: // type
361          this.type = TypeConvertor.castToCode(value); // CodeType
362          return value;
363        case -1376177026: // precision
364          this.precision = TypeConvertor.castToInteger(value); // IntegerType
365          return value;
366        default: return super.setProperty(hash, name, value);
367        }
368
369      }
370
371      @Override
372      public Base setProperty(String name, Base value) throws FHIRException {
373        if (name.equals("numerator")) {
374          this.numerator = TypeConvertor.castToDecimal(value); // DecimalType
375        } else if (name.equals("denominator")) {
376          this.denominator = TypeConvertor.castToDecimal(value); // DecimalType
377        } else if (name.equals("type")) {
378          this.type = TypeConvertor.castToCode(value); // CodeType
379        } else if (name.equals("precision")) {
380          this.precision = TypeConvertor.castToInteger(value); // IntegerType
381        } else
382          return super.setProperty(name, value);
383        return value;
384      }
385
386      @Override
387      public Base makeProperty(int hash, String name) throws FHIRException {
388        switch (hash) {
389        case 1747334793:  return getNumeratorElement();
390        case -1983274394:  return getDenominatorElement();
391        case 3575610:  return getTypeElement();
392        case -1376177026:  return getPrecisionElement();
393        default: return super.makeProperty(hash, name);
394        }
395
396      }
397
398      @Override
399      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
400        switch (hash) {
401        case 1747334793: /*numerator*/ return new String[] {"decimal"};
402        case -1983274394: /*denominator*/ return new String[] {"decimal"};
403        case 3575610: /*type*/ return new String[] {"code"};
404        case -1376177026: /*precision*/ return new String[] {"integer"};
405        default: return super.getTypesForProperty(hash, name);
406        }
407
408      }
409
410      @Override
411      public Base addChild(String name) throws FHIRException {
412        if (name.equals("numerator")) {
413          throw new FHIRException("Cannot call addChild on a singleton property DV_PROPORTION.numerator");
414        }
415        else if (name.equals("denominator")) {
416          throw new FHIRException("Cannot call addChild on a singleton property DV_PROPORTION.denominator");
417        }
418        else if (name.equals("type")) {
419          throw new FHIRException("Cannot call addChild on a singleton property DV_PROPORTION.type");
420        }
421        else if (name.equals("precision")) {
422          throw new FHIRException("Cannot call addChild on a singleton property DV_PROPORTION.precision");
423        }
424        else
425          return super.addChild(name);
426      }
427
428  public String fhirType() {
429    return "DV_PROPORTION";
430
431  }
432
433      public DV_PROPORTION copy() {
434        DV_PROPORTION dst = new DV_PROPORTION();
435        copyValues(dst);
436        return dst;
437      }
438
439      public void copyValues(DV_PROPORTION dst) {
440        super.copyValues(dst);
441        dst.numerator = numerator == null ? null : numerator.copy();
442        dst.denominator = denominator == null ? null : denominator.copy();
443        dst.type = type == null ? null : type.copy();
444        dst.precision = precision == null ? null : precision.copy();
445      }
446
447      protected DV_PROPORTION typedCopy() {
448        return copy();
449      }
450
451      @Override
452      public boolean equalsDeep(Base other_) {
453        if (!super.equalsDeep(other_))
454          return false;
455        if (!(other_ instanceof DV_PROPORTION))
456          return false;
457        DV_PROPORTION o = (DV_PROPORTION) other_;
458        return compareDeep(numerator, o.numerator, true) && compareDeep(denominator, o.denominator, true)
459           && compareDeep(type, o.type, true) && compareDeep(precision, o.precision, true);
460      }
461
462      @Override
463      public boolean equalsShallow(Base other_) {
464        if (!super.equalsShallow(other_))
465          return false;
466        if (!(other_ instanceof DV_PROPORTION))
467          return false;
468        DV_PROPORTION o = (DV_PROPORTION) other_;
469        return compareValues(numerator, o.numerator, true) && compareValues(denominator, o.denominator, true)
470           && compareValues(type, o.type, true) && compareValues(precision, o.precision, true);
471      }
472
473      public boolean isEmpty() {
474        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(numerator, denominator, type
475          , precision);
476      }
477
478
479}
480