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