001package org.hl7.fhir.dstu2.model; 002 003 004 005 006import java.math.BigDecimal; 007 008/* 009 Copyright (c) 2011+, HL7, Inc. 010 All rights reserved. 011 012 Redistribution and use in source and binary forms, with or without modification, 013 are permitted provided that the following conditions are met: 014 015 * Redistributions of source code must retain the above copyright notice, this 016 list of conditions and the following disclaimer. 017 * Redistributions in binary form must reproduce the above copyright notice, 018 this list of conditions and the following disclaimer in the documentation 019 and/or other materials provided with the distribution. 020 * Neither the name of HL7 nor the names of its contributors may be used to 021 endorse or promote products derived from this software without specific 022 prior written permission. 023 024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 025 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 027 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 028 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 029 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 031 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 032 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 033 POSSIBILITY OF SUCH DAMAGE. 034 035*/ 036 037// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 038import java.util.List; 039 040import ca.uhn.fhir.model.api.annotation.Child; 041import ca.uhn.fhir.model.api.annotation.DatatypeDef; 042import ca.uhn.fhir.model.api.annotation.Description; 043import org.hl7.fhir.instance.model.api.ICompositeType; 044import org.hl7.fhir.exceptions.FHIRException; 045import org.hl7.fhir.utilities.Utilities; 046/** 047 * A measured amount (or an amount that can potentially be measured). Note that measured amounts include amounts that are not precisely quantified, including amounts involving arbitrary units and floating currencies. 048 */ 049@DatatypeDef(name="Quantity") 050public class Quantity extends Type implements ICompositeType { 051 052 public enum QuantityComparator { 053 /** 054 * The actual value is less than the given value. 055 */ 056 LESS_THAN, 057 /** 058 * The actual value is less than or equal to the given value. 059 */ 060 LESS_OR_EQUAL, 061 /** 062 * The actual value is greater than or equal to the given value. 063 */ 064 GREATER_OR_EQUAL, 065 /** 066 * The actual value is greater than the given value. 067 */ 068 GREATER_THAN, 069 /** 070 * added to help the parsers 071 */ 072 NULL; 073 public static QuantityComparator fromCode(String codeString) throws FHIRException { 074 if (codeString == null || "".equals(codeString)) 075 return null; 076 if ("<".equals(codeString)) 077 return LESS_THAN; 078 if ("<=".equals(codeString)) 079 return LESS_OR_EQUAL; 080 if (">=".equals(codeString)) 081 return GREATER_OR_EQUAL; 082 if (">".equals(codeString)) 083 return GREATER_THAN; 084 throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'"); 085 } 086 public String toCode() { 087 switch (this) { 088 case LESS_THAN: return "<"; 089 case LESS_OR_EQUAL: return "<="; 090 case GREATER_OR_EQUAL: return ">="; 091 case GREATER_THAN: return ">"; 092 default: return "?"; 093 } 094 } 095 public String getSystem() { 096 switch (this) { 097 case LESS_THAN: return "http://hl7.org/fhir/quantity-comparator"; 098 case LESS_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator"; 099 case GREATER_OR_EQUAL: return "http://hl7.org/fhir/quantity-comparator"; 100 case GREATER_THAN: return "http://hl7.org/fhir/quantity-comparator"; 101 default: return "?"; 102 } 103 } 104 public String getDefinition() { 105 switch (this) { 106 case LESS_THAN: return "The actual value is less than the given value."; 107 case LESS_OR_EQUAL: return "The actual value is less than or equal to the given value."; 108 case GREATER_OR_EQUAL: return "The actual value is greater than or equal to the given value."; 109 case GREATER_THAN: return "The actual value is greater than the given value."; 110 default: return "?"; 111 } 112 } 113 public String getDisplay() { 114 switch (this) { 115 case LESS_THAN: return "Less than"; 116 case LESS_OR_EQUAL: return "Less or Equal to"; 117 case GREATER_OR_EQUAL: return "Greater or Equal to"; 118 case GREATER_THAN: return "Greater than"; 119 default: return "?"; 120 } 121 } 122 } 123 124 public static class QuantityComparatorEnumFactory implements EnumFactory<QuantityComparator> { 125 public QuantityComparator fromCode(String codeString) throws IllegalArgumentException { 126 if (codeString == null || "".equals(codeString)) 127 if (codeString == null || "".equals(codeString)) 128 return null; 129 if ("<".equals(codeString)) 130 return QuantityComparator.LESS_THAN; 131 if ("<=".equals(codeString)) 132 return QuantityComparator.LESS_OR_EQUAL; 133 if (">=".equals(codeString)) 134 return QuantityComparator.GREATER_OR_EQUAL; 135 if (">".equals(codeString)) 136 return QuantityComparator.GREATER_THAN; 137 throw new IllegalArgumentException("Unknown QuantityComparator code '"+codeString+"'"); 138 } 139 public Enumeration<QuantityComparator> fromType(Base code) throws FHIRException { 140 if (code == null || code.isEmpty()) 141 return null; 142 String codeString = ((PrimitiveType) code).asStringValue(); 143 if (codeString == null || "".equals(codeString)) 144 return null; 145 if ("<".equals(codeString)) 146 return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_THAN); 147 if ("<=".equals(codeString)) 148 return new Enumeration<QuantityComparator>(this, QuantityComparator.LESS_OR_EQUAL); 149 if (">=".equals(codeString)) 150 return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_OR_EQUAL); 151 if (">".equals(codeString)) 152 return new Enumeration<QuantityComparator>(this, QuantityComparator.GREATER_THAN); 153 throw new FHIRException("Unknown QuantityComparator code '"+codeString+"'"); 154 } 155 public String toCode(QuantityComparator code) { 156 if (code == QuantityComparator.LESS_THAN) 157 return "<"; 158 if (code == QuantityComparator.LESS_OR_EQUAL) 159 return "<="; 160 if (code == QuantityComparator.GREATER_OR_EQUAL) 161 return ">="; 162 if (code == QuantityComparator.GREATER_THAN) 163 return ">"; 164 return "?"; 165 } 166 } 167 168 /** 169 * The value of the measured amount. The value includes an implicit precision in the presentation of the value. 170 */ 171 @Child(name = "value", type = {DecimalType.class}, order=0, min=0, max=1, modifier=false, summary=true) 172 @Description(shortDefinition="Numerical value (with implicit precision)", formalDefinition="The value of the measured amount. The value includes an implicit precision in the presentation of the value." ) 173 protected DecimalType value; 174 175 /** 176 * How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is "<" , then the real value is < stated value. 177 */ 178 @Child(name = "comparator", type = {CodeType.class}, order=1, min=0, max=1, modifier=true, summary=true) 179 @Description(shortDefinition="< | <= | >= | > - how to understand the value", formalDefinition="How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is \"<\" , then the real value is < stated value." ) 180 protected Enumeration<QuantityComparator> comparator; 181 182 /** 183 * A human-readable form of the unit. 184 */ 185 @Child(name = "unit", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=true) 186 @Description(shortDefinition="Unit representation", formalDefinition="A human-readable form of the unit." ) 187 protected StringType unit; 188 189 /** 190 * The identification of the system that provides the coded form of the unit. 191 */ 192 @Child(name = "system", type = {UriType.class}, order=3, min=0, max=1, modifier=false, summary=true) 193 @Description(shortDefinition="System that defines coded unit form", formalDefinition="The identification of the system that provides the coded form of the unit." ) 194 protected UriType system; 195 196 /** 197 * A computer processable form of the unit in some unit representation system. 198 */ 199 @Child(name = "code", type = {CodeType.class}, order=4, min=0, max=1, modifier=false, summary=true) 200 @Description(shortDefinition="Coded form of the unit", formalDefinition="A computer processable form of the unit in some unit representation system." ) 201 protected CodeType code; 202 203 private static final long serialVersionUID = 1069574054L; 204 205 /* 206 * Constructor 207 */ 208 public Quantity() { 209 super(); 210 } 211 212 /** 213 * @return {@link #value} (The value of the measured amount. The value includes an implicit precision in the presentation of the value.). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value 214 */ 215 public DecimalType getValueElement() { 216 if (this.value == null) 217 if (Configuration.errorOnAutoCreate()) 218 throw new Error("Attempt to auto-create Quantity.value"); 219 else if (Configuration.doAutoCreate()) 220 this.value = new DecimalType(); // bb 221 return this.value; 222 } 223 224 public boolean hasValueElement() { 225 return this.value != null && !this.value.isEmpty(); 226 } 227 228 public boolean hasValue() { 229 return this.value != null && !this.value.isEmpty(); 230 } 231 232 /** 233 * @param value {@link #value} (The value of the measured amount. The value includes an implicit precision in the presentation of the value.). This is the underlying object with id, value and extensions. The accessor "getValue" gives direct access to the value 234 */ 235 public Quantity setValueElement(DecimalType value) { 236 this.value = value; 237 return this; 238 } 239 240 /** 241 * @return The value of the measured amount. The value includes an implicit precision in the presentation of the value. 242 */ 243 public BigDecimal getValue() { 244 return this.value == null ? null : this.value.getValue(); 245 } 246 247 /** 248 * @param value The value of the measured amount. The value includes an implicit precision in the presentation of the value. 249 */ 250 public Quantity setValue(BigDecimal value) { 251 if (value == null) 252 this.value = null; 253 else { 254 if (this.value == null) 255 this.value = new DecimalType(); 256 this.value.setValue(value); 257 } 258 return this; 259 } 260 261 /** 262 * @return {@link #comparator} (How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is "<" , then the real value is < stated value.). This is the underlying object with id, value and extensions. The accessor "getComparator" gives direct access to the value 263 */ 264 public Enumeration<QuantityComparator> getComparatorElement() { 265 if (this.comparator == null) 266 if (Configuration.errorOnAutoCreate()) 267 throw new Error("Attempt to auto-create Quantity.comparator"); 268 else if (Configuration.doAutoCreate()) 269 this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory()); // bb 270 return this.comparator; 271 } 272 273 public boolean hasComparatorElement() { 274 return this.comparator != null && !this.comparator.isEmpty(); 275 } 276 277 public boolean hasComparator() { 278 return this.comparator != null && !this.comparator.isEmpty(); 279 } 280 281 /** 282 * @param value {@link #comparator} (How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is "<" , then the real value is < stated value.). This is the underlying object with id, value and extensions. The accessor "getComparator" gives direct access to the value 283 */ 284 public Quantity setComparatorElement(Enumeration<QuantityComparator> value) { 285 this.comparator = value; 286 return this; 287 } 288 289 /** 290 * @return How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is "<" , then the real value is < stated value. 291 */ 292 public QuantityComparator getComparator() { 293 return this.comparator == null ? null : this.comparator.getValue(); 294 } 295 296 /** 297 * @param value How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is "<" , then the real value is < stated value. 298 */ 299 public Quantity setComparator(QuantityComparator value) { 300 if (value == null) 301 this.comparator = null; 302 else { 303 if (this.comparator == null) 304 this.comparator = new Enumeration<QuantityComparator>(new QuantityComparatorEnumFactory()); 305 this.comparator.setValue(value); 306 } 307 return this; 308 } 309 310 /** 311 * @return {@link #unit} (A human-readable form of the unit.). This is the underlying object with id, value and extensions. The accessor "getUnit" gives direct access to the value 312 */ 313 public StringType getUnitElement() { 314 if (this.unit == null) 315 if (Configuration.errorOnAutoCreate()) 316 throw new Error("Attempt to auto-create Quantity.unit"); 317 else if (Configuration.doAutoCreate()) 318 this.unit = new StringType(); // bb 319 return this.unit; 320 } 321 322 public boolean hasUnitElement() { 323 return this.unit != null && !this.unit.isEmpty(); 324 } 325 326 public boolean hasUnit() { 327 return this.unit != null && !this.unit.isEmpty(); 328 } 329 330 /** 331 * @param value {@link #unit} (A human-readable form of the unit.). This is the underlying object with id, value and extensions. The accessor "getUnit" gives direct access to the value 332 */ 333 public Quantity setUnitElement(StringType value) { 334 this.unit = value; 335 return this; 336 } 337 338 /** 339 * @return A human-readable form of the unit. 340 */ 341 public String getUnit() { 342 return this.unit == null ? null : this.unit.getValue(); 343 } 344 345 /** 346 * @param value A human-readable form of the unit. 347 */ 348 public Quantity setUnit(String value) { 349 if (Utilities.noString(value)) 350 this.unit = null; 351 else { 352 if (this.unit == null) 353 this.unit = new StringType(); 354 this.unit.setValue(value); 355 } 356 return this; 357 } 358 359 /** 360 * @return {@link #system} (The identification of the system that provides the coded form of the unit.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value 361 */ 362 public UriType getSystemElement() { 363 if (this.system == null) 364 if (Configuration.errorOnAutoCreate()) 365 throw new Error("Attempt to auto-create Quantity.system"); 366 else if (Configuration.doAutoCreate()) 367 this.system = new UriType(); // bb 368 return this.system; 369 } 370 371 public boolean hasSystemElement() { 372 return this.system != null && !this.system.isEmpty(); 373 } 374 375 public boolean hasSystem() { 376 return this.system != null && !this.system.isEmpty(); 377 } 378 379 /** 380 * @param value {@link #system} (The identification of the system that provides the coded form of the unit.). This is the underlying object with id, value and extensions. The accessor "getSystem" gives direct access to the value 381 */ 382 public Quantity setSystemElement(UriType value) { 383 this.system = value; 384 return this; 385 } 386 387 /** 388 * @return The identification of the system that provides the coded form of the unit. 389 */ 390 public String getSystem() { 391 return this.system == null ? null : this.system.getValue(); 392 } 393 394 /** 395 * @param value The identification of the system that provides the coded form of the unit. 396 */ 397 public Quantity setSystem(String value) { 398 if (Utilities.noString(value)) 399 this.system = null; 400 else { 401 if (this.system == null) 402 this.system = new UriType(); 403 this.system.setValue(value); 404 } 405 return this; 406 } 407 408 /** 409 * @return {@link #code} (A computer processable form of the unit in some unit representation system.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value 410 */ 411 public CodeType getCodeElement() { 412 if (this.code == null) 413 if (Configuration.errorOnAutoCreate()) 414 throw new Error("Attempt to auto-create Quantity.code"); 415 else if (Configuration.doAutoCreate()) 416 this.code = new CodeType(); // bb 417 return this.code; 418 } 419 420 public boolean hasCodeElement() { 421 return this.code != null && !this.code.isEmpty(); 422 } 423 424 public boolean hasCode() { 425 return this.code != null && !this.code.isEmpty(); 426 } 427 428 /** 429 * @param value {@link #code} (A computer processable form of the unit in some unit representation system.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value 430 */ 431 public Quantity setCodeElement(CodeType value) { 432 this.code = value; 433 return this; 434 } 435 436 /** 437 * @return A computer processable form of the unit in some unit representation system. 438 */ 439 public String getCode() { 440 return this.code == null ? null : this.code.getValue(); 441 } 442 443 /** 444 * @param value A computer processable form of the unit in some unit representation system. 445 */ 446 public Quantity setCode(String value) { 447 if (Utilities.noString(value)) 448 this.code = null; 449 else { 450 if (this.code == null) 451 this.code = new CodeType(); 452 this.code.setValue(value); 453 } 454 return this; 455 } 456 457 protected void listChildren(List<Property> childrenList) { 458 super.listChildren(childrenList); 459 childrenList.add(new Property("value", "decimal", "The value of the measured amount. The value includes an implicit precision in the presentation of the value.", 0, java.lang.Integer.MAX_VALUE, value)); 460 childrenList.add(new Property("comparator", "code", "How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is \"<\" , then the real value is < stated value.", 0, java.lang.Integer.MAX_VALUE, comparator)); 461 childrenList.add(new Property("unit", "string", "A human-readable form of the unit.", 0, java.lang.Integer.MAX_VALUE, unit)); 462 childrenList.add(new Property("system", "uri", "The identification of the system that provides the coded form of the unit.", 0, java.lang.Integer.MAX_VALUE, system)); 463 childrenList.add(new Property("code", "code", "A computer processable form of the unit in some unit representation system.", 0, java.lang.Integer.MAX_VALUE, code)); 464 } 465 466 @Override 467 public void setProperty(String name, Base value) throws FHIRException { 468 if (name.equals("value")) 469 this.value = castToDecimal(value); // DecimalType 470 else if (name.equals("comparator")) 471 this.comparator = new QuantityComparatorEnumFactory().fromType(value); // Enumeration<QuantityComparator> 472 else if (name.equals("unit")) 473 this.unit = castToString(value); // StringType 474 else if (name.equals("system")) 475 this.system = castToUri(value); // UriType 476 else if (name.equals("code")) 477 this.code = castToCode(value); // CodeType 478 else 479 super.setProperty(name, value); 480 } 481 482 @Override 483 public Base addChild(String name) throws FHIRException { 484 if (name.equals("value")) { 485 throw new FHIRException("Cannot call addChild on a primitive type Quantity.value"); 486 } 487 else if (name.equals("comparator")) { 488 throw new FHIRException("Cannot call addChild on a primitive type Quantity.comparator"); 489 } 490 else if (name.equals("unit")) { 491 throw new FHIRException("Cannot call addChild on a primitive type Quantity.unit"); 492 } 493 else if (name.equals("system")) { 494 throw new FHIRException("Cannot call addChild on a primitive type Quantity.system"); 495 } 496 else if (name.equals("code")) { 497 throw new FHIRException("Cannot call addChild on a primitive type Quantity.code"); 498 } 499 else 500 return super.addChild(name); 501 } 502 503 public String fhirType() { 504 return "Quantity"; 505 506 } 507 508 public Quantity copy() { 509 Quantity dst = new Quantity(); 510 copyValues(dst); 511 dst.value = value == null ? null : value.copy(); 512 dst.comparator = comparator == null ? null : comparator.copy(); 513 dst.unit = unit == null ? null : unit.copy(); 514 dst.system = system == null ? null : system.copy(); 515 dst.code = code == null ? null : code.copy(); 516 return dst; 517 } 518 519 protected Quantity typedCopy() { 520 return copy(); 521 } 522 523 @Override 524 public boolean equalsDeep(Base other) { 525 if (!super.equalsDeep(other)) 526 return false; 527 if (!(other instanceof Quantity)) 528 return false; 529 Quantity o = (Quantity) other; 530 return compareDeep(value, o.value, true) && compareDeep(comparator, o.comparator, true) && compareDeep(unit, o.unit, true) 531 && compareDeep(system, o.system, true) && compareDeep(code, o.code, true); 532 } 533 534 @Override 535 public boolean equalsShallow(Base other) { 536 if (!super.equalsShallow(other)) 537 return false; 538 if (!(other instanceof Quantity)) 539 return false; 540 Quantity o = (Quantity) other; 541 return compareValues(value, o.value, true) && compareValues(comparator, o.comparator, true) && compareValues(unit, o.unit, true) 542 && compareValues(system, o.system, true) && compareValues(code, o.code, true); 543 } 544 545 public boolean isEmpty() { 546 return super.isEmpty() && (value == null || value.isEmpty()) && (comparator == null || comparator.isEmpty()) 547 && (unit == null || unit.isEmpty()) && (system == null || system.isEmpty()) && (code == null || code.isEmpty()) 548 ; 549 } 550 551 552}