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