001package org.hl7.fhir.r5.model;
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 org.hl7.fhir.r5.model.Enumerations.*;
038import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.instance.model.api.ICompositeType;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.ChildOrder;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Description;
045import ca.uhn.fhir.model.api.annotation.Block;
046
047/**
048 * Ratio Type: A relationship of two Quantity values - expressed as a numerator and a denominator.
049 */
050@DatatypeDef(name="Ratio")
051public class Ratio extends DataType implements ICompositeType {
052
053    /**
054     * The value of the numerator.
055     */
056    @Child(name = "numerator", type = {Quantity.class}, order=0, min=0, max=1, modifier=false, summary=true)
057    @Description(shortDefinition="Numerator value", formalDefinition="The value of the numerator." )
058    protected Quantity numerator;
059
060    /**
061     * The value of the denominator.
062     */
063    @Child(name = "denominator", type = {Quantity.class}, order=1, min=0, max=1, modifier=false, summary=true)
064    @Description(shortDefinition="Denominator value", formalDefinition="The value of the denominator." )
065    protected Quantity denominator;
066
067    private static final long serialVersionUID = 479922563L;
068
069  /**
070   * Constructor
071   */
072    public Ratio() {
073      super();
074    }
075
076    /**
077     * @return {@link #numerator} (The value of the numerator.)
078     */
079    public Quantity getNumerator() { 
080      if (this.numerator == null)
081        if (Configuration.errorOnAutoCreate())
082          throw new Error("Attempt to auto-create Ratio.numerator");
083        else if (Configuration.doAutoCreate())
084          this.numerator = new Quantity(); // cc
085      return this.numerator;
086    }
087
088    public boolean hasNumerator() { 
089      return this.numerator != null && !this.numerator.isEmpty();
090    }
091
092    /**
093     * @param value {@link #numerator} (The value of the numerator.)
094     */
095    public Ratio setNumerator(Quantity value) { 
096      this.numerator = value;
097      return this;
098    }
099
100    /**
101     * @return {@link #denominator} (The value of the denominator.)
102     */
103    public Quantity getDenominator() { 
104      if (this.denominator == null)
105        if (Configuration.errorOnAutoCreate())
106          throw new Error("Attempt to auto-create Ratio.denominator");
107        else if (Configuration.doAutoCreate())
108          this.denominator = new Quantity(); // cc
109      return this.denominator;
110    }
111
112    public boolean hasDenominator() { 
113      return this.denominator != null && !this.denominator.isEmpty();
114    }
115
116    /**
117     * @param value {@link #denominator} (The value of the denominator.)
118     */
119    public Ratio setDenominator(Quantity value) { 
120      this.denominator = value;
121      return this;
122    }
123
124      protected void listChildren(List<Property> children) {
125        super.listChildren(children);
126        children.add(new Property("numerator", "Quantity", "The value of the numerator.", 0, 1, numerator));
127        children.add(new Property("denominator", "Quantity", "The value of the denominator.", 0, 1, denominator));
128      }
129
130      @Override
131      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
132        switch (_hash) {
133        case 1747334793: /*numerator*/  return new Property("numerator", "Quantity", "The value of the numerator.", 0, 1, numerator);
134        case -1983274394: /*denominator*/  return new Property("denominator", "Quantity", "The value of the denominator.", 0, 1, denominator);
135        default: return super.getNamedProperty(_hash, _name, _checkValid);
136        }
137
138      }
139
140      @Override
141      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
142        switch (hash) {
143        case 1747334793: /*numerator*/ return this.numerator == null ? new Base[0] : new Base[] {this.numerator}; // Quantity
144        case -1983274394: /*denominator*/ return this.denominator == null ? new Base[0] : new Base[] {this.denominator}; // Quantity
145        default: return super.getProperty(hash, name, checkValid);
146        }
147
148      }
149
150      @Override
151      public Base setProperty(int hash, String name, Base value) throws FHIRException {
152        switch (hash) {
153        case 1747334793: // numerator
154          this.numerator = TypeConvertor.castToQuantity(value); // Quantity
155          return value;
156        case -1983274394: // denominator
157          this.denominator = TypeConvertor.castToQuantity(value); // Quantity
158          return value;
159        default: return super.setProperty(hash, name, value);
160        }
161
162      }
163
164      @Override
165      public Base setProperty(String name, Base value) throws FHIRException {
166        if (name.equals("numerator")) {
167          this.numerator = TypeConvertor.castToQuantity(value); // Quantity
168        } else if (name.equals("denominator")) {
169          this.denominator = TypeConvertor.castToQuantity(value); // Quantity
170        } else
171          return super.setProperty(name, value);
172        return value;
173      }
174
175  @Override
176  public void removeChild(String name, Base value) throws FHIRException {
177        if (name.equals("numerator")) {
178          this.numerator = null;
179        } else if (name.equals("denominator")) {
180          this.denominator = null;
181        } else
182          super.removeChild(name, value);
183        
184      }
185
186      @Override
187      public Base makeProperty(int hash, String name) throws FHIRException {
188        switch (hash) {
189        case 1747334793:  return getNumerator();
190        case -1983274394:  return getDenominator();
191        default: return super.makeProperty(hash, name);
192        }
193
194      }
195
196      @Override
197      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
198        switch (hash) {
199        case 1747334793: /*numerator*/ return new String[] {"Quantity"};
200        case -1983274394: /*denominator*/ return new String[] {"Quantity"};
201        default: return super.getTypesForProperty(hash, name);
202        }
203
204      }
205
206      @Override
207      public Base addChild(String name) throws FHIRException {
208        if (name.equals("numerator")) {
209          this.numerator = new Quantity();
210          return this.numerator;
211        }
212        else if (name.equals("denominator")) {
213          this.denominator = new Quantity();
214          return this.denominator;
215        }
216        else
217          return super.addChild(name);
218      }
219
220  public String fhirType() {
221    return "Ratio";
222
223  }
224
225      public Ratio copy() {
226        Ratio dst = new Ratio();
227        copyValues(dst);
228        return dst;
229      }
230
231      public void copyValues(Ratio dst) {
232        super.copyValues(dst);
233        dst.numerator = numerator == null ? null : numerator.copy();
234        dst.denominator = denominator == null ? null : denominator.copy();
235      }
236
237      protected Ratio typedCopy() {
238        return copy();
239      }
240
241      @Override
242      public boolean equalsDeep(Base other_) {
243        if (!super.equalsDeep(other_))
244          return false;
245        if (!(other_ instanceof Ratio))
246          return false;
247        Ratio o = (Ratio) other_;
248        return compareDeep(numerator, o.numerator, true) && compareDeep(denominator, o.denominator, true)
249          ;
250      }
251
252      @Override
253      public boolean equalsShallow(Base other_) {
254        if (!super.equalsShallow(other_))
255          return false;
256        if (!(other_ instanceof Ratio))
257          return false;
258        Ratio o = (Ratio) other_;
259        return true;
260      }
261
262      public boolean isEmpty() {
263        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(numerator, denominator);
264      }
265
266
267}
268