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