001package org.hl7.fhir.instance.model; 002 003/* 004 Copyright (c) 2011+, HL7, Inc. 005 All rights reserved. 006 007 Redistribution and use in source and binary forms, with or without modification, 008 are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2 033import java.util.*; 034 035import org.hl7.fhir.exceptions.FHIRException; 036import org.hl7.fhir.instance.model.api.IBaseBackboneElement; 037import org.hl7.fhir.utilities.Utilities; 038 039import ca.uhn.fhir.model.api.annotation.*; 040/** 041 * A homogeneous material with a definite composition. 042 */ 043@ResourceDef(name="Substance", profile="http://hl7.org/fhir/Profile/Substance") 044public class Substance extends DomainResource { 045 046 @Block() 047 public static class SubstanceInstanceComponent extends BackboneElement implements IBaseBackboneElement { 048 /** 049 * Identifier associated with the package/container (usually a label affixed directly). 050 */ 051 @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=1, modifier=false, summary=true) 052 @Description(shortDefinition="Identifier of the package/container", formalDefinition="Identifier associated with the package/container (usually a label affixed directly)." ) 053 protected Identifier identifier; 054 055 /** 056 * When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry. 057 */ 058 @Child(name = "expiry", type = {DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=true) 059 @Description(shortDefinition="When no longer valid to use", formalDefinition="When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry." ) 060 protected DateTimeType expiry; 061 062 /** 063 * The amount of the substance. 064 */ 065 @Child(name = "quantity", type = {SimpleQuantity.class}, order=3, min=0, max=1, modifier=false, summary=true) 066 @Description(shortDefinition="Amount of substance in the package", formalDefinition="The amount of the substance." ) 067 protected SimpleQuantity quantity; 068 069 private static final long serialVersionUID = -794314734L; 070 071 /* 072 * Constructor 073 */ 074 public SubstanceInstanceComponent() { 075 super(); 076 } 077 078 /** 079 * @return {@link #identifier} (Identifier associated with the package/container (usually a label affixed directly).) 080 */ 081 public Identifier getIdentifier() { 082 if (this.identifier == null) 083 if (Configuration.errorOnAutoCreate()) 084 throw new Error("Attempt to auto-create SubstanceInstanceComponent.identifier"); 085 else if (Configuration.doAutoCreate()) 086 this.identifier = new Identifier(); // cc 087 return this.identifier; 088 } 089 090 public boolean hasIdentifier() { 091 return this.identifier != null && !this.identifier.isEmpty(); 092 } 093 094 /** 095 * @param value {@link #identifier} (Identifier associated with the package/container (usually a label affixed directly).) 096 */ 097 public SubstanceInstanceComponent setIdentifier(Identifier value) { 098 this.identifier = value; 099 return this; 100 } 101 102 /** 103 * @return {@link #expiry} (When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.). This is the underlying object with id, value and extensions. The accessor "getExpiry" gives direct access to the value 104 */ 105 public DateTimeType getExpiryElement() { 106 if (this.expiry == null) 107 if (Configuration.errorOnAutoCreate()) 108 throw new Error("Attempt to auto-create SubstanceInstanceComponent.expiry"); 109 else if (Configuration.doAutoCreate()) 110 this.expiry = new DateTimeType(); // bb 111 return this.expiry; 112 } 113 114 public boolean hasExpiryElement() { 115 return this.expiry != null && !this.expiry.isEmpty(); 116 } 117 118 public boolean hasExpiry() { 119 return this.expiry != null && !this.expiry.isEmpty(); 120 } 121 122 /** 123 * @param value {@link #expiry} (When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.). This is the underlying object with id, value and extensions. The accessor "getExpiry" gives direct access to the value 124 */ 125 public SubstanceInstanceComponent setExpiryElement(DateTimeType value) { 126 this.expiry = value; 127 return this; 128 } 129 130 /** 131 * @return When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry. 132 */ 133 public Date getExpiry() { 134 return this.expiry == null ? null : this.expiry.getValue(); 135 } 136 137 /** 138 * @param value When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry. 139 */ 140 public SubstanceInstanceComponent setExpiry(Date value) { 141 if (value == null) 142 this.expiry = null; 143 else { 144 if (this.expiry == null) 145 this.expiry = new DateTimeType(); 146 this.expiry.setValue(value); 147 } 148 return this; 149 } 150 151 /** 152 * @return {@link #quantity} (The amount of the substance.) 153 */ 154 public SimpleQuantity getQuantity() { 155 if (this.quantity == null) 156 if (Configuration.errorOnAutoCreate()) 157 throw new Error("Attempt to auto-create SubstanceInstanceComponent.quantity"); 158 else if (Configuration.doAutoCreate()) 159 this.quantity = new SimpleQuantity(); // cc 160 return this.quantity; 161 } 162 163 public boolean hasQuantity() { 164 return this.quantity != null && !this.quantity.isEmpty(); 165 } 166 167 /** 168 * @param value {@link #quantity} (The amount of the substance.) 169 */ 170 public SubstanceInstanceComponent setQuantity(SimpleQuantity value) { 171 this.quantity = value; 172 return this; 173 } 174 175 protected void listChildren(List<Property> childrenList) { 176 super.listChildren(childrenList); 177 childrenList.add(new Property("identifier", "Identifier", "Identifier associated with the package/container (usually a label affixed directly).", 0, java.lang.Integer.MAX_VALUE, identifier)); 178 childrenList.add(new Property("expiry", "dateTime", "When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.", 0, java.lang.Integer.MAX_VALUE, expiry)); 179 childrenList.add(new Property("quantity", "SimpleQuantity", "The amount of the substance.", 0, java.lang.Integer.MAX_VALUE, quantity)); 180 } 181 182 @Override 183 public void setProperty(String name, Base value) throws FHIRException { 184 if (name.equals("identifier")) 185 this.identifier = castToIdentifier(value); // Identifier 186 else if (name.equals("expiry")) 187 this.expiry = castToDateTime(value); // DateTimeType 188 else if (name.equals("quantity")) 189 this.quantity = castToSimpleQuantity(value); // SimpleQuantity 190 else 191 super.setProperty(name, value); 192 } 193 194 @Override 195 public Base addChild(String name) throws FHIRException { 196 if (name.equals("identifier")) { 197 this.identifier = new Identifier(); 198 return this.identifier; 199 } 200 else if (name.equals("expiry")) { 201 throw new FHIRException("Cannot call addChild on a primitive type Substance.expiry"); 202 } 203 else if (name.equals("quantity")) { 204 this.quantity = new SimpleQuantity(); 205 return this.quantity; 206 } 207 else 208 return super.addChild(name); 209 } 210 211 public SubstanceInstanceComponent copy() { 212 SubstanceInstanceComponent dst = new SubstanceInstanceComponent(); 213 copyValues(dst); 214 dst.identifier = identifier == null ? null : identifier.copy(); 215 dst.expiry = expiry == null ? null : expiry.copy(); 216 dst.quantity = quantity == null ? null : quantity.copy(); 217 return dst; 218 } 219 220 @Override 221 public boolean equalsDeep(Base other) { 222 if (!super.equalsDeep(other)) 223 return false; 224 if (!(other instanceof SubstanceInstanceComponent)) 225 return false; 226 SubstanceInstanceComponent o = (SubstanceInstanceComponent) other; 227 return compareDeep(identifier, o.identifier, true) && compareDeep(expiry, o.expiry, true) && compareDeep(quantity, o.quantity, true) 228 ; 229 } 230 231 @Override 232 public boolean equalsShallow(Base other) { 233 if (!super.equalsShallow(other)) 234 return false; 235 if (!(other instanceof SubstanceInstanceComponent)) 236 return false; 237 SubstanceInstanceComponent o = (SubstanceInstanceComponent) other; 238 return compareValues(expiry, o.expiry, true); 239 } 240 241 public boolean isEmpty() { 242 return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (expiry == null || expiry.isEmpty()) 243 && (quantity == null || quantity.isEmpty()); 244 } 245 246 public String fhirType() { 247 return "Substance.instance"; 248 249 } 250 251 } 252 253 @Block() 254 public static class SubstanceIngredientComponent extends BackboneElement implements IBaseBackboneElement { 255 /** 256 * The amount of the ingredient in the substance - a concentration ratio. 257 */ 258 @Child(name = "quantity", type = {Ratio.class}, order=1, min=0, max=1, modifier=false, summary=true) 259 @Description(shortDefinition="Optional amount (concentration)", formalDefinition="The amount of the ingredient in the substance - a concentration ratio." ) 260 protected Ratio quantity; 261 262 /** 263 * Another substance that is a component of this substance. 264 */ 265 @Child(name = "substance", type = {Substance.class}, order=2, min=1, max=1, modifier=false, summary=true) 266 @Description(shortDefinition="A component of the substance", formalDefinition="Another substance that is a component of this substance." ) 267 protected Reference substance; 268 269 /** 270 * The actual object that is the target of the reference (Another substance that is a component of this substance.) 271 */ 272 protected Substance substanceTarget; 273 274 private static final long serialVersionUID = -1783242034L; 275 276 /* 277 * Constructor 278 */ 279 public SubstanceIngredientComponent() { 280 super(); 281 } 282 283 /* 284 * Constructor 285 */ 286 public SubstanceIngredientComponent(Reference substance) { 287 super(); 288 this.substance = substance; 289 } 290 291 /** 292 * @return {@link #quantity} (The amount of the ingredient in the substance - a concentration ratio.) 293 */ 294 public Ratio getQuantity() { 295 if (this.quantity == null) 296 if (Configuration.errorOnAutoCreate()) 297 throw new Error("Attempt to auto-create SubstanceIngredientComponent.quantity"); 298 else if (Configuration.doAutoCreate()) 299 this.quantity = new Ratio(); // cc 300 return this.quantity; 301 } 302 303 public boolean hasQuantity() { 304 return this.quantity != null && !this.quantity.isEmpty(); 305 } 306 307 /** 308 * @param value {@link #quantity} (The amount of the ingredient in the substance - a concentration ratio.) 309 */ 310 public SubstanceIngredientComponent setQuantity(Ratio value) { 311 this.quantity = value; 312 return this; 313 } 314 315 /** 316 * @return {@link #substance} (Another substance that is a component of this substance.) 317 */ 318 public Reference getSubstance() { 319 if (this.substance == null) 320 if (Configuration.errorOnAutoCreate()) 321 throw new Error("Attempt to auto-create SubstanceIngredientComponent.substance"); 322 else if (Configuration.doAutoCreate()) 323 this.substance = new Reference(); // cc 324 return this.substance; 325 } 326 327 public boolean hasSubstance() { 328 return this.substance != null && !this.substance.isEmpty(); 329 } 330 331 /** 332 * @param value {@link #substance} (Another substance that is a component of this substance.) 333 */ 334 public SubstanceIngredientComponent setSubstance(Reference value) { 335 this.substance = value; 336 return this; 337 } 338 339 /** 340 * @return {@link #substance} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Another substance that is a component of this substance.) 341 */ 342 public Substance getSubstanceTarget() { 343 if (this.substanceTarget == null) 344 if (Configuration.errorOnAutoCreate()) 345 throw new Error("Attempt to auto-create SubstanceIngredientComponent.substance"); 346 else if (Configuration.doAutoCreate()) 347 this.substanceTarget = new Substance(); // aa 348 return this.substanceTarget; 349 } 350 351 /** 352 * @param value {@link #substance} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Another substance that is a component of this substance.) 353 */ 354 public SubstanceIngredientComponent setSubstanceTarget(Substance value) { 355 this.substanceTarget = value; 356 return this; 357 } 358 359 protected void listChildren(List<Property> childrenList) { 360 super.listChildren(childrenList); 361 childrenList.add(new Property("quantity", "Ratio", "The amount of the ingredient in the substance - a concentration ratio.", 0, java.lang.Integer.MAX_VALUE, quantity)); 362 childrenList.add(new Property("substance", "Reference(Substance)", "Another substance that is a component of this substance.", 0, java.lang.Integer.MAX_VALUE, substance)); 363 } 364 365 @Override 366 public void setProperty(String name, Base value) throws FHIRException { 367 if (name.equals("quantity")) 368 this.quantity = castToRatio(value); // Ratio 369 else if (name.equals("substance")) 370 this.substance = castToReference(value); // Reference 371 else 372 super.setProperty(name, value); 373 } 374 375 @Override 376 public Base addChild(String name) throws FHIRException { 377 if (name.equals("quantity")) { 378 this.quantity = new Ratio(); 379 return this.quantity; 380 } 381 else if (name.equals("substance")) { 382 this.substance = new Reference(); 383 return this.substance; 384 } 385 else 386 return super.addChild(name); 387 } 388 389 public SubstanceIngredientComponent copy() { 390 SubstanceIngredientComponent dst = new SubstanceIngredientComponent(); 391 copyValues(dst); 392 dst.quantity = quantity == null ? null : quantity.copy(); 393 dst.substance = substance == null ? null : substance.copy(); 394 return dst; 395 } 396 397 @Override 398 public boolean equalsDeep(Base other) { 399 if (!super.equalsDeep(other)) 400 return false; 401 if (!(other instanceof SubstanceIngredientComponent)) 402 return false; 403 SubstanceIngredientComponent o = (SubstanceIngredientComponent) other; 404 return compareDeep(quantity, o.quantity, true) && compareDeep(substance, o.substance, true); 405 } 406 407 @Override 408 public boolean equalsShallow(Base other) { 409 if (!super.equalsShallow(other)) 410 return false; 411 if (!(other instanceof SubstanceIngredientComponent)) 412 return false; 413 SubstanceIngredientComponent o = (SubstanceIngredientComponent) other; 414 return true; 415 } 416 417 public boolean isEmpty() { 418 return super.isEmpty() && (quantity == null || quantity.isEmpty()) && (substance == null || substance.isEmpty()) 419 ; 420 } 421 422 public String fhirType() { 423 return "Substance.ingredient"; 424 425 } 426 427 } 428 429 /** 430 * Unique identifier for the substance. 431 */ 432 @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 433 @Description(shortDefinition="Unique identifier", formalDefinition="Unique identifier for the substance." ) 434 protected List<Identifier> identifier; 435 436 /** 437 * A code that classifies the general type of substance. This is used for searching, sorting and display purposes. 438 */ 439 @Child(name = "category", type = {CodeableConcept.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 440 @Description(shortDefinition="What class/type of substance this is", formalDefinition="A code that classifies the general type of substance. This is used for searching, sorting and display purposes." ) 441 protected List<CodeableConcept> category; 442 443 /** 444 * A code (or set of codes) that identify this substance. 445 */ 446 @Child(name = "code", type = {CodeableConcept.class}, order=2, min=1, max=1, modifier=false, summary=true) 447 @Description(shortDefinition="What substance this is", formalDefinition="A code (or set of codes) that identify this substance." ) 448 protected CodeableConcept code; 449 450 /** 451 * A description of the substance - its appearance, handling requirements, and other usage notes. 452 */ 453 @Child(name = "description", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true) 454 @Description(shortDefinition="Textual description of the substance, comments", formalDefinition="A description of the substance - its appearance, handling requirements, and other usage notes." ) 455 protected StringType description; 456 457 /** 458 * Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance. 459 */ 460 @Child(name = "instance", type = {}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 461 @Description(shortDefinition="If this describes a specific package/container of the substance", formalDefinition="Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance." ) 462 protected List<SubstanceInstanceComponent> instance; 463 464 /** 465 * A substance can be composed of other substances. 466 */ 467 @Child(name = "ingredient", type = {}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 468 @Description(shortDefinition="Composition information about the substance", formalDefinition="A substance can be composed of other substances." ) 469 protected List<SubstanceIngredientComponent> ingredient; 470 471 private static final long serialVersionUID = -1653977206L; 472 473 /* 474 * Constructor 475 */ 476 public Substance() { 477 super(); 478 } 479 480 /* 481 * Constructor 482 */ 483 public Substance(CodeableConcept code) { 484 super(); 485 this.code = code; 486 } 487 488 /** 489 * @return {@link #identifier} (Unique identifier for the substance.) 490 */ 491 public List<Identifier> getIdentifier() { 492 if (this.identifier == null) 493 this.identifier = new ArrayList<Identifier>(); 494 return this.identifier; 495 } 496 497 public boolean hasIdentifier() { 498 if (this.identifier == null) 499 return false; 500 for (Identifier item : this.identifier) 501 if (!item.isEmpty()) 502 return true; 503 return false; 504 } 505 506 /** 507 * @return {@link #identifier} (Unique identifier for the substance.) 508 */ 509 // syntactic sugar 510 public Identifier addIdentifier() { //3 511 Identifier t = new Identifier(); 512 if (this.identifier == null) 513 this.identifier = new ArrayList<Identifier>(); 514 this.identifier.add(t); 515 return t; 516 } 517 518 // syntactic sugar 519 public Substance addIdentifier(Identifier t) { //3 520 if (t == null) 521 return this; 522 if (this.identifier == null) 523 this.identifier = new ArrayList<Identifier>(); 524 this.identifier.add(t); 525 return this; 526 } 527 528 /** 529 * @return {@link #category} (A code that classifies the general type of substance. This is used for searching, sorting and display purposes.) 530 */ 531 public List<CodeableConcept> getCategory() { 532 if (this.category == null) 533 this.category = new ArrayList<CodeableConcept>(); 534 return this.category; 535 } 536 537 public boolean hasCategory() { 538 if (this.category == null) 539 return false; 540 for (CodeableConcept item : this.category) 541 if (!item.isEmpty()) 542 return true; 543 return false; 544 } 545 546 /** 547 * @return {@link #category} (A code that classifies the general type of substance. This is used for searching, sorting and display purposes.) 548 */ 549 // syntactic sugar 550 public CodeableConcept addCategory() { //3 551 CodeableConcept t = new CodeableConcept(); 552 if (this.category == null) 553 this.category = new ArrayList<CodeableConcept>(); 554 this.category.add(t); 555 return t; 556 } 557 558 // syntactic sugar 559 public Substance addCategory(CodeableConcept t) { //3 560 if (t == null) 561 return this; 562 if (this.category == null) 563 this.category = new ArrayList<CodeableConcept>(); 564 this.category.add(t); 565 return this; 566 } 567 568 /** 569 * @return {@link #code} (A code (or set of codes) that identify this substance.) 570 */ 571 public CodeableConcept getCode() { 572 if (this.code == null) 573 if (Configuration.errorOnAutoCreate()) 574 throw new Error("Attempt to auto-create Substance.code"); 575 else if (Configuration.doAutoCreate()) 576 this.code = new CodeableConcept(); // cc 577 return this.code; 578 } 579 580 public boolean hasCode() { 581 return this.code != null && !this.code.isEmpty(); 582 } 583 584 /** 585 * @param value {@link #code} (A code (or set of codes) that identify this substance.) 586 */ 587 public Substance setCode(CodeableConcept value) { 588 this.code = value; 589 return this; 590 } 591 592 /** 593 * @return {@link #description} (A description of the substance - its appearance, handling requirements, and other usage notes.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value 594 */ 595 public StringType getDescriptionElement() { 596 if (this.description == null) 597 if (Configuration.errorOnAutoCreate()) 598 throw new Error("Attempt to auto-create Substance.description"); 599 else if (Configuration.doAutoCreate()) 600 this.description = new StringType(); // bb 601 return this.description; 602 } 603 604 public boolean hasDescriptionElement() { 605 return this.description != null && !this.description.isEmpty(); 606 } 607 608 public boolean hasDescription() { 609 return this.description != null && !this.description.isEmpty(); 610 } 611 612 /** 613 * @param value {@link #description} (A description of the substance - its appearance, handling requirements, and other usage notes.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value 614 */ 615 public Substance setDescriptionElement(StringType value) { 616 this.description = value; 617 return this; 618 } 619 620 /** 621 * @return A description of the substance - its appearance, handling requirements, and other usage notes. 622 */ 623 public String getDescription() { 624 return this.description == null ? null : this.description.getValue(); 625 } 626 627 /** 628 * @param value A description of the substance - its appearance, handling requirements, and other usage notes. 629 */ 630 public Substance setDescription(String value) { 631 if (Utilities.noString(value)) 632 this.description = null; 633 else { 634 if (this.description == null) 635 this.description = new StringType(); 636 this.description.setValue(value); 637 } 638 return this; 639 } 640 641 /** 642 * @return {@link #instance} (Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.) 643 */ 644 public List<SubstanceInstanceComponent> getInstance() { 645 if (this.instance == null) 646 this.instance = new ArrayList<SubstanceInstanceComponent>(); 647 return this.instance; 648 } 649 650 public boolean hasInstance() { 651 if (this.instance == null) 652 return false; 653 for (SubstanceInstanceComponent item : this.instance) 654 if (!item.isEmpty()) 655 return true; 656 return false; 657 } 658 659 /** 660 * @return {@link #instance} (Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.) 661 */ 662 // syntactic sugar 663 public SubstanceInstanceComponent addInstance() { //3 664 SubstanceInstanceComponent t = new SubstanceInstanceComponent(); 665 if (this.instance == null) 666 this.instance = new ArrayList<SubstanceInstanceComponent>(); 667 this.instance.add(t); 668 return t; 669 } 670 671 // syntactic sugar 672 public Substance addInstance(SubstanceInstanceComponent t) { //3 673 if (t == null) 674 return this; 675 if (this.instance == null) 676 this.instance = new ArrayList<SubstanceInstanceComponent>(); 677 this.instance.add(t); 678 return this; 679 } 680 681 /** 682 * @return {@link #ingredient} (A substance can be composed of other substances.) 683 */ 684 public List<SubstanceIngredientComponent> getIngredient() { 685 if (this.ingredient == null) 686 this.ingredient = new ArrayList<SubstanceIngredientComponent>(); 687 return this.ingredient; 688 } 689 690 public boolean hasIngredient() { 691 if (this.ingredient == null) 692 return false; 693 for (SubstanceIngredientComponent item : this.ingredient) 694 if (!item.isEmpty()) 695 return true; 696 return false; 697 } 698 699 /** 700 * @return {@link #ingredient} (A substance can be composed of other substances.) 701 */ 702 // syntactic sugar 703 public SubstanceIngredientComponent addIngredient() { //3 704 SubstanceIngredientComponent t = new SubstanceIngredientComponent(); 705 if (this.ingredient == null) 706 this.ingredient = new ArrayList<SubstanceIngredientComponent>(); 707 this.ingredient.add(t); 708 return t; 709 } 710 711 // syntactic sugar 712 public Substance addIngredient(SubstanceIngredientComponent t) { //3 713 if (t == null) 714 return this; 715 if (this.ingredient == null) 716 this.ingredient = new ArrayList<SubstanceIngredientComponent>(); 717 this.ingredient.add(t); 718 return this; 719 } 720 721 protected void listChildren(List<Property> childrenList) { 722 super.listChildren(childrenList); 723 childrenList.add(new Property("identifier", "Identifier", "Unique identifier for the substance.", 0, java.lang.Integer.MAX_VALUE, identifier)); 724 childrenList.add(new Property("category", "CodeableConcept", "A code that classifies the general type of substance. This is used for searching, sorting and display purposes.", 0, java.lang.Integer.MAX_VALUE, category)); 725 childrenList.add(new Property("code", "CodeableConcept", "A code (or set of codes) that identify this substance.", 0, java.lang.Integer.MAX_VALUE, code)); 726 childrenList.add(new Property("description", "string", "A description of the substance - its appearance, handling requirements, and other usage notes.", 0, java.lang.Integer.MAX_VALUE, description)); 727 childrenList.add(new Property("instance", "", "Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.", 0, java.lang.Integer.MAX_VALUE, instance)); 728 childrenList.add(new Property("ingredient", "", "A substance can be composed of other substances.", 0, java.lang.Integer.MAX_VALUE, ingredient)); 729 } 730 731 @Override 732 public void setProperty(String name, Base value) throws FHIRException { 733 if (name.equals("identifier")) 734 this.getIdentifier().add(castToIdentifier(value)); 735 else if (name.equals("category")) 736 this.getCategory().add(castToCodeableConcept(value)); 737 else if (name.equals("code")) 738 this.code = castToCodeableConcept(value); // CodeableConcept 739 else if (name.equals("description")) 740 this.description = castToString(value); // StringType 741 else if (name.equals("instance")) 742 this.getInstance().add((SubstanceInstanceComponent) value); 743 else if (name.equals("ingredient")) 744 this.getIngredient().add((SubstanceIngredientComponent) value); 745 else 746 super.setProperty(name, value); 747 } 748 749 @Override 750 public Base addChild(String name) throws FHIRException { 751 if (name.equals("identifier")) { 752 return addIdentifier(); 753 } 754 else if (name.equals("category")) { 755 return addCategory(); 756 } 757 else if (name.equals("code")) { 758 this.code = new CodeableConcept(); 759 return this.code; 760 } 761 else if (name.equals("description")) { 762 throw new FHIRException("Cannot call addChild on a primitive type Substance.description"); 763 } 764 else if (name.equals("instance")) { 765 return addInstance(); 766 } 767 else if (name.equals("ingredient")) { 768 return addIngredient(); 769 } 770 else 771 return super.addChild(name); 772 } 773 774 public String fhirType() { 775 return "Substance"; 776 777 } 778 779 public Substance copy() { 780 Substance dst = new Substance(); 781 copyValues(dst); 782 if (identifier != null) { 783 dst.identifier = new ArrayList<Identifier>(); 784 for (Identifier i : identifier) 785 dst.identifier.add(i.copy()); 786 }; 787 if (category != null) { 788 dst.category = new ArrayList<CodeableConcept>(); 789 for (CodeableConcept i : category) 790 dst.category.add(i.copy()); 791 }; 792 dst.code = code == null ? null : code.copy(); 793 dst.description = description == null ? null : description.copy(); 794 if (instance != null) { 795 dst.instance = new ArrayList<SubstanceInstanceComponent>(); 796 for (SubstanceInstanceComponent i : instance) 797 dst.instance.add(i.copy()); 798 }; 799 if (ingredient != null) { 800 dst.ingredient = new ArrayList<SubstanceIngredientComponent>(); 801 for (SubstanceIngredientComponent i : ingredient) 802 dst.ingredient.add(i.copy()); 803 }; 804 return dst; 805 } 806 807 protected Substance typedCopy() { 808 return copy(); 809 } 810 811 @Override 812 public boolean equalsDeep(Base other) { 813 if (!super.equalsDeep(other)) 814 return false; 815 if (!(other instanceof Substance)) 816 return false; 817 Substance o = (Substance) other; 818 return compareDeep(identifier, o.identifier, true) && compareDeep(category, o.category, true) && compareDeep(code, o.code, true) 819 && compareDeep(description, o.description, true) && compareDeep(instance, o.instance, true) && compareDeep(ingredient, o.ingredient, true) 820 ; 821 } 822 823 @Override 824 public boolean equalsShallow(Base other) { 825 if (!super.equalsShallow(other)) 826 return false; 827 if (!(other instanceof Substance)) 828 return false; 829 Substance o = (Substance) other; 830 return compareValues(description, o.description, true); 831 } 832 833 public boolean isEmpty() { 834 return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (category == null || category.isEmpty()) 835 && (code == null || code.isEmpty()) && (description == null || description.isEmpty()) && (instance == null || instance.isEmpty()) 836 && (ingredient == null || ingredient.isEmpty()); 837 } 838 839 @Override 840 public ResourceType getResourceType() { 841 return ResourceType.Substance; 842 } 843 844 @SearchParamDefinition(name="identifier", path="Substance.identifier", description="Unique identifier for the substance", type="token" ) 845 public static final String SP_IDENTIFIER = "identifier"; 846 @SearchParamDefinition(name="container-identifier", path="Substance.instance.identifier", description="Identifier of the package/container", type="token" ) 847 public static final String SP_CONTAINERIDENTIFIER = "container-identifier"; 848 @SearchParamDefinition(name="code", path="Substance.code", description="The code of the substance", type="token" ) 849 public static final String SP_CODE = "code"; 850 @SearchParamDefinition(name="quantity", path="Substance.instance.quantity", description="Amount of substance in the package", type="quantity" ) 851 public static final String SP_QUANTITY = "quantity"; 852 @SearchParamDefinition(name="substance", path="Substance.ingredient.substance", description="A component of the substance", type="reference" ) 853 public static final String SP_SUBSTANCE = "substance"; 854 @SearchParamDefinition(name="expiry", path="Substance.instance.expiry", description="Expiry date of package or container of substance", type="date" ) 855 public static final String SP_EXPIRY = "expiry"; 856 @SearchParamDefinition(name="category", path="Substance.category", description="The category of the substance", type="token" ) 857 public static final String SP_CATEGORY = "category"; 858 859} 860