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 * MonetaryComponent Type: Availability data for an {item}. 051 */ 052@DatatypeDef(name="MonetaryComponent") 053public class MonetaryComponent extends DataType implements ICompositeType { 054 055 public enum PriceComponentType { 056 /** 057 * the amount is the base price used for calculating the total price before applying surcharges, discount or taxes. 058 */ 059 BASE, 060 /** 061 * the amount is a surcharge applied on the base price. 062 */ 063 SURCHARGE, 064 /** 065 * the amount is a deduction applied on the base price. 066 */ 067 DEDUCTION, 068 /** 069 * the amount is a discount applied on the base price. 070 */ 071 DISCOUNT, 072 /** 073 * the amount is the tax component of the total price. 074 */ 075 TAX, 076 /** 077 * the amount is of informational character, it has not been applied in the calculation of the total price. 078 */ 079 INFORMATIONAL, 080 /** 081 * added to help the parsers with the generic types 082 */ 083 NULL; 084 public static PriceComponentType fromCode(String codeString) throws FHIRException { 085 if (codeString == null || "".equals(codeString)) 086 return null; 087 if ("base".equals(codeString)) 088 return BASE; 089 if ("surcharge".equals(codeString)) 090 return SURCHARGE; 091 if ("deduction".equals(codeString)) 092 return DEDUCTION; 093 if ("discount".equals(codeString)) 094 return DISCOUNT; 095 if ("tax".equals(codeString)) 096 return TAX; 097 if ("informational".equals(codeString)) 098 return INFORMATIONAL; 099 if (Configuration.isAcceptInvalidEnums()) 100 return null; 101 else 102 throw new FHIRException("Unknown PriceComponentType code '"+codeString+"'"); 103 } 104 public String toCode() { 105 switch (this) { 106 case BASE: return "base"; 107 case SURCHARGE: return "surcharge"; 108 case DEDUCTION: return "deduction"; 109 case DISCOUNT: return "discount"; 110 case TAX: return "tax"; 111 case INFORMATIONAL: return "informational"; 112 case NULL: return null; 113 default: return "?"; 114 } 115 } 116 public String getSystem() { 117 switch (this) { 118 case BASE: return "http://hl7.org/fhir/price-component-type"; 119 case SURCHARGE: return "http://hl7.org/fhir/price-component-type"; 120 case DEDUCTION: return "http://hl7.org/fhir/price-component-type"; 121 case DISCOUNT: return "http://hl7.org/fhir/price-component-type"; 122 case TAX: return "http://hl7.org/fhir/price-component-type"; 123 case INFORMATIONAL: return "http://hl7.org/fhir/price-component-type"; 124 case NULL: return null; 125 default: return "?"; 126 } 127 } 128 public String getDefinition() { 129 switch (this) { 130 case BASE: return "the amount is the base price used for calculating the total price before applying surcharges, discount or taxes."; 131 case SURCHARGE: return "the amount is a surcharge applied on the base price."; 132 case DEDUCTION: return "the amount is a deduction applied on the base price."; 133 case DISCOUNT: return "the amount is a discount applied on the base price."; 134 case TAX: return "the amount is the tax component of the total price."; 135 case INFORMATIONAL: return "the amount is of informational character, it has not been applied in the calculation of the total price."; 136 case NULL: return null; 137 default: return "?"; 138 } 139 } 140 public String getDisplay() { 141 switch (this) { 142 case BASE: return "base price"; 143 case SURCHARGE: return "surcharge"; 144 case DEDUCTION: return "deduction"; 145 case DISCOUNT: return "discount"; 146 case TAX: return "tax"; 147 case INFORMATIONAL: return "informational"; 148 case NULL: return null; 149 default: return "?"; 150 } 151 } 152 } 153 154 public static class PriceComponentTypeEnumFactory implements EnumFactory<PriceComponentType> { 155 public PriceComponentType fromCode(String codeString) throws IllegalArgumentException { 156 if (codeString == null || "".equals(codeString)) 157 if (codeString == null || "".equals(codeString)) 158 return null; 159 if ("base".equals(codeString)) 160 return PriceComponentType.BASE; 161 if ("surcharge".equals(codeString)) 162 return PriceComponentType.SURCHARGE; 163 if ("deduction".equals(codeString)) 164 return PriceComponentType.DEDUCTION; 165 if ("discount".equals(codeString)) 166 return PriceComponentType.DISCOUNT; 167 if ("tax".equals(codeString)) 168 return PriceComponentType.TAX; 169 if ("informational".equals(codeString)) 170 return PriceComponentType.INFORMATIONAL; 171 throw new IllegalArgumentException("Unknown PriceComponentType code '"+codeString+"'"); 172 } 173 public Enumeration<PriceComponentType> fromType(PrimitiveType<?> code) throws FHIRException { 174 if (code == null) 175 return null; 176 if (code.isEmpty()) 177 return new Enumeration<PriceComponentType>(this, PriceComponentType.NULL, code); 178 String codeString = ((PrimitiveType) code).asStringValue(); 179 if (codeString == null || "".equals(codeString)) 180 return new Enumeration<PriceComponentType>(this, PriceComponentType.NULL, code); 181 if ("base".equals(codeString)) 182 return new Enumeration<PriceComponentType>(this, PriceComponentType.BASE, code); 183 if ("surcharge".equals(codeString)) 184 return new Enumeration<PriceComponentType>(this, PriceComponentType.SURCHARGE, code); 185 if ("deduction".equals(codeString)) 186 return new Enumeration<PriceComponentType>(this, PriceComponentType.DEDUCTION, code); 187 if ("discount".equals(codeString)) 188 return new Enumeration<PriceComponentType>(this, PriceComponentType.DISCOUNT, code); 189 if ("tax".equals(codeString)) 190 return new Enumeration<PriceComponentType>(this, PriceComponentType.TAX, code); 191 if ("informational".equals(codeString)) 192 return new Enumeration<PriceComponentType>(this, PriceComponentType.INFORMATIONAL, code); 193 throw new FHIRException("Unknown PriceComponentType code '"+codeString+"'"); 194 } 195 public String toCode(PriceComponentType code) { 196 if (code == PriceComponentType.BASE) 197 return "base"; 198 if (code == PriceComponentType.SURCHARGE) 199 return "surcharge"; 200 if (code == PriceComponentType.DEDUCTION) 201 return "deduction"; 202 if (code == PriceComponentType.DISCOUNT) 203 return "discount"; 204 if (code == PriceComponentType.TAX) 205 return "tax"; 206 if (code == PriceComponentType.INFORMATIONAL) 207 return "informational"; 208 return "?"; 209 } 210 public String toSystem(PriceComponentType code) { 211 return code.getSystem(); 212 } 213 } 214 215 /** 216 * base | surcharge | deduction | discount | tax | informational. 217 */ 218 @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true) 219 @Description(shortDefinition="base | surcharge | deduction | discount | tax | informational", formalDefinition="base | surcharge | deduction | discount | tax | informational." ) 220 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/price-component-type") 221 protected Enumeration<PriceComponentType> type; 222 223 /** 224 * Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc. 225 */ 226 @Child(name = "code", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=true) 227 @Description(shortDefinition="Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc.", formalDefinition="Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc." ) 228 protected CodeableConcept code; 229 230 /** 231 * Factor used for calculating this component. 232 */ 233 @Child(name = "factor", type = {DecimalType.class}, order=2, min=0, max=1, modifier=false, summary=true) 234 @Description(shortDefinition="Factor used for calculating this component", formalDefinition="Factor used for calculating this component." ) 235 protected DecimalType factor; 236 237 /** 238 * Explicit value amount to be used. 239 */ 240 @Child(name = "amount", type = {Money.class}, order=3, min=0, max=1, modifier=false, summary=true) 241 @Description(shortDefinition="Explicit value amount to be used", formalDefinition="Explicit value amount to be used." ) 242 protected Money amount; 243 244 private static final long serialVersionUID = 576423679L; 245 246 /** 247 * Constructor 248 */ 249 public MonetaryComponent() { 250 super(); 251 } 252 253 /** 254 * Constructor 255 */ 256 public MonetaryComponent(PriceComponentType type) { 257 super(); 258 this.setType(type); 259 } 260 261 /** 262 * @return {@link #type} (base | surcharge | deduction | discount | tax | informational.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 263 */ 264 public Enumeration<PriceComponentType> getTypeElement() { 265 if (this.type == null) 266 if (Configuration.errorOnAutoCreate()) 267 throw new Error("Attempt to auto-create MonetaryComponent.type"); 268 else if (Configuration.doAutoCreate()) 269 this.type = new Enumeration<PriceComponentType>(new PriceComponentTypeEnumFactory()); // bb 270 return this.type; 271 } 272 273 public boolean hasTypeElement() { 274 return this.type != null && !this.type.isEmpty(); 275 } 276 277 public boolean hasType() { 278 return this.type != null && !this.type.isEmpty(); 279 } 280 281 /** 282 * @param value {@link #type} (base | surcharge | deduction | discount | tax | informational.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 283 */ 284 public MonetaryComponent setTypeElement(Enumeration<PriceComponentType> value) { 285 this.type = value; 286 return this; 287 } 288 289 /** 290 * @return base | surcharge | deduction | discount | tax | informational. 291 */ 292 public PriceComponentType getType() { 293 return this.type == null ? null : this.type.getValue(); 294 } 295 296 /** 297 * @param value base | surcharge | deduction | discount | tax | informational. 298 */ 299 public MonetaryComponent setType(PriceComponentType value) { 300 if (this.type == null) 301 this.type = new Enumeration<PriceComponentType>(new PriceComponentTypeEnumFactory()); 302 this.type.setValue(value); 303 return this; 304 } 305 306 /** 307 * @return {@link #code} (Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc.) 308 */ 309 public CodeableConcept getCode() { 310 if (this.code == null) 311 if (Configuration.errorOnAutoCreate()) 312 throw new Error("Attempt to auto-create MonetaryComponent.code"); 313 else if (Configuration.doAutoCreate()) 314 this.code = new CodeableConcept(); // cc 315 return this.code; 316 } 317 318 public boolean hasCode() { 319 return this.code != null && !this.code.isEmpty(); 320 } 321 322 /** 323 * @param value {@link #code} (Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc.) 324 */ 325 public MonetaryComponent setCode(CodeableConcept value) { 326 this.code = value; 327 return this; 328 } 329 330 /** 331 * @return {@link #factor} (Factor used for calculating this component.). This is the underlying object with id, value and extensions. The accessor "getFactor" gives direct access to the value 332 */ 333 public DecimalType getFactorElement() { 334 if (this.factor == null) 335 if (Configuration.errorOnAutoCreate()) 336 throw new Error("Attempt to auto-create MonetaryComponent.factor"); 337 else if (Configuration.doAutoCreate()) 338 this.factor = new DecimalType(); // bb 339 return this.factor; 340 } 341 342 public boolean hasFactorElement() { 343 return this.factor != null && !this.factor.isEmpty(); 344 } 345 346 public boolean hasFactor() { 347 return this.factor != null && !this.factor.isEmpty(); 348 } 349 350 /** 351 * @param value {@link #factor} (Factor used for calculating this component.). This is the underlying object with id, value and extensions. The accessor "getFactor" gives direct access to the value 352 */ 353 public MonetaryComponent setFactorElement(DecimalType value) { 354 this.factor = value; 355 return this; 356 } 357 358 /** 359 * @return Factor used for calculating this component. 360 */ 361 public BigDecimal getFactor() { 362 return this.factor == null ? null : this.factor.getValue(); 363 } 364 365 /** 366 * @param value Factor used for calculating this component. 367 */ 368 public MonetaryComponent setFactor(BigDecimal value) { 369 if (value == null) 370 this.factor = null; 371 else { 372 if (this.factor == null) 373 this.factor = new DecimalType(); 374 this.factor.setValue(value); 375 } 376 return this; 377 } 378 379 /** 380 * @param value Factor used for calculating this component. 381 */ 382 public MonetaryComponent setFactor(long value) { 383 this.factor = new DecimalType(); 384 this.factor.setValue(value); 385 return this; 386 } 387 388 /** 389 * @param value Factor used for calculating this component. 390 */ 391 public MonetaryComponent setFactor(double value) { 392 this.factor = new DecimalType(); 393 this.factor.setValue(value); 394 return this; 395 } 396 397 /** 398 * @return {@link #amount} (Explicit value amount to be used.) 399 */ 400 public Money getAmount() { 401 if (this.amount == null) 402 if (Configuration.errorOnAutoCreate()) 403 throw new Error("Attempt to auto-create MonetaryComponent.amount"); 404 else if (Configuration.doAutoCreate()) 405 this.amount = new Money(); // cc 406 return this.amount; 407 } 408 409 public boolean hasAmount() { 410 return this.amount != null && !this.amount.isEmpty(); 411 } 412 413 /** 414 * @param value {@link #amount} (Explicit value amount to be used.) 415 */ 416 public MonetaryComponent setAmount(Money value) { 417 this.amount = value; 418 return this; 419 } 420 421 protected void listChildren(List<Property> children) { 422 super.listChildren(children); 423 children.add(new Property("type", "code", "base | surcharge | deduction | discount | tax | informational.", 0, 1, type)); 424 children.add(new Property("code", "CodeableConcept", "Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc.", 0, 1, code)); 425 children.add(new Property("factor", "decimal", "Factor used for calculating this component.", 0, 1, factor)); 426 children.add(new Property("amount", "Money", "Explicit value amount to be used.", 0, 1, amount)); 427 } 428 429 @Override 430 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 431 switch (_hash) { 432 case 3575610: /*type*/ return new Property("type", "code", "base | surcharge | deduction | discount | tax | informational.", 0, 1, type); 433 case 3059181: /*code*/ return new Property("code", "CodeableConcept", "Codes may be used to differentiate between kinds of taxes, surcharges, discounts etc.", 0, 1, code); 434 case -1282148017: /*factor*/ return new Property("factor", "decimal", "Factor used for calculating this component.", 0, 1, factor); 435 case -1413853096: /*amount*/ return new Property("amount", "Money", "Explicit value amount to be used.", 0, 1, amount); 436 default: return super.getNamedProperty(_hash, _name, _checkValid); 437 } 438 439 } 440 441 @Override 442 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 443 switch (hash) { 444 case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<PriceComponentType> 445 case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeableConcept 446 case -1282148017: /*factor*/ return this.factor == null ? new Base[0] : new Base[] {this.factor}; // DecimalType 447 case -1413853096: /*amount*/ return this.amount == null ? new Base[0] : new Base[] {this.amount}; // Money 448 default: return super.getProperty(hash, name, checkValid); 449 } 450 451 } 452 453 @Override 454 public Base setProperty(int hash, String name, Base value) throws FHIRException { 455 switch (hash) { 456 case 3575610: // type 457 value = new PriceComponentTypeEnumFactory().fromType(TypeConvertor.castToCode(value)); 458 this.type = (Enumeration) value; // Enumeration<PriceComponentType> 459 return value; 460 case 3059181: // code 461 this.code = TypeConvertor.castToCodeableConcept(value); // CodeableConcept 462 return value; 463 case -1282148017: // factor 464 this.factor = TypeConvertor.castToDecimal(value); // DecimalType 465 return value; 466 case -1413853096: // amount 467 this.amount = TypeConvertor.castToMoney(value); // Money 468 return value; 469 default: return super.setProperty(hash, name, value); 470 } 471 472 } 473 474 @Override 475 public Base setProperty(String name, Base value) throws FHIRException { 476 if (name.equals("type")) { 477 value = new PriceComponentTypeEnumFactory().fromType(TypeConvertor.castToCode(value)); 478 this.type = (Enumeration) value; // Enumeration<PriceComponentType> 479 } else if (name.equals("code")) { 480 this.code = TypeConvertor.castToCodeableConcept(value); // CodeableConcept 481 } else if (name.equals("factor")) { 482 this.factor = TypeConvertor.castToDecimal(value); // DecimalType 483 } else if (name.equals("amount")) { 484 this.amount = TypeConvertor.castToMoney(value); // Money 485 } else 486 return super.setProperty(name, value); 487 return value; 488 } 489 490 @Override 491 public Base makeProperty(int hash, String name) throws FHIRException { 492 switch (hash) { 493 case 3575610: return getTypeElement(); 494 case 3059181: return getCode(); 495 case -1282148017: return getFactorElement(); 496 case -1413853096: return getAmount(); 497 default: return super.makeProperty(hash, name); 498 } 499 500 } 501 502 @Override 503 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 504 switch (hash) { 505 case 3575610: /*type*/ return new String[] {"code"}; 506 case 3059181: /*code*/ return new String[] {"CodeableConcept"}; 507 case -1282148017: /*factor*/ return new String[] {"decimal"}; 508 case -1413853096: /*amount*/ return new String[] {"Money"}; 509 default: return super.getTypesForProperty(hash, name); 510 } 511 512 } 513 514 @Override 515 public Base addChild(String name) throws FHIRException { 516 if (name.equals("type")) { 517 throw new FHIRException("Cannot call addChild on a singleton property MonetaryComponent.type"); 518 } 519 else if (name.equals("code")) { 520 this.code = new CodeableConcept(); 521 return this.code; 522 } 523 else if (name.equals("factor")) { 524 throw new FHIRException("Cannot call addChild on a singleton property MonetaryComponent.factor"); 525 } 526 else if (name.equals("amount")) { 527 this.amount = new Money(); 528 return this.amount; 529 } 530 else 531 return super.addChild(name); 532 } 533 534 public String fhirType() { 535 return "MonetaryComponent"; 536 537 } 538 539 public MonetaryComponent copy() { 540 MonetaryComponent dst = new MonetaryComponent(); 541 copyValues(dst); 542 return dst; 543 } 544 545 public void copyValues(MonetaryComponent dst) { 546 super.copyValues(dst); 547 dst.type = type == null ? null : type.copy(); 548 dst.code = code == null ? null : code.copy(); 549 dst.factor = factor == null ? null : factor.copy(); 550 dst.amount = amount == null ? null : amount.copy(); 551 } 552 553 protected MonetaryComponent typedCopy() { 554 return copy(); 555 } 556 557 @Override 558 public boolean equalsDeep(Base other_) { 559 if (!super.equalsDeep(other_)) 560 return false; 561 if (!(other_ instanceof MonetaryComponent)) 562 return false; 563 MonetaryComponent o = (MonetaryComponent) other_; 564 return compareDeep(type, o.type, true) && compareDeep(code, o.code, true) && compareDeep(factor, o.factor, true) 565 && compareDeep(amount, o.amount, true); 566 } 567 568 @Override 569 public boolean equalsShallow(Base other_) { 570 if (!super.equalsShallow(other_)) 571 return false; 572 if (!(other_ instanceof MonetaryComponent)) 573 return false; 574 MonetaryComponent o = (MonetaryComponent) other_; 575 return compareValues(type, o.type, true) && compareValues(factor, o.factor, true); 576 } 577 578 public boolean isEmpty() { 579 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, code, factor, amount 580 ); 581 } 582 583 584} 585