001package org.hl7.fhir.r5.model; 002 003 004/* 005 Copyright (c) 2011+, HL7, Inc. 006 All rights reserved. 007 008 Redistribution and use in source and binary forms, with or without modification, \ 009 are permitted provided that the following conditions are met: 010 011 * Redistributions of source code must retain the above copyright notice, this \ 012 list of conditions and the following disclaimer. 013 * Redistributions in binary form must reproduce the above copyright notice, \ 014 this list of conditions and the following disclaimer in the documentation \ 015 and/or other materials provided with the distribution. 016 * Neither the name of HL7 nor the names of its contributors may be used to 017 endorse or promote products derived from this software without specific 018 prior written permission. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \ 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \ 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \ 023 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \ 024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \ 025 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \ 026 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \ 027 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \ 028 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \ 029 POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032// Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0 033 034import java.util.ArrayList; 035import java.util.Date; 036import java.util.List; 037import java.math.*; 038import org.hl7.fhir.utilities.Utilities; 039import org.hl7.fhir.r5.model.Enumerations.*; 040import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; 041import org.hl7.fhir.exceptions.FHIRException; 042import org.hl7.fhir.instance.model.api.ICompositeType; 043import ca.uhn.fhir.model.api.annotation.Child; 044import ca.uhn.fhir.model.api.annotation.ChildOrder; 045import ca.uhn.fhir.model.api.annotation.DatatypeDef; 046import ca.uhn.fhir.model.api.annotation.Description; 047import ca.uhn.fhir.model.api.annotation.Block; 048 049/** 050 * Money Type: An amount of economic utility in some recognized currency. 051 */ 052@DatatypeDef(name="Money") 053public class Money extends DataType implements ICompositeType { 054 055 /** 056 * Numerical value (with implicit precision). 057 */ 058 @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true) 059 @Description(shortDefinition="Numerical value (with implicit precision)", formalDefinition="Numerical value (with implicit precision)." ) 060 protected DecimalType value; 061 062 /** 063 * ISO 4217 Currency Code. 064 */ 065 @Child(name = "currency", type = {CodeType.class}, order=1, min=0, max=1, modifier=false, summary=true) 066 @Description(shortDefinition="ISO 4217 Currency Code", formalDefinition="ISO 4217 Currency Code." ) 067 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/currencies") 068 protected CodeType currency; 069 070 private static final long serialVersionUID = -484637938L; 071 072 /** 073 * Constructor 074 */ 075 public Money() { 076 super(); 077 } 078 079 /** 080 * @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 081 */ 082 public DecimalType getValueElement() { 083 if (this.value == null) 084 if (Configuration.errorOnAutoCreate()) 085 throw new Error("Attempt to auto-create Money.value"); 086 else if (Configuration.doAutoCreate()) 087 this.value = new DecimalType(); // bb 088 return this.value; 089 } 090 091 public boolean hasValueElement() { 092 return this.value != null && !this.value.isEmpty(); 093 } 094 095 public boolean hasValue() { 096 return this.value != null && !this.value.isEmpty(); 097 } 098 099 /** 100 * @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 101 */ 102 public Money setValueElement(DecimalType value) { 103 this.value = value; 104 return this; 105 } 106 107 /** 108 * @return Numerical value (with implicit precision). 109 */ 110 public BigDecimal getValue() { 111 return this.value == null ? null : this.value.getValue(); 112 } 113 114 /** 115 * @param value Numerical value (with implicit precision). 116 */ 117 public Money setValue(BigDecimal value) { 118 if (value == null) 119 this.value = null; 120 else { 121 if (this.value == null) 122 this.value = new DecimalType(); 123 this.value.setValue(value); 124 } 125 return this; 126 } 127 128 /** 129 * @param value Numerical value (with implicit precision). 130 */ 131 public Money setValue(long value) { 132 this.value = new DecimalType(); 133 this.value.setValue(value); 134 return this; 135 } 136 137 /** 138 * @param value Numerical value (with implicit precision). 139 */ 140 public Money setValue(double value) { 141 this.value = new DecimalType(); 142 this.value.setValue(value); 143 return this; 144 } 145 146 /** 147 * @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 148 */ 149 public CodeType getCurrencyElement() { 150 if (this.currency == null) 151 if (Configuration.errorOnAutoCreate()) 152 throw new Error("Attempt to auto-create Money.currency"); 153 else if (Configuration.doAutoCreate()) 154 this.currency = new CodeType(); // bb 155 return this.currency; 156 } 157 158 public boolean hasCurrencyElement() { 159 return this.currency != null && !this.currency.isEmpty(); 160 } 161 162 public boolean hasCurrency() { 163 return this.currency != null && !this.currency.isEmpty(); 164 } 165 166 /** 167 * @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 168 */ 169 public Money setCurrencyElement(CodeType value) { 170 this.currency = value; 171 return this; 172 } 173 174 /** 175 * @return ISO 4217 Currency Code. 176 */ 177 public String getCurrency() { 178 return this.currency == null ? null : this.currency.getValue(); 179 } 180 181 /** 182 * @param value ISO 4217 Currency Code. 183 */ 184 public Money setCurrency(String value) { 185 if (Utilities.noString(value)) 186 this.currency = null; 187 else { 188 if (this.currency == null) 189 this.currency = new CodeType(); 190 this.currency.setValue(value); 191 } 192 return this; 193 } 194 195 protected void listChildren(List<Property> children) { 196 super.listChildren(children); 197 children.add(new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value)); 198 children.add(new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency)); 199 } 200 201 @Override 202 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 203 switch (_hash) { 204 case 111972721: /*value*/ return new Property("value", "decimal", "Numerical value (with implicit precision).", 0, 1, value); 205 case 575402001: /*currency*/ return new Property("currency", "code", "ISO 4217 Currency Code.", 0, 1, currency); 206 default: return super.getNamedProperty(_hash, _name, _checkValid); 207 } 208 209 } 210 211 @Override 212 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 213 switch (hash) { 214 case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // DecimalType 215 case 575402001: /*currency*/ return this.currency == null ? new Base[0] : new Base[] {this.currency}; // CodeType 216 default: return super.getProperty(hash, name, checkValid); 217 } 218 219 } 220 221 @Override 222 public Base setProperty(int hash, String name, Base value) throws FHIRException { 223 switch (hash) { 224 case 111972721: // value 225 this.value = TypeConvertor.castToDecimal(value); // DecimalType 226 return value; 227 case 575402001: // currency 228 this.currency = TypeConvertor.castToCode(value); // CodeType 229 return value; 230 default: return super.setProperty(hash, name, value); 231 } 232 233 } 234 235 @Override 236 public Base setProperty(String name, Base value) throws FHIRException { 237 if (name.equals("value")) { 238 this.value = TypeConvertor.castToDecimal(value); // DecimalType 239 } else if (name.equals("currency")) { 240 this.currency = TypeConvertor.castToCode(value); // CodeType 241 } else 242 return super.setProperty(name, value); 243 return value; 244 } 245 246 @Override 247 public Base makeProperty(int hash, String name) throws FHIRException { 248 switch (hash) { 249 case 111972721: return getValueElement(); 250 case 575402001: return getCurrencyElement(); 251 default: return super.makeProperty(hash, name); 252 } 253 254 } 255 256 @Override 257 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 258 switch (hash) { 259 case 111972721: /*value*/ return new String[] {"decimal"}; 260 case 575402001: /*currency*/ return new String[] {"code"}; 261 default: return super.getTypesForProperty(hash, name); 262 } 263 264 } 265 266 @Override 267 public Base addChild(String name) throws FHIRException { 268 if (name.equals("value")) { 269 throw new FHIRException("Cannot call addChild on a singleton property Money.value"); 270 } 271 else if (name.equals("currency")) { 272 throw new FHIRException("Cannot call addChild on a singleton property Money.currency"); 273 } 274 else 275 return super.addChild(name); 276 } 277 278 public String fhirType() { 279 return "Money"; 280 281 } 282 283 public Money copy() { 284 Money dst = new Money(); 285 copyValues(dst); 286 return dst; 287 } 288 289 public void copyValues(Money dst) { 290 super.copyValues(dst); 291 dst.value = value == null ? null : value.copy(); 292 dst.currency = currency == null ? null : currency.copy(); 293 } 294 295 protected Money typedCopy() { 296 return copy(); 297 } 298 299 @Override 300 public boolean equalsDeep(Base other_) { 301 if (!super.equalsDeep(other_)) 302 return false; 303 if (!(other_ instanceof Money)) 304 return false; 305 Money o = (Money) other_; 306 return compareDeep(value, o.value, true) && compareDeep(currency, o.currency, true); 307 } 308 309 @Override 310 public boolean equalsShallow(Base other_) { 311 if (!super.equalsShallow(other_)) 312 return false; 313 if (!(other_ instanceof Money)) 314 return false; 315 Money o = (Money) other_; 316 return compareValues(value, o.value, true) && compareValues(currency, o.currency, true); 317 } 318 319 public boolean isEmpty() { 320 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(value, currency); 321 } 322 323 324} 325