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