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