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 java.math.*; 060import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 061import org.hl7.fhir.utilities.Utilities; 062import org.hl7.fhir.r5.model.Enumerations.*; 063import ca.uhn.fhir.model.api.annotation.Child; 064import ca.uhn.fhir.model.api.annotation.ChildOrder; 065import ca.uhn.fhir.model.api.annotation.DatatypeDef; 066import ca.uhn.fhir.model.api.annotation.Description; 067import ca.uhn.fhir.model.api.annotation.Block; 068/** 069 * An amount of economic utility in some recognized currency. 070 */ 071@DatatypeDef(name="Money") 072public class Money extends Type implements ICompositeType { 073 074 /** 075 * Numerical value (with implicit precision). 076 */ 077 @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true) 078 @Description(shortDefinition="Numerical value (with implicit precision)", formalDefinition="Numerical value (with implicit precision)." ) 079 protected DecimalType value; 080 081 /** 082 * ISO 4217 Currency Code. 083 */ 084 @Child(name = "currency", type = {CodeType.class}, order=1, min=0, max=1, modifier=false, summary=true) 085 @Description(shortDefinition="ISO 4217 Currency Code", formalDefinition="ISO 4217 Currency Code." ) 086 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/currencies") 087 protected CodeType currency; 088 089 private static final long serialVersionUID = -484637938L; 090 091 /** 092 * Constructor 093 */ 094 public Money() { 095 super(); 096 } 097 098 /** 099 * @return {@link #value} (Numerical value (with implicit precision).). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value 100 */ 101 public DecimalType getValueElement() { 102 if (this.value == null) 103 if (Configuration.errorOnAutoCreate()) 104 throw new Error("Attempt to auto-create Money.value"); 105 else if (Configuration.doAutoCreate()) 106 this.value = new DecimalType(); // bb 107 return this.value; 108 } 109 110 public boolean hasValueElement() { 111 return this.value != null && !this.value.isEmpty(); 112 } 113 114 public boolean hasValue() { 115 return this.value != null && !this.value.isEmpty(); 116 } 117 118 /** 119 * @param value {@link #value} (Numerical value (with implicit precision).). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value 120 */ 121 public Money setValueElement(DecimalType value) { 122 this.value = value; 123 return this; 124 } 125 126 /** 127 * @return Numerical value (with implicit precision). 128 */ 129 public BigDecimal getValue() { 130 return this.value == null ? null : this.value.getValue(); 131 } 132 133 /** 134 * @param value Numerical value (with implicit precision). 135 */ 136 public Money setValue(BigDecimal value) { 137 if (value == null) 138 this.value = null; 139 else { 140 if (this.value == null) 141 this.value = new DecimalType(); 142 this.value.setValue(value); 143 } 144 return this; 145 } 146 147 /** 148 * @param value Numerical value (with implicit precision). 149 */ 150 public Money setValue(long value) { 151 this.value = new DecimalType(); 152 this.value.setValue(value); 153 return this; 154 } 155 156 /** 157 * @param value Numerical value (with implicit precision). 158 */ 159 public Money setValue(double value) { 160 this.value = new DecimalType(); 161 this.value.setValue(value); 162 return this; 163 } 164 165 /** 166 * @return {@link #currency} (ISO 4217 Currency Code.). This is the underlying object with id, value and extensions. The accessor "getCurrency" gives direct access to the value 167 */ 168 public CodeType getCurrencyElement() { 169 if (this.currency == null) 170 if (Configuration.errorOnAutoCreate()) 171 throw new Error("Attempt to auto-create Money.currency"); 172 else if (Configuration.doAutoCreate()) 173 this.currency = new CodeType(); // bb 174 return this.currency; 175 } 176 177 public boolean hasCurrencyElement() { 178 return this.currency != null && !this.currency.isEmpty(); 179 } 180 181 public boolean hasCurrency() { 182 return this.currency != null && !this.currency.isEmpty(); 183 } 184 185 /** 186 * @param value {@link #currency} (ISO 4217 Currency Code.). This is the underlying object with id, value and extensions. The accessor "getCurrency" gives direct access to the value 187 */ 188 public Money setCurrencyElement(CodeType value) { 189 this.currency = value; 190 return this; 191 } 192 193 /** 194 * @return ISO 4217 Currency Code. 195 */ 196 public String getCurrency() { 197 return this.currency == null ? null : this.currency.getValue(); 198 } 199 200 /** 201 * @param value ISO 4217 Currency Code. 202 */ 203 public Money setCurrency(String value) { 204 if (Utilities.noString(value)) 205 this.currency = null; 206 else { 207 if (this.currency == null) 208 this.currency = new CodeType(); 209 this.currency.setValue(value); 210 } 211 return this; 212 } 213 214 protected void listChildren(List<Property> children) { 215 super.listChildren(children); 216 children.add(new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value)); 217 children.add(new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency)); 218 } 219 220 @Override 221 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 222 switch (_hash) { 223 case 111972721: /*value*/ return new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value); 224 case 575402001: /*currency*/ return new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency); 225 default: return super.getNamedProperty(_hash, _name, _checkValid); 226 } 227 228 } 229 230 @Override 231 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 232 switch (hash) { 233 case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // DecimalType 234 case 575402001: /*currency*/ return this.currency == null ? new Base[0] : new Base[] {this.currency}; // CodeType 235 default: return super.getProperty(hash, name, checkValid); 236 } 237 238 } 239 240 @Override 241 public Base setProperty(int hash, String name, Base value) throws FHIRException { 242 switch (hash) { 243 case 111972721: // value 244 this.value = castToDecimal(value); // DecimalType 245 return value; 246 case 575402001: // currency 247 this.currency = castToCode(value); // CodeType 248 return value; 249 default: return super.setProperty(hash, name, value); 250 } 251 252 } 253 254 @Override 255 public Base setProperty(String name, Base value) throws FHIRException { 256 if (name.equals("value")) { 257 this.value = castToDecimal(value); // DecimalType 258 } else if (name.equals("currency")) { 259 this.currency = castToCode(value); // CodeType 260 } else 261 return super.setProperty(name, value); 262 return value; 263 } 264 265 @Override 266 public Base makeProperty(int hash, String name) throws FHIRException { 267 switch (hash) { 268 case 111972721: return getValueElement(); 269 case 575402001: return getCurrencyElement(); 270 default: return super.makeProperty(hash, name); 271 } 272 273 } 274 275 @Override 276 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 277 switch (hash) { 278 case 111972721: /*value*/ return new String[] {"decimal"}; 279 case 575402001: /*currency*/ return new String[] {"code"}; 280 default: return super.getTypesForProperty(hash, name); 281 } 282 283 } 284 285 @Override 286 public Base addChild(String name) throws FHIRException { 287 if (name.equals("value")) { 288 throw new FHIRException("Cannot call addChild on a primitive type Money.value"); 289 } 290 else if (name.equals("currency")) { 291 throw new FHIRException("Cannot call addChild on a primitive type Money.currency"); 292 } 293 else 294 return super.addChild(name); 295 } 296 297 public String fhirType() { 298 return "Money"; 299 300 } 301 302 public Money copy() { 303 Money dst = new Money(); 304 copyValues(dst); 305 return dst; 306 } 307 308 public void copyValues(Money dst) { 309 super.copyValues(dst); 310 dst.value = value == null ? null : value.copy(); 311 dst.currency = currency == null ? null : currency.copy(); 312 } 313 314 protected Money typedCopy() { 315 return copy(); 316 } 317 318 @Override 319 public boolean equalsDeep(Base other_) { 320 if (!super.equalsDeep(other_)) 321 return false; 322 if (!(other_ instanceof Money)) 323 return false; 324 Money o = (Money) other_; 325 return compareDeep(value, o.value, true) && compareDeep(currency, o.currency, true); 326 } 327 328 @Override 329 public boolean equalsShallow(Base other_) { 330 if (!super.equalsShallow(other_)) 331 return false; 332 if (!(other_ instanceof Money)) 333 return false; 334 Money o = (Money) other_; 335 return compareValues(value, o.value, true) && compareValues(currency, o.currency, true); 336 } 337 338 public boolean isEmpty() { 339 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(value, currency); 340 } 341 342 343} 344