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