001package org.hl7.fhir.dstu2016may.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 Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037import org.hl7.fhir.exceptions.FHIRException;
038import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
039import org.hl7.fhir.utilities.Utilities;
040
041import ca.uhn.fhir.model.api.annotation.Block;
042import ca.uhn.fhir.model.api.annotation.Child;
043import ca.uhn.fhir.model.api.annotation.Description;
044import ca.uhn.fhir.model.api.annotation.ResourceDef;
045import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
046/**
047 * A homogeneous material with a definite composition.
048 */
049@ResourceDef(name="Substance", profile="http://hl7.org/fhir/Profile/Substance")
050public class Substance extends DomainResource {
051
052    @Block()
053    public static class SubstanceInstanceComponent extends BackboneElement implements IBaseBackboneElement {
054        /**
055         * Identifier associated with the package/container (usually a label affixed directly).
056         */
057        @Child(name = "identifier", type = {Identifier.class}, order=1, min=0, max=1, modifier=false, summary=true)
058        @Description(shortDefinition="Identifier of the package/container", formalDefinition="Identifier associated with the package/container (usually a label affixed directly)." )
059        protected Identifier identifier;
060
061        /**
062         * When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.
063         */
064        @Child(name = "expiry", type = {DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
065        @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." )
066        protected DateTimeType expiry;
067
068        /**
069         * The amount of the substance.
070         */
071        @Child(name = "quantity", type = {SimpleQuantity.class}, order=3, min=0, max=1, modifier=false, summary=true)
072        @Description(shortDefinition="Amount of substance in the package", formalDefinition="The amount of the substance." )
073        protected SimpleQuantity quantity;
074
075        private static final long serialVersionUID = -794314734L;
076
077    /**
078     * Constructor
079     */
080      public SubstanceInstanceComponent() {
081        super();
082      }
083
084        /**
085         * @return {@link #identifier} (Identifier associated with the package/container (usually a label affixed directly).)
086         */
087        public Identifier getIdentifier() { 
088          if (this.identifier == null)
089            if (Configuration.errorOnAutoCreate())
090              throw new Error("Attempt to auto-create SubstanceInstanceComponent.identifier");
091            else if (Configuration.doAutoCreate())
092              this.identifier = new Identifier(); // cc
093          return this.identifier;
094        }
095
096        public boolean hasIdentifier() { 
097          return this.identifier != null && !this.identifier.isEmpty();
098        }
099
100        /**
101         * @param value {@link #identifier} (Identifier associated with the package/container (usually a label affixed directly).)
102         */
103        public SubstanceInstanceComponent setIdentifier(Identifier value) { 
104          this.identifier = value;
105          return this;
106        }
107
108        /**
109         * @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
110         */
111        public DateTimeType getExpiryElement() { 
112          if (this.expiry == null)
113            if (Configuration.errorOnAutoCreate())
114              throw new Error("Attempt to auto-create SubstanceInstanceComponent.expiry");
115            else if (Configuration.doAutoCreate())
116              this.expiry = new DateTimeType(); // bb
117          return this.expiry;
118        }
119
120        public boolean hasExpiryElement() { 
121          return this.expiry != null && !this.expiry.isEmpty();
122        }
123
124        public boolean hasExpiry() { 
125          return this.expiry != null && !this.expiry.isEmpty();
126        }
127
128        /**
129         * @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
130         */
131        public SubstanceInstanceComponent setExpiryElement(DateTimeType value) { 
132          this.expiry = value;
133          return this;
134        }
135
136        /**
137         * @return When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.
138         */
139        public Date getExpiry() { 
140          return this.expiry == null ? null : this.expiry.getValue();
141        }
142
143        /**
144         * @param value When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.
145         */
146        public SubstanceInstanceComponent setExpiry(Date value) { 
147          if (value == null)
148            this.expiry = null;
149          else {
150            if (this.expiry == null)
151              this.expiry = new DateTimeType();
152            this.expiry.setValue(value);
153          }
154          return this;
155        }
156
157        /**
158         * @return {@link #quantity} (The amount of the substance.)
159         */
160        public SimpleQuantity getQuantity() { 
161          if (this.quantity == null)
162            if (Configuration.errorOnAutoCreate())
163              throw new Error("Attempt to auto-create SubstanceInstanceComponent.quantity");
164            else if (Configuration.doAutoCreate())
165              this.quantity = new SimpleQuantity(); // cc
166          return this.quantity;
167        }
168
169        public boolean hasQuantity() { 
170          return this.quantity != null && !this.quantity.isEmpty();
171        }
172
173        /**
174         * @param value {@link #quantity} (The amount of the substance.)
175         */
176        public SubstanceInstanceComponent setQuantity(SimpleQuantity value) { 
177          this.quantity = value;
178          return this;
179        }
180
181        protected void listChildren(List<Property> childrenList) {
182          super.listChildren(childrenList);
183          childrenList.add(new Property("identifier", "Identifier", "Identifier associated with the package/container (usually a label affixed directly).", 0, java.lang.Integer.MAX_VALUE, identifier));
184          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));
185          childrenList.add(new Property("quantity", "SimpleQuantity", "The amount of the substance.", 0, java.lang.Integer.MAX_VALUE, quantity));
186        }
187
188      @Override
189      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
190        switch (hash) {
191        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier
192        case -1289159373: /*expiry*/ return this.expiry == null ? new Base[0] : new Base[] {this.expiry}; // DateTimeType
193        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // SimpleQuantity
194        default: return super.getProperty(hash, name, checkValid);
195        }
196
197      }
198
199      @Override
200      public void setProperty(int hash, String name, Base value) throws FHIRException {
201        switch (hash) {
202        case -1618432855: // identifier
203          this.identifier = castToIdentifier(value); // Identifier
204          break;
205        case -1289159373: // expiry
206          this.expiry = castToDateTime(value); // DateTimeType
207          break;
208        case -1285004149: // quantity
209          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
210          break;
211        default: super.setProperty(hash, name, value);
212        }
213
214      }
215
216      @Override
217      public void setProperty(String name, Base value) throws FHIRException {
218        if (name.equals("identifier"))
219          this.identifier = castToIdentifier(value); // Identifier
220        else if (name.equals("expiry"))
221          this.expiry = castToDateTime(value); // DateTimeType
222        else if (name.equals("quantity"))
223          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
224        else
225          super.setProperty(name, value);
226      }
227
228      @Override
229      public Base makeProperty(int hash, String name) throws FHIRException {
230        switch (hash) {
231        case -1618432855:  return getIdentifier(); // Identifier
232        case -1289159373: throw new FHIRException("Cannot make property expiry as it is not a complex type"); // DateTimeType
233        case -1285004149:  return getQuantity(); // SimpleQuantity
234        default: return super.makeProperty(hash, name);
235        }
236
237      }
238
239      @Override
240      public Base addChild(String name) throws FHIRException {
241        if (name.equals("identifier")) {
242          this.identifier = new Identifier();
243          return this.identifier;
244        }
245        else if (name.equals("expiry")) {
246          throw new FHIRException("Cannot call addChild on a primitive type Substance.expiry");
247        }
248        else if (name.equals("quantity")) {
249          this.quantity = new SimpleQuantity();
250          return this.quantity;
251        }
252        else
253          return super.addChild(name);
254      }
255
256      public SubstanceInstanceComponent copy() {
257        SubstanceInstanceComponent dst = new SubstanceInstanceComponent();
258        copyValues(dst);
259        dst.identifier = identifier == null ? null : identifier.copy();
260        dst.expiry = expiry == null ? null : expiry.copy();
261        dst.quantity = quantity == null ? null : quantity.copy();
262        return dst;
263      }
264
265      @Override
266      public boolean equalsDeep(Base other) {
267        if (!super.equalsDeep(other))
268          return false;
269        if (!(other instanceof SubstanceInstanceComponent))
270          return false;
271        SubstanceInstanceComponent o = (SubstanceInstanceComponent) other;
272        return compareDeep(identifier, o.identifier, true) && compareDeep(expiry, o.expiry, true) && compareDeep(quantity, o.quantity, true)
273          ;
274      }
275
276      @Override
277      public boolean equalsShallow(Base other) {
278        if (!super.equalsShallow(other))
279          return false;
280        if (!(other instanceof SubstanceInstanceComponent))
281          return false;
282        SubstanceInstanceComponent o = (SubstanceInstanceComponent) other;
283        return compareValues(expiry, o.expiry, true);
284      }
285
286      public boolean isEmpty() {
287        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (expiry == null || expiry.isEmpty())
288           && (quantity == null || quantity.isEmpty());
289      }
290
291  public String fhirType() {
292    return "Substance.instance";
293
294  }
295
296  }
297
298    @Block()
299    public static class SubstanceIngredientComponent extends BackboneElement implements IBaseBackboneElement {
300        /**
301         * The amount of the ingredient in the substance - a concentration ratio.
302         */
303        @Child(name = "quantity", type = {Ratio.class}, order=1, min=0, max=1, modifier=false, summary=true)
304        @Description(shortDefinition="Optional amount (concentration)", formalDefinition="The amount of the ingredient in the substance - a concentration ratio." )
305        protected Ratio quantity;
306
307        /**
308         * Another substance that is a component of this substance.
309         */
310        @Child(name = "substance", type = {Substance.class}, order=2, min=1, max=1, modifier=false, summary=true)
311        @Description(shortDefinition="A component of the substance", formalDefinition="Another substance that is a component of this substance." )
312        protected Reference substance;
313
314        /**
315         * The actual object that is the target of the reference (Another substance that is a component of this substance.)
316         */
317        protected Substance substanceTarget;
318
319        private static final long serialVersionUID = -1783242034L;
320
321    /**
322     * Constructor
323     */
324      public SubstanceIngredientComponent() {
325        super();
326      }
327
328    /**
329     * Constructor
330     */
331      public SubstanceIngredientComponent(Reference substance) {
332        super();
333        this.substance = substance;
334      }
335
336        /**
337         * @return {@link #quantity} (The amount of the ingredient in the substance - a concentration ratio.)
338         */
339        public Ratio getQuantity() { 
340          if (this.quantity == null)
341            if (Configuration.errorOnAutoCreate())
342              throw new Error("Attempt to auto-create SubstanceIngredientComponent.quantity");
343            else if (Configuration.doAutoCreate())
344              this.quantity = new Ratio(); // cc
345          return this.quantity;
346        }
347
348        public boolean hasQuantity() { 
349          return this.quantity != null && !this.quantity.isEmpty();
350        }
351
352        /**
353         * @param value {@link #quantity} (The amount of the ingredient in the substance - a concentration ratio.)
354         */
355        public SubstanceIngredientComponent setQuantity(Ratio value) { 
356          this.quantity = value;
357          return this;
358        }
359
360        /**
361         * @return {@link #substance} (Another substance that is a component of this substance.)
362         */
363        public Reference getSubstance() { 
364          if (this.substance == null)
365            if (Configuration.errorOnAutoCreate())
366              throw new Error("Attempt to auto-create SubstanceIngredientComponent.substance");
367            else if (Configuration.doAutoCreate())
368              this.substance = new Reference(); // cc
369          return this.substance;
370        }
371
372        public boolean hasSubstance() { 
373          return this.substance != null && !this.substance.isEmpty();
374        }
375
376        /**
377         * @param value {@link #substance} (Another substance that is a component of this substance.)
378         */
379        public SubstanceIngredientComponent setSubstance(Reference value) { 
380          this.substance = value;
381          return this;
382        }
383
384        /**
385         * @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.)
386         */
387        public Substance getSubstanceTarget() { 
388          if (this.substanceTarget == null)
389            if (Configuration.errorOnAutoCreate())
390              throw new Error("Attempt to auto-create SubstanceIngredientComponent.substance");
391            else if (Configuration.doAutoCreate())
392              this.substanceTarget = new Substance(); // aa
393          return this.substanceTarget;
394        }
395
396        /**
397         * @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.)
398         */
399        public SubstanceIngredientComponent setSubstanceTarget(Substance value) { 
400          this.substanceTarget = value;
401          return this;
402        }
403
404        protected void listChildren(List<Property> childrenList) {
405          super.listChildren(childrenList);
406          childrenList.add(new Property("quantity", "Ratio", "The amount of the ingredient in the substance - a concentration ratio.", 0, java.lang.Integer.MAX_VALUE, quantity));
407          childrenList.add(new Property("substance", "Reference(Substance)", "Another substance that is a component of this substance.", 0, java.lang.Integer.MAX_VALUE, substance));
408        }
409
410      @Override
411      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
412        switch (hash) {
413        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // Ratio
414        case 530040176: /*substance*/ return this.substance == null ? new Base[0] : new Base[] {this.substance}; // Reference
415        default: return super.getProperty(hash, name, checkValid);
416        }
417
418      }
419
420      @Override
421      public void setProperty(int hash, String name, Base value) throws FHIRException {
422        switch (hash) {
423        case -1285004149: // quantity
424          this.quantity = castToRatio(value); // Ratio
425          break;
426        case 530040176: // substance
427          this.substance = castToReference(value); // Reference
428          break;
429        default: super.setProperty(hash, name, value);
430        }
431
432      }
433
434      @Override
435      public void setProperty(String name, Base value) throws FHIRException {
436        if (name.equals("quantity"))
437          this.quantity = castToRatio(value); // Ratio
438        else if (name.equals("substance"))
439          this.substance = castToReference(value); // Reference
440        else
441          super.setProperty(name, value);
442      }
443
444      @Override
445      public Base makeProperty(int hash, String name) throws FHIRException {
446        switch (hash) {
447        case -1285004149:  return getQuantity(); // Ratio
448        case 530040176:  return getSubstance(); // Reference
449        default: return super.makeProperty(hash, name);
450        }
451
452      }
453
454      @Override
455      public Base addChild(String name) throws FHIRException {
456        if (name.equals("quantity")) {
457          this.quantity = new Ratio();
458          return this.quantity;
459        }
460        else if (name.equals("substance")) {
461          this.substance = new Reference();
462          return this.substance;
463        }
464        else
465          return super.addChild(name);
466      }
467
468      public SubstanceIngredientComponent copy() {
469        SubstanceIngredientComponent dst = new SubstanceIngredientComponent();
470        copyValues(dst);
471        dst.quantity = quantity == null ? null : quantity.copy();
472        dst.substance = substance == null ? null : substance.copy();
473        return dst;
474      }
475
476      @Override
477      public boolean equalsDeep(Base other) {
478        if (!super.equalsDeep(other))
479          return false;
480        if (!(other instanceof SubstanceIngredientComponent))
481          return false;
482        SubstanceIngredientComponent o = (SubstanceIngredientComponent) other;
483        return compareDeep(quantity, o.quantity, true) && compareDeep(substance, o.substance, true);
484      }
485
486      @Override
487      public boolean equalsShallow(Base other) {
488        if (!super.equalsShallow(other))
489          return false;
490        if (!(other instanceof SubstanceIngredientComponent))
491          return false;
492        SubstanceIngredientComponent o = (SubstanceIngredientComponent) other;
493        return true;
494      }
495
496      public boolean isEmpty() {
497        return super.isEmpty() && (quantity == null || quantity.isEmpty()) && (substance == null || substance.isEmpty())
498          ;
499      }
500
501  public String fhirType() {
502    return "Substance.ingredient";
503
504  }
505
506  }
507
508    /**
509     * Unique identifier for the substance.
510     */
511    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
512    @Description(shortDefinition="Unique identifier", formalDefinition="Unique identifier for the substance." )
513    protected List<Identifier> identifier;
514
515    /**
516     * A code that classifies the general type of substance.  This is used  for searching, sorting and display purposes.
517     */
518    @Child(name = "category", type = {CodeableConcept.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
519    @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." )
520    protected List<CodeableConcept> category;
521
522    /**
523     * A code (or set of codes) that identify this substance.
524     */
525    @Child(name = "code", type = {CodeableConcept.class}, order=2, min=1, max=1, modifier=false, summary=true)
526    @Description(shortDefinition="What substance this is", formalDefinition="A code (or set of codes) that identify this substance." )
527    protected CodeableConcept code;
528
529    /**
530     * A description of the substance - its appearance, handling requirements, and other usage notes.
531     */
532    @Child(name = "description", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
533    @Description(shortDefinition="Textual description of the substance, comments", formalDefinition="A description of the substance - its appearance, handling requirements, and other usage notes." )
534    protected StringType description;
535
536    /**
537     * Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.
538     */
539    @Child(name = "instance", type = {}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
540    @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." )
541    protected List<SubstanceInstanceComponent> instance;
542
543    /**
544     * A substance can be composed of other substances.
545     */
546    @Child(name = "ingredient", type = {}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
547    @Description(shortDefinition="Composition information about the substance", formalDefinition="A substance can be composed of other substances." )
548    protected List<SubstanceIngredientComponent> ingredient;
549
550    private static final long serialVersionUID = -1653977206L;
551
552  /**
553   * Constructor
554   */
555    public Substance() {
556      super();
557    }
558
559  /**
560   * Constructor
561   */
562    public Substance(CodeableConcept code) {
563      super();
564      this.code = code;
565    }
566
567    /**
568     * @return {@link #identifier} (Unique identifier for the substance.)
569     */
570    public List<Identifier> getIdentifier() { 
571      if (this.identifier == null)
572        this.identifier = new ArrayList<Identifier>();
573      return this.identifier;
574    }
575
576    public boolean hasIdentifier() { 
577      if (this.identifier == null)
578        return false;
579      for (Identifier item : this.identifier)
580        if (!item.isEmpty())
581          return true;
582      return false;
583    }
584
585    /**
586     * @return {@link #identifier} (Unique identifier for the substance.)
587     */
588    // syntactic sugar
589    public Identifier addIdentifier() { //3
590      Identifier t = new Identifier();
591      if (this.identifier == null)
592        this.identifier = new ArrayList<Identifier>();
593      this.identifier.add(t);
594      return t;
595    }
596
597    // syntactic sugar
598    public Substance addIdentifier(Identifier t) { //3
599      if (t == null)
600        return this;
601      if (this.identifier == null)
602        this.identifier = new ArrayList<Identifier>();
603      this.identifier.add(t);
604      return this;
605    }
606
607    /**
608     * @return {@link #category} (A code that classifies the general type of substance.  This is used  for searching, sorting and display purposes.)
609     */
610    public List<CodeableConcept> getCategory() { 
611      if (this.category == null)
612        this.category = new ArrayList<CodeableConcept>();
613      return this.category;
614    }
615
616    public boolean hasCategory() { 
617      if (this.category == null)
618        return false;
619      for (CodeableConcept item : this.category)
620        if (!item.isEmpty())
621          return true;
622      return false;
623    }
624
625    /**
626     * @return {@link #category} (A code that classifies the general type of substance.  This is used  for searching, sorting and display purposes.)
627     */
628    // syntactic sugar
629    public CodeableConcept addCategory() { //3
630      CodeableConcept t = new CodeableConcept();
631      if (this.category == null)
632        this.category = new ArrayList<CodeableConcept>();
633      this.category.add(t);
634      return t;
635    }
636
637    // syntactic sugar
638    public Substance addCategory(CodeableConcept t) { //3
639      if (t == null)
640        return this;
641      if (this.category == null)
642        this.category = new ArrayList<CodeableConcept>();
643      this.category.add(t);
644      return this;
645    }
646
647    /**
648     * @return {@link #code} (A code (or set of codes) that identify this substance.)
649     */
650    public CodeableConcept getCode() { 
651      if (this.code == null)
652        if (Configuration.errorOnAutoCreate())
653          throw new Error("Attempt to auto-create Substance.code");
654        else if (Configuration.doAutoCreate())
655          this.code = new CodeableConcept(); // cc
656      return this.code;
657    }
658
659    public boolean hasCode() { 
660      return this.code != null && !this.code.isEmpty();
661    }
662
663    /**
664     * @param value {@link #code} (A code (or set of codes) that identify this substance.)
665     */
666    public Substance setCode(CodeableConcept value) { 
667      this.code = value;
668      return this;
669    }
670
671    /**
672     * @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
673     */
674    public StringType getDescriptionElement() { 
675      if (this.description == null)
676        if (Configuration.errorOnAutoCreate())
677          throw new Error("Attempt to auto-create Substance.description");
678        else if (Configuration.doAutoCreate())
679          this.description = new StringType(); // bb
680      return this.description;
681    }
682
683    public boolean hasDescriptionElement() { 
684      return this.description != null && !this.description.isEmpty();
685    }
686
687    public boolean hasDescription() { 
688      return this.description != null && !this.description.isEmpty();
689    }
690
691    /**
692     * @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
693     */
694    public Substance setDescriptionElement(StringType value) { 
695      this.description = value;
696      return this;
697    }
698
699    /**
700     * @return A description of the substance - its appearance, handling requirements, and other usage notes.
701     */
702    public String getDescription() { 
703      return this.description == null ? null : this.description.getValue();
704    }
705
706    /**
707     * @param value A description of the substance - its appearance, handling requirements, and other usage notes.
708     */
709    public Substance setDescription(String value) { 
710      if (Utilities.noString(value))
711        this.description = null;
712      else {
713        if (this.description == null)
714          this.description = new StringType();
715        this.description.setValue(value);
716      }
717      return this;
718    }
719
720    /**
721     * @return {@link #instance} (Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.)
722     */
723    public List<SubstanceInstanceComponent> getInstance() { 
724      if (this.instance == null)
725        this.instance = new ArrayList<SubstanceInstanceComponent>();
726      return this.instance;
727    }
728
729    public boolean hasInstance() { 
730      if (this.instance == null)
731        return false;
732      for (SubstanceInstanceComponent item : this.instance)
733        if (!item.isEmpty())
734          return true;
735      return false;
736    }
737
738    /**
739     * @return {@link #instance} (Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.)
740     */
741    // syntactic sugar
742    public SubstanceInstanceComponent addInstance() { //3
743      SubstanceInstanceComponent t = new SubstanceInstanceComponent();
744      if (this.instance == null)
745        this.instance = new ArrayList<SubstanceInstanceComponent>();
746      this.instance.add(t);
747      return t;
748    }
749
750    // syntactic sugar
751    public Substance addInstance(SubstanceInstanceComponent t) { //3
752      if (t == null)
753        return this;
754      if (this.instance == null)
755        this.instance = new ArrayList<SubstanceInstanceComponent>();
756      this.instance.add(t);
757      return this;
758    }
759
760    /**
761     * @return {@link #ingredient} (A substance can be composed of other substances.)
762     */
763    public List<SubstanceIngredientComponent> getIngredient() { 
764      if (this.ingredient == null)
765        this.ingredient = new ArrayList<SubstanceIngredientComponent>();
766      return this.ingredient;
767    }
768
769    public boolean hasIngredient() { 
770      if (this.ingredient == null)
771        return false;
772      for (SubstanceIngredientComponent item : this.ingredient)
773        if (!item.isEmpty())
774          return true;
775      return false;
776    }
777
778    /**
779     * @return {@link #ingredient} (A substance can be composed of other substances.)
780     */
781    // syntactic sugar
782    public SubstanceIngredientComponent addIngredient() { //3
783      SubstanceIngredientComponent t = new SubstanceIngredientComponent();
784      if (this.ingredient == null)
785        this.ingredient = new ArrayList<SubstanceIngredientComponent>();
786      this.ingredient.add(t);
787      return t;
788    }
789
790    // syntactic sugar
791    public Substance addIngredient(SubstanceIngredientComponent t) { //3
792      if (t == null)
793        return this;
794      if (this.ingredient == null)
795        this.ingredient = new ArrayList<SubstanceIngredientComponent>();
796      this.ingredient.add(t);
797      return this;
798    }
799
800      protected void listChildren(List<Property> childrenList) {
801        super.listChildren(childrenList);
802        childrenList.add(new Property("identifier", "Identifier", "Unique identifier for the substance.", 0, java.lang.Integer.MAX_VALUE, identifier));
803        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));
804        childrenList.add(new Property("code", "CodeableConcept", "A code (or set of codes) that identify this substance.", 0, java.lang.Integer.MAX_VALUE, code));
805        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));
806        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));
807        childrenList.add(new Property("ingredient", "", "A substance can be composed of other substances.", 0, java.lang.Integer.MAX_VALUE, ingredient));
808      }
809
810      @Override
811      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
812        switch (hash) {
813        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
814        case 50511102: /*category*/ return this.category == null ? new Base[0] : this.category.toArray(new Base[this.category.size()]); // CodeableConcept
815        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeableConcept
816        case -1724546052: /*description*/ return this.description == null ? new Base[0] : new Base[] {this.description}; // StringType
817        case 555127957: /*instance*/ return this.instance == null ? new Base[0] : this.instance.toArray(new Base[this.instance.size()]); // SubstanceInstanceComponent
818        case -206409263: /*ingredient*/ return this.ingredient == null ? new Base[0] : this.ingredient.toArray(new Base[this.ingredient.size()]); // SubstanceIngredientComponent
819        default: return super.getProperty(hash, name, checkValid);
820        }
821
822      }
823
824      @Override
825      public void setProperty(int hash, String name, Base value) throws FHIRException {
826        switch (hash) {
827        case -1618432855: // identifier
828          this.getIdentifier().add(castToIdentifier(value)); // Identifier
829          break;
830        case 50511102: // category
831          this.getCategory().add(castToCodeableConcept(value)); // CodeableConcept
832          break;
833        case 3059181: // code
834          this.code = castToCodeableConcept(value); // CodeableConcept
835          break;
836        case -1724546052: // description
837          this.description = castToString(value); // StringType
838          break;
839        case 555127957: // instance
840          this.getInstance().add((SubstanceInstanceComponent) value); // SubstanceInstanceComponent
841          break;
842        case -206409263: // ingredient
843          this.getIngredient().add((SubstanceIngredientComponent) value); // SubstanceIngredientComponent
844          break;
845        default: super.setProperty(hash, name, value);
846        }
847
848      }
849
850      @Override
851      public void setProperty(String name, Base value) throws FHIRException {
852        if (name.equals("identifier"))
853          this.getIdentifier().add(castToIdentifier(value));
854        else if (name.equals("category"))
855          this.getCategory().add(castToCodeableConcept(value));
856        else if (name.equals("code"))
857          this.code = castToCodeableConcept(value); // CodeableConcept
858        else if (name.equals("description"))
859          this.description = castToString(value); // StringType
860        else if (name.equals("instance"))
861          this.getInstance().add((SubstanceInstanceComponent) value);
862        else if (name.equals("ingredient"))
863          this.getIngredient().add((SubstanceIngredientComponent) value);
864        else
865          super.setProperty(name, value);
866      }
867
868      @Override
869      public Base makeProperty(int hash, String name) throws FHIRException {
870        switch (hash) {
871        case -1618432855:  return addIdentifier(); // Identifier
872        case 50511102:  return addCategory(); // CodeableConcept
873        case 3059181:  return getCode(); // CodeableConcept
874        case -1724546052: throw new FHIRException("Cannot make property description as it is not a complex type"); // StringType
875        case 555127957:  return addInstance(); // SubstanceInstanceComponent
876        case -206409263:  return addIngredient(); // SubstanceIngredientComponent
877        default: return super.makeProperty(hash, name);
878        }
879
880      }
881
882      @Override
883      public Base addChild(String name) throws FHIRException {
884        if (name.equals("identifier")) {
885          return addIdentifier();
886        }
887        else if (name.equals("category")) {
888          return addCategory();
889        }
890        else if (name.equals("code")) {
891          this.code = new CodeableConcept();
892          return this.code;
893        }
894        else if (name.equals("description")) {
895          throw new FHIRException("Cannot call addChild on a primitive type Substance.description");
896        }
897        else if (name.equals("instance")) {
898          return addInstance();
899        }
900        else if (name.equals("ingredient")) {
901          return addIngredient();
902        }
903        else
904          return super.addChild(name);
905      }
906
907  public String fhirType() {
908    return "Substance";
909
910  }
911
912      public Substance copy() {
913        Substance dst = new Substance();
914        copyValues(dst);
915        if (identifier != null) {
916          dst.identifier = new ArrayList<Identifier>();
917          for (Identifier i : identifier)
918            dst.identifier.add(i.copy());
919        };
920        if (category != null) {
921          dst.category = new ArrayList<CodeableConcept>();
922          for (CodeableConcept i : category)
923            dst.category.add(i.copy());
924        };
925        dst.code = code == null ? null : code.copy();
926        dst.description = description == null ? null : description.copy();
927        if (instance != null) {
928          dst.instance = new ArrayList<SubstanceInstanceComponent>();
929          for (SubstanceInstanceComponent i : instance)
930            dst.instance.add(i.copy());
931        };
932        if (ingredient != null) {
933          dst.ingredient = new ArrayList<SubstanceIngredientComponent>();
934          for (SubstanceIngredientComponent i : ingredient)
935            dst.ingredient.add(i.copy());
936        };
937        return dst;
938      }
939
940      protected Substance typedCopy() {
941        return copy();
942      }
943
944      @Override
945      public boolean equalsDeep(Base other) {
946        if (!super.equalsDeep(other))
947          return false;
948        if (!(other instanceof Substance))
949          return false;
950        Substance o = (Substance) other;
951        return compareDeep(identifier, o.identifier, true) && compareDeep(category, o.category, true) && compareDeep(code, o.code, true)
952           && compareDeep(description, o.description, true) && compareDeep(instance, o.instance, true) && compareDeep(ingredient, o.ingredient, true)
953          ;
954      }
955
956      @Override
957      public boolean equalsShallow(Base other) {
958        if (!super.equalsShallow(other))
959          return false;
960        if (!(other instanceof Substance))
961          return false;
962        Substance o = (Substance) other;
963        return compareValues(description, o.description, true);
964      }
965
966      public boolean isEmpty() {
967        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (category == null || category.isEmpty())
968           && (code == null || code.isEmpty()) && (description == null || description.isEmpty()) && (instance == null || instance.isEmpty())
969           && (ingredient == null || ingredient.isEmpty());
970      }
971
972  @Override
973  public ResourceType getResourceType() {
974    return ResourceType.Substance;
975   }
976
977 /**
978   * Search parameter: <b>substance</b>
979   * <p>
980   * Description: <b>A component of the substance</b><br>
981   * Type: <b>reference</b><br>
982   * Path: <b>Substance.ingredient.substance</b><br>
983   * </p>
984   */
985  @SearchParamDefinition(name="substance", path="Substance.ingredient.substance", description="A component of the substance", type="reference" )
986  public static final String SP_SUBSTANCE = "substance";
987 /**
988   * <b>Fluent Client</b> search parameter constant for <b>substance</b>
989   * <p>
990   * Description: <b>A component of the substance</b><br>
991   * Type: <b>reference</b><br>
992   * Path: <b>Substance.ingredient.substance</b><br>
993   * </p>
994   */
995  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBSTANCE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUBSTANCE);
996
997/**
998   * Constant for fluent queries to be used to add include statements. Specifies
999   * the path value of "<b>Substance:substance</b>".
1000   */
1001  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBSTANCE = new ca.uhn.fhir.model.api.Include("Substance:substance").toLocked();
1002
1003 /**
1004   * Search parameter: <b>container-identifier</b>
1005   * <p>
1006   * Description: <b>Identifier of the package/container</b><br>
1007   * Type: <b>token</b><br>
1008   * Path: <b>Substance.instance.identifier</b><br>
1009   * </p>
1010   */
1011  @SearchParamDefinition(name="container-identifier", path="Substance.instance.identifier", description="Identifier of the package/container", type="token" )
1012  public static final String SP_CONTAINER_IDENTIFIER = "container-identifier";
1013 /**
1014   * <b>Fluent Client</b> search parameter constant for <b>container-identifier</b>
1015   * <p>
1016   * Description: <b>Identifier of the package/container</b><br>
1017   * Type: <b>token</b><br>
1018   * Path: <b>Substance.instance.identifier</b><br>
1019   * </p>
1020   */
1021  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CONTAINER_IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CONTAINER_IDENTIFIER);
1022
1023 /**
1024   * Search parameter: <b>category</b>
1025   * <p>
1026   * Description: <b>The category of the substance</b><br>
1027   * Type: <b>token</b><br>
1028   * Path: <b>Substance.category</b><br>
1029   * </p>
1030   */
1031  @SearchParamDefinition(name="category", path="Substance.category", description="The category of the substance", type="token" )
1032  public static final String SP_CATEGORY = "category";
1033 /**
1034   * <b>Fluent Client</b> search parameter constant for <b>category</b>
1035   * <p>
1036   * Description: <b>The category of the substance</b><br>
1037   * Type: <b>token</b><br>
1038   * Path: <b>Substance.category</b><br>
1039   * </p>
1040   */
1041  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CATEGORY = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CATEGORY);
1042
1043 /**
1044   * Search parameter: <b>quantity</b>
1045   * <p>
1046   * Description: <b>Amount of substance in the package</b><br>
1047   * Type: <b>quantity</b><br>
1048   * Path: <b>Substance.instance.quantity</b><br>
1049   * </p>
1050   */
1051  @SearchParamDefinition(name="quantity", path="Substance.instance.quantity", description="Amount of substance in the package", type="quantity" )
1052  public static final String SP_QUANTITY = "quantity";
1053 /**
1054   * <b>Fluent Client</b> search parameter constant for <b>quantity</b>
1055   * <p>
1056   * Description: <b>Amount of substance in the package</b><br>
1057   * Type: <b>quantity</b><br>
1058   * Path: <b>Substance.instance.quantity</b><br>
1059   * </p>
1060   */
1061  public static final ca.uhn.fhir.rest.gclient.QuantityClientParam QUANTITY = new ca.uhn.fhir.rest.gclient.QuantityClientParam(SP_QUANTITY);
1062
1063 /**
1064   * Search parameter: <b>code</b>
1065   * <p>
1066   * Description: <b>The code of the substance</b><br>
1067   * Type: <b>token</b><br>
1068   * Path: <b>Substance.code</b><br>
1069   * </p>
1070   */
1071  @SearchParamDefinition(name="code", path="Substance.code", description="The code of the substance", type="token" )
1072  public static final String SP_CODE = "code";
1073 /**
1074   * <b>Fluent Client</b> search parameter constant for <b>code</b>
1075   * <p>
1076   * Description: <b>The code of the substance</b><br>
1077   * Type: <b>token</b><br>
1078   * Path: <b>Substance.code</b><br>
1079   * </p>
1080   */
1081  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CODE);
1082
1083 /**
1084   * Search parameter: <b>identifier</b>
1085   * <p>
1086   * Description: <b>Unique identifier for the substance</b><br>
1087   * Type: <b>token</b><br>
1088   * Path: <b>Substance.identifier</b><br>
1089   * </p>
1090   */
1091  @SearchParamDefinition(name="identifier", path="Substance.identifier", description="Unique identifier for the substance", type="token" )
1092  public static final String SP_IDENTIFIER = "identifier";
1093 /**
1094   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1095   * <p>
1096   * Description: <b>Unique identifier for the substance</b><br>
1097   * Type: <b>token</b><br>
1098   * Path: <b>Substance.identifier</b><br>
1099   * </p>
1100   */
1101  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1102
1103 /**
1104   * Search parameter: <b>expiry</b>
1105   * <p>
1106   * Description: <b>Expiry date of package or container of substance</b><br>
1107   * Type: <b>date</b><br>
1108   * Path: <b>Substance.instance.expiry</b><br>
1109   * </p>
1110   */
1111  @SearchParamDefinition(name="expiry", path="Substance.instance.expiry", description="Expiry date of package or container of substance", type="date" )
1112  public static final String SP_EXPIRY = "expiry";
1113 /**
1114   * <b>Fluent Client</b> search parameter constant for <b>expiry</b>
1115   * <p>
1116   * Description: <b>Expiry date of package or container of substance</b><br>
1117   * Type: <b>date</b><br>
1118   * Path: <b>Substance.instance.expiry</b><br>
1119   * </p>
1120   */
1121  public static final ca.uhn.fhir.rest.gclient.DateClientParam EXPIRY = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_EXPIRY);
1122
1123
1124}
1125