All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hl7.fhir.r4.model.MedicationAdministration Maven / Gradle / Ivy

Go to download

Builds the hapi fhir r4. Requires hapi-fhir-base and hapi-fhir-utilities be built first and be excluded from any other poms requiring it.

The newest version!
package org.hl7.fhir.r4.model;

/*
  Copyright (c) 2011+, HL7, Inc.
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without modification, 
  are permitted provided that the following conditions are met:
  
   * Redistributions of source code must retain the above copyright notice, this 
     list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice, 
     this list of conditions and the following disclaimer in the documentation 
     and/or other materials provided with the distribution.
   * Neither the name of HL7 nor the names of its contributors may be used to 
     endorse or promote products derived from this software without specific 
     prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  POSSIBILITY OF SUCH DAMAGE.
  
*/

// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
import java.util.ArrayList;
import java.util.List;

import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.utilities.Utilities;

import ca.uhn.fhir.model.api.annotation.Block;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;

/**
 * Describes the event of a patient consuming or otherwise being administered a
 * medication. This may be as simple as swallowing a tablet or it may be a long
 * running infusion. Related resources tie this event to the authorizing
 * prescription, and the specific encounter between patient and health care
 * practitioner.
 */
@ResourceDef(name = "MedicationAdministration", profile = "http://hl7.org/fhir/StructureDefinition/MedicationAdministration")
public class MedicationAdministration extends DomainResource {

  public enum MedicationAdministrationStatus {
    /**
     * The administration has started but has not yet completed.
     */
    INPROGRESS,
    /**
     * The administration was terminated prior to any impact on the subject (though
     * preparatory actions may have been taken)
     */
    NOTDONE,
    /**
     * Actions implied by the administration have been temporarily halted, but are
     * expected to continue later. May also be called 'suspended'.
     */
    ONHOLD,
    /**
     * All actions that are implied by the administration have occurred.
     */
    COMPLETED,
    /**
     * The administration was entered in error and therefore nullified.
     */
    ENTEREDINERROR,
    /**
     * Actions implied by the administration have been permanently halted, before
     * all of them occurred.
     */
    STOPPED,
    /**
     * The authoring system does not know which of the status values currently
     * applies for this request. Note: This concept is not to be used for 'other' -
     * one of the listed statuses is presumed to apply, it's just not known which
     * one.
     */
    UNKNOWN,
    /**
     * added to help the parsers with the generic types
     */
    NULL;

    public static MedicationAdministrationStatus fromCode(String codeString) throws FHIRException {
      if (codeString == null || "".equals(codeString))
        return null;
      if ("in-progress".equals(codeString))
        return INPROGRESS;
      if ("not-done".equals(codeString))
        return NOTDONE;
      if ("on-hold".equals(codeString))
        return ONHOLD;
      if ("completed".equals(codeString))
        return COMPLETED;
      if ("entered-in-error".equals(codeString))
        return ENTEREDINERROR;
      if ("stopped".equals(codeString))
        return STOPPED;
      if ("unknown".equals(codeString))
        return UNKNOWN;
      if (Configuration.isAcceptInvalidEnums())
        return null;
      else
        throw new FHIRException("Unknown MedicationAdministrationStatus code '" + codeString + "'");
    }

    public String toCode() {
      switch (this) {
      case INPROGRESS:
        return "in-progress";
      case NOTDONE:
        return "not-done";
      case ONHOLD:
        return "on-hold";
      case COMPLETED:
        return "completed";
      case ENTEREDINERROR:
        return "entered-in-error";
      case STOPPED:
        return "stopped";
      case UNKNOWN:
        return "unknown";
      case NULL:
        return null;
      default:
        return "?";
      }
    }

    public String getSystem() {
      switch (this) {
      case INPROGRESS:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case NOTDONE:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case ONHOLD:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case COMPLETED:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case ENTEREDINERROR:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case STOPPED:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case UNKNOWN:
        return "http://terminology.hl7.org/CodeSystem/medication-admin-status";
      case NULL:
        return null;
      default:
        return "?";
      }
    }

    public String getDefinition() {
      switch (this) {
      case INPROGRESS:
        return "The administration has started but has not yet completed.";
      case NOTDONE:
        return "The administration was terminated prior to any impact on the subject (though preparatory actions may have been taken)";
      case ONHOLD:
        return "Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called 'suspended'.";
      case COMPLETED:
        return "All actions that are implied by the administration have occurred.";
      case ENTEREDINERROR:
        return "The administration was entered in error and therefore nullified.";
      case STOPPED:
        return "Actions implied by the administration have been permanently halted, before all of them occurred.";
      case UNKNOWN:
        return "The authoring system does not know which of the status values currently applies for this request. Note: This concept is not to be used for 'other' - one of the listed statuses is presumed to apply, it's just not known which one.";
      case NULL:
        return null;
      default:
        return "?";
      }
    }

    public String getDisplay() {
      switch (this) {
      case INPROGRESS:
        return "In Progress";
      case NOTDONE:
        return "Not Done";
      case ONHOLD:
        return "On Hold";
      case COMPLETED:
        return "Completed";
      case ENTEREDINERROR:
        return "Entered in Error";
      case STOPPED:
        return "Stopped";
      case UNKNOWN:
        return "Unknown";
      case NULL:
        return null;
      default:
        return "?";
      }
    }
  }

  public static class MedicationAdministrationStatusEnumFactory implements EnumFactory {
    public MedicationAdministrationStatus fromCode(String codeString) throws IllegalArgumentException {
      if (codeString == null || "".equals(codeString))
        if (codeString == null || "".equals(codeString))
          return null;
      if ("in-progress".equals(codeString))
        return MedicationAdministrationStatus.INPROGRESS;
      if ("not-done".equals(codeString))
        return MedicationAdministrationStatus.NOTDONE;
      if ("on-hold".equals(codeString))
        return MedicationAdministrationStatus.ONHOLD;
      if ("completed".equals(codeString))
        return MedicationAdministrationStatus.COMPLETED;
      if ("entered-in-error".equals(codeString))
        return MedicationAdministrationStatus.ENTEREDINERROR;
      if ("stopped".equals(codeString))
        return MedicationAdministrationStatus.STOPPED;
      if ("unknown".equals(codeString))
        return MedicationAdministrationStatus.UNKNOWN;
      throw new IllegalArgumentException("Unknown MedicationAdministrationStatus code '" + codeString + "'");
    }

    public Enumeration fromType(PrimitiveType code) throws FHIRException {
      if (code == null)
        return null;
      if (code.isEmpty())
        return new Enumeration(this, MedicationAdministrationStatus.NULL, code);
      String codeString = code.asStringValue();
      if (codeString == null || "".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.NULL, code);
      if ("in-progress".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.INPROGRESS, code);
      if ("not-done".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.NOTDONE, code);
      if ("on-hold".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.ONHOLD, code);
      if ("completed".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.COMPLETED, code);
      if ("entered-in-error".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.ENTEREDINERROR,
            code);
      if ("stopped".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.STOPPED, code);
      if ("unknown".equals(codeString))
        return new Enumeration(this, MedicationAdministrationStatus.UNKNOWN, code);
      throw new FHIRException("Unknown MedicationAdministrationStatus code '" + codeString + "'");
    }

    public String toCode(MedicationAdministrationStatus code) {
      if (code == MedicationAdministrationStatus.INPROGRESS)
        return "in-progress";
      if (code == MedicationAdministrationStatus.NOTDONE)
        return "not-done";
      if (code == MedicationAdministrationStatus.ONHOLD)
        return "on-hold";
      if (code == MedicationAdministrationStatus.COMPLETED)
        return "completed";
      if (code == MedicationAdministrationStatus.ENTEREDINERROR)
        return "entered-in-error";
      if (code == MedicationAdministrationStatus.STOPPED)
        return "stopped";
      if (code == MedicationAdministrationStatus.UNKNOWN)
        return "unknown";
      return "?";
    }

    public String toSystem(MedicationAdministrationStatus code) {
      return code.getSystem();
    }
  }

  @Block()
  public static class MedicationAdministrationPerformerComponent extends BackboneElement
      implements IBaseBackboneElement {
    /**
     * Distinguishes the type of involvement of the performer in the medication
     * administration.
     */
    @Child(name = "function", type = {
        CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Type of performance", formalDefinition = "Distinguishes the type of involvement of the performer in the medication administration.")
    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/med-admin-perform-function")
    protected CodeableConcept function;

    /**
     * Indicates who or what performed the medication administration.
     */
    @Child(name = "actor", type = { Practitioner.class, PractitionerRole.class, Patient.class, RelatedPerson.class,
        Device.class }, order = 2, min = 1, max = 1, modifier = false, summary = true)
    @Description(shortDefinition = "Who performed the medication administration", formalDefinition = "Indicates who or what performed the medication administration.")
    protected Reference actor;

    /**
     * The actual object that is the target of the reference (Indicates who or what
     * performed the medication administration.)
     */
    protected Resource actorTarget;

    private static final long serialVersionUID = 1424001049L;

    /**
     * Constructor
     */
    public MedicationAdministrationPerformerComponent() {
      super();
    }

    /**
     * Constructor
     */
    public MedicationAdministrationPerformerComponent(Reference actor) {
      super();
      this.actor = actor;
    }

    /**
     * @return {@link #function} (Distinguishes the type of involvement of the
     *         performer in the medication administration.)
     */
    public CodeableConcept getFunction() {
      if (this.function == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationPerformerComponent.function");
        else if (Configuration.doAutoCreate())
          this.function = new CodeableConcept(); // cc
      return this.function;
    }

    public boolean hasFunction() {
      return this.function != null && !this.function.isEmpty();
    }

    /**
     * @param value {@link #function} (Distinguishes the type of involvement of the
     *              performer in the medication administration.)
     */
    public MedicationAdministrationPerformerComponent setFunction(CodeableConcept value) {
      this.function = value;
      return this;
    }

    /**
     * @return {@link #actor} (Indicates who or what performed the medication
     *         administration.)
     */
    public Reference getActor() {
      if (this.actor == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationPerformerComponent.actor");
        else if (Configuration.doAutoCreate())
          this.actor = new Reference(); // cc
      return this.actor;
    }

    public boolean hasActor() {
      return this.actor != null && !this.actor.isEmpty();
    }

    /**
     * @param value {@link #actor} (Indicates who or what performed the medication
     *              administration.)
     */
    public MedicationAdministrationPerformerComponent setActor(Reference value) {
      this.actor = value;
      return this;
    }

    /**
     * @return {@link #actor} 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. (Indicates who or what performed
     *         the medication administration.)
     */
    public Resource getActorTarget() {
      return this.actorTarget;
    }

    /**
     * @param value {@link #actor} 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. (Indicates who or
     *              what performed the medication administration.)
     */
    public MedicationAdministrationPerformerComponent setActorTarget(Resource value) {
      this.actorTarget = value;
      return this;
    }

    protected void listChildren(List children) {
      super.listChildren(children);
      children.add(new Property("function", "CodeableConcept",
          "Distinguishes the type of involvement of the performer in the medication administration.", 0, 1, function));
      children.add(new Property("actor", "Reference(Practitioner|PractitionerRole|Patient|RelatedPerson|Device)",
          "Indicates who or what performed the medication administration.", 0, 1, actor));
    }

    @Override
    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
      switch (_hash) {
      case 1380938712:
        /* function */ return new Property("function", "CodeableConcept",
            "Distinguishes the type of involvement of the performer in the medication administration.", 0, 1, function);
      case 92645877:
        /* actor */ return new Property("actor",
            "Reference(Practitioner|PractitionerRole|Patient|RelatedPerson|Device)",
            "Indicates who or what performed the medication administration.", 0, 1, actor);
      default:
        return super.getNamedProperty(_hash, _name, _checkValid);
      }

    }

    @Override
    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
      switch (hash) {
      case 1380938712:
        /* function */ return this.function == null ? new Base[0] : new Base[] { this.function }; // CodeableConcept
      case 92645877:
        /* actor */ return this.actor == null ? new Base[0] : new Base[] { this.actor }; // Reference
      default:
        return super.getProperty(hash, name, checkValid);
      }

    }

    @Override
    public Base setProperty(int hash, String name, Base value) throws FHIRException {
      switch (hash) {
      case 1380938712: // function
        this.function = castToCodeableConcept(value); // CodeableConcept
        return value;
      case 92645877: // actor
        this.actor = castToReference(value); // Reference
        return value;
      default:
        return super.setProperty(hash, name, value);
      }

    }

    @Override
    public Base setProperty(String name, Base value) throws FHIRException {
      if (name.equals("function")) {
        this.function = castToCodeableConcept(value); // CodeableConcept
      } else if (name.equals("actor")) {
        this.actor = castToReference(value); // Reference
      } else
        return super.setProperty(name, value);
      return value;
    }

  @Override
  public void removeChild(String name, Base value) throws FHIRException {
      if (name.equals("function")) {
        this.function = null;
      } else if (name.equals("actor")) {
        this.actor = null;
      } else
        super.removeChild(name, value);
      
    }

    @Override
    public Base makeProperty(int hash, String name) throws FHIRException {
      switch (hash) {
      case 1380938712:
        return getFunction();
      case 92645877:
        return getActor();
      default:
        return super.makeProperty(hash, name);
      }

    }

    @Override
    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
      switch (hash) {
      case 1380938712:
        /* function */ return new String[] { "CodeableConcept" };
      case 92645877:
        /* actor */ return new String[] { "Reference" };
      default:
        return super.getTypesForProperty(hash, name);
      }

    }

    @Override
    public Base addChild(String name) throws FHIRException {
      if (name.equals("function")) {
        this.function = new CodeableConcept();
        return this.function;
      } else if (name.equals("actor")) {
        this.actor = new Reference();
        return this.actor;
      } else
        return super.addChild(name);
    }

    public MedicationAdministrationPerformerComponent copy() {
      MedicationAdministrationPerformerComponent dst = new MedicationAdministrationPerformerComponent();
      copyValues(dst);
      return dst;
    }

    public void copyValues(MedicationAdministrationPerformerComponent dst) {
      super.copyValues(dst);
      dst.function = function == null ? null : function.copy();
      dst.actor = actor == null ? null : actor.copy();
    }

    @Override
    public boolean equalsDeep(Base other_) {
      if (!super.equalsDeep(other_))
        return false;
      if (!(other_ instanceof MedicationAdministrationPerformerComponent))
        return false;
      MedicationAdministrationPerformerComponent o = (MedicationAdministrationPerformerComponent) other_;
      return compareDeep(function, o.function, true) && compareDeep(actor, o.actor, true);
    }

    @Override
    public boolean equalsShallow(Base other_) {
      if (!super.equalsShallow(other_))
        return false;
      if (!(other_ instanceof MedicationAdministrationPerformerComponent))
        return false;
      MedicationAdministrationPerformerComponent o = (MedicationAdministrationPerformerComponent) other_;
      return true;
    }

    public boolean isEmpty() {
      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(function, actor);
    }

    public String fhirType() {
      return "MedicationAdministration.performer";

    }

  }

  @Block()
  public static class MedicationAdministrationDosageComponent extends BackboneElement implements IBaseBackboneElement {
    /**
     * Free text dosage can be used for cases where the dosage administered is too
     * complex to code. When coded dosage is present, the free text dosage may still
     * be present for display to humans.
     * 
     * The dosage instructions should reflect the dosage of the medication that was
     * administered.
     */
    @Child(name = "text", type = { StringType.class }, order = 1, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Free text dosage instructions e.g. SIG", formalDefinition = "Free text dosage can be used for cases where the dosage administered is too complex to code. When coded dosage is present, the free text dosage may still be present for display to humans.\r\rThe dosage instructions should reflect the dosage of the medication that was administered.")
    protected StringType text;

    /**
     * A coded specification of the anatomic site where the medication first entered
     * the body. For example, "left arm".
     */
    @Child(name = "site", type = {
        CodeableConcept.class }, order = 2, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Body site administered to", formalDefinition = "A coded specification of the anatomic site where the medication first entered the body.  For example, \"left arm\".")
    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/approach-site-codes")
    protected CodeableConcept site;

    /**
     * A code specifying the route or physiological path of administration of a
     * therapeutic agent into or onto the patient. For example, topical,
     * intravenous, etc.
     */
    @Child(name = "route", type = {
        CodeableConcept.class }, order = 3, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Path of substance into body", formalDefinition = "A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.")
    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/route-codes")
    protected CodeableConcept route;

    /**
     * A coded value indicating the method by which the medication is intended to be
     * or was introduced into or on the body. This attribute will most often NOT be
     * populated. It is most commonly used for injections. For example, Slow Push,
     * Deep IV.
     */
    @Child(name = "method", type = {
        CodeableConcept.class }, order = 4, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "How drug was administered", formalDefinition = "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.")
    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/administration-method-codes")
    protected CodeableConcept method;

    /**
     * The amount of the medication given at one administration event. Use this
     * value when the administration is essentially an instantaneous event such as a
     * swallowing a tablet or giving an injection.
     */
    @Child(name = "dose", type = { Quantity.class }, order = 5, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Amount of medication per dose", formalDefinition = "The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.")
    protected Quantity dose;

    /**
     * Identifies the speed with which the medication was or will be introduced into
     * the patient. Typically, the rate for an infusion e.g. 100 ml per 1 hour or
     * 100 ml/hr. May also be expressed as a rate per unit of time, e.g. 500 ml per
     * 2 hours. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.
     */
    @Child(name = "rate", type = { Ratio.class,
        Quantity.class }, order = 6, min = 0, max = 1, modifier = false, summary = false)
    @Description(shortDefinition = "Dose quantity per unit of time", formalDefinition = "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.")
    protected Type rate;

    private static final long serialVersionUID = 947835626L;

    /**
     * Constructor
     */
    public MedicationAdministrationDosageComponent() {
      super();
    }

    /**
     * @return {@link #text} (Free text dosage can be used for cases where the
     *         dosage administered is too complex to code. When coded dosage is
     *         present, the free text dosage may still be present for display to
     *         humans.
     * 
     *         The dosage instructions should reflect the dosage of the medication
     *         that was administered.). This is the underlying object with id, value
     *         and extensions. The accessor "getText" gives direct access to the
     *         value
     */
    public StringType getTextElement() {
      if (this.text == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.text");
        else if (Configuration.doAutoCreate())
          this.text = new StringType(); // bb
      return this.text;
    }

    public boolean hasTextElement() {
      return this.text != null && !this.text.isEmpty();
    }

    public boolean hasText() {
      return this.text != null && !this.text.isEmpty();
    }

    /**
     * @param value {@link #text} (Free text dosage can be used for cases where the
     *              dosage administered is too complex to code. When coded dosage is
     *              present, the free text dosage may still be present for display
     *              to humans.
     * 
     *              The dosage instructions should reflect the dosage of the
     *              medication that was administered.). This is the underlying
     *              object with id, value and extensions. The accessor "getText"
     *              gives direct access to the value
     */
    public MedicationAdministrationDosageComponent setTextElement(StringType value) {
      this.text = value;
      return this;
    }

    /**
     * @return Free text dosage can be used for cases where the dosage administered
     *         is too complex to code. When coded dosage is present, the free text
     *         dosage may still be present for display to humans.
     * 
     *         The dosage instructions should reflect the dosage of the medication
     *         that was administered.
     */
    public String getText() {
      return this.text == null ? null : this.text.getValue();
    }

    /**
     * @param value Free text dosage can be used for cases where the dosage
     *              administered is too complex to code. When coded dosage is
     *              present, the free text dosage may still be present for display
     *              to humans.
     * 
     *              The dosage instructions should reflect the dosage of the
     *              medication that was administered.
     */
    public MedicationAdministrationDosageComponent setText(String value) {
      if (Utilities.noString(value))
        this.text = null;
      else {
        if (this.text == null)
          this.text = new StringType();
        this.text.setValue(value);
      }
      return this;
    }

    /**
     * @return {@link #site} (A coded specification of the anatomic site where the
     *         medication first entered the body. For example, "left arm".)
     */
    public CodeableConcept getSite() {
      if (this.site == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.site");
        else if (Configuration.doAutoCreate())
          this.site = new CodeableConcept(); // cc
      return this.site;
    }

    public boolean hasSite() {
      return this.site != null && !this.site.isEmpty();
    }

    /**
     * @param value {@link #site} (A coded specification of the anatomic site where
     *              the medication first entered the body. For example, "left arm".)
     */
    public MedicationAdministrationDosageComponent setSite(CodeableConcept value) {
      this.site = value;
      return this;
    }

    /**
     * @return {@link #route} (A code specifying the route or physiological path of
     *         administration of a therapeutic agent into or onto the patient. For
     *         example, topical, intravenous, etc.)
     */
    public CodeableConcept getRoute() {
      if (this.route == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.route");
        else if (Configuration.doAutoCreate())
          this.route = new CodeableConcept(); // cc
      return this.route;
    }

    public boolean hasRoute() {
      return this.route != null && !this.route.isEmpty();
    }

    /**
     * @param value {@link #route} (A code specifying the route or physiological
     *              path of administration of a therapeutic agent into or onto the
     *              patient. For example, topical, intravenous, etc.)
     */
    public MedicationAdministrationDosageComponent setRoute(CodeableConcept value) {
      this.route = value;
      return this;
    }

    /**
     * @return {@link #method} (A coded value indicating the method by which the
     *         medication is intended to be or was introduced into or on the body.
     *         This attribute will most often NOT be populated. It is most commonly
     *         used for injections. For example, Slow Push, Deep IV.)
     */
    public CodeableConcept getMethod() {
      if (this.method == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.method");
        else if (Configuration.doAutoCreate())
          this.method = new CodeableConcept(); // cc
      return this.method;
    }

    public boolean hasMethod() {
      return this.method != null && !this.method.isEmpty();
    }

    /**
     * @param value {@link #method} (A coded value indicating the method by which
     *              the medication is intended to be or was introduced into or on
     *              the body. This attribute will most often NOT be populated. It is
     *              most commonly used for injections. For example, Slow Push, Deep
     *              IV.)
     */
    public MedicationAdministrationDosageComponent setMethod(CodeableConcept value) {
      this.method = value;
      return this;
    }

    /**
     * @return {@link #dose} (The amount of the medication given at one
     *         administration event. Use this value when the administration is
     *         essentially an instantaneous event such as a swallowing a tablet or
     *         giving an injection.)
     */
    public Quantity getDose() {
      if (this.dose == null)
        if (Configuration.errorOnAutoCreate())
          throw new Error("Attempt to auto-create MedicationAdministrationDosageComponent.dose");
        else if (Configuration.doAutoCreate())
          this.dose = new Quantity(); // cc
      return this.dose;
    }

    public boolean hasDose() {
      return this.dose != null && !this.dose.isEmpty();
    }

    /**
     * @param value {@link #dose} (The amount of the medication given at one
     *              administration event. Use this value when the administration is
     *              essentially an instantaneous event such as a swallowing a tablet
     *              or giving an injection.)
     */
    public MedicationAdministrationDosageComponent setDose(Quantity value) {
      this.dose = value;
      return this;
    }

    /**
     * @return {@link #rate} (Identifies the speed with which the medication was or
     *         will be introduced into the patient. Typically, the rate for an
     *         infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be expressed
     *         as a rate per unit of time, e.g. 500 ml per 2 hours. Other examples:
     *         200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
     */
    public Type getRate() {
      return this.rate;
    }

    /**
     * @return {@link #rate} (Identifies the speed with which the medication was or
     *         will be introduced into the patient. Typically, the rate for an
     *         infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be expressed
     *         as a rate per unit of time, e.g. 500 ml per 2 hours. Other examples:
     *         200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
     */
    public Ratio getRateRatio() throws FHIRException {
      if (this.rate == null)
        this.rate = new Ratio();
      if (!(this.rate instanceof Ratio))
        throw new FHIRException(
            "Type mismatch: the type Ratio was expected, but " + this.rate.getClass().getName() + " was encountered");
      return (Ratio) this.rate;
    }

    public boolean hasRateRatio() {
      return this != null && this.rate instanceof Ratio;
    }

    /**
     * @return {@link #rate} (Identifies the speed with which the medication was or
     *         will be introduced into the patient. Typically, the rate for an
     *         infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be expressed
     *         as a rate per unit of time, e.g. 500 ml per 2 hours. Other examples:
     *         200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
     */
    public Quantity getRateQuantity() throws FHIRException {
      if (this.rate == null)
        this.rate = new Quantity();
      if (!(this.rate instanceof Quantity))
        throw new FHIRException("Type mismatch: the type Quantity was expected, but " + this.rate.getClass().getName()
            + " was encountered");
      return (Quantity) this.rate;
    }

    public boolean hasRateQuantity() {
      return this != null && this.rate instanceof Quantity;
    }

    public boolean hasRate() {
      return this.rate != null && !this.rate.isEmpty();
    }

    /**
     * @param value {@link #rate} (Identifies the speed with which the medication
     *              was or will be introduced into the patient. Typically, the rate
     *              for an infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be
     *              expressed as a rate per unit of time, e.g. 500 ml per 2 hours.
     *              Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8
     *              hours.)
     */
    public MedicationAdministrationDosageComponent setRate(Type value) {
      if (value != null && !(value instanceof Ratio || value instanceof Quantity))
        throw new Error("Not the right type for MedicationAdministration.dosage.rate[x]: " + value.fhirType());
      this.rate = value;
      return this;
    }

    protected void listChildren(List children) {
      super.listChildren(children);
      children.add(new Property("text", "string",
          "Free text dosage can be used for cases where the dosage administered is too complex to code. When coded dosage is present, the free text dosage may still be present for display to humans.\r\rThe dosage instructions should reflect the dosage of the medication that was administered.",
          0, 1, text));
      children.add(new Property("site", "CodeableConcept",
          "A coded specification of the anatomic site where the medication first entered the body.  For example, \"left arm\".",
          0, 1, site));
      children.add(new Property("route", "CodeableConcept",
          "A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.",
          0, 1, route));
      children.add(new Property("method", "CodeableConcept",
          "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.",
          0, 1, method));
      children.add(new Property("dose", "SimpleQuantity",
          "The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.",
          0, 1, dose));
      children.add(new Property("rate[x]", "Ratio|SimpleQuantity",
          "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.",
          0, 1, rate));
    }

    @Override
    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
      switch (_hash) {
      case 3556653:
        /* text */ return new Property("text", "string",
            "Free text dosage can be used for cases where the dosage administered is too complex to code. When coded dosage is present, the free text dosage may still be present for display to humans.\r\rThe dosage instructions should reflect the dosage of the medication that was administered.",
            0, 1, text);
      case 3530567:
        /* site */ return new Property("site", "CodeableConcept",
            "A coded specification of the anatomic site where the medication first entered the body.  For example, \"left arm\".",
            0, 1, site);
      case 108704329:
        /* route */ return new Property("route", "CodeableConcept",
            "A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient.  For example, topical, intravenous, etc.",
            0, 1, route);
      case -1077554975:
        /* method */ return new Property("method", "CodeableConcept",
            "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.  This attribute will most often NOT be populated.  It is most commonly used for injections.  For example, Slow Push, Deep IV.",
            0, 1, method);
      case 3089437:
        /* dose */ return new Property("dose", "SimpleQuantity",
            "The amount of the medication given at one administration event.   Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.",
            0, 1, dose);
      case 983460768:
        /* rate[x] */ return new Property("rate[x]", "Ratio|SimpleQuantity",
            "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.",
            0, 1, rate);
      case 3493088:
        /* rate */ return new Property("rate[x]", "Ratio|SimpleQuantity",
            "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.",
            0, 1, rate);
      case 204021515:
        /* rateRatio */ return new Property("rate[x]", "Ratio|SimpleQuantity",
            "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.",
            0, 1, rate);
      case -1085459061:
        /* rateQuantity */ return new Property("rate[x]", "Ratio|SimpleQuantity",
            "Identifies the speed with which the medication was or will be introduced into the patient.  Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours.  Other examples:  200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.",
            0, 1, rate);
      default:
        return super.getNamedProperty(_hash, _name, _checkValid);
      }

    }

    @Override
    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
      switch (hash) {
      case 3556653:
        /* text */ return this.text == null ? new Base[0] : new Base[] { this.text }; // StringType
      case 3530567:
        /* site */ return this.site == null ? new Base[0] : new Base[] { this.site }; // CodeableConcept
      case 108704329:
        /* route */ return this.route == null ? new Base[0] : new Base[] { this.route }; // CodeableConcept
      case -1077554975:
        /* method */ return this.method == null ? new Base[0] : new Base[] { this.method }; // CodeableConcept
      case 3089437:
        /* dose */ return this.dose == null ? new Base[0] : new Base[] { this.dose }; // Quantity
      case 3493088:
        /* rate */ return this.rate == null ? new Base[0] : new Base[] { this.rate }; // Type
      default:
        return super.getProperty(hash, name, checkValid);
      }

    }

    @Override
    public Base setProperty(int hash, String name, Base value) throws FHIRException {
      switch (hash) {
      case 3556653: // text
        this.text = castToString(value); // StringType
        return value;
      case 3530567: // site
        this.site = castToCodeableConcept(value); // CodeableConcept
        return value;
      case 108704329: // route
        this.route = castToCodeableConcept(value); // CodeableConcept
        return value;
      case -1077554975: // method
        this.method = castToCodeableConcept(value); // CodeableConcept
        return value;
      case 3089437: // dose
        this.dose = castToQuantity(value); // Quantity
        return value;
      case 3493088: // rate
        this.rate = castToType(value); // Type
        return value;
      default:
        return super.setProperty(hash, name, value);
      }

    }

    @Override
    public Base setProperty(String name, Base value) throws FHIRException {
      if (name.equals("text")) {
        this.text = castToString(value); // StringType
      } else if (name.equals("site")) {
        this.site = castToCodeableConcept(value); // CodeableConcept
      } else if (name.equals("route")) {
        this.route = castToCodeableConcept(value); // CodeableConcept
      } else if (name.equals("method")) {
        this.method = castToCodeableConcept(value); // CodeableConcept
      } else if (name.equals("dose")) {
        this.dose = castToQuantity(value); // Quantity
      } else if (name.equals("rate[x]")) {
        this.rate = castToType(value); // Type
      } else
        return super.setProperty(name, value);
      return value;
    }

  @Override
  public void removeChild(String name, Base value) throws FHIRException {
      if (name.equals("text")) {
        this.text = null;
      } else if (name.equals("site")) {
        this.site = null;
      } else if (name.equals("route")) {
        this.route = null;
      } else if (name.equals("method")) {
        this.method = null;
      } else if (name.equals("dose")) {
        this.dose = null;
      } else if (name.equals("rate[x]")) {
        this.rate = null;
      } else
        super.removeChild(name, value);
      
    }

    @Override
    public Base makeProperty(int hash, String name) throws FHIRException {
      switch (hash) {
      case 3556653:
        return getTextElement();
      case 3530567:
        return getSite();
      case 108704329:
        return getRoute();
      case -1077554975:
        return getMethod();
      case 3089437:
        return getDose();
      case 983460768:
        return getRate();
      case 3493088:
        return getRate();
      default:
        return super.makeProperty(hash, name);
      }

    }

    @Override
    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
      switch (hash) {
      case 3556653:
        /* text */ return new String[] { "string" };
      case 3530567:
        /* site */ return new String[] { "CodeableConcept" };
      case 108704329:
        /* route */ return new String[] { "CodeableConcept" };
      case -1077554975:
        /* method */ return new String[] { "CodeableConcept" };
      case 3089437:
        /* dose */ return new String[] { "SimpleQuantity" };
      case 3493088:
        /* rate */ return new String[] { "Ratio", "SimpleQuantity" };
      default:
        return super.getTypesForProperty(hash, name);
      }

    }

    @Override
    public Base addChild(String name) throws FHIRException {
      if (name.equals("text")) {
        throw new FHIRException("Cannot call addChild on a singleton property MedicationAdministration.text");
      } else if (name.equals("site")) {
        this.site = new CodeableConcept();
        return this.site;
      } else if (name.equals("route")) {
        this.route = new CodeableConcept();
        return this.route;
      } else if (name.equals("method")) {
        this.method = new CodeableConcept();
        return this.method;
      } else if (name.equals("dose")) {
        this.dose = new Quantity();
        return this.dose;
      } else if (name.equals("rateRatio")) {
        this.rate = new Ratio();
        return this.rate;
      } else if (name.equals("rateQuantity")) {
        this.rate = new Quantity();
        return this.rate;
      } else
        return super.addChild(name);
    }

    public MedicationAdministrationDosageComponent copy() {
      MedicationAdministrationDosageComponent dst = new MedicationAdministrationDosageComponent();
      copyValues(dst);
      return dst;
    }

    public void copyValues(MedicationAdministrationDosageComponent dst) {
      super.copyValues(dst);
      dst.text = text == null ? null : text.copy();
      dst.site = site == null ? null : site.copy();
      dst.route = route == null ? null : route.copy();
      dst.method = method == null ? null : method.copy();
      dst.dose = dose == null ? null : dose.copy();
      dst.rate = rate == null ? null : rate.copy();
    }

    @Override
    public boolean equalsDeep(Base other_) {
      if (!super.equalsDeep(other_))
        return false;
      if (!(other_ instanceof MedicationAdministrationDosageComponent))
        return false;
      MedicationAdministrationDosageComponent o = (MedicationAdministrationDosageComponent) other_;
      return compareDeep(text, o.text, true) && compareDeep(site, o.site, true) && compareDeep(route, o.route, true)
          && compareDeep(method, o.method, true) && compareDeep(dose, o.dose, true) && compareDeep(rate, o.rate, true);
    }

    @Override
    public boolean equalsShallow(Base other_) {
      if (!super.equalsShallow(other_))
        return false;
      if (!(other_ instanceof MedicationAdministrationDosageComponent))
        return false;
      MedicationAdministrationDosageComponent o = (MedicationAdministrationDosageComponent) other_;
      return compareValues(text, o.text, true);
    }

    public boolean isEmpty() {
      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(text, site, route, method, dose, rate);
    }

    public String fhirType() {
      return "MedicationAdministration.dosage";

    }

  }

  /**
   * Identifiers associated with this Medication Administration that are defined
   * by business processes and/or used to refer to it when a direct URL reference
   * to the resource itself is not appropriate. They are business identifiers
   * assigned to this resource by the performer or other systems and remain
   * constant as the resource is updated and propagates from server to server.
   */
  @Child(name = "identifier", type = {
      Identifier.class }, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "External identifier", formalDefinition = "Identifiers associated with this Medication Administration that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. They are business identifiers assigned to this resource by the performer or other systems and remain constant as the resource is updated and propagates from server to server.")
  protected List identifier;

  /**
   * A protocol, guideline, orderset, or other definition that was adhered to in
   * whole or in part by this event.
   */
  @Child(name = "instantiates", type = {
      UriType.class }, order = 1, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
  @Description(shortDefinition = "Instantiates protocol or definition", formalDefinition = "A protocol, guideline, orderset, or other definition that was adhered to in whole or in part by this event.")
  protected List instantiates;

  /**
   * A larger event of which this particular event is a component or step.
   */
  @Child(name = "partOf", type = { MedicationAdministration.class,
      Procedure.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
  @Description(shortDefinition = "Part of referenced event", formalDefinition = "A larger event of which this particular event is a component or step.")
  protected List partOf;
  /**
   * The actual objects that are the target of the reference (A larger event of
   * which this particular event is a component or step.)
   */
  protected List partOfTarget;

  /**
   * Will generally be set to show that the administration has been completed. For
   * some long running administrations such as infusions, it is possible for an
   * administration to be started but not completed or it may be paused while some
   * other process is under way.
   */
  @Child(name = "status", type = { CodeType.class }, order = 3, min = 1, max = 1, modifier = true, summary = true)
  @Description(shortDefinition = "in-progress | not-done | on-hold | completed | entered-in-error | stopped | unknown", formalDefinition = "Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions, it is possible for an administration to be started but not completed or it may be paused while some other process is under way.")
  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/medication-admin-status")
  protected Enumeration status;

  /**
   * A code indicating why the administration was not performed.
   */
  @Child(name = "statusReason", type = {
      CodeableConcept.class }, order = 4, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Reason administration not performed", formalDefinition = "A code indicating why the administration was not performed.")
  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/reason-medication-not-given-codes")
  protected List statusReason;

  /**
   * Indicates where the medication is expected to be consumed or administered.
   */
  @Child(name = "category", type = {
      CodeableConcept.class }, order = 5, min = 0, max = 1, modifier = false, summary = false)
  @Description(shortDefinition = "Type of medication usage", formalDefinition = "Indicates where the medication is expected to be consumed or administered.")
  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/medication-admin-category")
  protected CodeableConcept category;

  /**
   * Identifies the medication that was administered. This is either a link to a
   * resource representing the details of the medication or a simple attribute
   * carrying a code that identifies the medication from a known list of
   * medications.
   */
  @Child(name = "medication", type = { CodeableConcept.class,
      Medication.class }, order = 6, min = 1, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "What was administered", formalDefinition = "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.")
  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/medication-codes")
  protected Type medication;

  /**
   * The person or animal or group receiving the medication.
   */
  @Child(name = "subject", type = { Patient.class,
      Group.class }, order = 7, min = 1, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Who received medication", formalDefinition = "The person or animal or group receiving the medication.")
  protected Reference subject;

  /**
   * The actual object that is the target of the reference (The person or animal
   * or group receiving the medication.)
   */
  protected Resource subjectTarget;

  /**
   * The visit, admission, or other contact between patient and health care
   * provider during which the medication administration was performed.
   */
  @Child(name = "context", type = { Encounter.class,
      EpisodeOfCare.class }, order = 8, min = 0, max = 1, modifier = false, summary = false)
  @Description(shortDefinition = "Encounter or Episode of Care administered as part of", formalDefinition = "The visit, admission, or other contact between patient and health care provider during which the medication administration was performed.")
  protected Reference context;

  /**
   * The actual object that is the target of the reference (The visit, admission,
   * or other contact between patient and health care provider during which the
   * medication administration was performed.)
   */
  protected Resource contextTarget;

  /**
   * Additional information (for example, patient height and weight) that supports
   * the administration of the medication.
   */
  @Child(name = "supportingInformation", type = {
      Reference.class }, order = 9, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Additional information to support administration", formalDefinition = "Additional information (for example, patient height and weight) that supports the administration of the medication.")
  protected List supportingInformation;
  /**
   * The actual objects that are the target of the reference (Additional
   * information (for example, patient height and weight) that supports the
   * administration of the medication.)
   */
  protected List supportingInformationTarget;

  /**
   * A specific date/time or interval of time during which the administration took
   * place (or did not take place, when the 'notGiven' attribute is true). For
   * many administrations, such as swallowing a tablet the use of dateTime is more
   * appropriate.
   */
  @Child(name = "effective", type = { DateTimeType.class,
      Period.class }, order = 10, min = 1, max = 1, modifier = false, summary = true)
  @Description(shortDefinition = "Start and end time of administration", formalDefinition = "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.")
  protected Type effective;

  /**
   * Indicates who or what performed the medication administration and how they
   * were involved.
   */
  @Child(name = "performer", type = {}, order = 11, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
  @Description(shortDefinition = "Who performed the medication administration and what they did", formalDefinition = "Indicates who or what performed the medication administration and how they were involved.")
  protected List performer;

  /**
   * A code indicating why the medication was given.
   */
  @Child(name = "reasonCode", type = {
      CodeableConcept.class }, order = 12, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Reason administration performed", formalDefinition = "A code indicating why the medication was given.")
  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/reason-medication-given-codes")
  protected List reasonCode;

  /**
   * Condition or observation that supports why the medication was administered.
   */
  @Child(name = "reasonReference", type = { Condition.class, Observation.class,
      DiagnosticReport.class }, order = 13, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Condition or observation that supports why the medication was administered", formalDefinition = "Condition or observation that supports why the medication was administered.")
  protected List reasonReference;
  /**
   * The actual objects that are the target of the reference (Condition or
   * observation that supports why the medication was administered.)
   */
  protected List reasonReferenceTarget;

  /**
   * The original request, instruction or authority to perform the administration.
   */
  @Child(name = "request", type = {
      MedicationRequest.class }, order = 14, min = 0, max = 1, modifier = false, summary = false)
  @Description(shortDefinition = "Request administration performed against", formalDefinition = "The original request, instruction or authority to perform the administration.")
  protected Reference request;

  /**
   * The actual object that is the target of the reference (The original request,
   * instruction or authority to perform the administration.)
   */
  protected MedicationRequest requestTarget;

  /**
   * The device used in administering the medication to the patient. For example,
   * a particular infusion pump.
   */
  @Child(name = "device", type = {
      Device.class }, order = 15, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Device used to administer", formalDefinition = "The device used in administering the medication to the patient.  For example, a particular infusion pump.")
  protected List device;
  /**
   * The actual objects that are the target of the reference (The device used in
   * administering the medication to the patient. For example, a particular
   * infusion pump.)
   */
  protected List deviceTarget;

  /**
   * Extra information about the medication administration that is not conveyed by
   * the other attributes.
   */
  @Child(name = "note", type = {
      Annotation.class }, order = 16, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "Information about the administration", formalDefinition = "Extra information about the medication administration that is not conveyed by the other attributes.")
  protected List note;

  /**
   * Describes the medication dosage information details e.g. dose, rate, site,
   * route, etc.
   */
  @Child(name = "dosage", type = {}, order = 17, min = 0, max = 1, modifier = false, summary = false)
  @Description(shortDefinition = "Details of how medication was taken", formalDefinition = "Describes the medication dosage information details e.g. dose, rate, site, route, etc.")
  protected MedicationAdministrationDosageComponent dosage;

  /**
   * A summary of the events of interest that have occurred, such as when the
   * administration was verified.
   */
  @Child(name = "eventHistory", type = {
      Provenance.class }, order = 18, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
  @Description(shortDefinition = "A list of events of interest in the lifecycle", formalDefinition = "A summary of the events of interest that have occurred, such as when the administration was verified.")
  protected List eventHistory;
  /**
   * The actual objects that are the target of the reference (A summary of the
   * events of interest that have occurred, such as when the administration was
   * verified.)
   */
  protected List eventHistoryTarget;

  private static final long serialVersionUID = 463158971L;

  /**
   * Constructor
   */
  public MedicationAdministration() {
    super();
  }

  /**
   * Constructor
   */
  public MedicationAdministration(Enumeration status, Type medication,
      Reference subject, Type effective) {
    super();
    this.status = status;
    this.medication = medication;
    this.subject = subject;
    this.effective = effective;
  }

  /**
   * @return {@link #identifier} (Identifiers associated with this Medication
   *         Administration that are defined by business processes and/or used to
   *         refer to it when a direct URL reference to the resource itself is not
   *         appropriate. They are business identifiers assigned to this resource
   *         by the performer or other systems and remain constant as the resource
   *         is updated and propagates from server to server.)
   */
  public List getIdentifier() {
    if (this.identifier == null)
      this.identifier = new ArrayList();
    return this.identifier;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setIdentifier(List theIdentifier) {
    this.identifier = theIdentifier;
    return this;
  }

  public boolean hasIdentifier() {
    if (this.identifier == null)
      return false;
    for (Identifier item : this.identifier)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Identifier addIdentifier() { // 3
    Identifier t = new Identifier();
    if (this.identifier == null)
      this.identifier = new ArrayList();
    this.identifier.add(t);
    return t;
  }

  public MedicationAdministration addIdentifier(Identifier t) { // 3
    if (t == null)
      return this;
    if (this.identifier == null)
      this.identifier = new ArrayList();
    this.identifier.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #identifier}, creating
   *         it if it does not already exist
   */
  public Identifier getIdentifierFirstRep() {
    if (getIdentifier().isEmpty()) {
      addIdentifier();
    }
    return getIdentifier().get(0);
  }

  /**
   * @return {@link #instantiates} (A protocol, guideline, orderset, or other
   *         definition that was adhered to in whole or in part by this event.)
   */
  public List getInstantiates() {
    if (this.instantiates == null)
      this.instantiates = new ArrayList();
    return this.instantiates;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setInstantiates(List theInstantiates) {
    this.instantiates = theInstantiates;
    return this;
  }

  public boolean hasInstantiates() {
    if (this.instantiates == null)
      return false;
    for (UriType item : this.instantiates)
      if (!item.isEmpty())
        return true;
    return false;
  }

  /**
   * @return {@link #instantiates} (A protocol, guideline, orderset, or other
   *         definition that was adhered to in whole or in part by this event.)
   */
  public UriType addInstantiatesElement() {// 2
    UriType t = new UriType();
    if (this.instantiates == null)
      this.instantiates = new ArrayList();
    this.instantiates.add(t);
    return t;
  }

  /**
   * @param value {@link #instantiates} (A protocol, guideline, orderset, or other
   *              definition that was adhered to in whole or in part by this
   *              event.)
   */
  public MedicationAdministration addInstantiates(String value) { // 1
    UriType t = new UriType();
    t.setValue(value);
    if (this.instantiates == null)
      this.instantiates = new ArrayList();
    this.instantiates.add(t);
    return this;
  }

  /**
   * @param value {@link #instantiates} (A protocol, guideline, orderset, or other
   *              definition that was adhered to in whole or in part by this
   *              event.)
   */
  public boolean hasInstantiates(String value) {
    if (this.instantiates == null)
      return false;
    for (UriType v : this.instantiates)
      if (v.getValue().equals(value)) // uri
        return true;
    return false;
  }

  /**
   * @return {@link #partOf} (A larger event of which this particular event is a
   *         component or step.)
   */
  public List getPartOf() {
    if (this.partOf == null)
      this.partOf = new ArrayList();
    return this.partOf;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setPartOf(List thePartOf) {
    this.partOf = thePartOf;
    return this;
  }

  public boolean hasPartOf() {
    if (this.partOf == null)
      return false;
    for (Reference item : this.partOf)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Reference addPartOf() { // 3
    Reference t = new Reference();
    if (this.partOf == null)
      this.partOf = new ArrayList();
    this.partOf.add(t);
    return t;
  }

  public MedicationAdministration addPartOf(Reference t) { // 3
    if (t == null)
      return this;
    if (this.partOf == null)
      this.partOf = new ArrayList();
    this.partOf.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #partOf}, creating it
   *         if it does not already exist
   */
  public Reference getPartOfFirstRep() {
    if (getPartOf().isEmpty()) {
      addPartOf();
    }
    return getPartOf().get(0);
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public List getPartOfTarget() {
    if (this.partOfTarget == null)
      this.partOfTarget = new ArrayList();
    return this.partOfTarget;
  }

  /**
   * @return {@link #status} (Will generally be set to show that the
   *         administration has been completed. For some long running
   *         administrations such as infusions, it is possible for an
   *         administration to be started but not completed or it may be paused
   *         while some other process is under way.). This is the underlying
   *         object with id, value and extensions. The accessor "getStatus" gives
   *         direct access to the value
   */
  public Enumeration getStatusElement() {
    if (this.status == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.status");
      else if (Configuration.doAutoCreate())
        this.status = new Enumeration(new MedicationAdministrationStatusEnumFactory()); // bb
    return this.status;
  }

  public boolean hasStatusElement() {
    return this.status != null && !this.status.isEmpty();
  }

  public boolean hasStatus() {
    return this.status != null && !this.status.isEmpty();
  }

  /**
   * @param value {@link #status} (Will generally be set to show that the
   *              administration has been completed. For some long running
   *              administrations such as infusions, it is possible for an
   *              administration to be started but not completed or it may be
   *              paused while some other process is under way.). This is the
   *              underlying object with id, value and extensions. The accessor
   *              "getStatus" gives direct access to the value
   */
  public MedicationAdministration setStatusElement(Enumeration value) {
    this.status = value;
    return this;
  }

  /**
   * @return Will generally be set to show that the administration has been
   *         completed. For some long running administrations such as infusions,
   *         it is possible for an administration to be started but not completed
   *         or it may be paused while some other process is under way.
   */
  public MedicationAdministrationStatus getStatus() {
    return this.status == null ? null : this.status.getValue();
  }

  /**
   * @param value Will generally be set to show that the administration has been
   *              completed. For some long running administrations such as
   *              infusions, it is possible for an administration to be started
   *              but not completed or it may be paused while some other process
   *              is under way.
   */
  public MedicationAdministration setStatus(MedicationAdministrationStatus value) {
    if (this.status == null)
      this.status = new Enumeration(new MedicationAdministrationStatusEnumFactory());
    this.status.setValue(value);
    return this;
  }

  /**
   * @return {@link #statusReason} (A code indicating why the administration was
   *         not performed.)
   */
  public List getStatusReason() {
    if (this.statusReason == null)
      this.statusReason = new ArrayList();
    return this.statusReason;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setStatusReason(List theStatusReason) {
    this.statusReason = theStatusReason;
    return this;
  }

  public boolean hasStatusReason() {
    if (this.statusReason == null)
      return false;
    for (CodeableConcept item : this.statusReason)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public CodeableConcept addStatusReason() { // 3
    CodeableConcept t = new CodeableConcept();
    if (this.statusReason == null)
      this.statusReason = new ArrayList();
    this.statusReason.add(t);
    return t;
  }

  public MedicationAdministration addStatusReason(CodeableConcept t) { // 3
    if (t == null)
      return this;
    if (this.statusReason == null)
      this.statusReason = new ArrayList();
    this.statusReason.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #statusReason},
   *         creating it if it does not already exist
   */
  public CodeableConcept getStatusReasonFirstRep() {
    if (getStatusReason().isEmpty()) {
      addStatusReason();
    }
    return getStatusReason().get(0);
  }

  /**
   * @return {@link #category} (Indicates where the medication is expected to be
   *         consumed or administered.)
   */
  public CodeableConcept getCategory() {
    if (this.category == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.category");
      else if (Configuration.doAutoCreate())
        this.category = new CodeableConcept(); // cc
    return this.category;
  }

  public boolean hasCategory() {
    return this.category != null && !this.category.isEmpty();
  }

  /**
   * @param value {@link #category} (Indicates where the medication is expected to
   *              be consumed or administered.)
   */
  public MedicationAdministration setCategory(CodeableConcept value) {
    this.category = value;
    return this;
  }

  /**
   * @return {@link #medication} (Identifies the medication that was administered.
   *         This is either a link to a resource representing the details of the
   *         medication or a simple attribute carrying a code that identifies the
   *         medication from a known list of medications.)
   */
  public Type getMedication() {
    return this.medication;
  }

  /**
   * @return {@link #medication} (Identifies the medication that was administered.
   *         This is either a link to a resource representing the details of the
   *         medication or a simple attribute carrying a code that identifies the
   *         medication from a known list of medications.)
   */
  public CodeableConcept getMedicationCodeableConcept() throws FHIRException {
    if (this.medication == null)
      this.medication = new CodeableConcept();
    if (!(this.medication instanceof CodeableConcept))
      throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "
          + this.medication.getClass().getName() + " was encountered");
    return (CodeableConcept) this.medication;
  }

  public boolean hasMedicationCodeableConcept() {
    return this != null && this.medication instanceof CodeableConcept;
  }

  /**
   * @return {@link #medication} (Identifies the medication that was administered.
   *         This is either a link to a resource representing the details of the
   *         medication or a simple attribute carrying a code that identifies the
   *         medication from a known list of medications.)
   */
  public Reference getMedicationReference() throws FHIRException {
    if (this.medication == null)
      this.medication = new Reference();
    if (!(this.medication instanceof Reference))
      throw new FHIRException("Type mismatch: the type Reference was expected, but "
          + this.medication.getClass().getName() + " was encountered");
    return (Reference) this.medication;
  }

  public boolean hasMedicationReference() {
    return this != null && this.medication instanceof Reference;
  }

  public boolean hasMedication() {
    return this.medication != null && !this.medication.isEmpty();
  }

  /**
   * @param value {@link #medication} (Identifies the medication that was
   *              administered. This is either a link to a resource representing
   *              the details of the medication or a simple attribute carrying a
   *              code that identifies the medication from a known list of
   *              medications.)
   */
  public MedicationAdministration setMedication(Type value) {
    if (value != null && !(value instanceof CodeableConcept || value instanceof Reference))
      throw new Error("Not the right type for MedicationAdministration.medication[x]: " + value.fhirType());
    this.medication = value;
    return this;
  }

  /**
   * @return {@link #subject} (The person or animal or group receiving the
   *         medication.)
   */
  public Reference getSubject() {
    if (this.subject == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.subject");
      else if (Configuration.doAutoCreate())
        this.subject = new Reference(); // cc
    return this.subject;
  }

  public boolean hasSubject() {
    return this.subject != null && !this.subject.isEmpty();
  }

  /**
   * @param value {@link #subject} (The person or animal or group receiving the
   *              medication.)
   */
  public MedicationAdministration setSubject(Reference value) {
    this.subject = value;
    return this;
  }

  /**
   * @return {@link #subject} 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. (The person or animal
   *         or group receiving the medication.)
   */
  public Resource getSubjectTarget() {
    return this.subjectTarget;
  }

  /**
   * @param value {@link #subject} 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. (The person or
   *              animal or group receiving the medication.)
   */
  public MedicationAdministration setSubjectTarget(Resource value) {
    this.subjectTarget = value;
    return this;
  }

  /**
   * @return {@link #context} (The visit, admission, or other contact between
   *         patient and health care provider during which the medication
   *         administration was performed.)
   */
  public Reference getContext() {
    if (this.context == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.context");
      else if (Configuration.doAutoCreate())
        this.context = new Reference(); // cc
    return this.context;
  }

  public boolean hasContext() {
    return this.context != null && !this.context.isEmpty();
  }

  /**
   * @param value {@link #context} (The visit, admission, or other contact between
   *              patient and health care provider during which the medication
   *              administration was performed.)
   */
  public MedicationAdministration setContext(Reference value) {
    this.context = value;
    return this;
  }

  /**
   * @return {@link #context} 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. (The visit, admission,
   *         or other contact between patient and health care provider during
   *         which the medication administration was performed.)
   */
  public Resource getContextTarget() {
    return this.contextTarget;
  }

  /**
   * @param value {@link #context} 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. (The visit,
   *              admission, or other contact between patient and health care
   *              provider during which the medication administration was
   *              performed.)
   */
  public MedicationAdministration setContextTarget(Resource value) {
    this.contextTarget = value;
    return this;
  }

  /**
   * @return {@link #supportingInformation} (Additional information (for example,
   *         patient height and weight) that supports the administration of the
   *         medication.)
   */
  public List getSupportingInformation() {
    if (this.supportingInformation == null)
      this.supportingInformation = new ArrayList();
    return this.supportingInformation;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setSupportingInformation(List theSupportingInformation) {
    this.supportingInformation = theSupportingInformation;
    return this;
  }

  public boolean hasSupportingInformation() {
    if (this.supportingInformation == null)
      return false;
    for (Reference item : this.supportingInformation)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Reference addSupportingInformation() { // 3
    Reference t = new Reference();
    if (this.supportingInformation == null)
      this.supportingInformation = new ArrayList();
    this.supportingInformation.add(t);
    return t;
  }

  public MedicationAdministration addSupportingInformation(Reference t) { // 3
    if (t == null)
      return this;
    if (this.supportingInformation == null)
      this.supportingInformation = new ArrayList();
    this.supportingInformation.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field
   *         {@link #supportingInformation}, creating it if it does not already
   *         exist
   */
  public Reference getSupportingInformationFirstRep() {
    if (getSupportingInformation().isEmpty()) {
      addSupportingInformation();
    }
    return getSupportingInformation().get(0);
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public List getSupportingInformationTarget() {
    if (this.supportingInformationTarget == null)
      this.supportingInformationTarget = new ArrayList();
    return this.supportingInformationTarget;
  }

  /**
   * @return {@link #effective} (A specific date/time or interval of time during
   *         which the administration took place (or did not take place, when the
   *         'notGiven' attribute is true). For many administrations, such as
   *         swallowing a tablet the use of dateTime is more appropriate.)
   */
  public Type getEffective() {
    return this.effective;
  }

  /**
   * @return {@link #effective} (A specific date/time or interval of time during
   *         which the administration took place (or did not take place, when the
   *         'notGiven' attribute is true). For many administrations, such as
   *         swallowing a tablet the use of dateTime is more appropriate.)
   */
  public DateTimeType getEffectiveDateTimeType() throws FHIRException {
    if (this.effective == null)
      this.effective = new DateTimeType();
    if (!(this.effective instanceof DateTimeType))
      throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "
          + this.effective.getClass().getName() + " was encountered");
    return (DateTimeType) this.effective;
  }

  public boolean hasEffectiveDateTimeType() {
    return this != null && this.effective instanceof DateTimeType;
  }

  /**
   * @return {@link #effective} (A specific date/time or interval of time during
   *         which the administration took place (or did not take place, when the
   *         'notGiven' attribute is true). For many administrations, such as
   *         swallowing a tablet the use of dateTime is more appropriate.)
   */
  public Period getEffectivePeriod() throws FHIRException {
    if (this.effective == null)
      this.effective = new Period();
    if (!(this.effective instanceof Period))
      throw new FHIRException("Type mismatch: the type Period was expected, but " + this.effective.getClass().getName()
          + " was encountered");
    return (Period) this.effective;
  }

  public boolean hasEffectivePeriod() {
    return this != null && this.effective instanceof Period;
  }

  public boolean hasEffective() {
    return this.effective != null && !this.effective.isEmpty();
  }

  /**
   * @param value {@link #effective} (A specific date/time or interval of time
   *              during which the administration took place (or did not take
   *              place, when the 'notGiven' attribute is true). For many
   *              administrations, such as swallowing a tablet the use of dateTime
   *              is more appropriate.)
   */
  public MedicationAdministration setEffective(Type value) {
    if (value != null && !(value instanceof DateTimeType || value instanceof Period))
      throw new Error("Not the right type for MedicationAdministration.effective[x]: " + value.fhirType());
    this.effective = value;
    return this;
  }

  /**
   * @return {@link #performer} (Indicates who or what performed the medication
   *         administration and how they were involved.)
   */
  public List getPerformer() {
    if (this.performer == null)
      this.performer = new ArrayList();
    return this.performer;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setPerformer(List thePerformer) {
    this.performer = thePerformer;
    return this;
  }

  public boolean hasPerformer() {
    if (this.performer == null)
      return false;
    for (MedicationAdministrationPerformerComponent item : this.performer)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public MedicationAdministrationPerformerComponent addPerformer() { // 3
    MedicationAdministrationPerformerComponent t = new MedicationAdministrationPerformerComponent();
    if (this.performer == null)
      this.performer = new ArrayList();
    this.performer.add(t);
    return t;
  }

  public MedicationAdministration addPerformer(MedicationAdministrationPerformerComponent t) { // 3
    if (t == null)
      return this;
    if (this.performer == null)
      this.performer = new ArrayList();
    this.performer.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #performer}, creating
   *         it if it does not already exist
   */
  public MedicationAdministrationPerformerComponent getPerformerFirstRep() {
    if (getPerformer().isEmpty()) {
      addPerformer();
    }
    return getPerformer().get(0);
  }

  /**
   * @return {@link #reasonCode} (A code indicating why the medication was given.)
   */
  public List getReasonCode() {
    if (this.reasonCode == null)
      this.reasonCode = new ArrayList();
    return this.reasonCode;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setReasonCode(List theReasonCode) {
    this.reasonCode = theReasonCode;
    return this;
  }

  public boolean hasReasonCode() {
    if (this.reasonCode == null)
      return false;
    for (CodeableConcept item : this.reasonCode)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public CodeableConcept addReasonCode() { // 3
    CodeableConcept t = new CodeableConcept();
    if (this.reasonCode == null)
      this.reasonCode = new ArrayList();
    this.reasonCode.add(t);
    return t;
  }

  public MedicationAdministration addReasonCode(CodeableConcept t) { // 3
    if (t == null)
      return this;
    if (this.reasonCode == null)
      this.reasonCode = new ArrayList();
    this.reasonCode.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #reasonCode}, creating
   *         it if it does not already exist
   */
  public CodeableConcept getReasonCodeFirstRep() {
    if (getReasonCode().isEmpty()) {
      addReasonCode();
    }
    return getReasonCode().get(0);
  }

  /**
   * @return {@link #reasonReference} (Condition or observation that supports why
   *         the medication was administered.)
   */
  public List getReasonReference() {
    if (this.reasonReference == null)
      this.reasonReference = new ArrayList();
    return this.reasonReference;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setReasonReference(List theReasonReference) {
    this.reasonReference = theReasonReference;
    return this;
  }

  public boolean hasReasonReference() {
    if (this.reasonReference == null)
      return false;
    for (Reference item : this.reasonReference)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Reference addReasonReference() { // 3
    Reference t = new Reference();
    if (this.reasonReference == null)
      this.reasonReference = new ArrayList();
    this.reasonReference.add(t);
    return t;
  }

  public MedicationAdministration addReasonReference(Reference t) { // 3
    if (t == null)
      return this;
    if (this.reasonReference == null)
      this.reasonReference = new ArrayList();
    this.reasonReference.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #reasonReference},
   *         creating it if it does not already exist
   */
  public Reference getReasonReferenceFirstRep() {
    if (getReasonReference().isEmpty()) {
      addReasonReference();
    }
    return getReasonReference().get(0);
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public List getReasonReferenceTarget() {
    if (this.reasonReferenceTarget == null)
      this.reasonReferenceTarget = new ArrayList();
    return this.reasonReferenceTarget;
  }

  /**
   * @return {@link #request} (The original request, instruction or authority to
   *         perform the administration.)
   */
  public Reference getRequest() {
    if (this.request == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.request");
      else if (Configuration.doAutoCreate())
        this.request = new Reference(); // cc
    return this.request;
  }

  public boolean hasRequest() {
    return this.request != null && !this.request.isEmpty();
  }

  /**
   * @param value {@link #request} (The original request, instruction or authority
   *              to perform the administration.)
   */
  public MedicationAdministration setRequest(Reference value) {
    this.request = value;
    return this;
  }

  /**
   * @return {@link #request} 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. (The original request,
   *         instruction or authority to perform the administration.)
   */
  public MedicationRequest getRequestTarget() {
    if (this.requestTarget == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.request");
      else if (Configuration.doAutoCreate())
        this.requestTarget = new MedicationRequest(); // aa
    return this.requestTarget;
  }

  /**
   * @param value {@link #request} 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. (The original
   *              request, instruction or authority to perform the
   *              administration.)
   */
  public MedicationAdministration setRequestTarget(MedicationRequest value) {
    this.requestTarget = value;
    return this;
  }

  /**
   * @return {@link #device} (The device used in administering the medication to
   *         the patient. For example, a particular infusion pump.)
   */
  public List getDevice() {
    if (this.device == null)
      this.device = new ArrayList();
    return this.device;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setDevice(List theDevice) {
    this.device = theDevice;
    return this;
  }

  public boolean hasDevice() {
    if (this.device == null)
      return false;
    for (Reference item : this.device)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Reference addDevice() { // 3
    Reference t = new Reference();
    if (this.device == null)
      this.device = new ArrayList();
    this.device.add(t);
    return t;
  }

  public MedicationAdministration addDevice(Reference t) { // 3
    if (t == null)
      return this;
    if (this.device == null)
      this.device = new ArrayList();
    this.device.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #device}, creating it
   *         if it does not already exist
   */
  public Reference getDeviceFirstRep() {
    if (getDevice().isEmpty()) {
      addDevice();
    }
    return getDevice().get(0);
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public List getDeviceTarget() {
    if (this.deviceTarget == null)
      this.deviceTarget = new ArrayList();
    return this.deviceTarget;
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public Device addDeviceTarget() {
    Device r = new Device();
    if (this.deviceTarget == null)
      this.deviceTarget = new ArrayList();
    this.deviceTarget.add(r);
    return r;
  }

  /**
   * @return {@link #note} (Extra information about the medication administration
   *         that is not conveyed by the other attributes.)
   */
  public List getNote() {
    if (this.note == null)
      this.note = new ArrayList();
    return this.note;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setNote(List theNote) {
    this.note = theNote;
    return this;
  }

  public boolean hasNote() {
    if (this.note == null)
      return false;
    for (Annotation item : this.note)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Annotation addNote() { // 3
    Annotation t = new Annotation();
    if (this.note == null)
      this.note = new ArrayList();
    this.note.add(t);
    return t;
  }

  public MedicationAdministration addNote(Annotation t) { // 3
    if (t == null)
      return this;
    if (this.note == null)
      this.note = new ArrayList();
    this.note.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #note}, creating it if
   *         it does not already exist
   */
  public Annotation getNoteFirstRep() {
    if (getNote().isEmpty()) {
      addNote();
    }
    return getNote().get(0);
  }

  /**
   * @return {@link #dosage} (Describes the medication dosage information details
   *         e.g. dose, rate, site, route, etc.)
   */
  public MedicationAdministrationDosageComponent getDosage() {
    if (this.dosage == null)
      if (Configuration.errorOnAutoCreate())
        throw new Error("Attempt to auto-create MedicationAdministration.dosage");
      else if (Configuration.doAutoCreate())
        this.dosage = new MedicationAdministrationDosageComponent(); // cc
    return this.dosage;
  }

  public boolean hasDosage() {
    return this.dosage != null && !this.dosage.isEmpty();
  }

  /**
   * @param value {@link #dosage} (Describes the medication dosage information
   *              details e.g. dose, rate, site, route, etc.)
   */
  public MedicationAdministration setDosage(MedicationAdministrationDosageComponent value) {
    this.dosage = value;
    return this;
  }

  /**
   * @return {@link #eventHistory} (A summary of the events of interest that have
   *         occurred, such as when the administration was verified.)
   */
  public List getEventHistory() {
    if (this.eventHistory == null)
      this.eventHistory = new ArrayList();
    return this.eventHistory;
  }

  /**
   * @return Returns a reference to this for easy method chaining
   */
  public MedicationAdministration setEventHistory(List theEventHistory) {
    this.eventHistory = theEventHistory;
    return this;
  }

  public boolean hasEventHistory() {
    if (this.eventHistory == null)
      return false;
    for (Reference item : this.eventHistory)
      if (!item.isEmpty())
        return true;
    return false;
  }

  public Reference addEventHistory() { // 3
    Reference t = new Reference();
    if (this.eventHistory == null)
      this.eventHistory = new ArrayList();
    this.eventHistory.add(t);
    return t;
  }

  public MedicationAdministration addEventHistory(Reference t) { // 3
    if (t == null)
      return this;
    if (this.eventHistory == null)
      this.eventHistory = new ArrayList();
    this.eventHistory.add(t);
    return this;
  }

  /**
   * @return The first repetition of repeating field {@link #eventHistory},
   *         creating it if it does not already exist
   */
  public Reference getEventHistoryFirstRep() {
    if (getEventHistory().isEmpty()) {
      addEventHistory();
    }
    return getEventHistory().get(0);
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public List getEventHistoryTarget() {
    if (this.eventHistoryTarget == null)
      this.eventHistoryTarget = new ArrayList();
    return this.eventHistoryTarget;
  }

  /**
   * @deprecated Use Reference#setResource(IBaseResource) instead
   */
  @Deprecated
  public Provenance addEventHistoryTarget() {
    Provenance r = new Provenance();
    if (this.eventHistoryTarget == null)
      this.eventHistoryTarget = new ArrayList();
    this.eventHistoryTarget.add(r);
    return r;
  }

  protected void listChildren(List children) {
    super.listChildren(children);
    children.add(new Property("identifier", "Identifier",
        "Identifiers associated with this Medication Administration that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. They are business identifiers assigned to this resource by the performer or other systems and remain constant as the resource is updated and propagates from server to server.",
        0, java.lang.Integer.MAX_VALUE, identifier));
    children.add(new Property("instantiates", "uri",
        "A protocol, guideline, orderset, or other definition that was adhered to in whole or in part by this event.",
        0, java.lang.Integer.MAX_VALUE, instantiates));
    children.add(new Property("partOf", "Reference(MedicationAdministration|Procedure)",
        "A larger event of which this particular event is a component or step.", 0, java.lang.Integer.MAX_VALUE,
        partOf));
    children.add(new Property("status", "code",
        "Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions, it is possible for an administration to be started but not completed or it may be paused while some other process is under way.",
        0, 1, status));
    children.add(new Property("statusReason", "CodeableConcept",
        "A code indicating why the administration was not performed.", 0, java.lang.Integer.MAX_VALUE, statusReason));
    children.add(new Property("category", "CodeableConcept",
        "Indicates where the medication is expected to be consumed or administered.", 0, 1, category));
    children.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)",
        "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.",
        0, 1, medication));
    children.add(new Property("subject", "Reference(Patient|Group)",
        "The person or animal or group receiving the medication.", 0, 1, subject));
    children.add(new Property("context", "Reference(Encounter|EpisodeOfCare)",
        "The visit, admission, or other contact between patient and health care provider during which the medication administration was performed.",
        0, 1, context));
    children.add(new Property("supportingInformation", "Reference(Any)",
        "Additional information (for example, patient height and weight) that supports the administration of the medication.",
        0, java.lang.Integer.MAX_VALUE, supportingInformation));
    children.add(new Property("effective[x]", "dateTime|Period",
        "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.",
        0, 1, effective));
    children.add(new Property("performer", "",
        "Indicates who or what performed the medication administration and how they were involved.", 0,
        java.lang.Integer.MAX_VALUE, performer));
    children.add(new Property("reasonCode", "CodeableConcept", "A code indicating why the medication was given.", 0,
        java.lang.Integer.MAX_VALUE, reasonCode));
    children.add(new Property("reasonReference", "Reference(Condition|Observation|DiagnosticReport)",
        "Condition or observation that supports why the medication was administered.", 0, java.lang.Integer.MAX_VALUE,
        reasonReference));
    children.add(new Property("request", "Reference(MedicationRequest)",
        "The original request, instruction or authority to perform the administration.", 0, 1, request));
    children.add(new Property("device", "Reference(Device)",
        "The device used in administering the medication to the patient.  For example, a particular infusion pump.", 0,
        java.lang.Integer.MAX_VALUE, device));
    children.add(new Property("note", "Annotation",
        "Extra information about the medication administration that is not conveyed by the other attributes.", 0,
        java.lang.Integer.MAX_VALUE, note));
    children.add(new Property("dosage", "",
        "Describes the medication dosage information details e.g. dose, rate, site, route, etc.", 0, 1, dosage));
    children.add(new Property("eventHistory", "Reference(Provenance)",
        "A summary of the events of interest that have occurred, such as when the administration was verified.", 0,
        java.lang.Integer.MAX_VALUE, eventHistory));
  }

  @Override
  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
    switch (_hash) {
    case -1618432855:
      /* identifier */ return new Property("identifier", "Identifier",
          "Identifiers associated with this Medication Administration that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. They are business identifiers assigned to this resource by the performer or other systems and remain constant as the resource is updated and propagates from server to server.",
          0, java.lang.Integer.MAX_VALUE, identifier);
    case -246883639:
      /* instantiates */ return new Property("instantiates", "uri",
          "A protocol, guideline, orderset, or other definition that was adhered to in whole or in part by this event.",
          0, java.lang.Integer.MAX_VALUE, instantiates);
    case -995410646:
      /* partOf */ return new Property("partOf", "Reference(MedicationAdministration|Procedure)",
          "A larger event of which this particular event is a component or step.", 0, java.lang.Integer.MAX_VALUE,
          partOf);
    case -892481550:
      /* status */ return new Property("status", "code",
          "Will generally be set to show that the administration has been completed.  For some long running administrations such as infusions, it is possible for an administration to be started but not completed or it may be paused while some other process is under way.",
          0, 1, status);
    case 2051346646:
      /* statusReason */ return new Property("statusReason", "CodeableConcept",
          "A code indicating why the administration was not performed.", 0, java.lang.Integer.MAX_VALUE, statusReason);
    case 50511102:
      /* category */ return new Property("category", "CodeableConcept",
          "Indicates where the medication is expected to be consumed or administered.", 0, 1, category);
    case 1458402129:
      /* medication[x] */ return new Property("medication[x]", "CodeableConcept|Reference(Medication)",
          "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.",
          0, 1, medication);
    case 1998965455:
      /* medication */ return new Property("medication[x]", "CodeableConcept|Reference(Medication)",
          "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.",
          0, 1, medication);
    case -209845038:
      /* medicationCodeableConcept */ return new Property("medication[x]", "CodeableConcept|Reference(Medication)",
          "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.",
          0, 1, medication);
    case 2104315196:
      /* medicationReference */ return new Property("medication[x]", "CodeableConcept|Reference(Medication)",
          "Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.",
          0, 1, medication);
    case -1867885268:
      /* subject */ return new Property("subject", "Reference(Patient|Group)",
          "The person or animal or group receiving the medication.", 0, 1, subject);
    case 951530927:
      /* context */ return new Property("context", "Reference(Encounter|EpisodeOfCare)",
          "The visit, admission, or other contact between patient and health care provider during which the medication administration was performed.",
          0, 1, context);
    case -1248768647:
      /* supportingInformation */ return new Property("supportingInformation", "Reference(Any)",
          "Additional information (for example, patient height and weight) that supports the administration of the medication.",
          0, java.lang.Integer.MAX_VALUE, supportingInformation);
    case 247104889:
      /* effective[x] */ return new Property("effective[x]", "dateTime|Period",
          "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.",
          0, 1, effective);
    case -1468651097:
      /* effective */ return new Property("effective[x]", "dateTime|Period",
          "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.",
          0, 1, effective);
    case -275306910:
      /* effectiveDateTime */ return new Property("effective[x]", "dateTime|Period",
          "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.",
          0, 1, effective);
    case -403934648:
      /* effectivePeriod */ return new Property("effective[x]", "dateTime|Period",
          "A specific date/time or interval of time during which the administration took place (or did not take place, when the 'notGiven' attribute is true). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.",
          0, 1, effective);
    case 481140686:
      /* performer */ return new Property("performer", "",
          "Indicates who or what performed the medication administration and how they were involved.", 0,
          java.lang.Integer.MAX_VALUE, performer);
    case 722137681:
      /* reasonCode */ return new Property("reasonCode", "CodeableConcept",
          "A code indicating why the medication was given.", 0, java.lang.Integer.MAX_VALUE, reasonCode);
    case -1146218137:
      /* reasonReference */ return new Property("reasonReference", "Reference(Condition|Observation|DiagnosticReport)",
          "Condition or observation that supports why the medication was administered.", 0, java.lang.Integer.MAX_VALUE,
          reasonReference);
    case 1095692943:
      /* request */ return new Property("request", "Reference(MedicationRequest)",
          "The original request, instruction or authority to perform the administration.", 0, 1, request);
    case -1335157162:
      /* device */ return new Property("device", "Reference(Device)",
          "The device used in administering the medication to the patient.  For example, a particular infusion pump.",
          0, java.lang.Integer.MAX_VALUE, device);
    case 3387378:
      /* note */ return new Property("note", "Annotation",
          "Extra information about the medication administration that is not conveyed by the other attributes.", 0,
          java.lang.Integer.MAX_VALUE, note);
    case -1326018889:
      /* dosage */ return new Property("dosage", "",
          "Describes the medication dosage information details e.g. dose, rate, site, route, etc.", 0, 1, dosage);
    case 1835190426:
      /* eventHistory */ return new Property("eventHistory", "Reference(Provenance)",
          "A summary of the events of interest that have occurred, such as when the administration was verified.", 0,
          java.lang.Integer.MAX_VALUE, eventHistory);
    default:
      return super.getNamedProperty(_hash, _name, _checkValid);
    }

  }

  @Override
  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
    switch (hash) {
    case -1618432855:
      /* identifier */ return this.identifier == null ? new Base[0]
          : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
    case -246883639:
      /* instantiates */ return this.instantiates == null ? new Base[0]
          : this.instantiates.toArray(new Base[this.instantiates.size()]); // UriType
    case -995410646:
      /* partOf */ return this.partOf == null ? new Base[0] : this.partOf.toArray(new Base[this.partOf.size()]); // Reference
    case -892481550:
      /* status */ return this.status == null ? new Base[0] : new Base[] { this.status }; // Enumeration
    case 2051346646:
      /* statusReason */ return this.statusReason == null ? new Base[0]
          : this.statusReason.toArray(new Base[this.statusReason.size()]); // CodeableConcept
    case 50511102:
      /* category */ return this.category == null ? new Base[0] : new Base[] { this.category }; // CodeableConcept
    case 1998965455:
      /* medication */ return this.medication == null ? new Base[0] : new Base[] { this.medication }; // Type
    case -1867885268:
      /* subject */ return this.subject == null ? new Base[0] : new Base[] { this.subject }; // Reference
    case 951530927:
      /* context */ return this.context == null ? new Base[0] : new Base[] { this.context }; // Reference
    case -1248768647:
      /* supportingInformation */ return this.supportingInformation == null ? new Base[0]
          : this.supportingInformation.toArray(new Base[this.supportingInformation.size()]); // Reference
    case -1468651097:
      /* effective */ return this.effective == null ? new Base[0] : new Base[] { this.effective }; // Type
    case 481140686:
      /* performer */ return this.performer == null ? new Base[0]
          : this.performer.toArray(new Base[this.performer.size()]); // MedicationAdministrationPerformerComponent
    case 722137681:
      /* reasonCode */ return this.reasonCode == null ? new Base[0]
          : this.reasonCode.toArray(new Base[this.reasonCode.size()]); // CodeableConcept
    case -1146218137:
      /* reasonReference */ return this.reasonReference == null ? new Base[0]
          : this.reasonReference.toArray(new Base[this.reasonReference.size()]); // Reference
    case 1095692943:
      /* request */ return this.request == null ? new Base[0] : new Base[] { this.request }; // Reference
    case -1335157162:
      /* device */ return this.device == null ? new Base[0] : this.device.toArray(new Base[this.device.size()]); // Reference
    case 3387378:
      /* note */ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
    case -1326018889:
      /* dosage */ return this.dosage == null ? new Base[0] : new Base[] { this.dosage }; // MedicationAdministrationDosageComponent
    case 1835190426:
      /* eventHistory */ return this.eventHistory == null ? new Base[0]
          : this.eventHistory.toArray(new Base[this.eventHistory.size()]); // Reference
    default:
      return super.getProperty(hash, name, checkValid);
    }

  }

  @Override
  public Base setProperty(int hash, String name, Base value) throws FHIRException {
    switch (hash) {
    case -1618432855: // identifier
      this.getIdentifier().add(castToIdentifier(value)); // Identifier
      return value;
    case -246883639: // instantiates
      this.getInstantiates().add(castToUri(value)); // UriType
      return value;
    case -995410646: // partOf
      this.getPartOf().add(castToReference(value)); // Reference
      return value;
    case -892481550: // status
      value = new MedicationAdministrationStatusEnumFactory().fromType(castToCode(value));
      this.status = (Enumeration) value; // Enumeration
      return value;
    case 2051346646: // statusReason
      this.getStatusReason().add(castToCodeableConcept(value)); // CodeableConcept
      return value;
    case 50511102: // category
      this.category = castToCodeableConcept(value); // CodeableConcept
      return value;
    case 1998965455: // medication
      this.medication = castToType(value); // Type
      return value;
    case -1867885268: // subject
      this.subject = castToReference(value); // Reference
      return value;
    case 951530927: // context
      this.context = castToReference(value); // Reference
      return value;
    case -1248768647: // supportingInformation
      this.getSupportingInformation().add(castToReference(value)); // Reference
      return value;
    case -1468651097: // effective
      this.effective = castToType(value); // Type
      return value;
    case 481140686: // performer
      this.getPerformer().add((MedicationAdministrationPerformerComponent) value); // MedicationAdministrationPerformerComponent
      return value;
    case 722137681: // reasonCode
      this.getReasonCode().add(castToCodeableConcept(value)); // CodeableConcept
      return value;
    case -1146218137: // reasonReference
      this.getReasonReference().add(castToReference(value)); // Reference
      return value;
    case 1095692943: // request
      this.request = castToReference(value); // Reference
      return value;
    case -1335157162: // device
      this.getDevice().add(castToReference(value)); // Reference
      return value;
    case 3387378: // note
      this.getNote().add(castToAnnotation(value)); // Annotation
      return value;
    case -1326018889: // dosage
      this.dosage = (MedicationAdministrationDosageComponent) value; // MedicationAdministrationDosageComponent
      return value;
    case 1835190426: // eventHistory
      this.getEventHistory().add(castToReference(value)); // Reference
      return value;
    default:
      return super.setProperty(hash, name, value);
    }

  }

  @Override
  public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("identifier")) {
      this.getIdentifier().add(castToIdentifier(value));
    } else if (name.equals("instantiates")) {
      this.getInstantiates().add(castToUri(value));
    } else if (name.equals("partOf")) {
      this.getPartOf().add(castToReference(value));
    } else if (name.equals("status")) {
      value = new MedicationAdministrationStatusEnumFactory().fromType(castToCode(value));
      this.status = (Enumeration) value; // Enumeration
    } else if (name.equals("statusReason")) {
      this.getStatusReason().add(castToCodeableConcept(value));
    } else if (name.equals("category")) {
      this.category = castToCodeableConcept(value); // CodeableConcept
    } else if (name.equals("medication[x]")) {
      this.medication = castToType(value); // Type
    } else if (name.equals("subject")) {
      this.subject = castToReference(value); // Reference
    } else if (name.equals("context")) {
      this.context = castToReference(value); // Reference
    } else if (name.equals("supportingInformation")) {
      this.getSupportingInformation().add(castToReference(value));
    } else if (name.equals("effective[x]")) {
      this.effective = castToType(value); // Type
    } else if (name.equals("performer")) {
      this.getPerformer().add((MedicationAdministrationPerformerComponent) value);
    } else if (name.equals("reasonCode")) {
      this.getReasonCode().add(castToCodeableConcept(value));
    } else if (name.equals("reasonReference")) {
      this.getReasonReference().add(castToReference(value));
    } else if (name.equals("request")) {
      this.request = castToReference(value); // Reference
    } else if (name.equals("device")) {
      this.getDevice().add(castToReference(value));
    } else if (name.equals("note")) {
      this.getNote().add(castToAnnotation(value));
    } else if (name.equals("dosage")) {
      this.dosage = (MedicationAdministrationDosageComponent) value; // MedicationAdministrationDosageComponent
    } else if (name.equals("eventHistory")) {
      this.getEventHistory().add(castToReference(value));
    } else
      return super.setProperty(name, value);
    return value;
  }

  @Override
  public void removeChild(String name, Base value) throws FHIRException {
    if (name.equals("identifier")) {
      this.getIdentifier().remove(castToIdentifier(value));
    } else if (name.equals("instantiates")) {
      this.getInstantiates().remove(castToUri(value));
    } else if (name.equals("partOf")) {
      this.getPartOf().remove(castToReference(value));
    } else if (name.equals("status")) {
      this.status = null;
    } else if (name.equals("statusReason")) {
      this.getStatusReason().remove(castToCodeableConcept(value));
    } else if (name.equals("category")) {
      this.category = null;
    } else if (name.equals("medication[x]")) {
      this.medication = null;
    } else if (name.equals("subject")) {
      this.subject = null;
    } else if (name.equals("context")) {
      this.context = null;
    } else if (name.equals("supportingInformation")) {
      this.getSupportingInformation().remove(castToReference(value));
    } else if (name.equals("effective[x]")) {
      this.effective = null;
    } else if (name.equals("performer")) {
      this.getPerformer().remove((MedicationAdministrationPerformerComponent) value);
    } else if (name.equals("reasonCode")) {
      this.getReasonCode().remove(castToCodeableConcept(value));
    } else if (name.equals("reasonReference")) {
      this.getReasonReference().remove(castToReference(value));
    } else if (name.equals("request")) {
      this.request = null;
    } else if (name.equals("device")) {
      this.getDevice().remove(castToReference(value));
    } else if (name.equals("note")) {
      this.getNote().remove(castToAnnotation(value));
    } else if (name.equals("dosage")) {
      this.dosage = (MedicationAdministrationDosageComponent) value; // MedicationAdministrationDosageComponent
    } else if (name.equals("eventHistory")) {
      this.getEventHistory().remove(castToReference(value));
    } else
      super.removeChild(name, value);
    
  }

  @Override
  public Base makeProperty(int hash, String name) throws FHIRException {
    switch (hash) {
    case -1618432855:
      return addIdentifier();
    case -246883639:
      return addInstantiatesElement();
    case -995410646:
      return addPartOf();
    case -892481550:
      return getStatusElement();
    case 2051346646:
      return addStatusReason();
    case 50511102:
      return getCategory();
    case 1458402129:
      return getMedication();
    case 1998965455:
      return getMedication();
    case -1867885268:
      return getSubject();
    case 951530927:
      return getContext();
    case -1248768647:
      return addSupportingInformation();
    case 247104889:
      return getEffective();
    case -1468651097:
      return getEffective();
    case 481140686:
      return addPerformer();
    case 722137681:
      return addReasonCode();
    case -1146218137:
      return addReasonReference();
    case 1095692943:
      return getRequest();
    case -1335157162:
      return addDevice();
    case 3387378:
      return addNote();
    case -1326018889:
      return getDosage();
    case 1835190426:
      return addEventHistory();
    default:
      return super.makeProperty(hash, name);
    }

  }

  @Override
  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
    switch (hash) {
    case -1618432855:
      /* identifier */ return new String[] { "Identifier" };
    case -246883639:
      /* instantiates */ return new String[] { "uri" };
    case -995410646:
      /* partOf */ return new String[] { "Reference" };
    case -892481550:
      /* status */ return new String[] { "code" };
    case 2051346646:
      /* statusReason */ return new String[] { "CodeableConcept" };
    case 50511102:
      /* category */ return new String[] { "CodeableConcept" };
    case 1998965455:
      /* medication */ return new String[] { "CodeableConcept", "Reference" };
    case -1867885268:
      /* subject */ return new String[] { "Reference" };
    case 951530927:
      /* context */ return new String[] { "Reference" };
    case -1248768647:
      /* supportingInformation */ return new String[] { "Reference" };
    case -1468651097:
      /* effective */ return new String[] { "dateTime", "Period" };
    case 481140686:
      /* performer */ return new String[] {};
    case 722137681:
      /* reasonCode */ return new String[] { "CodeableConcept" };
    case -1146218137:
      /* reasonReference */ return new String[] { "Reference" };
    case 1095692943:
      /* request */ return new String[] { "Reference" };
    case -1335157162:
      /* device */ return new String[] { "Reference" };
    case 3387378:
      /* note */ return new String[] { "Annotation" };
    case -1326018889:
      /* dosage */ return new String[] {};
    case 1835190426:
      /* eventHistory */ return new String[] { "Reference" };
    default:
      return super.getTypesForProperty(hash, name);
    }

  }

  @Override
  public Base addChild(String name) throws FHIRException {
    if (name.equals("identifier")) {
      return addIdentifier();
    } else if (name.equals("instantiates")) {
      throw new FHIRException("Cannot call addChild on a singleton property MedicationAdministration.instantiates");
    } else if (name.equals("partOf")) {
      return addPartOf();
    } else if (name.equals("status")) {
      throw new FHIRException("Cannot call addChild on a singleton property MedicationAdministration.status");
    } else if (name.equals("statusReason")) {
      return addStatusReason();
    } else if (name.equals("category")) {
      this.category = new CodeableConcept();
      return this.category;
    } else if (name.equals("medicationCodeableConcept")) {
      this.medication = new CodeableConcept();
      return this.medication;
    } else if (name.equals("medicationReference")) {
      this.medication = new Reference();
      return this.medication;
    } else if (name.equals("subject")) {
      this.subject = new Reference();
      return this.subject;
    } else if (name.equals("context")) {
      this.context = new Reference();
      return this.context;
    } else if (name.equals("supportingInformation")) {
      return addSupportingInformation();
    } else if (name.equals("effectiveDateTime")) {
      this.effective = new DateTimeType();
      return this.effective;
    } else if (name.equals("effectivePeriod")) {
      this.effective = new Period();
      return this.effective;
    } else if (name.equals("performer")) {
      return addPerformer();
    } else if (name.equals("reasonCode")) {
      return addReasonCode();
    } else if (name.equals("reasonReference")) {
      return addReasonReference();
    } else if (name.equals("request")) {
      this.request = new Reference();
      return this.request;
    } else if (name.equals("device")) {
      return addDevice();
    } else if (name.equals("note")) {
      return addNote();
    } else if (name.equals("dosage")) {
      this.dosage = new MedicationAdministrationDosageComponent();
      return this.dosage;
    } else if (name.equals("eventHistory")) {
      return addEventHistory();
    } else
      return super.addChild(name);
  }

  public String fhirType() {
    return "MedicationAdministration";

  }

  public MedicationAdministration copy() {
    MedicationAdministration dst = new MedicationAdministration();
    copyValues(dst);
    return dst;
  }

  public void copyValues(MedicationAdministration dst) {
    super.copyValues(dst);
    if (identifier != null) {
      dst.identifier = new ArrayList();
      for (Identifier i : identifier)
        dst.identifier.add(i.copy());
    }
    ;
    if (instantiates != null) {
      dst.instantiates = new ArrayList();
      for (UriType i : instantiates)
        dst.instantiates.add(i.copy());
    }
    ;
    if (partOf != null) {
      dst.partOf = new ArrayList();
      for (Reference i : partOf)
        dst.partOf.add(i.copy());
    }
    ;
    dst.status = status == null ? null : status.copy();
    if (statusReason != null) {
      dst.statusReason = new ArrayList();
      for (CodeableConcept i : statusReason)
        dst.statusReason.add(i.copy());
    }
    ;
    dst.category = category == null ? null : category.copy();
    dst.medication = medication == null ? null : medication.copy();
    dst.subject = subject == null ? null : subject.copy();
    dst.context = context == null ? null : context.copy();
    if (supportingInformation != null) {
      dst.supportingInformation = new ArrayList();
      for (Reference i : supportingInformation)
        dst.supportingInformation.add(i.copy());
    }
    ;
    dst.effective = effective == null ? null : effective.copy();
    if (performer != null) {
      dst.performer = new ArrayList();
      for (MedicationAdministrationPerformerComponent i : performer)
        dst.performer.add(i.copy());
    }
    ;
    if (reasonCode != null) {
      dst.reasonCode = new ArrayList();
      for (CodeableConcept i : reasonCode)
        dst.reasonCode.add(i.copy());
    }
    ;
    if (reasonReference != null) {
      dst.reasonReference = new ArrayList();
      for (Reference i : reasonReference)
        dst.reasonReference.add(i.copy());
    }
    ;
    dst.request = request == null ? null : request.copy();
    if (device != null) {
      dst.device = new ArrayList();
      for (Reference i : device)
        dst.device.add(i.copy());
    }
    ;
    if (note != null) {
      dst.note = new ArrayList();
      for (Annotation i : note)
        dst.note.add(i.copy());
    }
    ;
    dst.dosage = dosage == null ? null : dosage.copy();
    if (eventHistory != null) {
      dst.eventHistory = new ArrayList();
      for (Reference i : eventHistory)
        dst.eventHistory.add(i.copy());
    }
    ;
  }

  protected MedicationAdministration typedCopy() {
    return copy();
  }

  @Override
  public boolean equalsDeep(Base other_) {
    if (!super.equalsDeep(other_))
      return false;
    if (!(other_ instanceof MedicationAdministration))
      return false;
    MedicationAdministration o = (MedicationAdministration) other_;
    return compareDeep(identifier, o.identifier, true) && compareDeep(instantiates, o.instantiates, true)
        && compareDeep(partOf, o.partOf, true) && compareDeep(status, o.status, true)
        && compareDeep(statusReason, o.statusReason, true) && compareDeep(category, o.category, true)
        && compareDeep(medication, o.medication, true) && compareDeep(subject, o.subject, true)
        && compareDeep(context, o.context, true) && compareDeep(supportingInformation, o.supportingInformation, true)
        && compareDeep(effective, o.effective, true) && compareDeep(performer, o.performer, true)
        && compareDeep(reasonCode, o.reasonCode, true) && compareDeep(reasonReference, o.reasonReference, true)
        && compareDeep(request, o.request, true) && compareDeep(device, o.device, true)
        && compareDeep(note, o.note, true) && compareDeep(dosage, o.dosage, true)
        && compareDeep(eventHistory, o.eventHistory, true);
  }

  @Override
  public boolean equalsShallow(Base other_) {
    if (!super.equalsShallow(other_))
      return false;
    if (!(other_ instanceof MedicationAdministration))
      return false;
    MedicationAdministration o = (MedicationAdministration) other_;
    return compareValues(instantiates, o.instantiates, true) && compareValues(status, o.status, true);
  }

  public boolean isEmpty() {
    return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, instantiates, partOf, status,
        statusReason, category, medication, subject, context, supportingInformation, effective, performer, reasonCode,
        reasonReference, request, device, note, dosage, eventHistory);
  }

  @Override
  public ResourceType getResourceType() {
    return ResourceType.MedicationAdministration;
  }

  /**
   * Search parameter: identifier
   * 

* Description: Return administrations with this external identifier
* Type: token
* Path: MedicationAdministration.identifier
*

*/ @SearchParamDefinition(name = "identifier", path = "MedicationAdministration.identifier", description = "Return administrations with this external identifier", type = "token") public static final String SP_IDENTIFIER = "identifier"; /** * Fluent Client search parameter constant for identifier *

* Description: Return administrations with this external identifier
* Type: token
* Path: MedicationAdministration.identifier
*

*/ public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam( SP_IDENTIFIER); /** * Search parameter: request *

* Description: The identity of a request to list administrations * from
* Type: reference
* Path: MedicationAdministration.request
*

*/ @SearchParamDefinition(name = "request", path = "MedicationAdministration.request", description = "The identity of a request to list administrations from", type = "reference", target = { MedicationRequest.class }) public static final String SP_REQUEST = "request"; /** * Fluent Client search parameter constant for request *

* Description: The identity of a request to list administrations * from
* Type: reference
* Path: MedicationAdministration.request
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam REQUEST = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_REQUEST); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:request". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_REQUEST = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:request").toLocked(); /** * Search parameter: code *

* Description: Return administrations of this medication code
* Type: token
* Path: MedicationAdministration.medicationCodeableConcept
*

*/ @SearchParamDefinition(name = "code", path = "(MedicationAdministration.medication as CodeableConcept)", description = "Return administrations of this medication code", type = "token") public static final String SP_CODE = "code"; /** * Fluent Client search parameter constant for code *

* Description: Return administrations of this medication code
* Type: token
* Path: MedicationAdministration.medicationCodeableConcept
*

*/ public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam( SP_CODE); /** * Search parameter: performer *

* Description: The identity of the individual who administered the * medication
* Type: reference
* Path: MedicationAdministration.performer.actor
*

*/ @SearchParamDefinition(name = "performer", path = "MedicationAdministration.performer.actor", description = "The identity of the individual who administered the medication", type = "reference", providesMembershipIn = { @ca.uhn.fhir.model.api.annotation.Compartment(name = "Patient"), @ca.uhn.fhir.model.api.annotation.Compartment(name = "Practitioner"), @ca.uhn.fhir.model.api.annotation.Compartment(name = "RelatedPerson") }, target = { Device.class, Patient.class, Practitioner.class, PractitionerRole.class, RelatedPerson.class }) public static final String SP_PERFORMER = "performer"; /** * Fluent Client search parameter constant for performer *

* Description: The identity of the individual who administered the * medication
* Type: reference
* Path: MedicationAdministration.performer.actor
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PERFORMER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_PERFORMER); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:performer". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_PERFORMER = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:performer").toLocked(); /** * Search parameter: subject *

* Description: The identity of the individual or group to list * administrations for
* Type: reference
* Path: MedicationAdministration.subject
*

*/ @SearchParamDefinition(name = "subject", path = "MedicationAdministration.subject", description = "The identity of the individual or group to list administrations for", type = "reference", providesMembershipIn = { @ca.uhn.fhir.model.api.annotation.Compartment(name = "Patient") }, target = { Group.class, Patient.class }) public static final String SP_SUBJECT = "subject"; /** * Fluent Client search parameter constant for subject *

* Description: The identity of the individual or group to list * administrations for
* Type: reference
* Path: MedicationAdministration.subject
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBJECT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_SUBJECT); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:subject". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBJECT = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:subject").toLocked(); /** * Search parameter: medication *

* Description: Return administrations of this medication resource
* Type: reference
* Path: MedicationAdministration.medicationReference
*

*/ @SearchParamDefinition(name = "medication", path = "(MedicationAdministration.medication as Reference)", description = "Return administrations of this medication resource", type = "reference", target = { Medication.class }) public static final String SP_MEDICATION = "medication"; /** * Fluent Client search parameter constant for medication *

* Description: Return administrations of this medication resource
* Type: reference
* Path: MedicationAdministration.medicationReference
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam MEDICATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_MEDICATION); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:medication". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_MEDICATION = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:medication").toLocked(); /** * Search parameter: reason-given *

* Description: Reasons for administering the medication
* Type: token
* Path: MedicationAdministration.reasonCode
*

*/ @SearchParamDefinition(name = "reason-given", path = "MedicationAdministration.reasonCode", description = "Reasons for administering the medication", type = "token") public static final String SP_REASON_GIVEN = "reason-given"; /** * Fluent Client search parameter constant for reason-given *

* Description: Reasons for administering the medication
* Type: token
* Path: MedicationAdministration.reasonCode
*

*/ public static final ca.uhn.fhir.rest.gclient.TokenClientParam REASON_GIVEN = new ca.uhn.fhir.rest.gclient.TokenClientParam( SP_REASON_GIVEN); /** * Search parameter: patient *

* Description: The identity of a patient to list administrations for
* Type: reference
* Path: MedicationAdministration.subject
*

*/ @SearchParamDefinition(name = "patient", path = "MedicationAdministration.subject.where(resolve() is Patient)", description = "The identity of a patient to list administrations for", type = "reference", providesMembershipIn = { @ca.uhn.fhir.model.api.annotation.Compartment(name = "Patient") }, target = { Patient.class }) public static final String SP_PATIENT = "patient"; /** * Fluent Client search parameter constant for patient *

* Description: The identity of a patient to list administrations for
* Type: reference
* Path: MedicationAdministration.subject
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_PATIENT); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:patient". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:patient").toLocked(); /** * Search parameter: effective-time *

* Description: Date administration happened (or did not happen)
* Type: date
* Path: MedicationAdministration.effective[x]
*

*/ @SearchParamDefinition(name = "effective-time", path = "MedicationAdministration.effective", description = "Date administration happened (or did not happen)", type = "date") public static final String SP_EFFECTIVE_TIME = "effective-time"; /** * Fluent Client search parameter constant for effective-time *

* Description: Date administration happened (or did not happen)
* Type: date
* Path: MedicationAdministration.effective[x]
*

*/ public static final ca.uhn.fhir.rest.gclient.DateClientParam EFFECTIVE_TIME = new ca.uhn.fhir.rest.gclient.DateClientParam( SP_EFFECTIVE_TIME); /** * Search parameter: context *

* Description: Return administrations that share this encounter or episode * of care
* Type: reference
* Path: MedicationAdministration.context
*

*/ @SearchParamDefinition(name = "context", path = "MedicationAdministration.context", description = "Return administrations that share this encounter or episode of care", type = "reference", providesMembershipIn = { @ca.uhn.fhir.model.api.annotation.Compartment(name = "Encounter") }, target = { Encounter.class, EpisodeOfCare.class }) public static final String SP_CONTEXT = "context"; /** * Fluent Client search parameter constant for context *

* Description: Return administrations that share this encounter or episode * of care
* Type: reference
* Path: MedicationAdministration.context
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CONTEXT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_CONTEXT); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:context". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_CONTEXT = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:context").toLocked(); /** * Search parameter: reason-not-given *

* Description: Reasons for not administering the medication
* Type: token
* Path: MedicationAdministration.statusReason
*

*/ @SearchParamDefinition(name = "reason-not-given", path = "MedicationAdministration.statusReason", description = "Reasons for not administering the medication", type = "token") public static final String SP_REASON_NOT_GIVEN = "reason-not-given"; /** * Fluent Client search parameter constant for reason-not-given *

* Description: Reasons for not administering the medication
* Type: token
* Path: MedicationAdministration.statusReason
*

*/ public static final ca.uhn.fhir.rest.gclient.TokenClientParam REASON_NOT_GIVEN = new ca.uhn.fhir.rest.gclient.TokenClientParam( SP_REASON_NOT_GIVEN); /** * Search parameter: device *

* Description: Return administrations with this administration device * identity
* Type: reference
* Path: MedicationAdministration.device
*

*/ @SearchParamDefinition(name = "device", path = "MedicationAdministration.device", description = "Return administrations with this administration device identity", type = "reference", providesMembershipIn = { @ca.uhn.fhir.model.api.annotation.Compartment(name = "Device") }, target = { Device.class }) public static final String SP_DEVICE = "device"; /** * Fluent Client search parameter constant for device *

* Description: Return administrations with this administration device * identity
* Type: reference
* Path: MedicationAdministration.device
*

*/ public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam DEVICE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam( SP_DEVICE); /** * Constant for fluent queries to be used to add include statements. Specifies * the path value of "MedicationAdministration:device". */ public static final ca.uhn.fhir.model.api.Include INCLUDE_DEVICE = new ca.uhn.fhir.model.api.Include( "MedicationAdministration:device").toLocked(); /** * Search parameter: status *

* Description: MedicationAdministration event status (for example one of * active/paused/completed/nullified)
* Type: token
* Path: MedicationAdministration.status
*

*/ @SearchParamDefinition(name = "status", path = "MedicationAdministration.status", description = "MedicationAdministration event status (for example one of active/paused/completed/nullified)", type = "token") public static final String SP_STATUS = "status"; /** * Fluent Client search parameter constant for status *

* Description: MedicationAdministration event status (for example one of * active/paused/completed/nullified)
* Type: token
* Path: MedicationAdministration.status
*

*/ public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam( SP_STATUS); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy