001package org.hl7.fhir.dstu3.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.ResourceDef;
038import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.ChildOrder;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.Block;
043import org.hl7.fhir.instance.model.api.*;
044import org.hl7.fhir.exceptions.FHIRException;
045import org.hl7.fhir.exceptions.FHIRFormatError;
046/**
047 * Indicates that a medication product is to be or has been dispensed for a named person/patient.  This includes a description of the medication product (supply) provided and the instructions for administering the medication.  The medication dispense is the result of a pharmacy system responding to a medication order.
048 */
049@ResourceDef(name="MedicationDispense", profile="http://hl7.org/fhir/StructureDefinition/MedicationDispense")
050public class MedicationDispense extends DomainResource {
051
052    public enum MedicationDispenseStatus {
053        /**
054         * The core event has not started yet, but some staging activities have begun (e.g. initial compounding or packaging of medication). Preparation stages may be tracked for billing purposes.
055         */
056        PREPARATION, 
057        /**
058         * The dispense has started but has not yet completed.
059         */
060        INPROGRESS, 
061        /**
062         * Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called "suspended"
063         */
064        ONHOLD, 
065        /**
066         * All actions that are implied by the dispense have occurred.
067         */
068        COMPLETED, 
069        /**
070         * The dispense was entered in error and therefore nullified.
071         */
072        ENTEREDINERROR, 
073        /**
074         * Actions implied by the dispense have been permanently halted, before all of them occurred.
075         */
076        STOPPED, 
077        /**
078         * added to help the parsers with the generic types
079         */
080        NULL;
081        public static MedicationDispenseStatus fromCode(String codeString) throws FHIRException {
082            if (codeString == null || "".equals(codeString))
083                return null;
084        if ("preparation".equals(codeString))
085          return PREPARATION;
086        if ("in-progress".equals(codeString))
087          return INPROGRESS;
088        if ("on-hold".equals(codeString))
089          return ONHOLD;
090        if ("completed".equals(codeString))
091          return COMPLETED;
092        if ("entered-in-error".equals(codeString))
093          return ENTEREDINERROR;
094        if ("stopped".equals(codeString))
095          return STOPPED;
096        if (Configuration.isAcceptInvalidEnums())
097          return null;
098        else
099          throw new FHIRException("Unknown MedicationDispenseStatus code '"+codeString+"'");
100        }
101        public String toCode() {
102          switch (this) {
103            case PREPARATION: return "preparation";
104            case INPROGRESS: return "in-progress";
105            case ONHOLD: return "on-hold";
106            case COMPLETED: return "completed";
107            case ENTEREDINERROR: return "entered-in-error";
108            case STOPPED: return "stopped";
109            default: return "?";
110          }
111        }
112        public String getSystem() {
113          switch (this) {
114            case PREPARATION: return "http://hl7.org/fhir/medication-dispense-status";
115            case INPROGRESS: return "http://hl7.org/fhir/medication-dispense-status";
116            case ONHOLD: return "http://hl7.org/fhir/medication-dispense-status";
117            case COMPLETED: return "http://hl7.org/fhir/medication-dispense-status";
118            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-dispense-status";
119            case STOPPED: return "http://hl7.org/fhir/medication-dispense-status";
120            default: return "?";
121          }
122        }
123        public String getDefinition() {
124          switch (this) {
125            case PREPARATION: return "The core event has not started yet, but some staging activities have begun (e.g. initial compounding or packaging of medication). Preparation stages may be tracked for billing purposes.";
126            case INPROGRESS: return "The dispense has started but has not yet completed.";
127            case ONHOLD: return "Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called \"suspended\"";
128            case COMPLETED: return "All actions that are implied by the dispense have occurred.";
129            case ENTEREDINERROR: return "The dispense was entered in error and therefore nullified.";
130            case STOPPED: return "Actions implied by the dispense have been permanently halted, before all of them occurred.";
131            default: return "?";
132          }
133        }
134        public String getDisplay() {
135          switch (this) {
136            case PREPARATION: return "Preparation";
137            case INPROGRESS: return "In Progress";
138            case ONHOLD: return "On Hold";
139            case COMPLETED: return "Completed";
140            case ENTEREDINERROR: return "Entered in-Error";
141            case STOPPED: return "Stopped";
142            default: return "?";
143          }
144        }
145    }
146
147  public static class MedicationDispenseStatusEnumFactory implements EnumFactory<MedicationDispenseStatus> {
148    public MedicationDispenseStatus fromCode(String codeString) throws IllegalArgumentException {
149      if (codeString == null || "".equals(codeString))
150            if (codeString == null || "".equals(codeString))
151                return null;
152        if ("preparation".equals(codeString))
153          return MedicationDispenseStatus.PREPARATION;
154        if ("in-progress".equals(codeString))
155          return MedicationDispenseStatus.INPROGRESS;
156        if ("on-hold".equals(codeString))
157          return MedicationDispenseStatus.ONHOLD;
158        if ("completed".equals(codeString))
159          return MedicationDispenseStatus.COMPLETED;
160        if ("entered-in-error".equals(codeString))
161          return MedicationDispenseStatus.ENTEREDINERROR;
162        if ("stopped".equals(codeString))
163          return MedicationDispenseStatus.STOPPED;
164        throw new IllegalArgumentException("Unknown MedicationDispenseStatus code '"+codeString+"'");
165        }
166        public Enumeration<MedicationDispenseStatus> fromType(Base code) throws FHIRException {
167          if (code == null)
168            return null;
169          if (code.isEmpty())
170            return new Enumeration<MedicationDispenseStatus>(this);
171          String codeString = ((PrimitiveType) code).asStringValue();
172          if (codeString == null || "".equals(codeString))
173            return null;
174        if ("preparation".equals(codeString))
175          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.PREPARATION);
176        if ("in-progress".equals(codeString))
177          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.INPROGRESS);
178        if ("on-hold".equals(codeString))
179          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.ONHOLD);
180        if ("completed".equals(codeString))
181          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.COMPLETED);
182        if ("entered-in-error".equals(codeString))
183          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.ENTEREDINERROR);
184        if ("stopped".equals(codeString))
185          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.STOPPED);
186        throw new FHIRException("Unknown MedicationDispenseStatus code '"+codeString+"'");
187        }
188    public String toCode(MedicationDispenseStatus code) {
189      if (code == MedicationDispenseStatus.PREPARATION)
190        return "preparation";
191      if (code == MedicationDispenseStatus.INPROGRESS)
192        return "in-progress";
193      if (code == MedicationDispenseStatus.ONHOLD)
194        return "on-hold";
195      if (code == MedicationDispenseStatus.COMPLETED)
196        return "completed";
197      if (code == MedicationDispenseStatus.ENTEREDINERROR)
198        return "entered-in-error";
199      if (code == MedicationDispenseStatus.STOPPED)
200        return "stopped";
201      return "?";
202      }
203    public String toSystem(MedicationDispenseStatus code) {
204      return code.getSystem();
205      }
206    }
207
208    @Block()
209    public static class MedicationDispensePerformerComponent extends BackboneElement implements IBaseBackboneElement {
210        /**
211         * The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.
212         */
213        @Child(name = "actor", type = {Practitioner.class, Organization.class, Patient.class, Device.class, RelatedPerson.class}, order=1, min=1, max=1, modifier=false, summary=false)
214        @Description(shortDefinition="Individual who was performing", formalDefinition="The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication." )
215        protected Reference actor;
216
217        /**
218         * The actual object that is the target of the reference (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.)
219         */
220        protected Resource actorTarget;
221
222        /**
223         * The organization the device or practitioner was acting on behalf of.
224         */
225        @Child(name = "onBehalfOf", type = {Organization.class}, order=2, min=0, max=1, modifier=false, summary=false)
226        @Description(shortDefinition="Organization organization was acting for", formalDefinition="The organization the device or practitioner was acting on behalf of." )
227        protected Reference onBehalfOf;
228
229        /**
230         * The actual object that is the target of the reference (The organization the device or practitioner was acting on behalf of.)
231         */
232        protected Organization onBehalfOfTarget;
233
234        private static final long serialVersionUID = -488386403L;
235
236    /**
237     * Constructor
238     */
239      public MedicationDispensePerformerComponent() {
240        super();
241      }
242
243    /**
244     * Constructor
245     */
246      public MedicationDispensePerformerComponent(Reference actor) {
247        super();
248        this.actor = actor;
249      }
250
251        /**
252         * @return {@link #actor} (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.)
253         */
254        public Reference getActor() { 
255          if (this.actor == null)
256            if (Configuration.errorOnAutoCreate())
257              throw new Error("Attempt to auto-create MedicationDispensePerformerComponent.actor");
258            else if (Configuration.doAutoCreate())
259              this.actor = new Reference(); // cc
260          return this.actor;
261        }
262
263        public boolean hasActor() { 
264          return this.actor != null && !this.actor.isEmpty();
265        }
266
267        /**
268         * @param value {@link #actor} (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.)
269         */
270        public MedicationDispensePerformerComponent setActor(Reference value)  { 
271          this.actor = value;
272          return this;
273        }
274
275        /**
276         * @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. (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.)
277         */
278        public Resource getActorTarget() { 
279          return this.actorTarget;
280        }
281
282        /**
283         * @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. (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.)
284         */
285        public MedicationDispensePerformerComponent setActorTarget(Resource value) { 
286          this.actorTarget = value;
287          return this;
288        }
289
290        /**
291         * @return {@link #onBehalfOf} (The organization the device or practitioner was acting on behalf of.)
292         */
293        public Reference getOnBehalfOf() { 
294          if (this.onBehalfOf == null)
295            if (Configuration.errorOnAutoCreate())
296              throw new Error("Attempt to auto-create MedicationDispensePerformerComponent.onBehalfOf");
297            else if (Configuration.doAutoCreate())
298              this.onBehalfOf = new Reference(); // cc
299          return this.onBehalfOf;
300        }
301
302        public boolean hasOnBehalfOf() { 
303          return this.onBehalfOf != null && !this.onBehalfOf.isEmpty();
304        }
305
306        /**
307         * @param value {@link #onBehalfOf} (The organization the device or practitioner was acting on behalf of.)
308         */
309        public MedicationDispensePerformerComponent setOnBehalfOf(Reference value)  { 
310          this.onBehalfOf = value;
311          return this;
312        }
313
314        /**
315         * @return {@link #onBehalfOf} 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 organization the device or practitioner was acting on behalf of.)
316         */
317        public Organization getOnBehalfOfTarget() { 
318          if (this.onBehalfOfTarget == null)
319            if (Configuration.errorOnAutoCreate())
320              throw new Error("Attempt to auto-create MedicationDispensePerformerComponent.onBehalfOf");
321            else if (Configuration.doAutoCreate())
322              this.onBehalfOfTarget = new Organization(); // aa
323          return this.onBehalfOfTarget;
324        }
325
326        /**
327         * @param value {@link #onBehalfOf} 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 organization the device or practitioner was acting on behalf of.)
328         */
329        public MedicationDispensePerformerComponent setOnBehalfOfTarget(Organization value) { 
330          this.onBehalfOfTarget = value;
331          return this;
332        }
333
334        protected void listChildren(List<Property> children) {
335          super.listChildren(children);
336          children.add(new Property("actor", "Reference(Practitioner|Organization|Patient|Device|RelatedPerson)", "The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.", 0, 1, actor));
337          children.add(new Property("onBehalfOf", "Reference(Organization)", "The organization the device or practitioner was acting on behalf of.", 0, 1, onBehalfOf));
338        }
339
340        @Override
341        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
342          switch (_hash) {
343          case 92645877: /*actor*/  return new Property("actor", "Reference(Practitioner|Organization|Patient|Device|RelatedPerson)", "The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the medication.", 0, 1, actor);
344          case -14402964: /*onBehalfOf*/  return new Property("onBehalfOf", "Reference(Organization)", "The organization the device or practitioner was acting on behalf of.", 0, 1, onBehalfOf);
345          default: return super.getNamedProperty(_hash, _name, _checkValid);
346          }
347
348        }
349
350      @Override
351      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
352        switch (hash) {
353        case 92645877: /*actor*/ return this.actor == null ? new Base[0] : new Base[] {this.actor}; // Reference
354        case -14402964: /*onBehalfOf*/ return this.onBehalfOf == null ? new Base[0] : new Base[] {this.onBehalfOf}; // Reference
355        default: return super.getProperty(hash, name, checkValid);
356        }
357
358      }
359
360      @Override
361      public Base setProperty(int hash, String name, Base value) throws FHIRException {
362        switch (hash) {
363        case 92645877: // actor
364          this.actor = castToReference(value); // Reference
365          return value;
366        case -14402964: // onBehalfOf
367          this.onBehalfOf = castToReference(value); // Reference
368          return value;
369        default: return super.setProperty(hash, name, value);
370        }
371
372      }
373
374      @Override
375      public Base setProperty(String name, Base value) throws FHIRException {
376        if (name.equals("actor")) {
377          this.actor = castToReference(value); // Reference
378        } else if (name.equals("onBehalfOf")) {
379          this.onBehalfOf = castToReference(value); // Reference
380        } else
381          return super.setProperty(name, value);
382        return value;
383      }
384
385      @Override
386      public Base makeProperty(int hash, String name) throws FHIRException {
387        switch (hash) {
388        case 92645877:  return getActor(); 
389        case -14402964:  return getOnBehalfOf(); 
390        default: return super.makeProperty(hash, name);
391        }
392
393      }
394
395      @Override
396      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
397        switch (hash) {
398        case 92645877: /*actor*/ return new String[] {"Reference"};
399        case -14402964: /*onBehalfOf*/ return new String[] {"Reference"};
400        default: return super.getTypesForProperty(hash, name);
401        }
402
403      }
404
405      @Override
406      public Base addChild(String name) throws FHIRException {
407        if (name.equals("actor")) {
408          this.actor = new Reference();
409          return this.actor;
410        }
411        else if (name.equals("onBehalfOf")) {
412          this.onBehalfOf = new Reference();
413          return this.onBehalfOf;
414        }
415        else
416          return super.addChild(name);
417      }
418
419      public MedicationDispensePerformerComponent copy() {
420        MedicationDispensePerformerComponent dst = new MedicationDispensePerformerComponent();
421        copyValues(dst);
422        dst.actor = actor == null ? null : actor.copy();
423        dst.onBehalfOf = onBehalfOf == null ? null : onBehalfOf.copy();
424        return dst;
425      }
426
427      @Override
428      public boolean equalsDeep(Base other_) {
429        if (!super.equalsDeep(other_))
430          return false;
431        if (!(other_ instanceof MedicationDispensePerformerComponent))
432          return false;
433        MedicationDispensePerformerComponent o = (MedicationDispensePerformerComponent) other_;
434        return compareDeep(actor, o.actor, true) && compareDeep(onBehalfOf, o.onBehalfOf, true);
435      }
436
437      @Override
438      public boolean equalsShallow(Base other_) {
439        if (!super.equalsShallow(other_))
440          return false;
441        if (!(other_ instanceof MedicationDispensePerformerComponent))
442          return false;
443        MedicationDispensePerformerComponent o = (MedicationDispensePerformerComponent) other_;
444        return true;
445      }
446
447      public boolean isEmpty() {
448        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(actor, onBehalfOf);
449      }
450
451  public String fhirType() {
452    return "MedicationDispense.performer";
453
454  }
455
456  }
457
458    @Block()
459    public static class MedicationDispenseSubstitutionComponent extends BackboneElement implements IBaseBackboneElement {
460        /**
461         * True if the dispenser dispensed a different drug or product from what was prescribed.
462         */
463        @Child(name = "wasSubstituted", type = {BooleanType.class}, order=1, min=1, max=1, modifier=false, summary=false)
464        @Description(shortDefinition="Whether a substitution was or was not performed on the dispense", formalDefinition="True if the dispenser dispensed a different drug or product from what was prescribed." )
465        protected BooleanType wasSubstituted;
466
467        /**
468         * A code signifying whether a different drug was dispensed from what was prescribed.
469         */
470        @Child(name = "type", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=false)
471        @Description(shortDefinition="Code signifying whether a different drug was dispensed from what was prescribed", formalDefinition="A code signifying whether a different drug was dispensed from what was prescribed." )
472        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/v3-ActSubstanceAdminSubstitutionCode")
473        protected CodeableConcept type;
474
475        /**
476         * Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.
477         */
478        @Child(name = "reason", type = {CodeableConcept.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
479        @Description(shortDefinition="Why was substitution made", formalDefinition="Indicates the reason for the substitution of (or lack of substitution) from what was prescribed." )
480        @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/v3-SubstanceAdminSubstitutionReason")
481        protected List<CodeableConcept> reason;
482
483        /**
484         * The person or organization that has primary responsibility for the substitution.
485         */
486        @Child(name = "responsibleParty", type = {Practitioner.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
487        @Description(shortDefinition="Who is responsible for the substitution", formalDefinition="The person or organization that has primary responsibility for the substitution." )
488        protected List<Reference> responsibleParty;
489        /**
490         * The actual objects that are the target of the reference (The person or organization that has primary responsibility for the substitution.)
491         */
492        protected List<Practitioner> responsiblePartyTarget;
493
494
495        private static final long serialVersionUID = -728152257L;
496
497    /**
498     * Constructor
499     */
500      public MedicationDispenseSubstitutionComponent() {
501        super();
502      }
503
504    /**
505     * Constructor
506     */
507      public MedicationDispenseSubstitutionComponent(BooleanType wasSubstituted) {
508        super();
509        this.wasSubstituted = wasSubstituted;
510      }
511
512        /**
513         * @return {@link #wasSubstituted} (True if the dispenser dispensed a different drug or product from what was prescribed.). This is the underlying object with id, value and extensions. The accessor "getWasSubstituted" gives direct access to the value
514         */
515        public BooleanType getWasSubstitutedElement() { 
516          if (this.wasSubstituted == null)
517            if (Configuration.errorOnAutoCreate())
518              throw new Error("Attempt to auto-create MedicationDispenseSubstitutionComponent.wasSubstituted");
519            else if (Configuration.doAutoCreate())
520              this.wasSubstituted = new BooleanType(); // bb
521          return this.wasSubstituted;
522        }
523
524        public boolean hasWasSubstitutedElement() { 
525          return this.wasSubstituted != null && !this.wasSubstituted.isEmpty();
526        }
527
528        public boolean hasWasSubstituted() { 
529          return this.wasSubstituted != null && !this.wasSubstituted.isEmpty();
530        }
531
532        /**
533         * @param value {@link #wasSubstituted} (True if the dispenser dispensed a different drug or product from what was prescribed.). This is the underlying object with id, value and extensions. The accessor "getWasSubstituted" gives direct access to the value
534         */
535        public MedicationDispenseSubstitutionComponent setWasSubstitutedElement(BooleanType value) { 
536          this.wasSubstituted = value;
537          return this;
538        }
539
540        /**
541         * @return True if the dispenser dispensed a different drug or product from what was prescribed.
542         */
543        public boolean getWasSubstituted() { 
544          return this.wasSubstituted == null || this.wasSubstituted.isEmpty() ? false : this.wasSubstituted.getValue();
545        }
546
547        /**
548         * @param value True if the dispenser dispensed a different drug or product from what was prescribed.
549         */
550        public MedicationDispenseSubstitutionComponent setWasSubstituted(boolean value) { 
551            if (this.wasSubstituted == null)
552              this.wasSubstituted = new BooleanType();
553            this.wasSubstituted.setValue(value);
554          return this;
555        }
556
557        /**
558         * @return {@link #type} (A code signifying whether a different drug was dispensed from what was prescribed.)
559         */
560        public CodeableConcept getType() { 
561          if (this.type == null)
562            if (Configuration.errorOnAutoCreate())
563              throw new Error("Attempt to auto-create MedicationDispenseSubstitutionComponent.type");
564            else if (Configuration.doAutoCreate())
565              this.type = new CodeableConcept(); // cc
566          return this.type;
567        }
568
569        public boolean hasType() { 
570          return this.type != null && !this.type.isEmpty();
571        }
572
573        /**
574         * @param value {@link #type} (A code signifying whether a different drug was dispensed from what was prescribed.)
575         */
576        public MedicationDispenseSubstitutionComponent setType(CodeableConcept value)  { 
577          this.type = value;
578          return this;
579        }
580
581        /**
582         * @return {@link #reason} (Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.)
583         */
584        public List<CodeableConcept> getReason() { 
585          if (this.reason == null)
586            this.reason = new ArrayList<CodeableConcept>();
587          return this.reason;
588        }
589
590        /**
591         * @return Returns a reference to <code>this</code> for easy method chaining
592         */
593        public MedicationDispenseSubstitutionComponent setReason(List<CodeableConcept> theReason) { 
594          this.reason = theReason;
595          return this;
596        }
597
598        public boolean hasReason() { 
599          if (this.reason == null)
600            return false;
601          for (CodeableConcept item : this.reason)
602            if (!item.isEmpty())
603              return true;
604          return false;
605        }
606
607        public CodeableConcept addReason() { //3
608          CodeableConcept t = new CodeableConcept();
609          if (this.reason == null)
610            this.reason = new ArrayList<CodeableConcept>();
611          this.reason.add(t);
612          return t;
613        }
614
615        public MedicationDispenseSubstitutionComponent addReason(CodeableConcept t) { //3
616          if (t == null)
617            return this;
618          if (this.reason == null)
619            this.reason = new ArrayList<CodeableConcept>();
620          this.reason.add(t);
621          return this;
622        }
623
624        /**
625         * @return The first repetition of repeating field {@link #reason}, creating it if it does not already exist
626         */
627        public CodeableConcept getReasonFirstRep() { 
628          if (getReason().isEmpty()) {
629            addReason();
630          }
631          return getReason().get(0);
632        }
633
634        /**
635         * @return {@link #responsibleParty} (The person or organization that has primary responsibility for the substitution.)
636         */
637        public List<Reference> getResponsibleParty() { 
638          if (this.responsibleParty == null)
639            this.responsibleParty = new ArrayList<Reference>();
640          return this.responsibleParty;
641        }
642
643        /**
644         * @return Returns a reference to <code>this</code> for easy method chaining
645         */
646        public MedicationDispenseSubstitutionComponent setResponsibleParty(List<Reference> theResponsibleParty) { 
647          this.responsibleParty = theResponsibleParty;
648          return this;
649        }
650
651        public boolean hasResponsibleParty() { 
652          if (this.responsibleParty == null)
653            return false;
654          for (Reference item : this.responsibleParty)
655            if (!item.isEmpty())
656              return true;
657          return false;
658        }
659
660        public Reference addResponsibleParty() { //3
661          Reference t = new Reference();
662          if (this.responsibleParty == null)
663            this.responsibleParty = new ArrayList<Reference>();
664          this.responsibleParty.add(t);
665          return t;
666        }
667
668        public MedicationDispenseSubstitutionComponent addResponsibleParty(Reference t) { //3
669          if (t == null)
670            return this;
671          if (this.responsibleParty == null)
672            this.responsibleParty = new ArrayList<Reference>();
673          this.responsibleParty.add(t);
674          return this;
675        }
676
677        /**
678         * @return The first repetition of repeating field {@link #responsibleParty}, creating it if it does not already exist
679         */
680        public Reference getResponsiblePartyFirstRep() { 
681          if (getResponsibleParty().isEmpty()) {
682            addResponsibleParty();
683          }
684          return getResponsibleParty().get(0);
685        }
686
687        /**
688         * @deprecated Use Reference#setResource(IBaseResource) instead
689         */
690        @Deprecated
691        public List<Practitioner> getResponsiblePartyTarget() { 
692          if (this.responsiblePartyTarget == null)
693            this.responsiblePartyTarget = new ArrayList<Practitioner>();
694          return this.responsiblePartyTarget;
695        }
696
697        /**
698         * @deprecated Use Reference#setResource(IBaseResource) instead
699         */
700        @Deprecated
701        public Practitioner addResponsiblePartyTarget() { 
702          Practitioner r = new Practitioner();
703          if (this.responsiblePartyTarget == null)
704            this.responsiblePartyTarget = new ArrayList<Practitioner>();
705          this.responsiblePartyTarget.add(r);
706          return r;
707        }
708
709        protected void listChildren(List<Property> children) {
710          super.listChildren(children);
711          children.add(new Property("wasSubstituted", "boolean", "True if the dispenser dispensed a different drug or product from what was prescribed.", 0, 1, wasSubstituted));
712          children.add(new Property("type", "CodeableConcept", "A code signifying whether a different drug was dispensed from what was prescribed.", 0, 1, type));
713          children.add(new Property("reason", "CodeableConcept", "Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.", 0, java.lang.Integer.MAX_VALUE, reason));
714          children.add(new Property("responsibleParty", "Reference(Practitioner)", "The person or organization that has primary responsibility for the substitution.", 0, java.lang.Integer.MAX_VALUE, responsibleParty));
715        }
716
717        @Override
718        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
719          switch (_hash) {
720          case -592113567: /*wasSubstituted*/  return new Property("wasSubstituted", "boolean", "True if the dispenser dispensed a different drug or product from what was prescribed.", 0, 1, wasSubstituted);
721          case 3575610: /*type*/  return new Property("type", "CodeableConcept", "A code signifying whether a different drug was dispensed from what was prescribed.", 0, 1, type);
722          case -934964668: /*reason*/  return new Property("reason", "CodeableConcept", "Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.", 0, java.lang.Integer.MAX_VALUE, reason);
723          case 1511509392: /*responsibleParty*/  return new Property("responsibleParty", "Reference(Practitioner)", "The person or organization that has primary responsibility for the substitution.", 0, java.lang.Integer.MAX_VALUE, responsibleParty);
724          default: return super.getNamedProperty(_hash, _name, _checkValid);
725          }
726
727        }
728
729      @Override
730      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
731        switch (hash) {
732        case -592113567: /*wasSubstituted*/ return this.wasSubstituted == null ? new Base[0] : new Base[] {this.wasSubstituted}; // BooleanType
733        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // CodeableConcept
734        case -934964668: /*reason*/ return this.reason == null ? new Base[0] : this.reason.toArray(new Base[this.reason.size()]); // CodeableConcept
735        case 1511509392: /*responsibleParty*/ return this.responsibleParty == null ? new Base[0] : this.responsibleParty.toArray(new Base[this.responsibleParty.size()]); // Reference
736        default: return super.getProperty(hash, name, checkValid);
737        }
738
739      }
740
741      @Override
742      public Base setProperty(int hash, String name, Base value) throws FHIRException {
743        switch (hash) {
744        case -592113567: // wasSubstituted
745          this.wasSubstituted = castToBoolean(value); // BooleanType
746          return value;
747        case 3575610: // type
748          this.type = castToCodeableConcept(value); // CodeableConcept
749          return value;
750        case -934964668: // reason
751          this.getReason().add(castToCodeableConcept(value)); // CodeableConcept
752          return value;
753        case 1511509392: // responsibleParty
754          this.getResponsibleParty().add(castToReference(value)); // Reference
755          return value;
756        default: return super.setProperty(hash, name, value);
757        }
758
759      }
760
761      @Override
762      public Base setProperty(String name, Base value) throws FHIRException {
763        if (name.equals("wasSubstituted")) {
764          this.wasSubstituted = castToBoolean(value); // BooleanType
765        } else if (name.equals("type")) {
766          this.type = castToCodeableConcept(value); // CodeableConcept
767        } else if (name.equals("reason")) {
768          this.getReason().add(castToCodeableConcept(value));
769        } else if (name.equals("responsibleParty")) {
770          this.getResponsibleParty().add(castToReference(value));
771        } else
772          return super.setProperty(name, value);
773        return value;
774      }
775
776      @Override
777      public Base makeProperty(int hash, String name) throws FHIRException {
778        switch (hash) {
779        case -592113567:  return getWasSubstitutedElement();
780        case 3575610:  return getType(); 
781        case -934964668:  return addReason(); 
782        case 1511509392:  return addResponsibleParty(); 
783        default: return super.makeProperty(hash, name);
784        }
785
786      }
787
788      @Override
789      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
790        switch (hash) {
791        case -592113567: /*wasSubstituted*/ return new String[] {"boolean"};
792        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
793        case -934964668: /*reason*/ return new String[] {"CodeableConcept"};
794        case 1511509392: /*responsibleParty*/ return new String[] {"Reference"};
795        default: return super.getTypesForProperty(hash, name);
796        }
797
798      }
799
800      @Override
801      public Base addChild(String name) throws FHIRException {
802        if (name.equals("wasSubstituted")) {
803          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.wasSubstituted");
804        }
805        else if (name.equals("type")) {
806          this.type = new CodeableConcept();
807          return this.type;
808        }
809        else if (name.equals("reason")) {
810          return addReason();
811        }
812        else if (name.equals("responsibleParty")) {
813          return addResponsibleParty();
814        }
815        else
816          return super.addChild(name);
817      }
818
819      public MedicationDispenseSubstitutionComponent copy() {
820        MedicationDispenseSubstitutionComponent dst = new MedicationDispenseSubstitutionComponent();
821        copyValues(dst);
822        dst.wasSubstituted = wasSubstituted == null ? null : wasSubstituted.copy();
823        dst.type = type == null ? null : type.copy();
824        if (reason != null) {
825          dst.reason = new ArrayList<CodeableConcept>();
826          for (CodeableConcept i : reason)
827            dst.reason.add(i.copy());
828        };
829        if (responsibleParty != null) {
830          dst.responsibleParty = new ArrayList<Reference>();
831          for (Reference i : responsibleParty)
832            dst.responsibleParty.add(i.copy());
833        };
834        return dst;
835      }
836
837      @Override
838      public boolean equalsDeep(Base other_) {
839        if (!super.equalsDeep(other_))
840          return false;
841        if (!(other_ instanceof MedicationDispenseSubstitutionComponent))
842          return false;
843        MedicationDispenseSubstitutionComponent o = (MedicationDispenseSubstitutionComponent) other_;
844        return compareDeep(wasSubstituted, o.wasSubstituted, true) && compareDeep(type, o.type, true) && compareDeep(reason, o.reason, true)
845           && compareDeep(responsibleParty, o.responsibleParty, true);
846      }
847
848      @Override
849      public boolean equalsShallow(Base other_) {
850        if (!super.equalsShallow(other_))
851          return false;
852        if (!(other_ instanceof MedicationDispenseSubstitutionComponent))
853          return false;
854        MedicationDispenseSubstitutionComponent o = (MedicationDispenseSubstitutionComponent) other_;
855        return compareValues(wasSubstituted, o.wasSubstituted, true);
856      }
857
858      public boolean isEmpty() {
859        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(wasSubstituted, type, reason
860          , responsibleParty);
861      }
862
863  public String fhirType() {
864    return "MedicationDispense.substitution";
865
866  }
867
868  }
869
870    /**
871     * Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.
872     */
873    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
874    @Description(shortDefinition="External identifier", formalDefinition="Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR." )
875    protected List<Identifier> identifier;
876
877    /**
878     * The procedure that the dispense is done because of.
879     */
880    @Child(name = "partOf", type = {Procedure.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
881    @Description(shortDefinition="Event that dispense is part of", formalDefinition="The procedure that the dispense is done because of." )
882    protected List<Reference> partOf;
883    /**
884     * The actual objects that are the target of the reference (The procedure that the dispense is done because of.)
885     */
886    protected List<Procedure> partOfTarget;
887
888
889    /**
890     * A code specifying the state of the set of dispense events.
891     */
892    @Child(name = "status", type = {CodeType.class}, order=2, min=0, max=1, modifier=true, summary=true)
893    @Description(shortDefinition="preparation | in-progress | on-hold | completed | entered-in-error | stopped", formalDefinition="A code specifying the state of the set of dispense events." )
894    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-dispense-status")
895    protected Enumeration<MedicationDispenseStatus> status;
896
897    /**
898     * Indicates type of medication dispense and where the medication is expected to be consumed or administered.
899     */
900    @Child(name = "category", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=false)
901    @Description(shortDefinition="Type of medication dispense", formalDefinition="Indicates type of medication dispense and where the medication is expected to be consumed or administered." )
902    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-dispense-category")
903    protected CodeableConcept category;
904
905    /**
906     * Identifies the medication being 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.
907     */
908    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=4, min=1, max=1, modifier=false, summary=true)
909    @Description(shortDefinition="What medication was supplied", formalDefinition="Identifies the medication being 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." )
910    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/medication-codes")
911    protected Type medication;
912
913    /**
914     * A link to a resource representing the person or the group to whom the medication will be given.
915     */
916    @Child(name = "subject", type = {Patient.class, Group.class}, order=5, min=0, max=1, modifier=false, summary=true)
917    @Description(shortDefinition="Who the dispense is for", formalDefinition="A link to a resource representing the person or the group to whom the medication will be given." )
918    protected Reference subject;
919
920    /**
921     * The actual object that is the target of the reference (A link to a resource representing the person or the group to whom the medication will be given.)
922     */
923    protected Resource subjectTarget;
924
925    /**
926     * The encounter or episode of care that establishes the context for this event.
927     */
928    @Child(name = "context", type = {Encounter.class, EpisodeOfCare.class}, order=6, min=0, max=1, modifier=false, summary=false)
929    @Description(shortDefinition="Encounter / Episode associated with event", formalDefinition="The encounter or episode of care that establishes the context for this event." )
930    protected Reference context;
931
932    /**
933     * The actual object that is the target of the reference (The encounter or episode of care that establishes the context for this event.)
934     */
935    protected Resource contextTarget;
936
937    /**
938     * Additional information that supports the medication being dispensed.
939     */
940    @Child(name = "supportingInformation", type = {Reference.class}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
941    @Description(shortDefinition="Information that supports the dispensing of the medication", formalDefinition="Additional information that supports the medication being dispensed." )
942    protected List<Reference> supportingInformation;
943    /**
944     * The actual objects that are the target of the reference (Additional information that supports the medication being dispensed.)
945     */
946    protected List<Resource> supportingInformationTarget;
947
948
949    /**
950     * Indicates who or what performed the event.  It should be assumed that the performer is the dispenser of the medication.
951     */
952    @Child(name = "performer", type = {}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
953    @Description(shortDefinition="Who performed event", formalDefinition="Indicates who or what performed the event.  It should be assumed that the performer is the dispenser of the medication." )
954    protected List<MedicationDispensePerformerComponent> performer;
955
956    /**
957     * Indicates the medication order that is being dispensed against.
958     */
959    @Child(name = "authorizingPrescription", type = {MedicationRequest.class}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
960    @Description(shortDefinition="Medication order that authorizes the dispense", formalDefinition="Indicates the medication order that is being dispensed against." )
961    protected List<Reference> authorizingPrescription;
962    /**
963     * The actual objects that are the target of the reference (Indicates the medication order that is being dispensed against.)
964     */
965    protected List<MedicationRequest> authorizingPrescriptionTarget;
966
967
968    /**
969     * Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.
970     */
971    @Child(name = "type", type = {CodeableConcept.class}, order=10, min=0, max=1, modifier=false, summary=false)
972    @Description(shortDefinition="Trial fill, partial fill, emergency fill, etc.", formalDefinition="Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc." )
973    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/v3-ActPharmacySupplyType")
974    protected CodeableConcept type;
975
976    /**
977     * The amount of medication that has been dispensed. Includes unit of measure.
978     */
979    @Child(name = "quantity", type = {SimpleQuantity.class}, order=11, min=0, max=1, modifier=false, summary=false)
980    @Description(shortDefinition="Amount dispensed", formalDefinition="The amount of medication that has been dispensed. Includes unit of measure." )
981    protected SimpleQuantity quantity;
982
983    /**
984     * The amount of medication expressed as a timing amount.
985     */
986    @Child(name = "daysSupply", type = {SimpleQuantity.class}, order=12, min=0, max=1, modifier=false, summary=false)
987    @Description(shortDefinition="Amount of medication expressed as a timing amount", formalDefinition="The amount of medication expressed as a timing amount." )
988    protected SimpleQuantity daysSupply;
989
990    /**
991     * The time when the dispensed product was packaged and reviewed.
992     */
993    @Child(name = "whenPrepared", type = {DateTimeType.class}, order=13, min=0, max=1, modifier=false, summary=true)
994    @Description(shortDefinition="When product was packaged and reviewed", formalDefinition="The time when the dispensed product was packaged and reviewed." )
995    protected DateTimeType whenPrepared;
996
997    /**
998     * The time the dispensed product was provided to the patient or their representative.
999     */
1000    @Child(name = "whenHandedOver", type = {DateTimeType.class}, order=14, min=0, max=1, modifier=false, summary=false)
1001    @Description(shortDefinition="When product was given out", formalDefinition="The time the dispensed product was provided to the patient or their representative." )
1002    protected DateTimeType whenHandedOver;
1003
1004    /**
1005     * Identification of the facility/location where the medication was shipped to, as part of the dispense event.
1006     */
1007    @Child(name = "destination", type = {Location.class}, order=15, min=0, max=1, modifier=false, summary=false)
1008    @Description(shortDefinition="Where the medication was sent", formalDefinition="Identification of the facility/location where the medication was shipped to, as part of the dispense event." )
1009    protected Reference destination;
1010
1011    /**
1012     * The actual object that is the target of the reference (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1013     */
1014    protected Location destinationTarget;
1015
1016    /**
1017     * Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional.
1018     */
1019    @Child(name = "receiver", type = {Patient.class, Practitioner.class}, order=16, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1020    @Description(shortDefinition="Who collected the medication", formalDefinition="Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional." )
1021    protected List<Reference> receiver;
1022    /**
1023     * The actual objects that are the target of the reference (Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional.)
1024     */
1025    protected List<Resource> receiverTarget;
1026
1027
1028    /**
1029     * Extra information about the dispense that could not be conveyed in the other attributes.
1030     */
1031    @Child(name = "note", type = {Annotation.class}, order=17, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1032    @Description(shortDefinition="Information about the dispense", formalDefinition="Extra information about the dispense that could not be conveyed in the other attributes." )
1033    protected List<Annotation> note;
1034
1035    /**
1036     * Indicates how the medication is to be used by the patient.
1037     */
1038    @Child(name = "dosageInstruction", type = {Dosage.class}, order=18, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1039    @Description(shortDefinition="How the medication is to be used by the patient or administered by the caregiver", formalDefinition="Indicates how the medication is to be used by the patient." )
1040    protected List<Dosage> dosageInstruction;
1041
1042    /**
1043     * Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done.
1044     */
1045    @Child(name = "substitution", type = {}, order=19, min=0, max=1, modifier=false, summary=false)
1046    @Description(shortDefinition="Whether a substitution was performed on the dispense", formalDefinition="Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done." )
1047    protected MedicationDispenseSubstitutionComponent substitution;
1048
1049    /**
1050     * Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.
1051     */
1052    @Child(name = "detectedIssue", type = {DetectedIssue.class}, order=20, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1053    @Description(shortDefinition="Clinical issue with action", formalDefinition="Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc." )
1054    protected List<Reference> detectedIssue;
1055    /**
1056     * The actual objects that are the target of the reference (Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.)
1057     */
1058    protected List<DetectedIssue> detectedIssueTarget;
1059
1060
1061    /**
1062     * True if the dispense was not performed for some reason.
1063     */
1064    @Child(name = "notDone", type = {BooleanType.class}, order=21, min=0, max=1, modifier=false, summary=false)
1065    @Description(shortDefinition="Whether the dispense was or was not performed", formalDefinition="True if the dispense was not performed for some reason." )
1066    protected BooleanType notDone;
1067
1068    /**
1069     * Indicates the reason why a dispense was not performed.
1070     */
1071    @Child(name = "notDoneReason", type = {CodeableConcept.class, DetectedIssue.class}, order=22, min=0, max=1, modifier=false, summary=false)
1072    @Description(shortDefinition="Why a dispense was not performed", formalDefinition="Indicates the reason why a dispense was not performed." )
1073    protected Type notDoneReason;
1074
1075    /**
1076     * A summary of the events of interest that have occurred, such as when the dispense was verified.
1077     */
1078    @Child(name = "eventHistory", type = {Provenance.class}, order=23, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
1079    @Description(shortDefinition="A list of releveant lifecycle events", formalDefinition="A summary of the events of interest that have occurred, such as when the dispense was verified." )
1080    protected List<Reference> eventHistory;
1081    /**
1082     * The actual objects that are the target of the reference (A summary of the events of interest that have occurred, such as when the dispense was verified.)
1083     */
1084    protected List<Provenance> eventHistoryTarget;
1085
1086
1087    private static final long serialVersionUID = 1951426869L;
1088
1089  /**
1090   * Constructor
1091   */
1092    public MedicationDispense() {
1093      super();
1094    }
1095
1096  /**
1097   * Constructor
1098   */
1099    public MedicationDispense(Type medication) {
1100      super();
1101      this.medication = medication;
1102    }
1103
1104    /**
1105     * @return {@link #identifier} (Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.)
1106     */
1107    public List<Identifier> getIdentifier() { 
1108      if (this.identifier == null)
1109        this.identifier = new ArrayList<Identifier>();
1110      return this.identifier;
1111    }
1112
1113    /**
1114     * @return Returns a reference to <code>this</code> for easy method chaining
1115     */
1116    public MedicationDispense setIdentifier(List<Identifier> theIdentifier) { 
1117      this.identifier = theIdentifier;
1118      return this;
1119    }
1120
1121    public boolean hasIdentifier() { 
1122      if (this.identifier == null)
1123        return false;
1124      for (Identifier item : this.identifier)
1125        if (!item.isEmpty())
1126          return true;
1127      return false;
1128    }
1129
1130    public Identifier addIdentifier() { //3
1131      Identifier t = new Identifier();
1132      if (this.identifier == null)
1133        this.identifier = new ArrayList<Identifier>();
1134      this.identifier.add(t);
1135      return t;
1136    }
1137
1138    public MedicationDispense addIdentifier(Identifier t) { //3
1139      if (t == null)
1140        return this;
1141      if (this.identifier == null)
1142        this.identifier = new ArrayList<Identifier>();
1143      this.identifier.add(t);
1144      return this;
1145    }
1146
1147    /**
1148     * @return The first repetition of repeating field {@link #identifier}, creating it if it does not already exist
1149     */
1150    public Identifier getIdentifierFirstRep() { 
1151      if (getIdentifier().isEmpty()) {
1152        addIdentifier();
1153      }
1154      return getIdentifier().get(0);
1155    }
1156
1157    /**
1158     * @return {@link #partOf} (The procedure that the dispense is done because of.)
1159     */
1160    public List<Reference> getPartOf() { 
1161      if (this.partOf == null)
1162        this.partOf = new ArrayList<Reference>();
1163      return this.partOf;
1164    }
1165
1166    /**
1167     * @return Returns a reference to <code>this</code> for easy method chaining
1168     */
1169    public MedicationDispense setPartOf(List<Reference> thePartOf) { 
1170      this.partOf = thePartOf;
1171      return this;
1172    }
1173
1174    public boolean hasPartOf() { 
1175      if (this.partOf == null)
1176        return false;
1177      for (Reference item : this.partOf)
1178        if (!item.isEmpty())
1179          return true;
1180      return false;
1181    }
1182
1183    public Reference addPartOf() { //3
1184      Reference t = new Reference();
1185      if (this.partOf == null)
1186        this.partOf = new ArrayList<Reference>();
1187      this.partOf.add(t);
1188      return t;
1189    }
1190
1191    public MedicationDispense addPartOf(Reference t) { //3
1192      if (t == null)
1193        return this;
1194      if (this.partOf == null)
1195        this.partOf = new ArrayList<Reference>();
1196      this.partOf.add(t);
1197      return this;
1198    }
1199
1200    /**
1201     * @return The first repetition of repeating field {@link #partOf}, creating it if it does not already exist
1202     */
1203    public Reference getPartOfFirstRep() { 
1204      if (getPartOf().isEmpty()) {
1205        addPartOf();
1206      }
1207      return getPartOf().get(0);
1208    }
1209
1210    /**
1211     * @deprecated Use Reference#setResource(IBaseResource) instead
1212     */
1213    @Deprecated
1214    public List<Procedure> getPartOfTarget() { 
1215      if (this.partOfTarget == null)
1216        this.partOfTarget = new ArrayList<Procedure>();
1217      return this.partOfTarget;
1218    }
1219
1220    /**
1221     * @deprecated Use Reference#setResource(IBaseResource) instead
1222     */
1223    @Deprecated
1224    public Procedure addPartOfTarget() { 
1225      Procedure r = new Procedure();
1226      if (this.partOfTarget == null)
1227        this.partOfTarget = new ArrayList<Procedure>();
1228      this.partOfTarget.add(r);
1229      return r;
1230    }
1231
1232    /**
1233     * @return {@link #status} (A code specifying the state of the set of dispense events.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1234     */
1235    public Enumeration<MedicationDispenseStatus> getStatusElement() { 
1236      if (this.status == null)
1237        if (Configuration.errorOnAutoCreate())
1238          throw new Error("Attempt to auto-create MedicationDispense.status");
1239        else if (Configuration.doAutoCreate())
1240          this.status = new Enumeration<MedicationDispenseStatus>(new MedicationDispenseStatusEnumFactory()); // bb
1241      return this.status;
1242    }
1243
1244    public boolean hasStatusElement() { 
1245      return this.status != null && !this.status.isEmpty();
1246    }
1247
1248    public boolean hasStatus() { 
1249      return this.status != null && !this.status.isEmpty();
1250    }
1251
1252    /**
1253     * @param value {@link #status} (A code specifying the state of the set of dispense events.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1254     */
1255    public MedicationDispense setStatusElement(Enumeration<MedicationDispenseStatus> value) { 
1256      this.status = value;
1257      return this;
1258    }
1259
1260    /**
1261     * @return A code specifying the state of the set of dispense events.
1262     */
1263    public MedicationDispenseStatus getStatus() { 
1264      return this.status == null ? null : this.status.getValue();
1265    }
1266
1267    /**
1268     * @param value A code specifying the state of the set of dispense events.
1269     */
1270    public MedicationDispense setStatus(MedicationDispenseStatus value) { 
1271      if (value == null)
1272        this.status = null;
1273      else {
1274        if (this.status == null)
1275          this.status = new Enumeration<MedicationDispenseStatus>(new MedicationDispenseStatusEnumFactory());
1276        this.status.setValue(value);
1277      }
1278      return this;
1279    }
1280
1281    /**
1282     * @return {@link #category} (Indicates type of medication dispense and where the medication is expected to be consumed or administered.)
1283     */
1284    public CodeableConcept getCategory() { 
1285      if (this.category == null)
1286        if (Configuration.errorOnAutoCreate())
1287          throw new Error("Attempt to auto-create MedicationDispense.category");
1288        else if (Configuration.doAutoCreate())
1289          this.category = new CodeableConcept(); // cc
1290      return this.category;
1291    }
1292
1293    public boolean hasCategory() { 
1294      return this.category != null && !this.category.isEmpty();
1295    }
1296
1297    /**
1298     * @param value {@link #category} (Indicates type of medication dispense and where the medication is expected to be consumed or administered.)
1299     */
1300    public MedicationDispense setCategory(CodeableConcept value)  { 
1301      this.category = value;
1302      return this;
1303    }
1304
1305    /**
1306     * @return {@link #medication} (Identifies the medication being 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.)
1307     */
1308    public Type getMedication() { 
1309      return this.medication;
1310    }
1311
1312    /**
1313     * @return {@link #medication} (Identifies the medication being 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.)
1314     */
1315    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1316      if (this.medication == null)
1317        return null;
1318      if (!(this.medication instanceof CodeableConcept))
1319        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1320      return (CodeableConcept) this.medication;
1321    }
1322
1323    public boolean hasMedicationCodeableConcept() { 
1324      return this != null && this.medication instanceof CodeableConcept;
1325    }
1326
1327    /**
1328     * @return {@link #medication} (Identifies the medication being 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.)
1329     */
1330    public Reference getMedicationReference() throws FHIRException { 
1331      if (this.medication == null)
1332        return null;
1333      if (!(this.medication instanceof Reference))
1334        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1335      return (Reference) this.medication;
1336    }
1337
1338    public boolean hasMedicationReference() { 
1339      return this != null && this.medication instanceof Reference;
1340    }
1341
1342    public boolean hasMedication() { 
1343      return this.medication != null && !this.medication.isEmpty();
1344    }
1345
1346    /**
1347     * @param value {@link #medication} (Identifies the medication being 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.)
1348     */
1349    public MedicationDispense setMedication(Type value) throws FHIRFormatError { 
1350      if (value != null && !(value instanceof CodeableConcept || value instanceof Reference))
1351        throw new FHIRFormatError("Not the right type for MedicationDispense.medication[x]: "+value.fhirType());
1352      this.medication = value;
1353      return this;
1354    }
1355
1356    /**
1357     * @return {@link #subject} (A link to a resource representing the person or the group to whom the medication will be given.)
1358     */
1359    public Reference getSubject() { 
1360      if (this.subject == null)
1361        if (Configuration.errorOnAutoCreate())
1362          throw new Error("Attempt to auto-create MedicationDispense.subject");
1363        else if (Configuration.doAutoCreate())
1364          this.subject = new Reference(); // cc
1365      return this.subject;
1366    }
1367
1368    public boolean hasSubject() { 
1369      return this.subject != null && !this.subject.isEmpty();
1370    }
1371
1372    /**
1373     * @param value {@link #subject} (A link to a resource representing the person or the group to whom the medication will be given.)
1374     */
1375    public MedicationDispense setSubject(Reference value)  { 
1376      this.subject = value;
1377      return this;
1378    }
1379
1380    /**
1381     * @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. (A link to a resource representing the person or the group to whom the medication will be given.)
1382     */
1383    public Resource getSubjectTarget() { 
1384      return this.subjectTarget;
1385    }
1386
1387    /**
1388     * @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. (A link to a resource representing the person or the group to whom the medication will be given.)
1389     */
1390    public MedicationDispense setSubjectTarget(Resource value) { 
1391      this.subjectTarget = value;
1392      return this;
1393    }
1394
1395    /**
1396     * @return {@link #context} (The encounter or episode of care that establishes the context for this event.)
1397     */
1398    public Reference getContext() { 
1399      if (this.context == null)
1400        if (Configuration.errorOnAutoCreate())
1401          throw new Error("Attempt to auto-create MedicationDispense.context");
1402        else if (Configuration.doAutoCreate())
1403          this.context = new Reference(); // cc
1404      return this.context;
1405    }
1406
1407    public boolean hasContext() { 
1408      return this.context != null && !this.context.isEmpty();
1409    }
1410
1411    /**
1412     * @param value {@link #context} (The encounter or episode of care that establishes the context for this event.)
1413     */
1414    public MedicationDispense setContext(Reference value)  { 
1415      this.context = value;
1416      return this;
1417    }
1418
1419    /**
1420     * @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 encounter or episode of care that establishes the context for this event.)
1421     */
1422    public Resource getContextTarget() { 
1423      return this.contextTarget;
1424    }
1425
1426    /**
1427     * @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 encounter or episode of care that establishes the context for this event.)
1428     */
1429    public MedicationDispense setContextTarget(Resource value) { 
1430      this.contextTarget = value;
1431      return this;
1432    }
1433
1434    /**
1435     * @return {@link #supportingInformation} (Additional information that supports the medication being dispensed.)
1436     */
1437    public List<Reference> getSupportingInformation() { 
1438      if (this.supportingInformation == null)
1439        this.supportingInformation = new ArrayList<Reference>();
1440      return this.supportingInformation;
1441    }
1442
1443    /**
1444     * @return Returns a reference to <code>this</code> for easy method chaining
1445     */
1446    public MedicationDispense setSupportingInformation(List<Reference> theSupportingInformation) { 
1447      this.supportingInformation = theSupportingInformation;
1448      return this;
1449    }
1450
1451    public boolean hasSupportingInformation() { 
1452      if (this.supportingInformation == null)
1453        return false;
1454      for (Reference item : this.supportingInformation)
1455        if (!item.isEmpty())
1456          return true;
1457      return false;
1458    }
1459
1460    public Reference addSupportingInformation() { //3
1461      Reference t = new Reference();
1462      if (this.supportingInformation == null)
1463        this.supportingInformation = new ArrayList<Reference>();
1464      this.supportingInformation.add(t);
1465      return t;
1466    }
1467
1468    public MedicationDispense addSupportingInformation(Reference t) { //3
1469      if (t == null)
1470        return this;
1471      if (this.supportingInformation == null)
1472        this.supportingInformation = new ArrayList<Reference>();
1473      this.supportingInformation.add(t);
1474      return this;
1475    }
1476
1477    /**
1478     * @return The first repetition of repeating field {@link #supportingInformation}, creating it if it does not already exist
1479     */
1480    public Reference getSupportingInformationFirstRep() { 
1481      if (getSupportingInformation().isEmpty()) {
1482        addSupportingInformation();
1483      }
1484      return getSupportingInformation().get(0);
1485    }
1486
1487    /**
1488     * @deprecated Use Reference#setResource(IBaseResource) instead
1489     */
1490    @Deprecated
1491    public List<Resource> getSupportingInformationTarget() { 
1492      if (this.supportingInformationTarget == null)
1493        this.supportingInformationTarget = new ArrayList<Resource>();
1494      return this.supportingInformationTarget;
1495    }
1496
1497    /**
1498     * @return {@link #performer} (Indicates who or what performed the event.  It should be assumed that the performer is the dispenser of the medication.)
1499     */
1500    public List<MedicationDispensePerformerComponent> getPerformer() { 
1501      if (this.performer == null)
1502        this.performer = new ArrayList<MedicationDispensePerformerComponent>();
1503      return this.performer;
1504    }
1505
1506    /**
1507     * @return Returns a reference to <code>this</code> for easy method chaining
1508     */
1509    public MedicationDispense setPerformer(List<MedicationDispensePerformerComponent> thePerformer) { 
1510      this.performer = thePerformer;
1511      return this;
1512    }
1513
1514    public boolean hasPerformer() { 
1515      if (this.performer == null)
1516        return false;
1517      for (MedicationDispensePerformerComponent item : this.performer)
1518        if (!item.isEmpty())
1519          return true;
1520      return false;
1521    }
1522
1523    public MedicationDispensePerformerComponent addPerformer() { //3
1524      MedicationDispensePerformerComponent t = new MedicationDispensePerformerComponent();
1525      if (this.performer == null)
1526        this.performer = new ArrayList<MedicationDispensePerformerComponent>();
1527      this.performer.add(t);
1528      return t;
1529    }
1530
1531    public MedicationDispense addPerformer(MedicationDispensePerformerComponent t) { //3
1532      if (t == null)
1533        return this;
1534      if (this.performer == null)
1535        this.performer = new ArrayList<MedicationDispensePerformerComponent>();
1536      this.performer.add(t);
1537      return this;
1538    }
1539
1540    /**
1541     * @return The first repetition of repeating field {@link #performer}, creating it if it does not already exist
1542     */
1543    public MedicationDispensePerformerComponent getPerformerFirstRep() { 
1544      if (getPerformer().isEmpty()) {
1545        addPerformer();
1546      }
1547      return getPerformer().get(0);
1548    }
1549
1550    /**
1551     * @return {@link #authorizingPrescription} (Indicates the medication order that is being dispensed against.)
1552     */
1553    public List<Reference> getAuthorizingPrescription() { 
1554      if (this.authorizingPrescription == null)
1555        this.authorizingPrescription = new ArrayList<Reference>();
1556      return this.authorizingPrescription;
1557    }
1558
1559    /**
1560     * @return Returns a reference to <code>this</code> for easy method chaining
1561     */
1562    public MedicationDispense setAuthorizingPrescription(List<Reference> theAuthorizingPrescription) { 
1563      this.authorizingPrescription = theAuthorizingPrescription;
1564      return this;
1565    }
1566
1567    public boolean hasAuthorizingPrescription() { 
1568      if (this.authorizingPrescription == null)
1569        return false;
1570      for (Reference item : this.authorizingPrescription)
1571        if (!item.isEmpty())
1572          return true;
1573      return false;
1574    }
1575
1576    public Reference addAuthorizingPrescription() { //3
1577      Reference t = new Reference();
1578      if (this.authorizingPrescription == null)
1579        this.authorizingPrescription = new ArrayList<Reference>();
1580      this.authorizingPrescription.add(t);
1581      return t;
1582    }
1583
1584    public MedicationDispense addAuthorizingPrescription(Reference t) { //3
1585      if (t == null)
1586        return this;
1587      if (this.authorizingPrescription == null)
1588        this.authorizingPrescription = new ArrayList<Reference>();
1589      this.authorizingPrescription.add(t);
1590      return this;
1591    }
1592
1593    /**
1594     * @return The first repetition of repeating field {@link #authorizingPrescription}, creating it if it does not already exist
1595     */
1596    public Reference getAuthorizingPrescriptionFirstRep() { 
1597      if (getAuthorizingPrescription().isEmpty()) {
1598        addAuthorizingPrescription();
1599      }
1600      return getAuthorizingPrescription().get(0);
1601    }
1602
1603    /**
1604     * @deprecated Use Reference#setResource(IBaseResource) instead
1605     */
1606    @Deprecated
1607    public List<MedicationRequest> getAuthorizingPrescriptionTarget() { 
1608      if (this.authorizingPrescriptionTarget == null)
1609        this.authorizingPrescriptionTarget = new ArrayList<MedicationRequest>();
1610      return this.authorizingPrescriptionTarget;
1611    }
1612
1613    /**
1614     * @deprecated Use Reference#setResource(IBaseResource) instead
1615     */
1616    @Deprecated
1617    public MedicationRequest addAuthorizingPrescriptionTarget() { 
1618      MedicationRequest r = new MedicationRequest();
1619      if (this.authorizingPrescriptionTarget == null)
1620        this.authorizingPrescriptionTarget = new ArrayList<MedicationRequest>();
1621      this.authorizingPrescriptionTarget.add(r);
1622      return r;
1623    }
1624
1625    /**
1626     * @return {@link #type} (Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.)
1627     */
1628    public CodeableConcept getType() { 
1629      if (this.type == null)
1630        if (Configuration.errorOnAutoCreate())
1631          throw new Error("Attempt to auto-create MedicationDispense.type");
1632        else if (Configuration.doAutoCreate())
1633          this.type = new CodeableConcept(); // cc
1634      return this.type;
1635    }
1636
1637    public boolean hasType() { 
1638      return this.type != null && !this.type.isEmpty();
1639    }
1640
1641    /**
1642     * @param value {@link #type} (Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.)
1643     */
1644    public MedicationDispense setType(CodeableConcept value)  { 
1645      this.type = value;
1646      return this;
1647    }
1648
1649    /**
1650     * @return {@link #quantity} (The amount of medication that has been dispensed. Includes unit of measure.)
1651     */
1652    public SimpleQuantity getQuantity() { 
1653      if (this.quantity == null)
1654        if (Configuration.errorOnAutoCreate())
1655          throw new Error("Attempt to auto-create MedicationDispense.quantity");
1656        else if (Configuration.doAutoCreate())
1657          this.quantity = new SimpleQuantity(); // cc
1658      return this.quantity;
1659    }
1660
1661    public boolean hasQuantity() { 
1662      return this.quantity != null && !this.quantity.isEmpty();
1663    }
1664
1665    /**
1666     * @param value {@link #quantity} (The amount of medication that has been dispensed. Includes unit of measure.)
1667     */
1668    public MedicationDispense setQuantity(SimpleQuantity value)  { 
1669      this.quantity = value;
1670      return this;
1671    }
1672
1673    /**
1674     * @return {@link #daysSupply} (The amount of medication expressed as a timing amount.)
1675     */
1676    public SimpleQuantity getDaysSupply() { 
1677      if (this.daysSupply == null)
1678        if (Configuration.errorOnAutoCreate())
1679          throw new Error("Attempt to auto-create MedicationDispense.daysSupply");
1680        else if (Configuration.doAutoCreate())
1681          this.daysSupply = new SimpleQuantity(); // cc
1682      return this.daysSupply;
1683    }
1684
1685    public boolean hasDaysSupply() { 
1686      return this.daysSupply != null && !this.daysSupply.isEmpty();
1687    }
1688
1689    /**
1690     * @param value {@link #daysSupply} (The amount of medication expressed as a timing amount.)
1691     */
1692    public MedicationDispense setDaysSupply(SimpleQuantity value)  { 
1693      this.daysSupply = value;
1694      return this;
1695    }
1696
1697    /**
1698     * @return {@link #whenPrepared} (The time when the dispensed product was packaged and reviewed.). This is the underlying object with id, value and extensions. The accessor "getWhenPrepared" gives direct access to the value
1699     */
1700    public DateTimeType getWhenPreparedElement() { 
1701      if (this.whenPrepared == null)
1702        if (Configuration.errorOnAutoCreate())
1703          throw new Error("Attempt to auto-create MedicationDispense.whenPrepared");
1704        else if (Configuration.doAutoCreate())
1705          this.whenPrepared = new DateTimeType(); // bb
1706      return this.whenPrepared;
1707    }
1708
1709    public boolean hasWhenPreparedElement() { 
1710      return this.whenPrepared != null && !this.whenPrepared.isEmpty();
1711    }
1712
1713    public boolean hasWhenPrepared() { 
1714      return this.whenPrepared != null && !this.whenPrepared.isEmpty();
1715    }
1716
1717    /**
1718     * @param value {@link #whenPrepared} (The time when the dispensed product was packaged and reviewed.). This is the underlying object with id, value and extensions. The accessor "getWhenPrepared" gives direct access to the value
1719     */
1720    public MedicationDispense setWhenPreparedElement(DateTimeType value) { 
1721      this.whenPrepared = value;
1722      return this;
1723    }
1724
1725    /**
1726     * @return The time when the dispensed product was packaged and reviewed.
1727     */
1728    public Date getWhenPrepared() { 
1729      return this.whenPrepared == null ? null : this.whenPrepared.getValue();
1730    }
1731
1732    /**
1733     * @param value The time when the dispensed product was packaged and reviewed.
1734     */
1735    public MedicationDispense setWhenPrepared(Date value) { 
1736      if (value == null)
1737        this.whenPrepared = null;
1738      else {
1739        if (this.whenPrepared == null)
1740          this.whenPrepared = new DateTimeType();
1741        this.whenPrepared.setValue(value);
1742      }
1743      return this;
1744    }
1745
1746    /**
1747     * @return {@link #whenHandedOver} (The time the dispensed product was provided to the patient or their representative.). This is the underlying object with id, value and extensions. The accessor "getWhenHandedOver" gives direct access to the value
1748     */
1749    public DateTimeType getWhenHandedOverElement() { 
1750      if (this.whenHandedOver == null)
1751        if (Configuration.errorOnAutoCreate())
1752          throw new Error("Attempt to auto-create MedicationDispense.whenHandedOver");
1753        else if (Configuration.doAutoCreate())
1754          this.whenHandedOver = new DateTimeType(); // bb
1755      return this.whenHandedOver;
1756    }
1757
1758    public boolean hasWhenHandedOverElement() { 
1759      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1760    }
1761
1762    public boolean hasWhenHandedOver() { 
1763      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1764    }
1765
1766    /**
1767     * @param value {@link #whenHandedOver} (The time the dispensed product was provided to the patient or their representative.). This is the underlying object with id, value and extensions. The accessor "getWhenHandedOver" gives direct access to the value
1768     */
1769    public MedicationDispense setWhenHandedOverElement(DateTimeType value) { 
1770      this.whenHandedOver = value;
1771      return this;
1772    }
1773
1774    /**
1775     * @return The time the dispensed product was provided to the patient or their representative.
1776     */
1777    public Date getWhenHandedOver() { 
1778      return this.whenHandedOver == null ? null : this.whenHandedOver.getValue();
1779    }
1780
1781    /**
1782     * @param value The time the dispensed product was provided to the patient or their representative.
1783     */
1784    public MedicationDispense setWhenHandedOver(Date value) { 
1785      if (value == null)
1786        this.whenHandedOver = null;
1787      else {
1788        if (this.whenHandedOver == null)
1789          this.whenHandedOver = new DateTimeType();
1790        this.whenHandedOver.setValue(value);
1791      }
1792      return this;
1793    }
1794
1795    /**
1796     * @return {@link #destination} (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1797     */
1798    public Reference getDestination() { 
1799      if (this.destination == null)
1800        if (Configuration.errorOnAutoCreate())
1801          throw new Error("Attempt to auto-create MedicationDispense.destination");
1802        else if (Configuration.doAutoCreate())
1803          this.destination = new Reference(); // cc
1804      return this.destination;
1805    }
1806
1807    public boolean hasDestination() { 
1808      return this.destination != null && !this.destination.isEmpty();
1809    }
1810
1811    /**
1812     * @param value {@link #destination} (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1813     */
1814    public MedicationDispense setDestination(Reference value)  { 
1815      this.destination = value;
1816      return this;
1817    }
1818
1819    /**
1820     * @return {@link #destination} 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. (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1821     */
1822    public Location getDestinationTarget() { 
1823      if (this.destinationTarget == null)
1824        if (Configuration.errorOnAutoCreate())
1825          throw new Error("Attempt to auto-create MedicationDispense.destination");
1826        else if (Configuration.doAutoCreate())
1827          this.destinationTarget = new Location(); // aa
1828      return this.destinationTarget;
1829    }
1830
1831    /**
1832     * @param value {@link #destination} 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. (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1833     */
1834    public MedicationDispense setDestinationTarget(Location value) { 
1835      this.destinationTarget = value;
1836      return this;
1837    }
1838
1839    /**
1840     * @return {@link #receiver} (Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional.)
1841     */
1842    public List<Reference> getReceiver() { 
1843      if (this.receiver == null)
1844        this.receiver = new ArrayList<Reference>();
1845      return this.receiver;
1846    }
1847
1848    /**
1849     * @return Returns a reference to <code>this</code> for easy method chaining
1850     */
1851    public MedicationDispense setReceiver(List<Reference> theReceiver) { 
1852      this.receiver = theReceiver;
1853      return this;
1854    }
1855
1856    public boolean hasReceiver() { 
1857      if (this.receiver == null)
1858        return false;
1859      for (Reference item : this.receiver)
1860        if (!item.isEmpty())
1861          return true;
1862      return false;
1863    }
1864
1865    public Reference addReceiver() { //3
1866      Reference t = new Reference();
1867      if (this.receiver == null)
1868        this.receiver = new ArrayList<Reference>();
1869      this.receiver.add(t);
1870      return t;
1871    }
1872
1873    public MedicationDispense addReceiver(Reference t) { //3
1874      if (t == null)
1875        return this;
1876      if (this.receiver == null)
1877        this.receiver = new ArrayList<Reference>();
1878      this.receiver.add(t);
1879      return this;
1880    }
1881
1882    /**
1883     * @return The first repetition of repeating field {@link #receiver}, creating it if it does not already exist
1884     */
1885    public Reference getReceiverFirstRep() { 
1886      if (getReceiver().isEmpty()) {
1887        addReceiver();
1888      }
1889      return getReceiver().get(0);
1890    }
1891
1892    /**
1893     * @deprecated Use Reference#setResource(IBaseResource) instead
1894     */
1895    @Deprecated
1896    public List<Resource> getReceiverTarget() { 
1897      if (this.receiverTarget == null)
1898        this.receiverTarget = new ArrayList<Resource>();
1899      return this.receiverTarget;
1900    }
1901
1902    /**
1903     * @return {@link #note} (Extra information about the dispense that could not be conveyed in the other attributes.)
1904     */
1905    public List<Annotation> getNote() { 
1906      if (this.note == null)
1907        this.note = new ArrayList<Annotation>();
1908      return this.note;
1909    }
1910
1911    /**
1912     * @return Returns a reference to <code>this</code> for easy method chaining
1913     */
1914    public MedicationDispense setNote(List<Annotation> theNote) { 
1915      this.note = theNote;
1916      return this;
1917    }
1918
1919    public boolean hasNote() { 
1920      if (this.note == null)
1921        return false;
1922      for (Annotation item : this.note)
1923        if (!item.isEmpty())
1924          return true;
1925      return false;
1926    }
1927
1928    public Annotation addNote() { //3
1929      Annotation t = new Annotation();
1930      if (this.note == null)
1931        this.note = new ArrayList<Annotation>();
1932      this.note.add(t);
1933      return t;
1934    }
1935
1936    public MedicationDispense addNote(Annotation t) { //3
1937      if (t == null)
1938        return this;
1939      if (this.note == null)
1940        this.note = new ArrayList<Annotation>();
1941      this.note.add(t);
1942      return this;
1943    }
1944
1945    /**
1946     * @return The first repetition of repeating field {@link #note}, creating it if it does not already exist
1947     */
1948    public Annotation getNoteFirstRep() { 
1949      if (getNote().isEmpty()) {
1950        addNote();
1951      }
1952      return getNote().get(0);
1953    }
1954
1955    /**
1956     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
1957     */
1958    public List<Dosage> getDosageInstruction() { 
1959      if (this.dosageInstruction == null)
1960        this.dosageInstruction = new ArrayList<Dosage>();
1961      return this.dosageInstruction;
1962    }
1963
1964    /**
1965     * @return Returns a reference to <code>this</code> for easy method chaining
1966     */
1967    public MedicationDispense setDosageInstruction(List<Dosage> theDosageInstruction) { 
1968      this.dosageInstruction = theDosageInstruction;
1969      return this;
1970    }
1971
1972    public boolean hasDosageInstruction() { 
1973      if (this.dosageInstruction == null)
1974        return false;
1975      for (Dosage item : this.dosageInstruction)
1976        if (!item.isEmpty())
1977          return true;
1978      return false;
1979    }
1980
1981    public Dosage addDosageInstruction() { //3
1982      Dosage t = new Dosage();
1983      if (this.dosageInstruction == null)
1984        this.dosageInstruction = new ArrayList<Dosage>();
1985      this.dosageInstruction.add(t);
1986      return t;
1987    }
1988
1989    public MedicationDispense addDosageInstruction(Dosage t) { //3
1990      if (t == null)
1991        return this;
1992      if (this.dosageInstruction == null)
1993        this.dosageInstruction = new ArrayList<Dosage>();
1994      this.dosageInstruction.add(t);
1995      return this;
1996    }
1997
1998    /**
1999     * @return The first repetition of repeating field {@link #dosageInstruction}, creating it if it does not already exist
2000     */
2001    public Dosage getDosageInstructionFirstRep() { 
2002      if (getDosageInstruction().isEmpty()) {
2003        addDosageInstruction();
2004      }
2005      return getDosageInstruction().get(0);
2006    }
2007
2008    /**
2009     * @return {@link #substitution} (Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done.)
2010     */
2011    public MedicationDispenseSubstitutionComponent getSubstitution() { 
2012      if (this.substitution == null)
2013        if (Configuration.errorOnAutoCreate())
2014          throw new Error("Attempt to auto-create MedicationDispense.substitution");
2015        else if (Configuration.doAutoCreate())
2016          this.substitution = new MedicationDispenseSubstitutionComponent(); // cc
2017      return this.substitution;
2018    }
2019
2020    public boolean hasSubstitution() { 
2021      return this.substitution != null && !this.substitution.isEmpty();
2022    }
2023
2024    /**
2025     * @param value {@link #substitution} (Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done.)
2026     */
2027    public MedicationDispense setSubstitution(MedicationDispenseSubstitutionComponent value)  { 
2028      this.substitution = value;
2029      return this;
2030    }
2031
2032    /**
2033     * @return {@link #detectedIssue} (Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.)
2034     */
2035    public List<Reference> getDetectedIssue() { 
2036      if (this.detectedIssue == null)
2037        this.detectedIssue = new ArrayList<Reference>();
2038      return this.detectedIssue;
2039    }
2040
2041    /**
2042     * @return Returns a reference to <code>this</code> for easy method chaining
2043     */
2044    public MedicationDispense setDetectedIssue(List<Reference> theDetectedIssue) { 
2045      this.detectedIssue = theDetectedIssue;
2046      return this;
2047    }
2048
2049    public boolean hasDetectedIssue() { 
2050      if (this.detectedIssue == null)
2051        return false;
2052      for (Reference item : this.detectedIssue)
2053        if (!item.isEmpty())
2054          return true;
2055      return false;
2056    }
2057
2058    public Reference addDetectedIssue() { //3
2059      Reference t = new Reference();
2060      if (this.detectedIssue == null)
2061        this.detectedIssue = new ArrayList<Reference>();
2062      this.detectedIssue.add(t);
2063      return t;
2064    }
2065
2066    public MedicationDispense addDetectedIssue(Reference t) { //3
2067      if (t == null)
2068        return this;
2069      if (this.detectedIssue == null)
2070        this.detectedIssue = new ArrayList<Reference>();
2071      this.detectedIssue.add(t);
2072      return this;
2073    }
2074
2075    /**
2076     * @return The first repetition of repeating field {@link #detectedIssue}, creating it if it does not already exist
2077     */
2078    public Reference getDetectedIssueFirstRep() { 
2079      if (getDetectedIssue().isEmpty()) {
2080        addDetectedIssue();
2081      }
2082      return getDetectedIssue().get(0);
2083    }
2084
2085    /**
2086     * @deprecated Use Reference#setResource(IBaseResource) instead
2087     */
2088    @Deprecated
2089    public List<DetectedIssue> getDetectedIssueTarget() { 
2090      if (this.detectedIssueTarget == null)
2091        this.detectedIssueTarget = new ArrayList<DetectedIssue>();
2092      return this.detectedIssueTarget;
2093    }
2094
2095    /**
2096     * @deprecated Use Reference#setResource(IBaseResource) instead
2097     */
2098    @Deprecated
2099    public DetectedIssue addDetectedIssueTarget() { 
2100      DetectedIssue r = new DetectedIssue();
2101      if (this.detectedIssueTarget == null)
2102        this.detectedIssueTarget = new ArrayList<DetectedIssue>();
2103      this.detectedIssueTarget.add(r);
2104      return r;
2105    }
2106
2107    /**
2108     * @return {@link #notDone} (True if the dispense was not performed for some reason.). This is the underlying object with id, value and extensions. The accessor "getNotDone" gives direct access to the value
2109     */
2110    public BooleanType getNotDoneElement() { 
2111      if (this.notDone == null)
2112        if (Configuration.errorOnAutoCreate())
2113          throw new Error("Attempt to auto-create MedicationDispense.notDone");
2114        else if (Configuration.doAutoCreate())
2115          this.notDone = new BooleanType(); // bb
2116      return this.notDone;
2117    }
2118
2119    public boolean hasNotDoneElement() { 
2120      return this.notDone != null && !this.notDone.isEmpty();
2121    }
2122
2123    public boolean hasNotDone() { 
2124      return this.notDone != null && !this.notDone.isEmpty();
2125    }
2126
2127    /**
2128     * @param value {@link #notDone} (True if the dispense was not performed for some reason.). This is the underlying object with id, value and extensions. The accessor "getNotDone" gives direct access to the value
2129     */
2130    public MedicationDispense setNotDoneElement(BooleanType value) { 
2131      this.notDone = value;
2132      return this;
2133    }
2134
2135    /**
2136     * @return True if the dispense was not performed for some reason.
2137     */
2138    public boolean getNotDone() { 
2139      return this.notDone == null || this.notDone.isEmpty() ? false : this.notDone.getValue();
2140    }
2141
2142    /**
2143     * @param value True if the dispense was not performed for some reason.
2144     */
2145    public MedicationDispense setNotDone(boolean value) { 
2146        if (this.notDone == null)
2147          this.notDone = new BooleanType();
2148        this.notDone.setValue(value);
2149      return this;
2150    }
2151
2152    /**
2153     * @return {@link #notDoneReason} (Indicates the reason why a dispense was not performed.)
2154     */
2155    public Type getNotDoneReason() { 
2156      return this.notDoneReason;
2157    }
2158
2159    /**
2160     * @return {@link #notDoneReason} (Indicates the reason why a dispense was not performed.)
2161     */
2162    public CodeableConcept getNotDoneReasonCodeableConcept() throws FHIRException { 
2163      if (this.notDoneReason == null)
2164        return null;
2165      if (!(this.notDoneReason instanceof CodeableConcept))
2166        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.notDoneReason.getClass().getName()+" was encountered");
2167      return (CodeableConcept) this.notDoneReason;
2168    }
2169
2170    public boolean hasNotDoneReasonCodeableConcept() { 
2171      return this != null && this.notDoneReason instanceof CodeableConcept;
2172    }
2173
2174    /**
2175     * @return {@link #notDoneReason} (Indicates the reason why a dispense was not performed.)
2176     */
2177    public Reference getNotDoneReasonReference() throws FHIRException { 
2178      if (this.notDoneReason == null)
2179        return null;
2180      if (!(this.notDoneReason instanceof Reference))
2181        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.notDoneReason.getClass().getName()+" was encountered");
2182      return (Reference) this.notDoneReason;
2183    }
2184
2185    public boolean hasNotDoneReasonReference() { 
2186      return this != null && this.notDoneReason instanceof Reference;
2187    }
2188
2189    public boolean hasNotDoneReason() { 
2190      return this.notDoneReason != null && !this.notDoneReason.isEmpty();
2191    }
2192
2193    /**
2194     * @param value {@link #notDoneReason} (Indicates the reason why a dispense was not performed.)
2195     */
2196    public MedicationDispense setNotDoneReason(Type value) throws FHIRFormatError { 
2197      if (value != null && !(value instanceof CodeableConcept || value instanceof Reference))
2198        throw new FHIRFormatError("Not the right type for MedicationDispense.notDoneReason[x]: "+value.fhirType());
2199      this.notDoneReason = value;
2200      return this;
2201    }
2202
2203    /**
2204     * @return {@link #eventHistory} (A summary of the events of interest that have occurred, such as when the dispense was verified.)
2205     */
2206    public List<Reference> getEventHistory() { 
2207      if (this.eventHistory == null)
2208        this.eventHistory = new ArrayList<Reference>();
2209      return this.eventHistory;
2210    }
2211
2212    /**
2213     * @return Returns a reference to <code>this</code> for easy method chaining
2214     */
2215    public MedicationDispense setEventHistory(List<Reference> theEventHistory) { 
2216      this.eventHistory = theEventHistory;
2217      return this;
2218    }
2219
2220    public boolean hasEventHistory() { 
2221      if (this.eventHistory == null)
2222        return false;
2223      for (Reference item : this.eventHistory)
2224        if (!item.isEmpty())
2225          return true;
2226      return false;
2227    }
2228
2229    public Reference addEventHistory() { //3
2230      Reference t = new Reference();
2231      if (this.eventHistory == null)
2232        this.eventHistory = new ArrayList<Reference>();
2233      this.eventHistory.add(t);
2234      return t;
2235    }
2236
2237    public MedicationDispense addEventHistory(Reference t) { //3
2238      if (t == null)
2239        return this;
2240      if (this.eventHistory == null)
2241        this.eventHistory = new ArrayList<Reference>();
2242      this.eventHistory.add(t);
2243      return this;
2244    }
2245
2246    /**
2247     * @return The first repetition of repeating field {@link #eventHistory}, creating it if it does not already exist
2248     */
2249    public Reference getEventHistoryFirstRep() { 
2250      if (getEventHistory().isEmpty()) {
2251        addEventHistory();
2252      }
2253      return getEventHistory().get(0);
2254    }
2255
2256    /**
2257     * @deprecated Use Reference#setResource(IBaseResource) instead
2258     */
2259    @Deprecated
2260    public List<Provenance> getEventHistoryTarget() { 
2261      if (this.eventHistoryTarget == null)
2262        this.eventHistoryTarget = new ArrayList<Provenance>();
2263      return this.eventHistoryTarget;
2264    }
2265
2266    /**
2267     * @deprecated Use Reference#setResource(IBaseResource) instead
2268     */
2269    @Deprecated
2270    public Provenance addEventHistoryTarget() { 
2271      Provenance r = new Provenance();
2272      if (this.eventHistoryTarget == null)
2273        this.eventHistoryTarget = new ArrayList<Provenance>();
2274      this.eventHistoryTarget.add(r);
2275      return r;
2276    }
2277
2278      protected void listChildren(List<Property> children) {
2279        super.listChildren(children);
2280        children.add(new Property("identifier", "Identifier", "Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.", 0, java.lang.Integer.MAX_VALUE, identifier));
2281        children.add(new Property("partOf", "Reference(Procedure)", "The procedure that the dispense is done because of.", 0, java.lang.Integer.MAX_VALUE, partOf));
2282        children.add(new Property("status", "code", "A code specifying the state of the set of dispense events.", 0, 1, status));
2283        children.add(new Property("category", "CodeableConcept", "Indicates type of medication dispense and where the medication is expected to be consumed or administered.", 0, 1, category));
2284        children.add(new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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));
2285        children.add(new Property("subject", "Reference(Patient|Group)", "A link to a resource representing the person or the group to whom the medication will be given.", 0, 1, subject));
2286        children.add(new Property("context", "Reference(Encounter|EpisodeOfCare)", "The encounter or episode of care that establishes the context for this event.", 0, 1, context));
2287        children.add(new Property("supportingInformation", "Reference(Any)", "Additional information that supports the medication being dispensed.", 0, java.lang.Integer.MAX_VALUE, supportingInformation));
2288        children.add(new Property("performer", "", "Indicates who or what performed the event.  It should be assumed that the performer is the dispenser of the medication.", 0, java.lang.Integer.MAX_VALUE, performer));
2289        children.add(new Property("authorizingPrescription", "Reference(MedicationRequest)", "Indicates the medication order that is being dispensed against.", 0, java.lang.Integer.MAX_VALUE, authorizingPrescription));
2290        children.add(new Property("type", "CodeableConcept", "Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.", 0, 1, type));
2291        children.add(new Property("quantity", "SimpleQuantity", "The amount of medication that has been dispensed. Includes unit of measure.", 0, 1, quantity));
2292        children.add(new Property("daysSupply", "SimpleQuantity", "The amount of medication expressed as a timing amount.", 0, 1, daysSupply));
2293        children.add(new Property("whenPrepared", "dateTime", "The time when the dispensed product was packaged and reviewed.", 0, 1, whenPrepared));
2294        children.add(new Property("whenHandedOver", "dateTime", "The time the dispensed product was provided to the patient or their representative.", 0, 1, whenHandedOver));
2295        children.add(new Property("destination", "Reference(Location)", "Identification of the facility/location where the medication was shipped to, as part of the dispense event.", 0, 1, destination));
2296        children.add(new Property("receiver", "Reference(Patient|Practitioner)", "Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional.", 0, java.lang.Integer.MAX_VALUE, receiver));
2297        children.add(new Property("note", "Annotation", "Extra information about the dispense that could not be conveyed in the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
2298        children.add(new Property("dosageInstruction", "Dosage", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction));
2299        children.add(new Property("substitution", "", "Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done.", 0, 1, substitution));
2300        children.add(new Property("detectedIssue", "Reference(DetectedIssue)", "Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.", 0, java.lang.Integer.MAX_VALUE, detectedIssue));
2301        children.add(new Property("notDone", "boolean", "True if the dispense was not performed for some reason.", 0, 1, notDone));
2302        children.add(new Property("notDoneReason[x]", "CodeableConcept|Reference(DetectedIssue)", "Indicates the reason why a dispense was not performed.", 0, 1, notDoneReason));
2303        children.add(new Property("eventHistory", "Reference(Provenance)", "A summary of the events of interest that have occurred, such as when the dispense was verified.", 0, java.lang.Integer.MAX_VALUE, eventHistory));
2304      }
2305
2306      @Override
2307      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
2308        switch (_hash) {
2309        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.", 0, java.lang.Integer.MAX_VALUE, identifier);
2310        case -995410646: /*partOf*/  return new Property("partOf", "Reference(Procedure)", "The procedure that the dispense is done because of.", 0, java.lang.Integer.MAX_VALUE, partOf);
2311        case -892481550: /*status*/  return new Property("status", "code", "A code specifying the state of the set of dispense events.", 0, 1, status);
2312        case 50511102: /*category*/  return new Property("category", "CodeableConcept", "Indicates type of medication dispense and where the medication is expected to be consumed or administered.", 0, 1, category);
2313        case 1458402129: /*medication[x]*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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);
2314        case 1998965455: /*medication*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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);
2315        case -209845038: /*medicationCodeableConcept*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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);
2316        case 2104315196: /*medicationReference*/  return new Property("medication[x]", "CodeableConcept|Reference(Medication)", "Identifies the medication being 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);
2317        case -1867885268: /*subject*/  return new Property("subject", "Reference(Patient|Group)", "A link to a resource representing the person or the group to whom the medication will be given.", 0, 1, subject);
2318        case 951530927: /*context*/  return new Property("context", "Reference(Encounter|EpisodeOfCare)", "The encounter or episode of care that establishes the context for this event.", 0, 1, context);
2319        case -1248768647: /*supportingInformation*/  return new Property("supportingInformation", "Reference(Any)", "Additional information that supports the medication being dispensed.", 0, java.lang.Integer.MAX_VALUE, supportingInformation);
2320        case 481140686: /*performer*/  return new Property("performer", "", "Indicates who or what performed the event.  It should be assumed that the performer is the dispenser of the medication.", 0, java.lang.Integer.MAX_VALUE, performer);
2321        case -1237557856: /*authorizingPrescription*/  return new Property("authorizingPrescription", "Reference(MedicationRequest)", "Indicates the medication order that is being dispensed against.", 0, java.lang.Integer.MAX_VALUE, authorizingPrescription);
2322        case 3575610: /*type*/  return new Property("type", "CodeableConcept", "Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.", 0, 1, type);
2323        case -1285004149: /*quantity*/  return new Property("quantity", "SimpleQuantity", "The amount of medication that has been dispensed. Includes unit of measure.", 0, 1, quantity);
2324        case 197175334: /*daysSupply*/  return new Property("daysSupply", "SimpleQuantity", "The amount of medication expressed as a timing amount.", 0, 1, daysSupply);
2325        case -562837097: /*whenPrepared*/  return new Property("whenPrepared", "dateTime", "The time when the dispensed product was packaged and reviewed.", 0, 1, whenPrepared);
2326        case -940241380: /*whenHandedOver*/  return new Property("whenHandedOver", "dateTime", "The time the dispensed product was provided to the patient or their representative.", 0, 1, whenHandedOver);
2327        case -1429847026: /*destination*/  return new Property("destination", "Reference(Location)", "Identification of the facility/location where the medication was shipped to, as part of the dispense event.", 0, 1, destination);
2328        case -808719889: /*receiver*/  return new Property("receiver", "Reference(Patient|Practitioner)", "Identifies the person who picked up the medication.  This will usually be a patient or their caregiver, but some cases exist where it can be a healthcare professional.", 0, java.lang.Integer.MAX_VALUE, receiver);
2329        case 3387378: /*note*/  return new Property("note", "Annotation", "Extra information about the dispense that could not be conveyed in the other attributes.", 0, java.lang.Integer.MAX_VALUE, note);
2330        case -1201373865: /*dosageInstruction*/  return new Property("dosageInstruction", "Dosage", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction);
2331        case 826147581: /*substitution*/  return new Property("substitution", "", "Indicates whether or not substitution was made as part of the dispense.  In some cases substitution will be expected but does not happen, in other cases substitution is not expected but does happen.  This block explains what substitution did or did not happen and why.  If nothing is specified, substitution was not done.", 0, 1, substitution);
2332        case 51602295: /*detectedIssue*/  return new Property("detectedIssue", "Reference(DetectedIssue)", "Indicates an actual or potential clinical issue with or between one or more active or proposed clinical actions for a patient; e.g. Drug-drug interaction, duplicate therapy, dosage alert etc.", 0, java.lang.Integer.MAX_VALUE, detectedIssue);
2333        case 2128257269: /*notDone*/  return new Property("notDone", "boolean", "True if the dispense was not performed for some reason.", 0, 1, notDone);
2334        case -1762771385: /*notDoneReason[x]*/  return new Property("notDoneReason[x]", "CodeableConcept|Reference(DetectedIssue)", "Indicates the reason why a dispense was not performed.", 0, 1, notDoneReason);
2335        case -1973169255: /*notDoneReason*/  return new Property("notDoneReason[x]", "CodeableConcept|Reference(DetectedIssue)", "Indicates the reason why a dispense was not performed.", 0, 1, notDoneReason);
2336        case -930607416: /*notDoneReasonCodeableConcept*/  return new Property("notDoneReason[x]", "CodeableConcept|Reference(DetectedIssue)", "Indicates the reason why a dispense was not performed.", 0, 1, notDoneReason);
2337        case 1030457266: /*notDoneReasonReference*/  return new Property("notDoneReason[x]", "CodeableConcept|Reference(DetectedIssue)", "Indicates the reason why a dispense was not performed.", 0, 1, notDoneReason);
2338        case 1835190426: /*eventHistory*/  return new Property("eventHistory", "Reference(Provenance)", "A summary of the events of interest that have occurred, such as when the dispense was verified.", 0, java.lang.Integer.MAX_VALUE, eventHistory);
2339        default: return super.getNamedProperty(_hash, _name, _checkValid);
2340        }
2341
2342      }
2343
2344      @Override
2345      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
2346        switch (hash) {
2347        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
2348        case -995410646: /*partOf*/ return this.partOf == null ? new Base[0] : this.partOf.toArray(new Base[this.partOf.size()]); // Reference
2349        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<MedicationDispenseStatus>
2350        case 50511102: /*category*/ return this.category == null ? new Base[0] : new Base[] {this.category}; // CodeableConcept
2351        case 1998965455: /*medication*/ return this.medication == null ? new Base[0] : new Base[] {this.medication}; // Type
2352        case -1867885268: /*subject*/ return this.subject == null ? new Base[0] : new Base[] {this.subject}; // Reference
2353        case 951530927: /*context*/ return this.context == null ? new Base[0] : new Base[] {this.context}; // Reference
2354        case -1248768647: /*supportingInformation*/ return this.supportingInformation == null ? new Base[0] : this.supportingInformation.toArray(new Base[this.supportingInformation.size()]); // Reference
2355        case 481140686: /*performer*/ return this.performer == null ? new Base[0] : this.performer.toArray(new Base[this.performer.size()]); // MedicationDispensePerformerComponent
2356        case -1237557856: /*authorizingPrescription*/ return this.authorizingPrescription == null ? new Base[0] : this.authorizingPrescription.toArray(new Base[this.authorizingPrescription.size()]); // Reference
2357        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // CodeableConcept
2358        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // SimpleQuantity
2359        case 197175334: /*daysSupply*/ return this.daysSupply == null ? new Base[0] : new Base[] {this.daysSupply}; // SimpleQuantity
2360        case -562837097: /*whenPrepared*/ return this.whenPrepared == null ? new Base[0] : new Base[] {this.whenPrepared}; // DateTimeType
2361        case -940241380: /*whenHandedOver*/ return this.whenHandedOver == null ? new Base[0] : new Base[] {this.whenHandedOver}; // DateTimeType
2362        case -1429847026: /*destination*/ return this.destination == null ? new Base[0] : new Base[] {this.destination}; // Reference
2363        case -808719889: /*receiver*/ return this.receiver == null ? new Base[0] : this.receiver.toArray(new Base[this.receiver.size()]); // Reference
2364        case 3387378: /*note*/ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
2365        case -1201373865: /*dosageInstruction*/ return this.dosageInstruction == null ? new Base[0] : this.dosageInstruction.toArray(new Base[this.dosageInstruction.size()]); // Dosage
2366        case 826147581: /*substitution*/ return this.substitution == null ? new Base[0] : new Base[] {this.substitution}; // MedicationDispenseSubstitutionComponent
2367        case 51602295: /*detectedIssue*/ return this.detectedIssue == null ? new Base[0] : this.detectedIssue.toArray(new Base[this.detectedIssue.size()]); // Reference
2368        case 2128257269: /*notDone*/ return this.notDone == null ? new Base[0] : new Base[] {this.notDone}; // BooleanType
2369        case -1973169255: /*notDoneReason*/ return this.notDoneReason == null ? new Base[0] : new Base[] {this.notDoneReason}; // Type
2370        case 1835190426: /*eventHistory*/ return this.eventHistory == null ? new Base[0] : this.eventHistory.toArray(new Base[this.eventHistory.size()]); // Reference
2371        default: return super.getProperty(hash, name, checkValid);
2372        }
2373
2374      }
2375
2376      @Override
2377      public Base setProperty(int hash, String name, Base value) throws FHIRException {
2378        switch (hash) {
2379        case -1618432855: // identifier
2380          this.getIdentifier().add(castToIdentifier(value)); // Identifier
2381          return value;
2382        case -995410646: // partOf
2383          this.getPartOf().add(castToReference(value)); // Reference
2384          return value;
2385        case -892481550: // status
2386          value = new MedicationDispenseStatusEnumFactory().fromType(castToCode(value));
2387          this.status = (Enumeration) value; // Enumeration<MedicationDispenseStatus>
2388          return value;
2389        case 50511102: // category
2390          this.category = castToCodeableConcept(value); // CodeableConcept
2391          return value;
2392        case 1998965455: // medication
2393          this.medication = castToType(value); // Type
2394          return value;
2395        case -1867885268: // subject
2396          this.subject = castToReference(value); // Reference
2397          return value;
2398        case 951530927: // context
2399          this.context = castToReference(value); // Reference
2400          return value;
2401        case -1248768647: // supportingInformation
2402          this.getSupportingInformation().add(castToReference(value)); // Reference
2403          return value;
2404        case 481140686: // performer
2405          this.getPerformer().add((MedicationDispensePerformerComponent) value); // MedicationDispensePerformerComponent
2406          return value;
2407        case -1237557856: // authorizingPrescription
2408          this.getAuthorizingPrescription().add(castToReference(value)); // Reference
2409          return value;
2410        case 3575610: // type
2411          this.type = castToCodeableConcept(value); // CodeableConcept
2412          return value;
2413        case -1285004149: // quantity
2414          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
2415          return value;
2416        case 197175334: // daysSupply
2417          this.daysSupply = castToSimpleQuantity(value); // SimpleQuantity
2418          return value;
2419        case -562837097: // whenPrepared
2420          this.whenPrepared = castToDateTime(value); // DateTimeType
2421          return value;
2422        case -940241380: // whenHandedOver
2423          this.whenHandedOver = castToDateTime(value); // DateTimeType
2424          return value;
2425        case -1429847026: // destination
2426          this.destination = castToReference(value); // Reference
2427          return value;
2428        case -808719889: // receiver
2429          this.getReceiver().add(castToReference(value)); // Reference
2430          return value;
2431        case 3387378: // note
2432          this.getNote().add(castToAnnotation(value)); // Annotation
2433          return value;
2434        case -1201373865: // dosageInstruction
2435          this.getDosageInstruction().add(castToDosage(value)); // Dosage
2436          return value;
2437        case 826147581: // substitution
2438          this.substitution = (MedicationDispenseSubstitutionComponent) value; // MedicationDispenseSubstitutionComponent
2439          return value;
2440        case 51602295: // detectedIssue
2441          this.getDetectedIssue().add(castToReference(value)); // Reference
2442          return value;
2443        case 2128257269: // notDone
2444          this.notDone = castToBoolean(value); // BooleanType
2445          return value;
2446        case -1973169255: // notDoneReason
2447          this.notDoneReason = castToType(value); // Type
2448          return value;
2449        case 1835190426: // eventHistory
2450          this.getEventHistory().add(castToReference(value)); // Reference
2451          return value;
2452        default: return super.setProperty(hash, name, value);
2453        }
2454
2455      }
2456
2457      @Override
2458      public Base setProperty(String name, Base value) throws FHIRException {
2459        if (name.equals("identifier")) {
2460          this.getIdentifier().add(castToIdentifier(value));
2461        } else if (name.equals("partOf")) {
2462          this.getPartOf().add(castToReference(value));
2463        } else if (name.equals("status")) {
2464          value = new MedicationDispenseStatusEnumFactory().fromType(castToCode(value));
2465          this.status = (Enumeration) value; // Enumeration<MedicationDispenseStatus>
2466        } else if (name.equals("category")) {
2467          this.category = castToCodeableConcept(value); // CodeableConcept
2468        } else if (name.equals("medication[x]")) {
2469          this.medication = castToType(value); // Type
2470        } else if (name.equals("subject")) {
2471          this.subject = castToReference(value); // Reference
2472        } else if (name.equals("context")) {
2473          this.context = castToReference(value); // Reference
2474        } else if (name.equals("supportingInformation")) {
2475          this.getSupportingInformation().add(castToReference(value));
2476        } else if (name.equals("performer")) {
2477          this.getPerformer().add((MedicationDispensePerformerComponent) value);
2478        } else if (name.equals("authorizingPrescription")) {
2479          this.getAuthorizingPrescription().add(castToReference(value));
2480        } else if (name.equals("type")) {
2481          this.type = castToCodeableConcept(value); // CodeableConcept
2482        } else if (name.equals("quantity")) {
2483          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
2484        } else if (name.equals("daysSupply")) {
2485          this.daysSupply = castToSimpleQuantity(value); // SimpleQuantity
2486        } else if (name.equals("whenPrepared")) {
2487          this.whenPrepared = castToDateTime(value); // DateTimeType
2488        } else if (name.equals("whenHandedOver")) {
2489          this.whenHandedOver = castToDateTime(value); // DateTimeType
2490        } else if (name.equals("destination")) {
2491          this.destination = castToReference(value); // Reference
2492        } else if (name.equals("receiver")) {
2493          this.getReceiver().add(castToReference(value));
2494        } else if (name.equals("note")) {
2495          this.getNote().add(castToAnnotation(value));
2496        } else if (name.equals("dosageInstruction")) {
2497          this.getDosageInstruction().add(castToDosage(value));
2498        } else if (name.equals("substitution")) {
2499          this.substitution = (MedicationDispenseSubstitutionComponent) value; // MedicationDispenseSubstitutionComponent
2500        } else if (name.equals("detectedIssue")) {
2501          this.getDetectedIssue().add(castToReference(value));
2502        } else if (name.equals("notDone")) {
2503          this.notDone = castToBoolean(value); // BooleanType
2504        } else if (name.equals("notDoneReason[x]")) {
2505          this.notDoneReason = castToType(value); // Type
2506        } else if (name.equals("eventHistory")) {
2507          this.getEventHistory().add(castToReference(value));
2508        } else
2509          return super.setProperty(name, value);
2510        return value;
2511      }
2512
2513      @Override
2514      public Base makeProperty(int hash, String name) throws FHIRException {
2515        switch (hash) {
2516        case -1618432855:  return addIdentifier(); 
2517        case -995410646:  return addPartOf(); 
2518        case -892481550:  return getStatusElement();
2519        case 50511102:  return getCategory(); 
2520        case 1458402129:  return getMedication(); 
2521        case 1998965455:  return getMedication(); 
2522        case -1867885268:  return getSubject(); 
2523        case 951530927:  return getContext(); 
2524        case -1248768647:  return addSupportingInformation(); 
2525        case 481140686:  return addPerformer(); 
2526        case -1237557856:  return addAuthorizingPrescription(); 
2527        case 3575610:  return getType(); 
2528        case -1285004149:  return getQuantity(); 
2529        case 197175334:  return getDaysSupply(); 
2530        case -562837097:  return getWhenPreparedElement();
2531        case -940241380:  return getWhenHandedOverElement();
2532        case -1429847026:  return getDestination(); 
2533        case -808719889:  return addReceiver(); 
2534        case 3387378:  return addNote(); 
2535        case -1201373865:  return addDosageInstruction(); 
2536        case 826147581:  return getSubstitution(); 
2537        case 51602295:  return addDetectedIssue(); 
2538        case 2128257269:  return getNotDoneElement();
2539        case -1762771385:  return getNotDoneReason(); 
2540        case -1973169255:  return getNotDoneReason(); 
2541        case 1835190426:  return addEventHistory(); 
2542        default: return super.makeProperty(hash, name);
2543        }
2544
2545      }
2546
2547      @Override
2548      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
2549        switch (hash) {
2550        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
2551        case -995410646: /*partOf*/ return new String[] {"Reference"};
2552        case -892481550: /*status*/ return new String[] {"code"};
2553        case 50511102: /*category*/ return new String[] {"CodeableConcept"};
2554        case 1998965455: /*medication*/ return new String[] {"CodeableConcept", "Reference"};
2555        case -1867885268: /*subject*/ return new String[] {"Reference"};
2556        case 951530927: /*context*/ return new String[] {"Reference"};
2557        case -1248768647: /*supportingInformation*/ return new String[] {"Reference"};
2558        case 481140686: /*performer*/ return new String[] {};
2559        case -1237557856: /*authorizingPrescription*/ return new String[] {"Reference"};
2560        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
2561        case -1285004149: /*quantity*/ return new String[] {"SimpleQuantity"};
2562        case 197175334: /*daysSupply*/ return new String[] {"SimpleQuantity"};
2563        case -562837097: /*whenPrepared*/ return new String[] {"dateTime"};
2564        case -940241380: /*whenHandedOver*/ return new String[] {"dateTime"};
2565        case -1429847026: /*destination*/ return new String[] {"Reference"};
2566        case -808719889: /*receiver*/ return new String[] {"Reference"};
2567        case 3387378: /*note*/ return new String[] {"Annotation"};
2568        case -1201373865: /*dosageInstruction*/ return new String[] {"Dosage"};
2569        case 826147581: /*substitution*/ return new String[] {};
2570        case 51602295: /*detectedIssue*/ return new String[] {"Reference"};
2571        case 2128257269: /*notDone*/ return new String[] {"boolean"};
2572        case -1973169255: /*notDoneReason*/ return new String[] {"CodeableConcept", "Reference"};
2573        case 1835190426: /*eventHistory*/ return new String[] {"Reference"};
2574        default: return super.getTypesForProperty(hash, name);
2575        }
2576
2577      }
2578
2579      @Override
2580      public Base addChild(String name) throws FHIRException {
2581        if (name.equals("identifier")) {
2582          return addIdentifier();
2583        }
2584        else if (name.equals("partOf")) {
2585          return addPartOf();
2586        }
2587        else if (name.equals("status")) {
2588          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.status");
2589        }
2590        else if (name.equals("category")) {
2591          this.category = new CodeableConcept();
2592          return this.category;
2593        }
2594        else if (name.equals("medicationCodeableConcept")) {
2595          this.medication = new CodeableConcept();
2596          return this.medication;
2597        }
2598        else if (name.equals("medicationReference")) {
2599          this.medication = new Reference();
2600          return this.medication;
2601        }
2602        else if (name.equals("subject")) {
2603          this.subject = new Reference();
2604          return this.subject;
2605        }
2606        else if (name.equals("context")) {
2607          this.context = new Reference();
2608          return this.context;
2609        }
2610        else if (name.equals("supportingInformation")) {
2611          return addSupportingInformation();
2612        }
2613        else if (name.equals("performer")) {
2614          return addPerformer();
2615        }
2616        else if (name.equals("authorizingPrescription")) {
2617          return addAuthorizingPrescription();
2618        }
2619        else if (name.equals("type")) {
2620          this.type = new CodeableConcept();
2621          return this.type;
2622        }
2623        else if (name.equals("quantity")) {
2624          this.quantity = new SimpleQuantity();
2625          return this.quantity;
2626        }
2627        else if (name.equals("daysSupply")) {
2628          this.daysSupply = new SimpleQuantity();
2629          return this.daysSupply;
2630        }
2631        else if (name.equals("whenPrepared")) {
2632          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.whenPrepared");
2633        }
2634        else if (name.equals("whenHandedOver")) {
2635          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.whenHandedOver");
2636        }
2637        else if (name.equals("destination")) {
2638          this.destination = new Reference();
2639          return this.destination;
2640        }
2641        else if (name.equals("receiver")) {
2642          return addReceiver();
2643        }
2644        else if (name.equals("note")) {
2645          return addNote();
2646        }
2647        else if (name.equals("dosageInstruction")) {
2648          return addDosageInstruction();
2649        }
2650        else if (name.equals("substitution")) {
2651          this.substitution = new MedicationDispenseSubstitutionComponent();
2652          return this.substitution;
2653        }
2654        else if (name.equals("detectedIssue")) {
2655          return addDetectedIssue();
2656        }
2657        else if (name.equals("notDone")) {
2658          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.notDone");
2659        }
2660        else if (name.equals("notDoneReasonCodeableConcept")) {
2661          this.notDoneReason = new CodeableConcept();
2662          return this.notDoneReason;
2663        }
2664        else if (name.equals("notDoneReasonReference")) {
2665          this.notDoneReason = new Reference();
2666          return this.notDoneReason;
2667        }
2668        else if (name.equals("eventHistory")) {
2669          return addEventHistory();
2670        }
2671        else
2672          return super.addChild(name);
2673      }
2674
2675  public String fhirType() {
2676    return "MedicationDispense";
2677
2678  }
2679
2680      public MedicationDispense copy() {
2681        MedicationDispense dst = new MedicationDispense();
2682        copyValues(dst);
2683        if (identifier != null) {
2684          dst.identifier = new ArrayList<Identifier>();
2685          for (Identifier i : identifier)
2686            dst.identifier.add(i.copy());
2687        };
2688        if (partOf != null) {
2689          dst.partOf = new ArrayList<Reference>();
2690          for (Reference i : partOf)
2691            dst.partOf.add(i.copy());
2692        };
2693        dst.status = status == null ? null : status.copy();
2694        dst.category = category == null ? null : category.copy();
2695        dst.medication = medication == null ? null : medication.copy();
2696        dst.subject = subject == null ? null : subject.copy();
2697        dst.context = context == null ? null : context.copy();
2698        if (supportingInformation != null) {
2699          dst.supportingInformation = new ArrayList<Reference>();
2700          for (Reference i : supportingInformation)
2701            dst.supportingInformation.add(i.copy());
2702        };
2703        if (performer != null) {
2704          dst.performer = new ArrayList<MedicationDispensePerformerComponent>();
2705          for (MedicationDispensePerformerComponent i : performer)
2706            dst.performer.add(i.copy());
2707        };
2708        if (authorizingPrescription != null) {
2709          dst.authorizingPrescription = new ArrayList<Reference>();
2710          for (Reference i : authorizingPrescription)
2711            dst.authorizingPrescription.add(i.copy());
2712        };
2713        dst.type = type == null ? null : type.copy();
2714        dst.quantity = quantity == null ? null : quantity.copy();
2715        dst.daysSupply = daysSupply == null ? null : daysSupply.copy();
2716        dst.whenPrepared = whenPrepared == null ? null : whenPrepared.copy();
2717        dst.whenHandedOver = whenHandedOver == null ? null : whenHandedOver.copy();
2718        dst.destination = destination == null ? null : destination.copy();
2719        if (receiver != null) {
2720          dst.receiver = new ArrayList<Reference>();
2721          for (Reference i : receiver)
2722            dst.receiver.add(i.copy());
2723        };
2724        if (note != null) {
2725          dst.note = new ArrayList<Annotation>();
2726          for (Annotation i : note)
2727            dst.note.add(i.copy());
2728        };
2729        if (dosageInstruction != null) {
2730          dst.dosageInstruction = new ArrayList<Dosage>();
2731          for (Dosage i : dosageInstruction)
2732            dst.dosageInstruction.add(i.copy());
2733        };
2734        dst.substitution = substitution == null ? null : substitution.copy();
2735        if (detectedIssue != null) {
2736          dst.detectedIssue = new ArrayList<Reference>();
2737          for (Reference i : detectedIssue)
2738            dst.detectedIssue.add(i.copy());
2739        };
2740        dst.notDone = notDone == null ? null : notDone.copy();
2741        dst.notDoneReason = notDoneReason == null ? null : notDoneReason.copy();
2742        if (eventHistory != null) {
2743          dst.eventHistory = new ArrayList<Reference>();
2744          for (Reference i : eventHistory)
2745            dst.eventHistory.add(i.copy());
2746        };
2747        return dst;
2748      }
2749
2750      protected MedicationDispense typedCopy() {
2751        return copy();
2752      }
2753
2754      @Override
2755      public boolean equalsDeep(Base other_) {
2756        if (!super.equalsDeep(other_))
2757          return false;
2758        if (!(other_ instanceof MedicationDispense))
2759          return false;
2760        MedicationDispense o = (MedicationDispense) other_;
2761        return compareDeep(identifier, o.identifier, true) && compareDeep(partOf, o.partOf, true) && compareDeep(status, o.status, true)
2762           && compareDeep(category, o.category, true) && compareDeep(medication, o.medication, true) && compareDeep(subject, o.subject, true)
2763           && compareDeep(context, o.context, true) && compareDeep(supportingInformation, o.supportingInformation, true)
2764           && compareDeep(performer, o.performer, true) && compareDeep(authorizingPrescription, o.authorizingPrescription, true)
2765           && compareDeep(type, o.type, true) && compareDeep(quantity, o.quantity, true) && compareDeep(daysSupply, o.daysSupply, true)
2766           && compareDeep(whenPrepared, o.whenPrepared, true) && compareDeep(whenHandedOver, o.whenHandedOver, true)
2767           && compareDeep(destination, o.destination, true) && compareDeep(receiver, o.receiver, true) && compareDeep(note, o.note, true)
2768           && compareDeep(dosageInstruction, o.dosageInstruction, true) && compareDeep(substitution, o.substitution, true)
2769           && compareDeep(detectedIssue, o.detectedIssue, true) && compareDeep(notDone, o.notDone, true) && compareDeep(notDoneReason, o.notDoneReason, true)
2770           && compareDeep(eventHistory, o.eventHistory, true);
2771      }
2772
2773      @Override
2774      public boolean equalsShallow(Base other_) {
2775        if (!super.equalsShallow(other_))
2776          return false;
2777        if (!(other_ instanceof MedicationDispense))
2778          return false;
2779        MedicationDispense o = (MedicationDispense) other_;
2780        return compareValues(status, o.status, true) && compareValues(whenPrepared, o.whenPrepared, true) && compareValues(whenHandedOver, o.whenHandedOver, true)
2781           && compareValues(notDone, o.notDone, true);
2782      }
2783
2784      public boolean isEmpty() {
2785        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, partOf, status
2786          , category, medication, subject, context, supportingInformation, performer, authorizingPrescription
2787          , type, quantity, daysSupply, whenPrepared, whenHandedOver, destination, receiver
2788          , note, dosageInstruction, substitution, detectedIssue, notDone, notDoneReason, eventHistory
2789          );
2790      }
2791
2792  @Override
2793  public ResourceType getResourceType() {
2794    return ResourceType.MedicationDispense;
2795   }
2796
2797 /**
2798   * Search parameter: <b>identifier</b>
2799   * <p>
2800   * Description: <b>Return dispenses with this external identifier</b><br>
2801   * Type: <b>token</b><br>
2802   * Path: <b>MedicationDispense.identifier</b><br>
2803   * </p>
2804   */
2805  @SearchParamDefinition(name="identifier", path="MedicationDispense.identifier", description="Return dispenses with this external identifier", type="token" )
2806  public static final String SP_IDENTIFIER = "identifier";
2807 /**
2808   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
2809   * <p>
2810   * Description: <b>Return dispenses with this external identifier</b><br>
2811   * Type: <b>token</b><br>
2812   * Path: <b>MedicationDispense.identifier</b><br>
2813   * </p>
2814   */
2815  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
2816
2817 /**
2818   * Search parameter: <b>performer</b>
2819   * <p>
2820   * Description: <b>Return dispenses performed by a specific individual</b><br>
2821   * Type: <b>reference</b><br>
2822   * Path: <b>MedicationDispense.performer.actor</b><br>
2823   * </p>
2824   */
2825  @SearchParamDefinition(name="performer", path="MedicationDispense.performer.actor", description="Return dispenses performed by a specific individual", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Practitioner") }, target={Device.class, Organization.class, Patient.class, Practitioner.class, RelatedPerson.class } )
2826  public static final String SP_PERFORMER = "performer";
2827 /**
2828   * <b>Fluent Client</b> search parameter constant for <b>performer</b>
2829   * <p>
2830   * Description: <b>Return dispenses performed by a specific individual</b><br>
2831   * Type: <b>reference</b><br>
2832   * Path: <b>MedicationDispense.performer.actor</b><br>
2833   * </p>
2834   */
2835  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PERFORMER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PERFORMER);
2836
2837/**
2838   * Constant for fluent queries to be used to add include statements. Specifies
2839   * the path value of "<b>MedicationDispense:performer</b>".
2840   */
2841  public static final ca.uhn.fhir.model.api.Include INCLUDE_PERFORMER = new ca.uhn.fhir.model.api.Include("MedicationDispense:performer").toLocked();
2842
2843 /**
2844   * Search parameter: <b>code</b>
2845   * <p>
2846   * Description: <b>Return dispenses of this medicine code</b><br>
2847   * Type: <b>token</b><br>
2848   * Path: <b>MedicationDispense.medicationCodeableConcept</b><br>
2849   * </p>
2850   */
2851  @SearchParamDefinition(name="code", path="MedicationDispense.medication.as(CodeableConcept)", description="Return dispenses of this medicine code", type="token" )
2852  public static final String SP_CODE = "code";
2853 /**
2854   * <b>Fluent Client</b> search parameter constant for <b>code</b>
2855   * <p>
2856   * Description: <b>Return dispenses of this medicine code</b><br>
2857   * Type: <b>token</b><br>
2858   * Path: <b>MedicationDispense.medicationCodeableConcept</b><br>
2859   * </p>
2860   */
2861  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CODE);
2862
2863 /**
2864   * Search parameter: <b>receiver</b>
2865   * <p>
2866   * Description: <b>The identity of a receiver to list dispenses for</b><br>
2867   * Type: <b>reference</b><br>
2868   * Path: <b>MedicationDispense.receiver</b><br>
2869   * </p>
2870   */
2871  @SearchParamDefinition(name="receiver", path="MedicationDispense.receiver", description="The identity of a receiver to list dispenses for", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Practitioner") }, target={Patient.class, Practitioner.class } )
2872  public static final String SP_RECEIVER = "receiver";
2873 /**
2874   * <b>Fluent Client</b> search parameter constant for <b>receiver</b>
2875   * <p>
2876   * Description: <b>The identity of a receiver to list dispenses for</b><br>
2877   * Type: <b>reference</b><br>
2878   * Path: <b>MedicationDispense.receiver</b><br>
2879   * </p>
2880   */
2881  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam RECEIVER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_RECEIVER);
2882
2883/**
2884   * Constant for fluent queries to be used to add include statements. Specifies
2885   * the path value of "<b>MedicationDispense:receiver</b>".
2886   */
2887  public static final ca.uhn.fhir.model.api.Include INCLUDE_RECEIVER = new ca.uhn.fhir.model.api.Include("MedicationDispense:receiver").toLocked();
2888
2889 /**
2890   * Search parameter: <b>subject</b>
2891   * <p>
2892   * Description: <b>The identity of a patient to list dispenses  for</b><br>
2893   * Type: <b>reference</b><br>
2894   * Path: <b>MedicationDispense.subject</b><br>
2895   * </p>
2896   */
2897  @SearchParamDefinition(name="subject", path="MedicationDispense.subject", description="The identity of a patient to list dispenses  for", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient") }, target={Group.class, Patient.class } )
2898  public static final String SP_SUBJECT = "subject";
2899 /**
2900   * <b>Fluent Client</b> search parameter constant for <b>subject</b>
2901   * <p>
2902   * Description: <b>The identity of a patient to list dispenses  for</b><br>
2903   * Type: <b>reference</b><br>
2904   * Path: <b>MedicationDispense.subject</b><br>
2905   * </p>
2906   */
2907  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBJECT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUBJECT);
2908
2909/**
2910   * Constant for fluent queries to be used to add include statements. Specifies
2911   * the path value of "<b>MedicationDispense:subject</b>".
2912   */
2913  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBJECT = new ca.uhn.fhir.model.api.Include("MedicationDispense:subject").toLocked();
2914
2915 /**
2916   * Search parameter: <b>destination</b>
2917   * <p>
2918   * Description: <b>Return dispenses that should be sent to a specific destination</b><br>
2919   * Type: <b>reference</b><br>
2920   * Path: <b>MedicationDispense.destination</b><br>
2921   * </p>
2922   */
2923  @SearchParamDefinition(name="destination", path="MedicationDispense.destination", description="Return dispenses that should be sent to a specific destination", type="reference", target={Location.class } )
2924  public static final String SP_DESTINATION = "destination";
2925 /**
2926   * <b>Fluent Client</b> search parameter constant for <b>destination</b>
2927   * <p>
2928   * Description: <b>Return dispenses that should be sent to a specific destination</b><br>
2929   * Type: <b>reference</b><br>
2930   * Path: <b>MedicationDispense.destination</b><br>
2931   * </p>
2932   */
2933  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam DESTINATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_DESTINATION);
2934
2935/**
2936   * Constant for fluent queries to be used to add include statements. Specifies
2937   * the path value of "<b>MedicationDispense:destination</b>".
2938   */
2939  public static final ca.uhn.fhir.model.api.Include INCLUDE_DESTINATION = new ca.uhn.fhir.model.api.Include("MedicationDispense:destination").toLocked();
2940
2941 /**
2942   * Search parameter: <b>medication</b>
2943   * <p>
2944   * Description: <b>Return dispenses of this medicine resource</b><br>
2945   * Type: <b>reference</b><br>
2946   * Path: <b>MedicationDispense.medicationReference</b><br>
2947   * </p>
2948   */
2949  @SearchParamDefinition(name="medication", path="MedicationDispense.medication.as(Reference)", description="Return dispenses of this medicine resource", type="reference", target={Medication.class } )
2950  public static final String SP_MEDICATION = "medication";
2951 /**
2952   * <b>Fluent Client</b> search parameter constant for <b>medication</b>
2953   * <p>
2954   * Description: <b>Return dispenses of this medicine resource</b><br>
2955   * Type: <b>reference</b><br>
2956   * Path: <b>MedicationDispense.medicationReference</b><br>
2957   * </p>
2958   */
2959  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam MEDICATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_MEDICATION);
2960
2961/**
2962   * Constant for fluent queries to be used to add include statements. Specifies
2963   * the path value of "<b>MedicationDispense:medication</b>".
2964   */
2965  public static final ca.uhn.fhir.model.api.Include INCLUDE_MEDICATION = new ca.uhn.fhir.model.api.Include("MedicationDispense:medication").toLocked();
2966
2967 /**
2968   * Search parameter: <b>responsibleparty</b>
2969   * <p>
2970   * Description: <b>Return dispenses with the specified responsible party</b><br>
2971   * Type: <b>reference</b><br>
2972   * Path: <b>MedicationDispense.substitution.responsibleParty</b><br>
2973   * </p>
2974   */
2975  @SearchParamDefinition(name="responsibleparty", path="MedicationDispense.substitution.responsibleParty", description="Return dispenses with the specified responsible party", type="reference", target={Practitioner.class } )
2976  public static final String SP_RESPONSIBLEPARTY = "responsibleparty";
2977 /**
2978   * <b>Fluent Client</b> search parameter constant for <b>responsibleparty</b>
2979   * <p>
2980   * Description: <b>Return dispenses with the specified responsible party</b><br>
2981   * Type: <b>reference</b><br>
2982   * Path: <b>MedicationDispense.substitution.responsibleParty</b><br>
2983   * </p>
2984   */
2985  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam RESPONSIBLEPARTY = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_RESPONSIBLEPARTY);
2986
2987/**
2988   * Constant for fluent queries to be used to add include statements. Specifies
2989   * the path value of "<b>MedicationDispense:responsibleparty</b>".
2990   */
2991  public static final ca.uhn.fhir.model.api.Include INCLUDE_RESPONSIBLEPARTY = new ca.uhn.fhir.model.api.Include("MedicationDispense:responsibleparty").toLocked();
2992
2993 /**
2994   * Search parameter: <b>type</b>
2995   * <p>
2996   * Description: <b>Return dispenses of a specific type</b><br>
2997   * Type: <b>token</b><br>
2998   * Path: <b>MedicationDispense.type</b><br>
2999   * </p>
3000   */
3001  @SearchParamDefinition(name="type", path="MedicationDispense.type", description="Return dispenses of a specific type", type="token" )
3002  public static final String SP_TYPE = "type";
3003 /**
3004   * <b>Fluent Client</b> search parameter constant for <b>type</b>
3005   * <p>
3006   * Description: <b>Return dispenses of a specific type</b><br>
3007   * Type: <b>token</b><br>
3008   * Path: <b>MedicationDispense.type</b><br>
3009   * </p>
3010   */
3011  public static final ca.uhn.fhir.rest.gclient.TokenClientParam TYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_TYPE);
3012
3013 /**
3014   * Search parameter: <b>whenhandedover</b>
3015   * <p>
3016   * Description: <b>Returns dispenses handed over on this date</b><br>
3017   * Type: <b>date</b><br>
3018   * Path: <b>MedicationDispense.whenHandedOver</b><br>
3019   * </p>
3020   */
3021  @SearchParamDefinition(name="whenhandedover", path="MedicationDispense.whenHandedOver", description="Returns dispenses handed over on this date", type="date" )
3022  public static final String SP_WHENHANDEDOVER = "whenhandedover";
3023 /**
3024   * <b>Fluent Client</b> search parameter constant for <b>whenhandedover</b>
3025   * <p>
3026   * Description: <b>Returns dispenses handed over on this date</b><br>
3027   * Type: <b>date</b><br>
3028   * Path: <b>MedicationDispense.whenHandedOver</b><br>
3029   * </p>
3030   */
3031  public static final ca.uhn.fhir.rest.gclient.DateClientParam WHENHANDEDOVER = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_WHENHANDEDOVER);
3032
3033 /**
3034   * Search parameter: <b>whenprepared</b>
3035   * <p>
3036   * Description: <b>Returns dispenses prepared on this date</b><br>
3037   * Type: <b>date</b><br>
3038   * Path: <b>MedicationDispense.whenPrepared</b><br>
3039   * </p>
3040   */
3041  @SearchParamDefinition(name="whenprepared", path="MedicationDispense.whenPrepared", description="Returns dispenses prepared on this date", type="date" )
3042  public static final String SP_WHENPREPARED = "whenprepared";
3043 /**
3044   * <b>Fluent Client</b> search parameter constant for <b>whenprepared</b>
3045   * <p>
3046   * Description: <b>Returns dispenses prepared on this date</b><br>
3047   * Type: <b>date</b><br>
3048   * Path: <b>MedicationDispense.whenPrepared</b><br>
3049   * </p>
3050   */
3051  public static final ca.uhn.fhir.rest.gclient.DateClientParam WHENPREPARED = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_WHENPREPARED);
3052
3053 /**
3054   * Search parameter: <b>prescription</b>
3055   * <p>
3056   * Description: <b>The identity of a prescription to list dispenses from</b><br>
3057   * Type: <b>reference</b><br>
3058   * Path: <b>MedicationDispense.authorizingPrescription</b><br>
3059   * </p>
3060   */
3061  @SearchParamDefinition(name="prescription", path="MedicationDispense.authorizingPrescription", description="The identity of a prescription to list dispenses from", type="reference", target={MedicationRequest.class } )
3062  public static final String SP_PRESCRIPTION = "prescription";
3063 /**
3064   * <b>Fluent Client</b> search parameter constant for <b>prescription</b>
3065   * <p>
3066   * Description: <b>The identity of a prescription to list dispenses from</b><br>
3067   * Type: <b>reference</b><br>
3068   * Path: <b>MedicationDispense.authorizingPrescription</b><br>
3069   * </p>
3070   */
3071  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PRESCRIPTION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PRESCRIPTION);
3072
3073/**
3074   * Constant for fluent queries to be used to add include statements. Specifies
3075   * the path value of "<b>MedicationDispense:prescription</b>".
3076   */
3077  public static final ca.uhn.fhir.model.api.Include INCLUDE_PRESCRIPTION = new ca.uhn.fhir.model.api.Include("MedicationDispense:prescription").toLocked();
3078
3079 /**
3080   * Search parameter: <b>patient</b>
3081   * <p>
3082   * Description: <b>The identity of a patient to list dispenses  for</b><br>
3083   * Type: <b>reference</b><br>
3084   * Path: <b>MedicationDispense.subject</b><br>
3085   * </p>
3086   */
3087  @SearchParamDefinition(name="patient", path="MedicationDispense.subject", description="The identity of a patient to list dispenses  for", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient") }, target={Patient.class } )
3088  public static final String SP_PATIENT = "patient";
3089 /**
3090   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
3091   * <p>
3092   * Description: <b>The identity of a patient to list dispenses  for</b><br>
3093   * Type: <b>reference</b><br>
3094   * Path: <b>MedicationDispense.subject</b><br>
3095   * </p>
3096   */
3097  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
3098
3099/**
3100   * Constant for fluent queries to be used to add include statements. Specifies
3101   * the path value of "<b>MedicationDispense:patient</b>".
3102   */
3103  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("MedicationDispense:patient").toLocked();
3104
3105 /**
3106   * Search parameter: <b>context</b>
3107   * <p>
3108   * Description: <b>Returns dispenses with a specific context (episode or episode of care)</b><br>
3109   * Type: <b>reference</b><br>
3110   * Path: <b>MedicationDispense.context</b><br>
3111   * </p>
3112   */
3113  @SearchParamDefinition(name="context", path="MedicationDispense.context", description="Returns dispenses with a specific context (episode or episode of care)", type="reference", target={Encounter.class, EpisodeOfCare.class } )
3114  public static final String SP_CONTEXT = "context";
3115 /**
3116   * <b>Fluent Client</b> search parameter constant for <b>context</b>
3117   * <p>
3118   * Description: <b>Returns dispenses with a specific context (episode or episode of care)</b><br>
3119   * Type: <b>reference</b><br>
3120   * Path: <b>MedicationDispense.context</b><br>
3121   * </p>
3122   */
3123  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam CONTEXT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_CONTEXT);
3124
3125/**
3126   * Constant for fluent queries to be used to add include statements. Specifies
3127   * the path value of "<b>MedicationDispense:context</b>".
3128   */
3129  public static final ca.uhn.fhir.model.api.Include INCLUDE_CONTEXT = new ca.uhn.fhir.model.api.Include("MedicationDispense:context").toLocked();
3130
3131 /**
3132   * Search parameter: <b>status</b>
3133   * <p>
3134   * Description: <b>Return dispenses with a specified dispense status</b><br>
3135   * Type: <b>token</b><br>
3136   * Path: <b>MedicationDispense.status</b><br>
3137   * </p>
3138   */
3139  @SearchParamDefinition(name="status", path="MedicationDispense.status", description="Return dispenses with a specified dispense status", type="token" )
3140  public static final String SP_STATUS = "status";
3141 /**
3142   * <b>Fluent Client</b> search parameter constant for <b>status</b>
3143   * <p>
3144   * Description: <b>Return dispenses with a specified dispense status</b><br>
3145   * Type: <b>token</b><br>
3146   * Path: <b>MedicationDispense.status</b><br>
3147   * </p>
3148   */
3149  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
3150
3151
3152}
3153