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