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