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