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