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