001package org.hl7.fhir.r4.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
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/*
024  Copyright (c) 2011+, HL7, Inc.
025  All rights reserved.
026  
027  Redistribution and use in source and binary forms, with or without modification, 
028  are permitted provided that the following conditions are met:
029  
030   * Redistributions of source code must retain the above copyright notice, this 
031     list of conditions and the following disclaimer.
032   * Redistributions in binary form must reproduce the above copyright notice, 
033     this list of conditions and the following disclaimer in the documentation 
034     and/or other materials provided with the distribution.
035   * Neither the name of HL7 nor the names of its contributors may be used to 
036     endorse or promote products derived from this software without specific 
037     prior written permission.
038  
039  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
040  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
041  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
042  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
043  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
044  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
045  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
046  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
047  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
048  POSSIBILITY OF SUCH DAMAGE.
049  
050*/
051
052// Generated on Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0
053import java.util.List;
054
055import org.hl7.fhir.exceptions.FHIRException;
056import org.hl7.fhir.instance.model.api.ICompositeType;
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;
061/**
062 * A relationship of two Quantity values - expressed as a numerator and a denominator.
063 */
064@DatatypeDef(name="Ratio")
065public class Ratio extends Type implements ICompositeType {
066
067    /**
068     * The value of the numerator.
069     */
070    @Child(name = "numerator", type = {Quantity.class}, order=0, min=0, max=1, modifier=false, summary=true)
071    @Description(shortDefinition="Numerator value", formalDefinition="The value of the numerator." )
072    protected Quantity numerator;
073
074    /**
075     * The value of the denominator.
076     */
077    @Child(name = "denominator", type = {Quantity.class}, order=1, min=0, max=1, modifier=false, summary=true)
078    @Description(shortDefinition="Denominator value", formalDefinition="The value of the denominator." )
079    protected Quantity denominator;
080
081    private static final long serialVersionUID = 479922563L;
082
083  /**
084   * Constructor
085   */
086    public Ratio() {
087      super();
088    }
089
090    /**
091     * @return {@link #numerator} (The value of the numerator.)
092     */
093    public Quantity getNumerator() { 
094      if (this.numerator == null)
095        if (Configuration.errorOnAutoCreate())
096          throw new Error("Attempt to auto-create Ratio.numerator");
097        else if (Configuration.doAutoCreate())
098          this.numerator = new Quantity(); // cc
099      return this.numerator;
100    }
101
102    public boolean hasNumerator() { 
103      return this.numerator != null && !this.numerator.isEmpty();
104    }
105
106    /**
107     * @param value {@link #numerator} (The value of the numerator.)
108     */
109    public Ratio setNumerator(Quantity value) { 
110      this.numerator = value;
111      return this;
112    }
113
114    /**
115     * @return {@link #denominator} (The value of the denominator.)
116     */
117    public Quantity getDenominator() { 
118      if (this.denominator == null)
119        if (Configuration.errorOnAutoCreate())
120          throw new Error("Attempt to auto-create Ratio.denominator");
121        else if (Configuration.doAutoCreate())
122          this.denominator = new Quantity(); // cc
123      return this.denominator;
124    }
125
126    public boolean hasDenominator() { 
127      return this.denominator != null && !this.denominator.isEmpty();
128    }
129
130    /**
131     * @param value {@link #denominator} (The value of the denominator.)
132     */
133    public Ratio setDenominator(Quantity value) { 
134      this.denominator = value;
135      return this;
136    }
137
138      protected void listChildren(List<Property> children) {
139        super.listChildren(children);
140        children.add(new Property("numerator", "Quantity", "The value of the numerator.", 0, 1, numerator));
141        children.add(new Property("denominator", "Quantity", "The value of the denominator.", 0, 1, denominator));
142      }
143
144      @Override
145      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
146        switch (_hash) {
147        case 1747334793: /*numerator*/  return new Property("numerator", "Quantity", "The value of the numerator.", 0, 1, numerator);
148        case -1983274394: /*denominator*/  return new Property("denominator", "Quantity", "The value of the denominator.", 0, 1, denominator);
149        default: return super.getNamedProperty(_hash, _name, _checkValid);
150        }
151
152      }
153
154      @Override
155      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
156        switch (hash) {
157        case 1747334793: /*numerator*/ return this.numerator == null ? new Base[0] : new Base[] {this.numerator}; // Quantity
158        case -1983274394: /*denominator*/ return this.denominator == null ? new Base[0] : new Base[] {this.denominator}; // Quantity
159        default: return super.getProperty(hash, name, checkValid);
160        }
161
162      }
163
164      @Override
165      public Base setProperty(int hash, String name, Base value) throws FHIRException {
166        switch (hash) {
167        case 1747334793: // numerator
168          this.numerator = castToQuantity(value); // Quantity
169          return value;
170        case -1983274394: // denominator
171          this.denominator = castToQuantity(value); // Quantity
172          return value;
173        default: return super.setProperty(hash, name, value);
174        }
175
176      }
177
178      @Override
179      public Base setProperty(String name, Base value) throws FHIRException {
180        if (name.equals("numerator")) {
181          this.numerator = castToQuantity(value); // Quantity
182        } else if (name.equals("denominator")) {
183          this.denominator = castToQuantity(value); // Quantity
184        } else
185          return super.setProperty(name, value);
186        return value;
187      }
188
189      @Override
190      public Base makeProperty(int hash, String name) throws FHIRException {
191        switch (hash) {
192        case 1747334793:  return getNumerator(); 
193        case -1983274394:  return getDenominator(); 
194        default: return super.makeProperty(hash, name);
195        }
196
197      }
198
199      @Override
200      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
201        switch (hash) {
202        case 1747334793: /*numerator*/ return new String[] {"Quantity"};
203        case -1983274394: /*denominator*/ return new String[] {"Quantity"};
204        default: return super.getTypesForProperty(hash, name);
205        }
206
207      }
208
209      @Override
210      public Base addChild(String name) throws FHIRException {
211        if (name.equals("numerator")) {
212          this.numerator = new Quantity();
213          return this.numerator;
214        }
215        else if (name.equals("denominator")) {
216          this.denominator = new Quantity();
217          return this.denominator;
218        }
219        else
220          return super.addChild(name);
221      }
222
223  public String fhirType() {
224    return "Ratio";
225
226  }
227
228      public Ratio copy() {
229        Ratio dst = new Ratio();
230        copyValues(dst);
231        dst.numerator = numerator == null ? null : numerator.copy();
232        dst.denominator = denominator == null ? null : denominator.copy();
233        return dst;
234      }
235
236      protected Ratio typedCopy() {
237        return copy();
238      }
239
240      @Override
241      public boolean equalsDeep(Base other_) {
242        if (!super.equalsDeep(other_))
243          return false;
244        if (!(other_ instanceof Ratio))
245          return false;
246        Ratio o = (Ratio) other_;
247        return compareDeep(numerator, o.numerator, true) && compareDeep(denominator, o.denominator, true)
248          ;
249      }
250
251      @Override
252      public boolean equalsShallow(Base other_) {
253        if (!super.equalsShallow(other_))
254          return false;
255        if (!(other_ instanceof Ratio))
256          return false;
257        Ratio o = (Ratio) other_;
258        return true;
259      }
260
261      public boolean isEmpty() {
262        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(numerator, denominator);
263      }
264
265
266}
267