001package org.hl7.fhir.r4.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 Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
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/**
048 * A homogeneous material with a definite composition.
049 */
050@ResourceDef(name = "Substance", profile = "http://hl7.org/fhir/StructureDefinition/Substance")
051public class Substance extends DomainResource {
052
053  public enum FHIRSubstanceStatus {
054    /**
055     * The substance is considered for use or reference.
056     */
057    ACTIVE,
058    /**
059     * The substance is considered for reference, but not for use.
060     */
061    INACTIVE,
062    /**
063     * The substance was entered in error.
064     */
065    ENTEREDINERROR,
066    /**
067     * added to help the parsers with the generic types
068     */
069    NULL;
070
071    public static FHIRSubstanceStatus fromCode(String codeString) throws FHIRException {
072      if (codeString == null || "".equals(codeString))
073        return null;
074      if ("active".equals(codeString))
075        return ACTIVE;
076      if ("inactive".equals(codeString))
077        return INACTIVE;
078      if ("entered-in-error".equals(codeString))
079        return ENTEREDINERROR;
080      if (Configuration.isAcceptInvalidEnums())
081        return null;
082      else
083        throw new FHIRException("Unknown FHIRSubstanceStatus code '" + codeString + "'");
084    }
085
086    public String toCode() {
087      switch (this) {
088      case ACTIVE:
089        return "active";
090      case INACTIVE:
091        return "inactive";
092      case ENTEREDINERROR:
093        return "entered-in-error";
094      case NULL:
095        return null;
096      default:
097        return "?";
098      }
099    }
100
101    public String getSystem() {
102      switch (this) {
103      case ACTIVE:
104        return "http://hl7.org/fhir/substance-status";
105      case INACTIVE:
106        return "http://hl7.org/fhir/substance-status";
107      case ENTEREDINERROR:
108        return "http://hl7.org/fhir/substance-status";
109      case NULL:
110        return null;
111      default:
112        return "?";
113      }
114    }
115
116    public String getDefinition() {
117      switch (this) {
118      case ACTIVE:
119        return "The substance is considered for use or reference.";
120      case INACTIVE:
121        return "The substance is considered for reference, but not for use.";
122      case ENTEREDINERROR:
123        return "The substance was entered in error.";
124      case NULL:
125        return null;
126      default:
127        return "?";
128      }
129    }
130
131    public String getDisplay() {
132      switch (this) {
133      case ACTIVE:
134        return "Active";
135      case INACTIVE:
136        return "Inactive";
137      case ENTEREDINERROR:
138        return "Entered in Error";
139      case NULL:
140        return null;
141      default:
142        return "?";
143      }
144    }
145  }
146
147  public static class FHIRSubstanceStatusEnumFactory implements EnumFactory<FHIRSubstanceStatus> {
148    public FHIRSubstanceStatus fromCode(String codeString) throws IllegalArgumentException {
149      if (codeString == null || "".equals(codeString))
150        if (codeString == null || "".equals(codeString))
151          return null;
152      if ("active".equals(codeString))
153        return FHIRSubstanceStatus.ACTIVE;
154      if ("inactive".equals(codeString))
155        return FHIRSubstanceStatus.INACTIVE;
156      if ("entered-in-error".equals(codeString))
157        return FHIRSubstanceStatus.ENTEREDINERROR;
158      throw new IllegalArgumentException("Unknown FHIRSubstanceStatus code '" + codeString + "'");
159    }
160
161    public Enumeration<FHIRSubstanceStatus> fromType(PrimitiveType<?> code) throws FHIRException {
162      if (code == null)
163        return null;
164      if (code.isEmpty())
165        return new Enumeration<FHIRSubstanceStatus>(this, FHIRSubstanceStatus.NULL, code);
166      String codeString = code.asStringValue();
167      if (codeString == null || "".equals(codeString))
168        return new Enumeration<FHIRSubstanceStatus>(this, FHIRSubstanceStatus.NULL, code);
169      if ("active".equals(codeString))
170        return new Enumeration<FHIRSubstanceStatus>(this, FHIRSubstanceStatus.ACTIVE, code);
171      if ("inactive".equals(codeString))
172        return new Enumeration<FHIRSubstanceStatus>(this, FHIRSubstanceStatus.INACTIVE, code);
173      if ("entered-in-error".equals(codeString))
174        return new Enumeration<FHIRSubstanceStatus>(this, FHIRSubstanceStatus.ENTEREDINERROR, code);
175      throw new FHIRException("Unknown FHIRSubstanceStatus code '" + codeString + "'");
176    }
177
178    public String toCode(FHIRSubstanceStatus code) {
179      if (code == FHIRSubstanceStatus.ACTIVE)
180        return "active";
181      if (code == FHIRSubstanceStatus.INACTIVE)
182        return "inactive";
183      if (code == FHIRSubstanceStatus.ENTEREDINERROR)
184        return "entered-in-error";
185      return "?";
186    }
187
188    public String toSystem(FHIRSubstanceStatus code) {
189      return code.getSystem();
190    }
191  }
192
193  @Block()
194  public static class SubstanceInstanceComponent extends BackboneElement implements IBaseBackboneElement {
195    /**
196     * Identifier associated with the package/container (usually a label affixed
197     * directly).
198     */
199    @Child(name = "identifier", type = {
200        Identifier.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
201    @Description(shortDefinition = "Identifier of the package/container", formalDefinition = "Identifier associated with the package/container (usually a label affixed directly).")
202    protected Identifier identifier;
203
204    /**
205     * When the substance is no longer valid to use. For some substances, a single
206     * arbitrary date is used for expiry.
207     */
208    @Child(name = "expiry", type = {
209        DateTimeType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
210    @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.")
211    protected DateTimeType expiry;
212
213    /**
214     * The amount of the substance.
215     */
216    @Child(name = "quantity", type = { Quantity.class }, order = 3, min = 0, max = 1, modifier = false, summary = true)
217    @Description(shortDefinition = "Amount of substance in the package", formalDefinition = "The amount of the substance.")
218    protected Quantity quantity;
219
220    private static final long serialVersionUID = -1474380480L;
221
222    /**
223     * Constructor
224     */
225    public SubstanceInstanceComponent() {
226      super();
227    }
228
229    /**
230     * @return {@link #identifier} (Identifier associated with the package/container
231     *         (usually a label affixed directly).)
232     */
233    public Identifier getIdentifier() {
234      if (this.identifier == null)
235        if (Configuration.errorOnAutoCreate())
236          throw new Error("Attempt to auto-create SubstanceInstanceComponent.identifier");
237        else if (Configuration.doAutoCreate())
238          this.identifier = new Identifier(); // cc
239      return this.identifier;
240    }
241
242    public boolean hasIdentifier() {
243      return this.identifier != null && !this.identifier.isEmpty();
244    }
245
246    /**
247     * @param value {@link #identifier} (Identifier associated with the
248     *              package/container (usually a label affixed directly).)
249     */
250    public SubstanceInstanceComponent setIdentifier(Identifier value) {
251      this.identifier = value;
252      return this;
253    }
254
255    /**
256     * @return {@link #expiry} (When the substance is no longer valid to use. For
257     *         some substances, a single arbitrary date is used for expiry.). This
258     *         is the underlying object with id, value and extensions. The accessor
259     *         "getExpiry" gives direct access to the value
260     */
261    public DateTimeType getExpiryElement() {
262      if (this.expiry == null)
263        if (Configuration.errorOnAutoCreate())
264          throw new Error("Attempt to auto-create SubstanceInstanceComponent.expiry");
265        else if (Configuration.doAutoCreate())
266          this.expiry = new DateTimeType(); // bb
267      return this.expiry;
268    }
269
270    public boolean hasExpiryElement() {
271      return this.expiry != null && !this.expiry.isEmpty();
272    }
273
274    public boolean hasExpiry() {
275      return this.expiry != null && !this.expiry.isEmpty();
276    }
277
278    /**
279     * @param value {@link #expiry} (When the substance is no longer valid to use.
280     *              For some substances, a single arbitrary date is used for
281     *              expiry.). This is the underlying object with id, value and
282     *              extensions. The accessor "getExpiry" gives direct access to the
283     *              value
284     */
285    public SubstanceInstanceComponent setExpiryElement(DateTimeType value) {
286      this.expiry = value;
287      return this;
288    }
289
290    /**
291     * @return When the substance is no longer valid to use. For some substances, a
292     *         single arbitrary date is used for expiry.
293     */
294    public Date getExpiry() {
295      return this.expiry == null ? null : this.expiry.getValue();
296    }
297
298    /**
299     * @param value When the substance is no longer valid to use. For some
300     *              substances, a single arbitrary date is used for expiry.
301     */
302    public SubstanceInstanceComponent setExpiry(Date value) {
303      if (value == null)
304        this.expiry = null;
305      else {
306        if (this.expiry == null)
307          this.expiry = new DateTimeType();
308        this.expiry.setValue(value);
309      }
310      return this;
311    }
312
313    /**
314     * @return {@link #quantity} (The amount of the substance.)
315     */
316    public Quantity getQuantity() {
317      if (this.quantity == null)
318        if (Configuration.errorOnAutoCreate())
319          throw new Error("Attempt to auto-create SubstanceInstanceComponent.quantity");
320        else if (Configuration.doAutoCreate())
321          this.quantity = new Quantity(); // cc
322      return this.quantity;
323    }
324
325    public boolean hasQuantity() {
326      return this.quantity != null && !this.quantity.isEmpty();
327    }
328
329    /**
330     * @param value {@link #quantity} (The amount of the substance.)
331     */
332    public SubstanceInstanceComponent setQuantity(Quantity value) {
333      this.quantity = value;
334      return this;
335    }
336
337    protected void listChildren(List<Property> children) {
338      super.listChildren(children);
339      children.add(new Property("identifier", "Identifier",
340          "Identifier associated with the package/container (usually a label affixed directly).", 0, 1, identifier));
341      children.add(new Property("expiry", "dateTime",
342          "When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.",
343          0, 1, expiry));
344      children.add(new Property("quantity", "SimpleQuantity", "The amount of the substance.", 0, 1, quantity));
345    }
346
347    @Override
348    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
349      switch (_hash) {
350      case -1618432855:
351        /* identifier */ return new Property("identifier", "Identifier",
352            "Identifier associated with the package/container (usually a label affixed directly).", 0, 1, identifier);
353      case -1289159373:
354        /* expiry */ return new Property("expiry", "dateTime",
355            "When the substance is no longer valid to use. For some substances, a single arbitrary date is used for expiry.",
356            0, 1, expiry);
357      case -1285004149:
358        /* quantity */ return new Property("quantity", "SimpleQuantity", "The amount of the substance.", 0, 1,
359            quantity);
360      default:
361        return super.getNamedProperty(_hash, _name, _checkValid);
362      }
363
364    }
365
366    @Override
367    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
368      switch (hash) {
369      case -1618432855:
370        /* identifier */ return this.identifier == null ? new Base[0] : new Base[] { this.identifier }; // Identifier
371      case -1289159373:
372        /* expiry */ return this.expiry == null ? new Base[0] : new Base[] { this.expiry }; // DateTimeType
373      case -1285004149:
374        /* quantity */ return this.quantity == null ? new Base[0] : new Base[] { this.quantity }; // Quantity
375      default:
376        return super.getProperty(hash, name, checkValid);
377      }
378
379    }
380
381    @Override
382    public Base setProperty(int hash, String name, Base value) throws FHIRException {
383      switch (hash) {
384      case -1618432855: // identifier
385        this.identifier = castToIdentifier(value); // Identifier
386        return value;
387      case -1289159373: // expiry
388        this.expiry = castToDateTime(value); // DateTimeType
389        return value;
390      case -1285004149: // quantity
391        this.quantity = castToQuantity(value); // Quantity
392        return value;
393      default:
394        return super.setProperty(hash, name, value);
395      }
396
397    }
398
399    @Override
400    public Base setProperty(String name, Base value) throws FHIRException {
401      if (name.equals("identifier")) {
402        this.identifier = castToIdentifier(value); // Identifier
403      } else if (name.equals("expiry")) {
404        this.expiry = castToDateTime(value); // DateTimeType
405      } else if (name.equals("quantity")) {
406        this.quantity = castToQuantity(value); // Quantity
407      } else
408        return super.setProperty(name, value);
409      return value;
410    }
411
412    @Override
413    public Base makeProperty(int hash, String name) throws FHIRException {
414      switch (hash) {
415      case -1618432855:
416        return getIdentifier();
417      case -1289159373:
418        return getExpiryElement();
419      case -1285004149:
420        return getQuantity();
421      default:
422        return super.makeProperty(hash, name);
423      }
424
425    }
426
427    @Override
428    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
429      switch (hash) {
430      case -1618432855:
431        /* identifier */ return new String[] { "Identifier" };
432      case -1289159373:
433        /* expiry */ return new String[] { "dateTime" };
434      case -1285004149:
435        /* quantity */ return new String[] { "SimpleQuantity" };
436      default:
437        return super.getTypesForProperty(hash, name);
438      }
439
440    }
441
442    @Override
443    public Base addChild(String name) throws FHIRException {
444      if (name.equals("identifier")) {
445        this.identifier = new Identifier();
446        return this.identifier;
447      } else if (name.equals("expiry")) {
448        throw new FHIRException("Cannot call addChild on a singleton property Substance.expiry");
449      } else if (name.equals("quantity")) {
450        this.quantity = new Quantity();
451        return this.quantity;
452      } else
453        return super.addChild(name);
454    }
455
456    public SubstanceInstanceComponent copy() {
457      SubstanceInstanceComponent dst = new SubstanceInstanceComponent();
458      copyValues(dst);
459      return dst;
460    }
461
462    public void copyValues(SubstanceInstanceComponent dst) {
463      super.copyValues(dst);
464      dst.identifier = identifier == null ? null : identifier.copy();
465      dst.expiry = expiry == null ? null : expiry.copy();
466      dst.quantity = quantity == null ? null : quantity.copy();
467    }
468
469    @Override
470    public boolean equalsDeep(Base other_) {
471      if (!super.equalsDeep(other_))
472        return false;
473      if (!(other_ instanceof SubstanceInstanceComponent))
474        return false;
475      SubstanceInstanceComponent o = (SubstanceInstanceComponent) other_;
476      return compareDeep(identifier, o.identifier, true) && compareDeep(expiry, o.expiry, true)
477          && compareDeep(quantity, o.quantity, true);
478    }
479
480    @Override
481    public boolean equalsShallow(Base other_) {
482      if (!super.equalsShallow(other_))
483        return false;
484      if (!(other_ instanceof SubstanceInstanceComponent))
485        return false;
486      SubstanceInstanceComponent o = (SubstanceInstanceComponent) other_;
487      return compareValues(expiry, o.expiry, true);
488    }
489
490    public boolean isEmpty() {
491      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, expiry, quantity);
492    }
493
494    public String fhirType() {
495      return "Substance.instance";
496
497    }
498
499  }
500
501  @Block()
502  public static class SubstanceIngredientComponent extends BackboneElement implements IBaseBackboneElement {
503    /**
504     * The amount of the ingredient in the substance - a concentration ratio.
505     */
506    @Child(name = "quantity", type = { Ratio.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
507    @Description(shortDefinition = "Optional amount (concentration)", formalDefinition = "The amount of the ingredient in the substance - a concentration ratio.")
508    protected Ratio quantity;
509
510    /**
511     * Another substance that is a component of this substance.
512     */
513    @Child(name = "substance", type = { CodeableConcept.class,
514        Substance.class }, order = 2, min = 1, max = 1, modifier = false, summary = true)
515    @Description(shortDefinition = "A component of the substance", formalDefinition = "Another substance that is a component of this substance.")
516    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/substance-code")
517    protected Type substance;
518
519    private static final long serialVersionUID = -469805322L;
520
521    /**
522     * Constructor
523     */
524    public SubstanceIngredientComponent() {
525      super();
526    }
527
528    /**
529     * Constructor
530     */
531    public SubstanceIngredientComponent(Type substance) {
532      super();
533      this.substance = substance;
534    }
535
536    /**
537     * @return {@link #quantity} (The amount of the ingredient in the substance - a
538     *         concentration ratio.)
539     */
540    public Ratio getQuantity() {
541      if (this.quantity == null)
542        if (Configuration.errorOnAutoCreate())
543          throw new Error("Attempt to auto-create SubstanceIngredientComponent.quantity");
544        else if (Configuration.doAutoCreate())
545          this.quantity = new Ratio(); // cc
546      return this.quantity;
547    }
548
549    public boolean hasQuantity() {
550      return this.quantity != null && !this.quantity.isEmpty();
551    }
552
553    /**
554     * @param value {@link #quantity} (The amount of the ingredient in the substance
555     *              - a concentration ratio.)
556     */
557    public SubstanceIngredientComponent setQuantity(Ratio value) {
558      this.quantity = value;
559      return this;
560    }
561
562    /**
563     * @return {@link #substance} (Another substance that is a component of this
564     *         substance.)
565     */
566    public Type getSubstance() {
567      return this.substance;
568    }
569
570    /**
571     * @return {@link #substance} (Another substance that is a component of this
572     *         substance.)
573     */
574    public CodeableConcept getSubstanceCodeableConcept() throws FHIRException {
575      if (this.substance == null)
576        this.substance = new CodeableConcept();
577      if (!(this.substance instanceof CodeableConcept))
578        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "
579            + this.substance.getClass().getName() + " was encountered");
580      return (CodeableConcept) this.substance;
581    }
582
583    public boolean hasSubstanceCodeableConcept() {
584      return this != null && this.substance instanceof CodeableConcept;
585    }
586
587    /**
588     * @return {@link #substance} (Another substance that is a component of this
589     *         substance.)
590     */
591    public Reference getSubstanceReference() throws FHIRException {
592      if (this.substance == null)
593        this.substance = new Reference();
594      if (!(this.substance instanceof Reference))
595        throw new FHIRException("Type mismatch: the type Reference was expected, but "
596            + this.substance.getClass().getName() + " was encountered");
597      return (Reference) this.substance;
598    }
599
600    public boolean hasSubstanceReference() {
601      return this != null && this.substance instanceof Reference;
602    }
603
604    public boolean hasSubstance() {
605      return this.substance != null && !this.substance.isEmpty();
606    }
607
608    /**
609     * @param value {@link #substance} (Another substance that is a component of
610     *              this substance.)
611     */
612    public SubstanceIngredientComponent setSubstance(Type value) {
613      if (value != null && !(value instanceof CodeableConcept || value instanceof Reference))
614        throw new Error("Not the right type for Substance.ingredient.substance[x]: " + value.fhirType());
615      this.substance = value;
616      return this;
617    }
618
619    protected void listChildren(List<Property> children) {
620      super.listChildren(children);
621      children.add(new Property("quantity", "Ratio",
622          "The amount of the ingredient in the substance - a concentration ratio.", 0, 1, quantity));
623      children.add(new Property("substance[x]", "CodeableConcept|Reference(Substance)",
624          "Another substance that is a component of this substance.", 0, 1, substance));
625    }
626
627    @Override
628    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
629      switch (_hash) {
630      case -1285004149:
631        /* quantity */ return new Property("quantity", "Ratio",
632            "The amount of the ingredient in the substance - a concentration ratio.", 0, 1, quantity);
633      case 2127194384:
634        /* substance[x] */ return new Property("substance[x]", "CodeableConcept|Reference(Substance)",
635            "Another substance that is a component of this substance.", 0, 1, substance);
636      case 530040176:
637        /* substance */ return new Property("substance[x]", "CodeableConcept|Reference(Substance)",
638            "Another substance that is a component of this substance.", 0, 1, substance);
639      case -1974119407:
640        /* substanceCodeableConcept */ return new Property("substance[x]", "CodeableConcept|Reference(Substance)",
641            "Another substance that is a component of this substance.", 0, 1, substance);
642      case 516208571:
643        /* substanceReference */ return new Property("substance[x]", "CodeableConcept|Reference(Substance)",
644            "Another substance that is a component of this substance.", 0, 1, substance);
645      default:
646        return super.getNamedProperty(_hash, _name, _checkValid);
647      }
648
649    }
650
651    @Override
652    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
653      switch (hash) {
654      case -1285004149:
655        /* quantity */ return this.quantity == null ? new Base[0] : new Base[] { this.quantity }; // Ratio
656      case 530040176:
657        /* substance */ return this.substance == null ? new Base[0] : new Base[] { this.substance }; // Type
658      default:
659        return super.getProperty(hash, name, checkValid);
660      }
661
662    }
663
664    @Override
665    public Base setProperty(int hash, String name, Base value) throws FHIRException {
666      switch (hash) {
667      case -1285004149: // quantity
668        this.quantity = castToRatio(value); // Ratio
669        return value;
670      case 530040176: // substance
671        this.substance = castToType(value); // Type
672        return value;
673      default:
674        return super.setProperty(hash, name, value);
675      }
676
677    }
678
679    @Override
680    public Base setProperty(String name, Base value) throws FHIRException {
681      if (name.equals("quantity")) {
682        this.quantity = castToRatio(value); // Ratio
683      } else if (name.equals("substance[x]")) {
684        this.substance = castToType(value); // Type
685      } else
686        return super.setProperty(name, value);
687      return value;
688    }
689
690    @Override
691    public Base makeProperty(int hash, String name) throws FHIRException {
692      switch (hash) {
693      case -1285004149:
694        return getQuantity();
695      case 2127194384:
696        return getSubstance();
697      case 530040176:
698        return getSubstance();
699      default:
700        return super.makeProperty(hash, name);
701      }
702
703    }
704
705    @Override
706    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
707      switch (hash) {
708      case -1285004149:
709        /* quantity */ return new String[] { "Ratio" };
710      case 530040176:
711        /* substance */ return new String[] { "CodeableConcept", "Reference" };
712      default:
713        return super.getTypesForProperty(hash, name);
714      }
715
716    }
717
718    @Override
719    public Base addChild(String name) throws FHIRException {
720      if (name.equals("quantity")) {
721        this.quantity = new Ratio();
722        return this.quantity;
723      } else if (name.equals("substanceCodeableConcept")) {
724        this.substance = new CodeableConcept();
725        return this.substance;
726      } else if (name.equals("substanceReference")) {
727        this.substance = new Reference();
728        return this.substance;
729      } else
730        return super.addChild(name);
731    }
732
733    public SubstanceIngredientComponent copy() {
734      SubstanceIngredientComponent dst = new SubstanceIngredientComponent();
735      copyValues(dst);
736      return dst;
737    }
738
739    public void copyValues(SubstanceIngredientComponent dst) {
740      super.copyValues(dst);
741      dst.quantity = quantity == null ? null : quantity.copy();
742      dst.substance = substance == null ? null : substance.copy();
743    }
744
745    @Override
746    public boolean equalsDeep(Base other_) {
747      if (!super.equalsDeep(other_))
748        return false;
749      if (!(other_ instanceof SubstanceIngredientComponent))
750        return false;
751      SubstanceIngredientComponent o = (SubstanceIngredientComponent) other_;
752      return compareDeep(quantity, o.quantity, true) && compareDeep(substance, o.substance, true);
753    }
754
755    @Override
756    public boolean equalsShallow(Base other_) {
757      if (!super.equalsShallow(other_))
758        return false;
759      if (!(other_ instanceof SubstanceIngredientComponent))
760        return false;
761      SubstanceIngredientComponent o = (SubstanceIngredientComponent) other_;
762      return true;
763    }
764
765    public boolean isEmpty() {
766      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(quantity, substance);
767    }
768
769    public String fhirType() {
770      return "Substance.ingredient";
771
772    }
773
774  }
775
776  /**
777   * Unique identifier for the substance.
778   */
779  @Child(name = "identifier", type = {
780      Identifier.class }, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
781  @Description(shortDefinition = "Unique identifier", formalDefinition = "Unique identifier for the substance.")
782  protected List<Identifier> identifier;
783
784  /**
785   * A code to indicate if the substance is actively used.
786   */
787  @Child(name = "status", type = { CodeType.class }, order = 1, min = 0, max = 1, modifier = true, summary = true)
788  @Description(shortDefinition = "active | inactive | entered-in-error", formalDefinition = "A code to indicate if the substance is actively used.")
789  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/substance-status")
790  protected Enumeration<FHIRSubstanceStatus> status;
791
792  /**
793   * A code that classifies the general type of substance. This is used for
794   * searching, sorting and display purposes.
795   */
796  @Child(name = "category", type = {
797      CodeableConcept.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
798  @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.")
799  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/substance-category")
800  protected List<CodeableConcept> category;
801
802  /**
803   * A code (or set of codes) that identify this substance.
804   */
805  @Child(name = "code", type = { CodeableConcept.class }, order = 3, min = 1, max = 1, modifier = false, summary = true)
806  @Description(shortDefinition = "What substance this is", formalDefinition = "A code (or set of codes) that identify this substance.")
807  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/substance-code")
808  protected CodeableConcept code;
809
810  /**
811   * A description of the substance - its appearance, handling requirements, and
812   * other usage notes.
813   */
814  @Child(name = "description", type = {
815      StringType.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
816  @Description(shortDefinition = "Textual description of the substance, comments", formalDefinition = "A description of the substance - its appearance, handling requirements, and other usage notes.")
817  protected StringType description;
818
819  /**
820   * Substance may be used to describe a kind of substance, or a specific
821   * package/container of the substance: an instance.
822   */
823  @Child(name = "instance", type = {}, order = 5, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
824  @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.")
825  protected List<SubstanceInstanceComponent> instance;
826
827  /**
828   * A substance can be composed of other substances.
829   */
830  @Child(name = "ingredient", type = {}, order = 6, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
831  @Description(shortDefinition = "Composition information about the substance", formalDefinition = "A substance can be composed of other substances.")
832  protected List<SubstanceIngredientComponent> ingredient;
833
834  private static final long serialVersionUID = -1467626602L;
835
836  /**
837   * Constructor
838   */
839  public Substance() {
840    super();
841  }
842
843  /**
844   * Constructor
845   */
846  public Substance(CodeableConcept code) {
847    super();
848    this.code = code;
849  }
850
851  /**
852   * @return {@link #identifier} (Unique identifier for the substance.)
853   */
854  public List<Identifier> getIdentifier() {
855    if (this.identifier == null)
856      this.identifier = new ArrayList<Identifier>();
857    return this.identifier;
858  }
859
860  /**
861   * @return Returns a reference to <code>this</code> for easy method chaining
862   */
863  public Substance setIdentifier(List<Identifier> theIdentifier) {
864    this.identifier = theIdentifier;
865    return this;
866  }
867
868  public boolean hasIdentifier() {
869    if (this.identifier == null)
870      return false;
871    for (Identifier item : this.identifier)
872      if (!item.isEmpty())
873        return true;
874    return false;
875  }
876
877  public Identifier addIdentifier() { // 3
878    Identifier t = new Identifier();
879    if (this.identifier == null)
880      this.identifier = new ArrayList<Identifier>();
881    this.identifier.add(t);
882    return t;
883  }
884
885  public Substance addIdentifier(Identifier t) { // 3
886    if (t == null)
887      return this;
888    if (this.identifier == null)
889      this.identifier = new ArrayList<Identifier>();
890    this.identifier.add(t);
891    return this;
892  }
893
894  /**
895   * @return The first repetition of repeating field {@link #identifier}, creating
896   *         it if it does not already exist
897   */
898  public Identifier getIdentifierFirstRep() {
899    if (getIdentifier().isEmpty()) {
900      addIdentifier();
901    }
902    return getIdentifier().get(0);
903  }
904
905  /**
906   * @return {@link #status} (A code to indicate if the substance is actively
907   *         used.). This is the underlying object with id, value and extensions.
908   *         The accessor "getStatus" gives direct access to the value
909   */
910  public Enumeration<FHIRSubstanceStatus> getStatusElement() {
911    if (this.status == null)
912      if (Configuration.errorOnAutoCreate())
913        throw new Error("Attempt to auto-create Substance.status");
914      else if (Configuration.doAutoCreate())
915        this.status = new Enumeration<FHIRSubstanceStatus>(new FHIRSubstanceStatusEnumFactory()); // bb
916    return this.status;
917  }
918
919  public boolean hasStatusElement() {
920    return this.status != null && !this.status.isEmpty();
921  }
922
923  public boolean hasStatus() {
924    return this.status != null && !this.status.isEmpty();
925  }
926
927  /**
928   * @param value {@link #status} (A code to indicate if the substance is actively
929   *              used.). This is the underlying object with id, value and
930   *              extensions. The accessor "getStatus" gives direct access to the
931   *              value
932   */
933  public Substance setStatusElement(Enumeration<FHIRSubstanceStatus> value) {
934    this.status = value;
935    return this;
936  }
937
938  /**
939   * @return A code to indicate if the substance is actively used.
940   */
941  public FHIRSubstanceStatus getStatus() {
942    return this.status == null ? null : this.status.getValue();
943  }
944
945  /**
946   * @param value A code to indicate if the substance is actively used.
947   */
948  public Substance setStatus(FHIRSubstanceStatus value) {
949    if (value == null)
950      this.status = null;
951    else {
952      if (this.status == null)
953        this.status = new Enumeration<FHIRSubstanceStatus>(new FHIRSubstanceStatusEnumFactory());
954      this.status.setValue(value);
955    }
956    return this;
957  }
958
959  /**
960   * @return {@link #category} (A code that classifies the general type of
961   *         substance. This is used for searching, sorting and display purposes.)
962   */
963  public List<CodeableConcept> getCategory() {
964    if (this.category == null)
965      this.category = new ArrayList<CodeableConcept>();
966    return this.category;
967  }
968
969  /**
970   * @return Returns a reference to <code>this</code> for easy method chaining
971   */
972  public Substance setCategory(List<CodeableConcept> theCategory) {
973    this.category = theCategory;
974    return this;
975  }
976
977  public boolean hasCategory() {
978    if (this.category == null)
979      return false;
980    for (CodeableConcept item : this.category)
981      if (!item.isEmpty())
982        return true;
983    return false;
984  }
985
986  public CodeableConcept addCategory() { // 3
987    CodeableConcept t = new CodeableConcept();
988    if (this.category == null)
989      this.category = new ArrayList<CodeableConcept>();
990    this.category.add(t);
991    return t;
992  }
993
994  public Substance addCategory(CodeableConcept t) { // 3
995    if (t == null)
996      return this;
997    if (this.category == null)
998      this.category = new ArrayList<CodeableConcept>();
999    this.category.add(t);
1000    return this;
1001  }
1002
1003  /**
1004   * @return The first repetition of repeating field {@link #category}, creating
1005   *         it if it does not already exist
1006   */
1007  public CodeableConcept getCategoryFirstRep() {
1008    if (getCategory().isEmpty()) {
1009      addCategory();
1010    }
1011    return getCategory().get(0);
1012  }
1013
1014  /**
1015   * @return {@link #code} (A code (or set of codes) that identify this
1016   *         substance.)
1017   */
1018  public CodeableConcept getCode() {
1019    if (this.code == null)
1020      if (Configuration.errorOnAutoCreate())
1021        throw new Error("Attempt to auto-create Substance.code");
1022      else if (Configuration.doAutoCreate())
1023        this.code = new CodeableConcept(); // cc
1024    return this.code;
1025  }
1026
1027  public boolean hasCode() {
1028    return this.code != null && !this.code.isEmpty();
1029  }
1030
1031  /**
1032   * @param value {@link #code} (A code (or set of codes) that identify this
1033   *              substance.)
1034   */
1035  public Substance setCode(CodeableConcept value) {
1036    this.code = value;
1037    return this;
1038  }
1039
1040  /**
1041   * @return {@link #description} (A description of the substance - its
1042   *         appearance, handling requirements, and other usage notes.). This is
1043   *         the underlying object with id, value and extensions. The accessor
1044   *         "getDescription" gives direct access to the value
1045   */
1046  public StringType getDescriptionElement() {
1047    if (this.description == null)
1048      if (Configuration.errorOnAutoCreate())
1049        throw new Error("Attempt to auto-create Substance.description");
1050      else if (Configuration.doAutoCreate())
1051        this.description = new StringType(); // bb
1052    return this.description;
1053  }
1054
1055  public boolean hasDescriptionElement() {
1056    return this.description != null && !this.description.isEmpty();
1057  }
1058
1059  public boolean hasDescription() {
1060    return this.description != null && !this.description.isEmpty();
1061  }
1062
1063  /**
1064   * @param value {@link #description} (A description of the substance - its
1065   *              appearance, handling requirements, and other usage notes.). This
1066   *              is the underlying object with id, value and extensions. The
1067   *              accessor "getDescription" gives direct access to the value
1068   */
1069  public Substance setDescriptionElement(StringType value) {
1070    this.description = value;
1071    return this;
1072  }
1073
1074  /**
1075   * @return A description of the substance - its appearance, handling
1076   *         requirements, and other usage notes.
1077   */
1078  public String getDescription() {
1079    return this.description == null ? null : this.description.getValue();
1080  }
1081
1082  /**
1083   * @param value A description of the substance - its appearance, handling
1084   *              requirements, and other usage notes.
1085   */
1086  public Substance setDescription(String value) {
1087    if (Utilities.noString(value))
1088      this.description = null;
1089    else {
1090      if (this.description == null)
1091        this.description = new StringType();
1092      this.description.setValue(value);
1093    }
1094    return this;
1095  }
1096
1097  /**
1098   * @return {@link #instance} (Substance may be used to describe a kind of
1099   *         substance, or a specific package/container of the substance: an
1100   *         instance.)
1101   */
1102  public List<SubstanceInstanceComponent> getInstance() {
1103    if (this.instance == null)
1104      this.instance = new ArrayList<SubstanceInstanceComponent>();
1105    return this.instance;
1106  }
1107
1108  /**
1109   * @return Returns a reference to <code>this</code> for easy method chaining
1110   */
1111  public Substance setInstance(List<SubstanceInstanceComponent> theInstance) {
1112    this.instance = theInstance;
1113    return this;
1114  }
1115
1116  public boolean hasInstance() {
1117    if (this.instance == null)
1118      return false;
1119    for (SubstanceInstanceComponent item : this.instance)
1120      if (!item.isEmpty())
1121        return true;
1122    return false;
1123  }
1124
1125  public SubstanceInstanceComponent addInstance() { // 3
1126    SubstanceInstanceComponent t = new SubstanceInstanceComponent();
1127    if (this.instance == null)
1128      this.instance = new ArrayList<SubstanceInstanceComponent>();
1129    this.instance.add(t);
1130    return t;
1131  }
1132
1133  public Substance addInstance(SubstanceInstanceComponent t) { // 3
1134    if (t == null)
1135      return this;
1136    if (this.instance == null)
1137      this.instance = new ArrayList<SubstanceInstanceComponent>();
1138    this.instance.add(t);
1139    return this;
1140  }
1141
1142  /**
1143   * @return The first repetition of repeating field {@link #instance}, creating
1144   *         it if it does not already exist
1145   */
1146  public SubstanceInstanceComponent getInstanceFirstRep() {
1147    if (getInstance().isEmpty()) {
1148      addInstance();
1149    }
1150    return getInstance().get(0);
1151  }
1152
1153  /**
1154   * @return {@link #ingredient} (A substance can be composed of other
1155   *         substances.)
1156   */
1157  public List<SubstanceIngredientComponent> getIngredient() {
1158    if (this.ingredient == null)
1159      this.ingredient = new ArrayList<SubstanceIngredientComponent>();
1160    return this.ingredient;
1161  }
1162
1163  /**
1164   * @return Returns a reference to <code>this</code> for easy method chaining
1165   */
1166  public Substance setIngredient(List<SubstanceIngredientComponent> theIngredient) {
1167    this.ingredient = theIngredient;
1168    return this;
1169  }
1170
1171  public boolean hasIngredient() {
1172    if (this.ingredient == null)
1173      return false;
1174    for (SubstanceIngredientComponent item : this.ingredient)
1175      if (!item.isEmpty())
1176        return true;
1177    return false;
1178  }
1179
1180  public SubstanceIngredientComponent addIngredient() { // 3
1181    SubstanceIngredientComponent t = new SubstanceIngredientComponent();
1182    if (this.ingredient == null)
1183      this.ingredient = new ArrayList<SubstanceIngredientComponent>();
1184    this.ingredient.add(t);
1185    return t;
1186  }
1187
1188  public Substance addIngredient(SubstanceIngredientComponent t) { // 3
1189    if (t == null)
1190      return this;
1191    if (this.ingredient == null)
1192      this.ingredient = new ArrayList<SubstanceIngredientComponent>();
1193    this.ingredient.add(t);
1194    return this;
1195  }
1196
1197  /**
1198   * @return The first repetition of repeating field {@link #ingredient}, creating
1199   *         it if it does not already exist
1200   */
1201  public SubstanceIngredientComponent getIngredientFirstRep() {
1202    if (getIngredient().isEmpty()) {
1203      addIngredient();
1204    }
1205    return getIngredient().get(0);
1206  }
1207
1208  protected void listChildren(List<Property> children) {
1209    super.listChildren(children);
1210    children.add(new Property("identifier", "Identifier", "Unique identifier for the substance.", 0,
1211        java.lang.Integer.MAX_VALUE, identifier));
1212    children.add(new Property("status", "code", "A code to indicate if the substance is actively used.", 0, 1, status));
1213    children.add(new Property("category", "CodeableConcept",
1214        "A code that classifies the general type of substance.  This is used  for searching, sorting and display purposes.",
1215        0, java.lang.Integer.MAX_VALUE, category));
1216    children.add(
1217        new Property("code", "CodeableConcept", "A code (or set of codes) that identify this substance.", 0, 1, code));
1218    children.add(new Property("description", "string",
1219        "A description of the substance - its appearance, handling requirements, and other usage notes.", 0, 1,
1220        description));
1221    children.add(new Property("instance", "",
1222        "Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.",
1223        0, java.lang.Integer.MAX_VALUE, instance));
1224    children.add(new Property("ingredient", "", "A substance can be composed of other substances.", 0,
1225        java.lang.Integer.MAX_VALUE, ingredient));
1226  }
1227
1228  @Override
1229  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1230    switch (_hash) {
1231    case -1618432855:
1232      /* identifier */ return new Property("identifier", "Identifier", "Unique identifier for the substance.", 0,
1233          java.lang.Integer.MAX_VALUE, identifier);
1234    case -892481550:
1235      /* status */ return new Property("status", "code", "A code to indicate if the substance is actively used.", 0, 1,
1236          status);
1237    case 50511102:
1238      /* category */ return new Property("category", "CodeableConcept",
1239          "A code that classifies the general type of substance.  This is used  for searching, sorting and display purposes.",
1240          0, java.lang.Integer.MAX_VALUE, category);
1241    case 3059181:
1242      /* code */ return new Property("code", "CodeableConcept",
1243          "A code (or set of codes) that identify this substance.", 0, 1, code);
1244    case -1724546052:
1245      /* description */ return new Property("description", "string",
1246          "A description of the substance - its appearance, handling requirements, and other usage notes.", 0, 1,
1247          description);
1248    case 555127957:
1249      /* instance */ return new Property("instance", "",
1250          "Substance may be used to describe a kind of substance, or a specific package/container of the substance: an instance.",
1251          0, java.lang.Integer.MAX_VALUE, instance);
1252    case -206409263:
1253      /* ingredient */ return new Property("ingredient", "", "A substance can be composed of other substances.", 0,
1254          java.lang.Integer.MAX_VALUE, ingredient);
1255    default:
1256      return super.getNamedProperty(_hash, _name, _checkValid);
1257    }
1258
1259  }
1260
1261  @Override
1262  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1263    switch (hash) {
1264    case -1618432855:
1265      /* identifier */ return this.identifier == null ? new Base[0]
1266          : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1267    case -892481550:
1268      /* status */ return this.status == null ? new Base[0] : new Base[] { this.status }; // Enumeration<FHIRSubstanceStatus>
1269    case 50511102:
1270      /* category */ return this.category == null ? new Base[0] : this.category.toArray(new Base[this.category.size()]); // CodeableConcept
1271    case 3059181:
1272      /* code */ return this.code == null ? new Base[0] : new Base[] { this.code }; // CodeableConcept
1273    case -1724546052:
1274      /* description */ return this.description == null ? new Base[0] : new Base[] { this.description }; // StringType
1275    case 555127957:
1276      /* instance */ return this.instance == null ? new Base[0] : this.instance.toArray(new Base[this.instance.size()]); // SubstanceInstanceComponent
1277    case -206409263:
1278      /* ingredient */ return this.ingredient == null ? new Base[0]
1279          : this.ingredient.toArray(new Base[this.ingredient.size()]); // SubstanceIngredientComponent
1280    default:
1281      return super.getProperty(hash, name, checkValid);
1282    }
1283
1284  }
1285
1286  @Override
1287  public Base setProperty(int hash, String name, Base value) throws FHIRException {
1288    switch (hash) {
1289    case -1618432855: // identifier
1290      this.getIdentifier().add(castToIdentifier(value)); // Identifier
1291      return value;
1292    case -892481550: // status
1293      value = new FHIRSubstanceStatusEnumFactory().fromType(castToCode(value));
1294      this.status = (Enumeration) value; // Enumeration<FHIRSubstanceStatus>
1295      return value;
1296    case 50511102: // category
1297      this.getCategory().add(castToCodeableConcept(value)); // CodeableConcept
1298      return value;
1299    case 3059181: // code
1300      this.code = castToCodeableConcept(value); // CodeableConcept
1301      return value;
1302    case -1724546052: // description
1303      this.description = castToString(value); // StringType
1304      return value;
1305    case 555127957: // instance
1306      this.getInstance().add((SubstanceInstanceComponent) value); // SubstanceInstanceComponent
1307      return value;
1308    case -206409263: // ingredient
1309      this.getIngredient().add((SubstanceIngredientComponent) value); // SubstanceIngredientComponent
1310      return value;
1311    default:
1312      return super.setProperty(hash, name, value);
1313    }
1314
1315  }
1316
1317  @Override
1318  public Base setProperty(String name, Base value) throws FHIRException {
1319    if (name.equals("identifier")) {
1320      this.getIdentifier().add(castToIdentifier(value));
1321    } else if (name.equals("status")) {
1322      value = new FHIRSubstanceStatusEnumFactory().fromType(castToCode(value));
1323      this.status = (Enumeration) value; // Enumeration<FHIRSubstanceStatus>
1324    } else if (name.equals("category")) {
1325      this.getCategory().add(castToCodeableConcept(value));
1326    } else if (name.equals("code")) {
1327      this.code = castToCodeableConcept(value); // CodeableConcept
1328    } else if (name.equals("description")) {
1329      this.description = castToString(value); // StringType
1330    } else if (name.equals("instance")) {
1331      this.getInstance().add((SubstanceInstanceComponent) value);
1332    } else if (name.equals("ingredient")) {
1333      this.getIngredient().add((SubstanceIngredientComponent) value);
1334    } else
1335      return super.setProperty(name, value);
1336    return value;
1337  }
1338
1339  @Override
1340  public Base makeProperty(int hash, String name) throws FHIRException {
1341    switch (hash) {
1342    case -1618432855:
1343      return addIdentifier();
1344    case -892481550:
1345      return getStatusElement();
1346    case 50511102:
1347      return addCategory();
1348    case 3059181:
1349      return getCode();
1350    case -1724546052:
1351      return getDescriptionElement();
1352    case 555127957:
1353      return addInstance();
1354    case -206409263:
1355      return addIngredient();
1356    default:
1357      return super.makeProperty(hash, name);
1358    }
1359
1360  }
1361
1362  @Override
1363  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1364    switch (hash) {
1365    case -1618432855:
1366      /* identifier */ return new String[] { "Identifier" };
1367    case -892481550:
1368      /* status */ return new String[] { "code" };
1369    case 50511102:
1370      /* category */ return new String[] { "CodeableConcept" };
1371    case 3059181:
1372      /* code */ return new String[] { "CodeableConcept" };
1373    case -1724546052:
1374      /* description */ return new String[] { "string" };
1375    case 555127957:
1376      /* instance */ return new String[] {};
1377    case -206409263:
1378      /* ingredient */ return new String[] {};
1379    default:
1380      return super.getTypesForProperty(hash, name);
1381    }
1382
1383  }
1384
1385  @Override
1386  public Base addChild(String name) throws FHIRException {
1387    if (name.equals("identifier")) {
1388      return addIdentifier();
1389    } else if (name.equals("status")) {
1390      throw new FHIRException("Cannot call addChild on a singleton property Substance.status");
1391    } else if (name.equals("category")) {
1392      return addCategory();
1393    } else if (name.equals("code")) {
1394      this.code = new CodeableConcept();
1395      return this.code;
1396    } else if (name.equals("description")) {
1397      throw new FHIRException("Cannot call addChild on a singleton property Substance.description");
1398    } else if (name.equals("instance")) {
1399      return addInstance();
1400    } else if (name.equals("ingredient")) {
1401      return addIngredient();
1402    } else
1403      return super.addChild(name);
1404  }
1405
1406  public String fhirType() {
1407    return "Substance";
1408
1409  }
1410
1411  public Substance copy() {
1412    Substance dst = new Substance();
1413    copyValues(dst);
1414    return dst;
1415  }
1416
1417  public void copyValues(Substance dst) {
1418    super.copyValues(dst);
1419    if (identifier != null) {
1420      dst.identifier = new ArrayList<Identifier>();
1421      for (Identifier i : identifier)
1422        dst.identifier.add(i.copy());
1423    }
1424    ;
1425    dst.status = status == null ? null : status.copy();
1426    if (category != null) {
1427      dst.category = new ArrayList<CodeableConcept>();
1428      for (CodeableConcept i : category)
1429        dst.category.add(i.copy());
1430    }
1431    ;
1432    dst.code = code == null ? null : code.copy();
1433    dst.description = description == null ? null : description.copy();
1434    if (instance != null) {
1435      dst.instance = new ArrayList<SubstanceInstanceComponent>();
1436      for (SubstanceInstanceComponent i : instance)
1437        dst.instance.add(i.copy());
1438    }
1439    ;
1440    if (ingredient != null) {
1441      dst.ingredient = new ArrayList<SubstanceIngredientComponent>();
1442      for (SubstanceIngredientComponent i : ingredient)
1443        dst.ingredient.add(i.copy());
1444    }
1445    ;
1446  }
1447
1448  protected Substance typedCopy() {
1449    return copy();
1450  }
1451
1452  @Override
1453  public boolean equalsDeep(Base other_) {
1454    if (!super.equalsDeep(other_))
1455      return false;
1456    if (!(other_ instanceof Substance))
1457      return false;
1458    Substance o = (Substance) other_;
1459    return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true)
1460        && compareDeep(category, o.category, true) && compareDeep(code, o.code, true)
1461        && compareDeep(description, o.description, true) && compareDeep(instance, o.instance, true)
1462        && compareDeep(ingredient, o.ingredient, true);
1463  }
1464
1465  @Override
1466  public boolean equalsShallow(Base other_) {
1467    if (!super.equalsShallow(other_))
1468      return false;
1469    if (!(other_ instanceof Substance))
1470      return false;
1471    Substance o = (Substance) other_;
1472    return compareValues(status, o.status, true) && compareValues(description, o.description, true);
1473  }
1474
1475  public boolean isEmpty() {
1476    return super.isEmpty()
1477        && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, status, category, code, description, instance, ingredient);
1478  }
1479
1480  @Override
1481  public ResourceType getResourceType() {
1482    return ResourceType.Substance;
1483  }
1484
1485  /**
1486   * Search parameter: <b>identifier</b>
1487   * <p>
1488   * Description: <b>Unique identifier for the substance</b><br>
1489   * Type: <b>token</b><br>
1490   * Path: <b>Substance.identifier</b><br>
1491   * </p>
1492   */
1493  @SearchParamDefinition(name = "identifier", path = "Substance.identifier", description = "Unique identifier for the substance", type = "token")
1494  public static final String SP_IDENTIFIER = "identifier";
1495  /**
1496   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1497   * <p>
1498   * Description: <b>Unique identifier for the substance</b><br>
1499   * Type: <b>token</b><br>
1500   * Path: <b>Substance.identifier</b><br>
1501   * </p>
1502   */
1503  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(
1504      SP_IDENTIFIER);
1505
1506  /**
1507   * Search parameter: <b>container-identifier</b>
1508   * <p>
1509   * Description: <b>Identifier of the package/container</b><br>
1510   * Type: <b>token</b><br>
1511   * Path: <b>Substance.instance.identifier</b><br>
1512   * </p>
1513   */
1514  @SearchParamDefinition(name = "container-identifier", path = "Substance.instance.identifier", description = "Identifier of the package/container", type = "token")
1515  public static final String SP_CONTAINER_IDENTIFIER = "container-identifier";
1516  /**
1517   * <b>Fluent Client</b> search parameter constant for
1518   * <b>container-identifier</b>
1519   * <p>
1520   * Description: <b>Identifier of the package/container</b><br>
1521   * Type: <b>token</b><br>
1522   * Path: <b>Substance.instance.identifier</b><br>
1523   * </p>
1524   */
1525  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CONTAINER_IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(
1526      SP_CONTAINER_IDENTIFIER);
1527
1528  /**
1529   * Search parameter: <b>code</b>
1530   * <p>
1531   * Description: <b>The code of the substance or ingredient</b><br>
1532   * Type: <b>token</b><br>
1533   * Path: <b>Substance.code,
1534   * Substance.ingredient.substanceCodeableConcept</b><br>
1535   * </p>
1536   */
1537  @SearchParamDefinition(name = "code", path = "Substance.code | (Substance.ingredient.substance as CodeableConcept)", description = "The code of the substance or ingredient", type = "token")
1538  public static final String SP_CODE = "code";
1539  /**
1540   * <b>Fluent Client</b> search parameter constant for <b>code</b>
1541   * <p>
1542   * Description: <b>The code of the substance or ingredient</b><br>
1543   * Type: <b>token</b><br>
1544   * Path: <b>Substance.code,
1545   * Substance.ingredient.substanceCodeableConcept</b><br>
1546   * </p>
1547   */
1548  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(
1549      SP_CODE);
1550
1551  /**
1552   * Search parameter: <b>quantity</b>
1553   * <p>
1554   * Description: <b>Amount of substance in the package</b><br>
1555   * Type: <b>quantity</b><br>
1556   * Path: <b>Substance.instance.quantity</b><br>
1557   * </p>
1558   */
1559  @SearchParamDefinition(name = "quantity", path = "Substance.instance.quantity", description = "Amount of substance in the package", type = "quantity")
1560  public static final String SP_QUANTITY = "quantity";
1561  /**
1562   * <b>Fluent Client</b> search parameter constant for <b>quantity</b>
1563   * <p>
1564   * Description: <b>Amount of substance in the package</b><br>
1565   * Type: <b>quantity</b><br>
1566   * Path: <b>Substance.instance.quantity</b><br>
1567   * </p>
1568   */
1569  public static final ca.uhn.fhir.rest.gclient.QuantityClientParam QUANTITY = new ca.uhn.fhir.rest.gclient.QuantityClientParam(
1570      SP_QUANTITY);
1571
1572  /**
1573   * Search parameter: <b>substance-reference</b>
1574   * <p>
1575   * Description: <b>A component of the substance</b><br>
1576   * Type: <b>reference</b><br>
1577   * Path: <b>Substance.ingredient.substanceReference</b><br>
1578   * </p>
1579   */
1580  @SearchParamDefinition(name = "substance-reference", path = "(Substance.ingredient.substance as Reference)", description = "A component of the substance", type = "reference", target = {
1581      Substance.class })
1582  public static final String SP_SUBSTANCE_REFERENCE = "substance-reference";
1583  /**
1584   * <b>Fluent Client</b> search parameter constant for <b>substance-reference</b>
1585   * <p>
1586   * Description: <b>A component of the substance</b><br>
1587   * Type: <b>reference</b><br>
1588   * Path: <b>Substance.ingredient.substanceReference</b><br>
1589   * </p>
1590   */
1591  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBSTANCE_REFERENCE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
1592      SP_SUBSTANCE_REFERENCE);
1593
1594  /**
1595   * Constant for fluent queries to be used to add include statements. Specifies
1596   * the path value of "<b>Substance:substance-reference</b>".
1597   */
1598  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBSTANCE_REFERENCE = new ca.uhn.fhir.model.api.Include(
1599      "Substance:substance-reference").toLocked();
1600
1601  /**
1602   * Search parameter: <b>expiry</b>
1603   * <p>
1604   * Description: <b>Expiry date of package or container of substance</b><br>
1605   * Type: <b>date</b><br>
1606   * Path: <b>Substance.instance.expiry</b><br>
1607   * </p>
1608   */
1609  @SearchParamDefinition(name = "expiry", path = "Substance.instance.expiry", description = "Expiry date of package or container of substance", type = "date")
1610  public static final String SP_EXPIRY = "expiry";
1611  /**
1612   * <b>Fluent Client</b> search parameter constant for <b>expiry</b>
1613   * <p>
1614   * Description: <b>Expiry date of package or container of substance</b><br>
1615   * Type: <b>date</b><br>
1616   * Path: <b>Substance.instance.expiry</b><br>
1617   * </p>
1618   */
1619  public static final ca.uhn.fhir.rest.gclient.DateClientParam EXPIRY = new ca.uhn.fhir.rest.gclient.DateClientParam(
1620      SP_EXPIRY);
1621
1622  /**
1623   * Search parameter: <b>category</b>
1624   * <p>
1625   * Description: <b>The category of the substance</b><br>
1626   * Type: <b>token</b><br>
1627   * Path: <b>Substance.category</b><br>
1628   * </p>
1629   */
1630  @SearchParamDefinition(name = "category", path = "Substance.category", description = "The category of the substance", type = "token")
1631  public static final String SP_CATEGORY = "category";
1632  /**
1633   * <b>Fluent Client</b> search parameter constant for <b>category</b>
1634   * <p>
1635   * Description: <b>The category of the substance</b><br>
1636   * Type: <b>token</b><br>
1637   * Path: <b>Substance.category</b><br>
1638   * </p>
1639   */
1640  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CATEGORY = new ca.uhn.fhir.rest.gclient.TokenClientParam(
1641      SP_CATEGORY);
1642
1643  /**
1644   * Search parameter: <b>status</b>
1645   * <p>
1646   * Description: <b>active | inactive | entered-in-error</b><br>
1647   * Type: <b>token</b><br>
1648   * Path: <b>Substance.status</b><br>
1649   * </p>
1650   */
1651  @SearchParamDefinition(name = "status", path = "Substance.status", description = "active | inactive | entered-in-error", type = "token")
1652  public static final String SP_STATUS = "status";
1653  /**
1654   * <b>Fluent Client</b> search parameter constant for <b>status</b>
1655   * <p>
1656   * Description: <b>active | inactive | entered-in-error</b><br>
1657   * Type: <b>token</b><br>
1658   * Path: <b>Substance.status</b><br>
1659   * </p>
1660   */
1661  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(
1662      SP_STATUS);
1663
1664}