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