001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
046import org.hl7.fhir.exceptions.FHIRException;
047import org.hl7.fhir.utilities.Utilities;
048/**
049 * Indicates that a medication product is to be or has been dispensed for a named person/patient.  This includes a description of the medication product (supply) provided and the instructions for administering the medication.  The medication dispense is the result of a pharmacy system responding to a medication order.
050 */
051@ResourceDef(name="MedicationDispense", profile="http://hl7.org/fhir/Profile/MedicationDispense")
052public class MedicationDispense extends DomainResource {
053
054    public enum MedicationDispenseStatus {
055        /**
056         * The dispense has started but has not yet completed.
057         */
058        INPROGRESS, 
059        /**
060         * Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called "suspended"
061         */
062        ONHOLD, 
063        /**
064         * All actions that are implied by the dispense have occurred.
065         */
066        COMPLETED, 
067        /**
068         * The dispense was entered in error and therefore nullified.
069         */
070        ENTEREDINERROR, 
071        /**
072         * Actions implied by the dispense have been permanently halted, before all of them occurred.
073         */
074        STOPPED, 
075        /**
076         * added to help the parsers
077         */
078        NULL;
079        public static MedicationDispenseStatus fromCode(String codeString) throws FHIRException {
080            if (codeString == null || "".equals(codeString))
081                return null;
082        if ("in-progress".equals(codeString))
083          return INPROGRESS;
084        if ("on-hold".equals(codeString))
085          return ONHOLD;
086        if ("completed".equals(codeString))
087          return COMPLETED;
088        if ("entered-in-error".equals(codeString))
089          return ENTEREDINERROR;
090        if ("stopped".equals(codeString))
091          return STOPPED;
092        throw new FHIRException("Unknown MedicationDispenseStatus code '"+codeString+"'");
093        }
094        public String toCode() {
095          switch (this) {
096            case INPROGRESS: return "in-progress";
097            case ONHOLD: return "on-hold";
098            case COMPLETED: return "completed";
099            case ENTEREDINERROR: return "entered-in-error";
100            case STOPPED: return "stopped";
101            case NULL: return null;
102            default: return "?";
103          }
104        }
105        public String getSystem() {
106          switch (this) {
107            case INPROGRESS: return "http://hl7.org/fhir/medication-dispense-status";
108            case ONHOLD: return "http://hl7.org/fhir/medication-dispense-status";
109            case COMPLETED: return "http://hl7.org/fhir/medication-dispense-status";
110            case ENTEREDINERROR: return "http://hl7.org/fhir/medication-dispense-status";
111            case STOPPED: return "http://hl7.org/fhir/medication-dispense-status";
112            case NULL: return null;
113            default: return "?";
114          }
115        }
116        public String getDefinition() {
117          switch (this) {
118            case INPROGRESS: return "The dispense has started but has not yet completed.";
119            case ONHOLD: return "Actions implied by the administration have been temporarily halted, but are expected to continue later. May also be called \"suspended\"";
120            case COMPLETED: return "All actions that are implied by the dispense have occurred.";
121            case ENTEREDINERROR: return "The dispense was entered in error and therefore nullified.";
122            case STOPPED: return "Actions implied by the dispense have been permanently halted, before all of them occurred.";
123            case NULL: return null;
124            default: return "?";
125          }
126        }
127        public String getDisplay() {
128          switch (this) {
129            case INPROGRESS: return "In Progress";
130            case ONHOLD: return "On Hold";
131            case COMPLETED: return "Completed";
132            case ENTEREDINERROR: return "Entered in-Error";
133            case STOPPED: return "Stopped";
134            case NULL: return null;
135            default: return "?";
136          }
137        }
138    }
139
140  public static class MedicationDispenseStatusEnumFactory implements EnumFactory<MedicationDispenseStatus> {
141    public MedicationDispenseStatus fromCode(String codeString) throws IllegalArgumentException {
142      if (codeString == null || "".equals(codeString))
143            if (codeString == null || "".equals(codeString))
144                return null;
145        if ("in-progress".equals(codeString))
146          return MedicationDispenseStatus.INPROGRESS;
147        if ("on-hold".equals(codeString))
148          return MedicationDispenseStatus.ONHOLD;
149        if ("completed".equals(codeString))
150          return MedicationDispenseStatus.COMPLETED;
151        if ("entered-in-error".equals(codeString))
152          return MedicationDispenseStatus.ENTEREDINERROR;
153        if ("stopped".equals(codeString))
154          return MedicationDispenseStatus.STOPPED;
155        throw new IllegalArgumentException("Unknown MedicationDispenseStatus code '"+codeString+"'");
156        }
157        public Enumeration<MedicationDispenseStatus> fromType(Base code) throws FHIRException {
158          if (code == null || code.isEmpty())
159            return null;
160          String codeString = ((PrimitiveType) code).asStringValue();
161          if (codeString == null || "".equals(codeString))
162            return null;
163        if ("in-progress".equals(codeString))
164          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.INPROGRESS);
165        if ("on-hold".equals(codeString))
166          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.ONHOLD);
167        if ("completed".equals(codeString))
168          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.COMPLETED);
169        if ("entered-in-error".equals(codeString))
170          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.ENTEREDINERROR);
171        if ("stopped".equals(codeString))
172          return new Enumeration<MedicationDispenseStatus>(this, MedicationDispenseStatus.STOPPED);
173        throw new FHIRException("Unknown MedicationDispenseStatus code '"+codeString+"'");
174        }
175    public String toCode(MedicationDispenseStatus code) {
176      if (code == MedicationDispenseStatus.INPROGRESS)
177        return "in-progress";
178      if (code == MedicationDispenseStatus.ONHOLD)
179        return "on-hold";
180      if (code == MedicationDispenseStatus.COMPLETED)
181        return "completed";
182      if (code == MedicationDispenseStatus.ENTEREDINERROR)
183        return "entered-in-error";
184      if (code == MedicationDispenseStatus.STOPPED)
185        return "stopped";
186      return "?";
187      }
188    }
189
190    @Block()
191    public static class MedicationDispenseDosageInstructionComponent extends BackboneElement implements IBaseBackboneElement {
192        /**
193         * Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
194         */
195        @Child(name = "text", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
196        @Description(shortDefinition="Dosage Instructions", formalDefinition="Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication." )
197        protected StringType text;
198
199        /**
200         * Additional instructions such as "Swallow with plenty of water" which may or may not be coded.
201         */
202        @Child(name = "additionalInstructions", type = {CodeableConcept.class}, order=2, min=0, max=1, modifier=false, summary=true)
203        @Description(shortDefinition="E.g. \"Take with food\"", formalDefinition="Additional instructions such as \"Swallow with plenty of water\" which may or may not be coded." )
204        protected CodeableConcept additionalInstructions;
205
206        /**
207         * The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions.  For example, "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".
208         */
209        @Child(name = "timing", type = {Timing.class}, order=3, min=0, max=1, modifier=false, summary=true)
210        @Description(shortDefinition="When medication should be administered", formalDefinition="The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions.  For example, \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\"." )
211        protected Timing timing;
212
213        /**
214         * Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
215
216Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.
217         */
218        @Child(name = "asNeeded", type = {BooleanType.class, CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
219        @Description(shortDefinition="Take \"as needed\" f(or x)", formalDefinition="Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule." )
220        protected Type asNeeded;
221
222        /**
223         * A coded specification of the anatomic site where the medication first enters the body.
224         */
225        @Child(name = "site", type = {CodeableConcept.class, BodySite.class}, order=5, min=0, max=1, modifier=false, summary=true)
226        @Description(shortDefinition="Body site to administer to", formalDefinition="A coded specification of the anatomic site where the medication first enters the body." )
227        protected Type site;
228
229        /**
230         * A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.
231         */
232        @Child(name = "route", type = {CodeableConcept.class}, order=6, min=0, max=1, modifier=false, summary=true)
233        @Description(shortDefinition="How drug should enter body", formalDefinition="A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject." )
234        protected CodeableConcept route;
235
236        /**
237         * A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.
238         */
239        @Child(name = "method", type = {CodeableConcept.class}, order=7, min=0, max=1, modifier=false, summary=true)
240        @Description(shortDefinition="Technique for administering medication", formalDefinition="A coded value indicating the method by which the medication is intended to be or was introduced into or on the body." )
241        protected CodeableConcept method;
242
243        /**
244         * The amount of therapeutic or other substance given at one administration event.
245         */
246        @Child(name = "dose", type = {Range.class, SimpleQuantity.class}, order=8, min=0, max=1, modifier=false, summary=true)
247        @Description(shortDefinition="Amount of medication per dose", formalDefinition="The amount of therapeutic or other substance given at one administration event." )
248        protected Type dose;
249
250        /**
251         * Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.
252         */
253        @Child(name = "rate", type = {Ratio.class, Range.class}, order=9, min=0, max=1, modifier=false, summary=true)
254        @Description(shortDefinition="Amount of medication per unit of time", formalDefinition="Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours." )
255        protected Type rate;
256
257        /**
258         * The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time,  e.g. 1000mg in 24 hours.
259         */
260        @Child(name = "maxDosePerPeriod", type = {Ratio.class}, order=10, min=0, max=1, modifier=false, summary=true)
261        @Description(shortDefinition="Upper limit on medication per unit of time", formalDefinition="The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time,  e.g. 1000mg in 24 hours." )
262        protected Ratio maxDosePerPeriod;
263
264        private static final long serialVersionUID = -1470136646L;
265
266    /*
267     * Constructor
268     */
269      public MedicationDispenseDosageInstructionComponent() {
270        super();
271      }
272
273        /**
274         * @return {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
275         */
276        public StringType getTextElement() { 
277          if (this.text == null)
278            if (Configuration.errorOnAutoCreate())
279              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.text");
280            else if (Configuration.doAutoCreate())
281              this.text = new StringType(); // bb
282          return this.text;
283        }
284
285        public boolean hasTextElement() { 
286          return this.text != null && !this.text.isEmpty();
287        }
288
289        public boolean hasText() { 
290          return this.text != null && !this.text.isEmpty();
291        }
292
293        /**
294         * @param value {@link #text} (Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
295         */
296        public MedicationDispenseDosageInstructionComponent setTextElement(StringType value) { 
297          this.text = value;
298          return this;
299        }
300
301        /**
302         * @return Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
303         */
304        public String getText() { 
305          return this.text == null ? null : this.text.getValue();
306        }
307
308        /**
309         * @param value Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.
310         */
311        public MedicationDispenseDosageInstructionComponent setText(String value) { 
312          if (Utilities.noString(value))
313            this.text = null;
314          else {
315            if (this.text == null)
316              this.text = new StringType();
317            this.text.setValue(value);
318          }
319          return this;
320        }
321
322        /**
323         * @return {@link #additionalInstructions} (Additional instructions such as "Swallow with plenty of water" which may or may not be coded.)
324         */
325        public CodeableConcept getAdditionalInstructions() { 
326          if (this.additionalInstructions == null)
327            if (Configuration.errorOnAutoCreate())
328              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.additionalInstructions");
329            else if (Configuration.doAutoCreate())
330              this.additionalInstructions = new CodeableConcept(); // cc
331          return this.additionalInstructions;
332        }
333
334        public boolean hasAdditionalInstructions() { 
335          return this.additionalInstructions != null && !this.additionalInstructions.isEmpty();
336        }
337
338        /**
339         * @param value {@link #additionalInstructions} (Additional instructions such as "Swallow with plenty of water" which may or may not be coded.)
340         */
341        public MedicationDispenseDosageInstructionComponent setAdditionalInstructions(CodeableConcept value) { 
342          this.additionalInstructions = value;
343          return this;
344        }
345
346        /**
347         * @return {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions.  For example, "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
348         */
349        public Timing getTiming() { 
350          if (this.timing == null)
351            if (Configuration.errorOnAutoCreate())
352              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.timing");
353            else if (Configuration.doAutoCreate())
354              this.timing = new Timing(); // cc
355          return this.timing;
356        }
357
358        public boolean hasTiming() { 
359          return this.timing != null && !this.timing.isEmpty();
360        }
361
362        /**
363         * @param value {@link #timing} (The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions.  For example, "Every  8 hours"; "Three times a day"; "1/2 an hour before breakfast for 10 days from 23-Dec 2011:";  "15 Oct 2013, 17 Oct 2013 and 1 Nov 2013".)
364         */
365        public MedicationDispenseDosageInstructionComponent setTiming(Timing value) { 
366          this.timing = value;
367          return this;
368        }
369
370        /**
371         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
372
373Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
374         */
375        public Type getAsNeeded() { 
376          return this.asNeeded;
377        }
378
379        /**
380         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
381
382Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
383         */
384        public BooleanType getAsNeededBooleanType() throws FHIRException { 
385          if (!(this.asNeeded instanceof BooleanType))
386            throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
387          return (BooleanType) this.asNeeded;
388        }
389
390        public boolean hasAsNeededBooleanType() { 
391          return this.asNeeded instanceof BooleanType;
392        }
393
394        /**
395         * @return {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
396
397Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
398         */
399        public CodeableConcept getAsNeededCodeableConcept() throws FHIRException { 
400          if (!(this.asNeeded instanceof CodeableConcept))
401            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.asNeeded.getClass().getName()+" was encountered");
402          return (CodeableConcept) this.asNeeded;
403        }
404
405        public boolean hasAsNeededCodeableConcept() { 
406          return this.asNeeded instanceof CodeableConcept;
407        }
408
409        public boolean hasAsNeeded() { 
410          return this.asNeeded != null && !this.asNeeded.isEmpty();
411        }
412
413        /**
414         * @param value {@link #asNeeded} (Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  
415
416Specifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.)
417         */
418        public MedicationDispenseDosageInstructionComponent setAsNeeded(Type value) { 
419          this.asNeeded = value;
420          return this;
421        }
422
423        /**
424         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
425         */
426        public Type getSite() { 
427          return this.site;
428        }
429
430        /**
431         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
432         */
433        public CodeableConcept getSiteCodeableConcept() throws FHIRException { 
434          if (!(this.site instanceof CodeableConcept))
435            throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.site.getClass().getName()+" was encountered");
436          return (CodeableConcept) this.site;
437        }
438
439        public boolean hasSiteCodeableConcept() { 
440          return this.site instanceof CodeableConcept;
441        }
442
443        /**
444         * @return {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
445         */
446        public Reference getSiteReference() throws FHIRException { 
447          if (!(this.site instanceof Reference))
448            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.site.getClass().getName()+" was encountered");
449          return (Reference) this.site;
450        }
451
452        public boolean hasSiteReference() { 
453          return this.site instanceof Reference;
454        }
455
456        public boolean hasSite() { 
457          return this.site != null && !this.site.isEmpty();
458        }
459
460        /**
461         * @param value {@link #site} (A coded specification of the anatomic site where the medication first enters the body.)
462         */
463        public MedicationDispenseDosageInstructionComponent setSite(Type value) { 
464          this.site = value;
465          return this;
466        }
467
468        /**
469         * @return {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
470         */
471        public CodeableConcept getRoute() { 
472          if (this.route == null)
473            if (Configuration.errorOnAutoCreate())
474              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.route");
475            else if (Configuration.doAutoCreate())
476              this.route = new CodeableConcept(); // cc
477          return this.route;
478        }
479
480        public boolean hasRoute() { 
481          return this.route != null && !this.route.isEmpty();
482        }
483
484        /**
485         * @param value {@link #route} (A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.)
486         */
487        public MedicationDispenseDosageInstructionComponent setRoute(CodeableConcept value) { 
488          this.route = value;
489          return this;
490        }
491
492        /**
493         * @return {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.)
494         */
495        public CodeableConcept getMethod() { 
496          if (this.method == null)
497            if (Configuration.errorOnAutoCreate())
498              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.method");
499            else if (Configuration.doAutoCreate())
500              this.method = new CodeableConcept(); // cc
501          return this.method;
502        }
503
504        public boolean hasMethod() { 
505          return this.method != null && !this.method.isEmpty();
506        }
507
508        /**
509         * @param value {@link #method} (A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.)
510         */
511        public MedicationDispenseDosageInstructionComponent setMethod(CodeableConcept value) { 
512          this.method = value;
513          return this;
514        }
515
516        /**
517         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
518         */
519        public Type getDose() { 
520          return this.dose;
521        }
522
523        /**
524         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
525         */
526        public Range getDoseRange() throws FHIRException { 
527          if (!(this.dose instanceof Range))
528            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.dose.getClass().getName()+" was encountered");
529          return (Range) this.dose;
530        }
531
532        public boolean hasDoseRange() { 
533          return this.dose instanceof Range;
534        }
535
536        /**
537         * @return {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
538         */
539        public SimpleQuantity getDoseSimpleQuantity() throws FHIRException { 
540          if (!(this.dose instanceof SimpleQuantity))
541            throw new FHIRException("Type mismatch: the type SimpleQuantity was expected, but "+this.dose.getClass().getName()+" was encountered");
542          return (SimpleQuantity) this.dose;
543        }
544
545        public boolean hasDoseSimpleQuantity() { 
546          return this.dose instanceof SimpleQuantity;
547        }
548
549        public boolean hasDose() { 
550          return this.dose != null && !this.dose.isEmpty();
551        }
552
553        /**
554         * @param value {@link #dose} (The amount of therapeutic or other substance given at one administration event.)
555         */
556        public MedicationDispenseDosageInstructionComponent setDose(Type value) { 
557          this.dose = value;
558          return this;
559        }
560
561        /**
562         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
563         */
564        public Type getRate() { 
565          return this.rate;
566        }
567
568        /**
569         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
570         */
571        public Ratio getRateRatio() throws FHIRException { 
572          if (!(this.rate instanceof Ratio))
573            throw new FHIRException("Type mismatch: the type Ratio was expected, but "+this.rate.getClass().getName()+" was encountered");
574          return (Ratio) this.rate;
575        }
576
577        public boolean hasRateRatio() { 
578          return this.rate instanceof Ratio;
579        }
580
581        /**
582         * @return {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
583         */
584        public Range getRateRange() throws FHIRException { 
585          if (!(this.rate instanceof Range))
586            throw new FHIRException("Type mismatch: the type Range was expected, but "+this.rate.getClass().getName()+" was encountered");
587          return (Range) this.rate;
588        }
589
590        public boolean hasRateRange() { 
591          return this.rate instanceof Range;
592        }
593
594        public boolean hasRate() { 
595          return this.rate != null && !this.rate.isEmpty();
596        }
597
598        /**
599         * @param value {@link #rate} (Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.)
600         */
601        public MedicationDispenseDosageInstructionComponent setRate(Type value) { 
602          this.rate = value;
603          return this;
604        }
605
606        /**
607         * @return {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time,  e.g. 1000mg in 24 hours.)
608         */
609        public Ratio getMaxDosePerPeriod() { 
610          if (this.maxDosePerPeriod == null)
611            if (Configuration.errorOnAutoCreate())
612              throw new Error("Attempt to auto-create MedicationDispenseDosageInstructionComponent.maxDosePerPeriod");
613            else if (Configuration.doAutoCreate())
614              this.maxDosePerPeriod = new Ratio(); // cc
615          return this.maxDosePerPeriod;
616        }
617
618        public boolean hasMaxDosePerPeriod() { 
619          return this.maxDosePerPeriod != null && !this.maxDosePerPeriod.isEmpty();
620        }
621
622        /**
623         * @param value {@link #maxDosePerPeriod} (The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time,  e.g. 1000mg in 24 hours.)
624         */
625        public MedicationDispenseDosageInstructionComponent setMaxDosePerPeriod(Ratio value) { 
626          this.maxDosePerPeriod = value;
627          return this;
628        }
629
630        protected void listChildren(List<Property> childrenList) {
631          super.listChildren(childrenList);
632          childrenList.add(new Property("text", "string", "Free text dosage instructions can be used for cases where the instructions are too complex to code. When coded instructions are present, the free text instructions may still be present for display to humans taking or administering the medication.", 0, java.lang.Integer.MAX_VALUE, text));
633          childrenList.add(new Property("additionalInstructions", "CodeableConcept", "Additional instructions such as \"Swallow with plenty of water\" which may or may not be coded.", 0, java.lang.Integer.MAX_VALUE, additionalInstructions));
634          childrenList.add(new Property("timing", "Timing", "The timing schedule for giving the medication to the patient.  The Schedule data type allows many different expressions.  For example, \"Every  8 hours\"; \"Three times a day\"; \"1/2 an hour before breakfast for 10 days from 23-Dec 2011:\";  \"15 Oct 2013, 17 Oct 2013 and 1 Nov 2013\".", 0, java.lang.Integer.MAX_VALUE, timing));
635          childrenList.add(new Property("asNeeded[x]", "boolean|CodeableConcept", "Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option), or it indicates the precondition for taking the Medication (CodeableConcept).  \n\nSpecifically if 'boolean' datatype is selected, then the following logic applies:  If set to True, this indicates that the medication is only taken when needed, within the specified schedule.", 0, java.lang.Integer.MAX_VALUE, asNeeded));
636          childrenList.add(new Property("site[x]", "CodeableConcept|Reference(BodySite)", "A coded specification of the anatomic site where the medication first enters the body.", 0, java.lang.Integer.MAX_VALUE, site));
637          childrenList.add(new Property("route", "CodeableConcept", "A code specifying the route or physiological path of administration of a therapeutic agent into or onto a subject.", 0, java.lang.Integer.MAX_VALUE, route));
638          childrenList.add(new Property("method", "CodeableConcept", "A coded value indicating the method by which the medication is intended to be or was introduced into or on the body.", 0, java.lang.Integer.MAX_VALUE, method));
639          childrenList.add(new Property("dose[x]", "Range|SimpleQuantity", "The amount of therapeutic or other substance given at one administration event.", 0, java.lang.Integer.MAX_VALUE, dose));
640          childrenList.add(new Property("rate[x]", "Ratio|Range", "Identifies the speed with which the medication was or will be introduced into the patient. Typically the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr.  May also be expressed as a rate per unit of time e.g. 500 ml per 2 hours.   Currently we do not specify a default of '1' in the denominator, but this is being discussed. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", 0, java.lang.Integer.MAX_VALUE, rate));
641          childrenList.add(new Property("maxDosePerPeriod", "Ratio", "The maximum total quantity of a therapeutic substance that may be administered to a subject over the period of time,  e.g. 1000mg in 24 hours.", 0, java.lang.Integer.MAX_VALUE, maxDosePerPeriod));
642        }
643
644      @Override
645      public void setProperty(String name, Base value) throws FHIRException {
646        if (name.equals("text"))
647          this.text = castToString(value); // StringType
648        else if (name.equals("additionalInstructions"))
649          this.additionalInstructions = castToCodeableConcept(value); // CodeableConcept
650        else if (name.equals("timing"))
651          this.timing = castToTiming(value); // Timing
652        else if (name.equals("asNeeded[x]"))
653          this.asNeeded = (Type) value; // Type
654        else if (name.equals("site[x]"))
655          this.site = (Type) value; // Type
656        else if (name.equals("route"))
657          this.route = castToCodeableConcept(value); // CodeableConcept
658        else if (name.equals("method"))
659          this.method = castToCodeableConcept(value); // CodeableConcept
660        else if (name.equals("dose[x]"))
661          this.dose = (Type) value; // Type
662        else if (name.equals("rate[x]"))
663          this.rate = (Type) value; // Type
664        else if (name.equals("maxDosePerPeriod"))
665          this.maxDosePerPeriod = castToRatio(value); // Ratio
666        else
667          super.setProperty(name, value);
668      }
669
670      @Override
671      public Base addChild(String name) throws FHIRException {
672        if (name.equals("text")) {
673          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.text");
674        }
675        else if (name.equals("additionalInstructions")) {
676          this.additionalInstructions = new CodeableConcept();
677          return this.additionalInstructions;
678        }
679        else if (name.equals("timing")) {
680          this.timing = new Timing();
681          return this.timing;
682        }
683        else if (name.equals("asNeededBoolean")) {
684          this.asNeeded = new BooleanType();
685          return this.asNeeded;
686        }
687        else if (name.equals("asNeededCodeableConcept")) {
688          this.asNeeded = new CodeableConcept();
689          return this.asNeeded;
690        }
691        else if (name.equals("siteCodeableConcept")) {
692          this.site = new CodeableConcept();
693          return this.site;
694        }
695        else if (name.equals("siteReference")) {
696          this.site = new Reference();
697          return this.site;
698        }
699        else if (name.equals("route")) {
700          this.route = new CodeableConcept();
701          return this.route;
702        }
703        else if (name.equals("method")) {
704          this.method = new CodeableConcept();
705          return this.method;
706        }
707        else if (name.equals("doseRange")) {
708          this.dose = new Range();
709          return this.dose;
710        }
711        else if (name.equals("doseSimpleQuantity")) {
712          this.dose = new SimpleQuantity();
713          return this.dose;
714        }
715        else if (name.equals("rateRatio")) {
716          this.rate = new Ratio();
717          return this.rate;
718        }
719        else if (name.equals("rateRange")) {
720          this.rate = new Range();
721          return this.rate;
722        }
723        else if (name.equals("maxDosePerPeriod")) {
724          this.maxDosePerPeriod = new Ratio();
725          return this.maxDosePerPeriod;
726        }
727        else
728          return super.addChild(name);
729      }
730
731      public MedicationDispenseDosageInstructionComponent copy() {
732        MedicationDispenseDosageInstructionComponent dst = new MedicationDispenseDosageInstructionComponent();
733        copyValues(dst);
734        dst.text = text == null ? null : text.copy();
735        dst.additionalInstructions = additionalInstructions == null ? null : additionalInstructions.copy();
736        dst.timing = timing == null ? null : timing.copy();
737        dst.asNeeded = asNeeded == null ? null : asNeeded.copy();
738        dst.site = site == null ? null : site.copy();
739        dst.route = route == null ? null : route.copy();
740        dst.method = method == null ? null : method.copy();
741        dst.dose = dose == null ? null : dose.copy();
742        dst.rate = rate == null ? null : rate.copy();
743        dst.maxDosePerPeriod = maxDosePerPeriod == null ? null : maxDosePerPeriod.copy();
744        return dst;
745      }
746
747      @Override
748      public boolean equalsDeep(Base other) {
749        if (!super.equalsDeep(other))
750          return false;
751        if (!(other instanceof MedicationDispenseDosageInstructionComponent))
752          return false;
753        MedicationDispenseDosageInstructionComponent o = (MedicationDispenseDosageInstructionComponent) other;
754        return compareDeep(text, o.text, true) && compareDeep(additionalInstructions, o.additionalInstructions, true)
755           && compareDeep(timing, o.timing, true) && compareDeep(asNeeded, o.asNeeded, true) && compareDeep(site, o.site, true)
756           && compareDeep(route, o.route, true) && compareDeep(method, o.method, true) && compareDeep(dose, o.dose, true)
757           && compareDeep(rate, o.rate, true) && compareDeep(maxDosePerPeriod, o.maxDosePerPeriod, true);
758      }
759
760      @Override
761      public boolean equalsShallow(Base other) {
762        if (!super.equalsShallow(other))
763          return false;
764        if (!(other instanceof MedicationDispenseDosageInstructionComponent))
765          return false;
766        MedicationDispenseDosageInstructionComponent o = (MedicationDispenseDosageInstructionComponent) other;
767        return compareValues(text, o.text, true);
768      }
769
770      public boolean isEmpty() {
771        return super.isEmpty() && (text == null || text.isEmpty()) && (additionalInstructions == null || additionalInstructions.isEmpty())
772           && (timing == null || timing.isEmpty()) && (asNeeded == null || asNeeded.isEmpty()) && (site == null || site.isEmpty())
773           && (route == null || route.isEmpty()) && (method == null || method.isEmpty()) && (dose == null || dose.isEmpty())
774           && (rate == null || rate.isEmpty()) && (maxDosePerPeriod == null || maxDosePerPeriod.isEmpty())
775          ;
776      }
777
778  public String fhirType() {
779    return "MedicationDispense.dosageInstruction";
780
781  }
782
783  }
784
785    @Block()
786    public static class MedicationDispenseSubstitutionComponent extends BackboneElement implements IBaseBackboneElement {
787        /**
788         * A code signifying whether a different drug was dispensed from what was prescribed.
789         */
790        @Child(name = "type", type = {CodeableConcept.class}, order=1, min=1, max=1, modifier=false, summary=true)
791        @Description(shortDefinition="Type of substitution", formalDefinition="A code signifying whether a different drug was dispensed from what was prescribed." )
792        protected CodeableConcept type;
793
794        /**
795         * Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.
796         */
797        @Child(name = "reason", type = {CodeableConcept.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
798        @Description(shortDefinition="Why was substitution made", formalDefinition="Indicates the reason for the substitution of (or lack of substitution) from what was prescribed." )
799        protected List<CodeableConcept> reason;
800
801        /**
802         * The person or organization that has primary responsibility for the substitution.
803         */
804        @Child(name = "responsibleParty", type = {Practitioner.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
805        @Description(shortDefinition="Who is responsible for the substitution", formalDefinition="The person or organization that has primary responsibility for the substitution." )
806        protected List<Reference> responsibleParty;
807        /**
808         * The actual objects that are the target of the reference (The person or organization that has primary responsibility for the substitution.)
809         */
810        protected List<Practitioner> responsiblePartyTarget;
811
812
813        private static final long serialVersionUID = 1218245830L;
814
815    /*
816     * Constructor
817     */
818      public MedicationDispenseSubstitutionComponent() {
819        super();
820      }
821
822    /*
823     * Constructor
824     */
825      public MedicationDispenseSubstitutionComponent(CodeableConcept type) {
826        super();
827        this.type = type;
828      }
829
830        /**
831         * @return {@link #type} (A code signifying whether a different drug was dispensed from what was prescribed.)
832         */
833        public CodeableConcept getType() { 
834          if (this.type == null)
835            if (Configuration.errorOnAutoCreate())
836              throw new Error("Attempt to auto-create MedicationDispenseSubstitutionComponent.type");
837            else if (Configuration.doAutoCreate())
838              this.type = new CodeableConcept(); // cc
839          return this.type;
840        }
841
842        public boolean hasType() { 
843          return this.type != null && !this.type.isEmpty();
844        }
845
846        /**
847         * @param value {@link #type} (A code signifying whether a different drug was dispensed from what was prescribed.)
848         */
849        public MedicationDispenseSubstitutionComponent setType(CodeableConcept value) { 
850          this.type = value;
851          return this;
852        }
853
854        /**
855         * @return {@link #reason} (Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.)
856         */
857        public List<CodeableConcept> getReason() { 
858          if (this.reason == null)
859            this.reason = new ArrayList<CodeableConcept>();
860          return this.reason;
861        }
862
863        public boolean hasReason() { 
864          if (this.reason == null)
865            return false;
866          for (CodeableConcept item : this.reason)
867            if (!item.isEmpty())
868              return true;
869          return false;
870        }
871
872        /**
873         * @return {@link #reason} (Indicates the reason for the substitution of (or lack of substitution) from what was prescribed.)
874         */
875    // syntactic sugar
876        public CodeableConcept addReason() { //3
877          CodeableConcept t = new CodeableConcept();
878          if (this.reason == null)
879            this.reason = new ArrayList<CodeableConcept>();
880          this.reason.add(t);
881          return t;
882        }
883
884    // syntactic sugar
885        public MedicationDispenseSubstitutionComponent addReason(CodeableConcept t) { //3
886          if (t == null)
887            return this;
888          if (this.reason == null)
889            this.reason = new ArrayList<CodeableConcept>();
890          this.reason.add(t);
891          return this;
892        }
893
894        /**
895         * @return {@link #responsibleParty} (The person or organization that has primary responsibility for the substitution.)
896         */
897        public List<Reference> getResponsibleParty() { 
898          if (this.responsibleParty == null)
899            this.responsibleParty = new ArrayList<Reference>();
900          return this.responsibleParty;
901        }
902
903        public boolean hasResponsibleParty() { 
904          if (this.responsibleParty == null)
905            return false;
906          for (Reference item : this.responsibleParty)
907            if (!item.isEmpty())
908              return true;
909          return false;
910        }
911
912        /**
913         * @return {@link #responsibleParty} (The person or organization that has primary responsibility for the substitution.)
914         */
915    // syntactic sugar
916        public Reference addResponsibleParty() { //3
917          Reference t = new Reference();
918          if (this.responsibleParty == null)
919            this.responsibleParty = new ArrayList<Reference>();
920          this.responsibleParty.add(t);
921          return t;
922        }
923
924    // syntactic sugar
925        public MedicationDispenseSubstitutionComponent addResponsibleParty(Reference t) { //3
926          if (t == null)
927            return this;
928          if (this.responsibleParty == null)
929            this.responsibleParty = new ArrayList<Reference>();
930          this.responsibleParty.add(t);
931          return this;
932        }
933
934        /**
935         * @return {@link #responsibleParty} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. The person or organization that has primary responsibility for the substitution.)
936         */
937        public List<Practitioner> getResponsiblePartyTarget() { 
938          if (this.responsiblePartyTarget == null)
939            this.responsiblePartyTarget = new ArrayList<Practitioner>();
940          return this.responsiblePartyTarget;
941        }
942
943    // syntactic sugar
944        /**
945         * @return {@link #responsibleParty} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. The person or organization that has primary responsibility for the substitution.)
946         */
947        public Practitioner addResponsiblePartyTarget() { 
948          Practitioner r = new Practitioner();
949          if (this.responsiblePartyTarget == null)
950            this.responsiblePartyTarget = new ArrayList<Practitioner>();
951          this.responsiblePartyTarget.add(r);
952          return r;
953        }
954
955        protected void listChildren(List<Property> childrenList) {
956          super.listChildren(childrenList);
957          childrenList.add(new Property("type", "CodeableConcept", "A code signifying whether a different drug was dispensed from what was prescribed.", 0, java.lang.Integer.MAX_VALUE, type));
958          childrenList.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));
959          childrenList.add(new Property("responsibleParty", "Reference(Practitioner)", "The person or organization that has primary responsibility for the substitution.", 0, java.lang.Integer.MAX_VALUE, responsibleParty));
960        }
961
962      @Override
963      public void setProperty(String name, Base value) throws FHIRException {
964        if (name.equals("type"))
965          this.type = castToCodeableConcept(value); // CodeableConcept
966        else if (name.equals("reason"))
967          this.getReason().add(castToCodeableConcept(value));
968        else if (name.equals("responsibleParty"))
969          this.getResponsibleParty().add(castToReference(value));
970        else
971          super.setProperty(name, value);
972      }
973
974      @Override
975      public Base addChild(String name) throws FHIRException {
976        if (name.equals("type")) {
977          this.type = new CodeableConcept();
978          return this.type;
979        }
980        else if (name.equals("reason")) {
981          return addReason();
982        }
983        else if (name.equals("responsibleParty")) {
984          return addResponsibleParty();
985        }
986        else
987          return super.addChild(name);
988      }
989
990      public MedicationDispenseSubstitutionComponent copy() {
991        MedicationDispenseSubstitutionComponent dst = new MedicationDispenseSubstitutionComponent();
992        copyValues(dst);
993        dst.type = type == null ? null : type.copy();
994        if (reason != null) {
995          dst.reason = new ArrayList<CodeableConcept>();
996          for (CodeableConcept i : reason)
997            dst.reason.add(i.copy());
998        };
999        if (responsibleParty != null) {
1000          dst.responsibleParty = new ArrayList<Reference>();
1001          for (Reference i : responsibleParty)
1002            dst.responsibleParty.add(i.copy());
1003        };
1004        return dst;
1005      }
1006
1007      @Override
1008      public boolean equalsDeep(Base other) {
1009        if (!super.equalsDeep(other))
1010          return false;
1011        if (!(other instanceof MedicationDispenseSubstitutionComponent))
1012          return false;
1013        MedicationDispenseSubstitutionComponent o = (MedicationDispenseSubstitutionComponent) other;
1014        return compareDeep(type, o.type, true) && compareDeep(reason, o.reason, true) && compareDeep(responsibleParty, o.responsibleParty, true)
1015          ;
1016      }
1017
1018      @Override
1019      public boolean equalsShallow(Base other) {
1020        if (!super.equalsShallow(other))
1021          return false;
1022        if (!(other instanceof MedicationDispenseSubstitutionComponent))
1023          return false;
1024        MedicationDispenseSubstitutionComponent o = (MedicationDispenseSubstitutionComponent) other;
1025        return true;
1026      }
1027
1028      public boolean isEmpty() {
1029        return super.isEmpty() && (type == null || type.isEmpty()) && (reason == null || reason.isEmpty())
1030           && (responsibleParty == null || responsibleParty.isEmpty());
1031      }
1032
1033  public String fhirType() {
1034    return "MedicationDispense.substitution";
1035
1036  }
1037
1038  }
1039
1040    /**
1041     * Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.
1042     */
1043    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=1, modifier=false, summary=true)
1044    @Description(shortDefinition="External identifier", formalDefinition="Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR." )
1045    protected Identifier identifier;
1046
1047    /**
1048     * A code specifying the state of the set of dispense events.
1049     */
1050    @Child(name = "status", type = {CodeType.class}, order=1, min=0, max=1, modifier=true, summary=true)
1051    @Description(shortDefinition="in-progress | on-hold | completed | entered-in-error | stopped", formalDefinition="A code specifying the state of the set of dispense events." )
1052    protected Enumeration<MedicationDispenseStatus> status;
1053
1054    /**
1055     * A link to a resource representing the person to whom the medication will be given.
1056     */
1057    @Child(name = "patient", type = {Patient.class}, order=2, min=0, max=1, modifier=false, summary=true)
1058    @Description(shortDefinition="Who the dispense is for", formalDefinition="A link to a resource representing the person to whom the medication will be given." )
1059    protected Reference patient;
1060
1061    /**
1062     * The actual object that is the target of the reference (A link to a resource representing the person to whom the medication will be given.)
1063     */
1064    protected Patient patientTarget;
1065
1066    /**
1067     * The individual responsible for dispensing the medication.
1068     */
1069    @Child(name = "dispenser", type = {Practitioner.class}, order=3, min=0, max=1, modifier=false, summary=true)
1070    @Description(shortDefinition="Practitioner responsible for dispensing medication", formalDefinition="The individual responsible for dispensing the medication." )
1071    protected Reference dispenser;
1072
1073    /**
1074     * The actual object that is the target of the reference (The individual responsible for dispensing the medication.)
1075     */
1076    protected Practitioner dispenserTarget;
1077
1078    /**
1079     * Indicates the medication order that is being dispensed against.
1080     */
1081    @Child(name = "authorizingPrescription", type = {MedicationOrder.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1082    @Description(shortDefinition="Medication order that authorizes the dispense", formalDefinition="Indicates the medication order that is being dispensed against." )
1083    protected List<Reference> authorizingPrescription;
1084    /**
1085     * The actual objects that are the target of the reference (Indicates the medication order that is being dispensed against.)
1086     */
1087    protected List<MedicationOrder> authorizingPrescriptionTarget;
1088
1089
1090    /**
1091     * Indicates the type of dispensing event that is performed. For example, Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.
1092     */
1093    @Child(name = "type", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
1094    @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." )
1095    protected CodeableConcept type;
1096
1097    /**
1098     * The amount of medication that has been dispensed. Includes unit of measure.
1099     */
1100    @Child(name = "quantity", type = {SimpleQuantity.class}, order=6, min=0, max=1, modifier=false, summary=true)
1101    @Description(shortDefinition="Amount dispensed", formalDefinition="The amount of medication that has been dispensed. Includes unit of measure." )
1102    protected SimpleQuantity quantity;
1103
1104    /**
1105     * The amount of medication expressed as a timing amount.
1106     */
1107    @Child(name = "daysSupply", type = {SimpleQuantity.class}, order=7, min=0, max=1, modifier=false, summary=true)
1108    @Description(shortDefinition="Days Supply", formalDefinition="The amount of medication expressed as a timing amount." )
1109    protected SimpleQuantity daysSupply;
1110
1111    /**
1112     * 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.
1113     */
1114    @Child(name = "medication", type = {CodeableConcept.class, Medication.class}, order=8, min=1, max=1, modifier=false, summary=true)
1115    @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." )
1116    protected Type medication;
1117
1118    /**
1119     * The time when the dispensed product was packaged and reviewed.
1120     */
1121    @Child(name = "whenPrepared", type = {DateTimeType.class}, order=9, min=0, max=1, modifier=false, summary=true)
1122    @Description(shortDefinition="Dispense processing time", formalDefinition="The time when the dispensed product was packaged and reviewed." )
1123    protected DateTimeType whenPrepared;
1124
1125    /**
1126     * The time the dispensed product was provided to the patient or their representative.
1127     */
1128    @Child(name = "whenHandedOver", type = {DateTimeType.class}, order=10, min=0, max=1, modifier=false, summary=true)
1129    @Description(shortDefinition="When product was given out", formalDefinition="The time the dispensed product was provided to the patient or their representative." )
1130    protected DateTimeType whenHandedOver;
1131
1132    /**
1133     * Identification of the facility/location where the medication was shipped to, as part of the dispense event.
1134     */
1135    @Child(name = "destination", type = {Location.class}, order=11, min=0, max=1, modifier=false, summary=true)
1136    @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." )
1137    protected Reference destination;
1138
1139    /**
1140     * 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.)
1141     */
1142    protected Location destinationTarget;
1143
1144    /**
1145     * 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.
1146     */
1147    @Child(name = "receiver", type = {Patient.class, Practitioner.class}, order=12, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1148    @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." )
1149    protected List<Reference> receiver;
1150    /**
1151     * 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.)
1152     */
1153    protected List<Resource> receiverTarget;
1154
1155
1156    /**
1157     * Extra information about the dispense that could not be conveyed in the other attributes.
1158     */
1159    @Child(name = "note", type = {StringType.class}, order=13, min=0, max=1, modifier=false, summary=true)
1160    @Description(shortDefinition="Information about the dispense", formalDefinition="Extra information about the dispense that could not be conveyed in the other attributes." )
1161    protected StringType note;
1162
1163    /**
1164     * Indicates how the medication is to be used by the patient.
1165     */
1166    @Child(name = "dosageInstruction", type = {}, order=14, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1167    @Description(shortDefinition="Medicine administration instructions to the patient/caregiver", formalDefinition="Indicates how the medication is to be used by the patient." )
1168    protected List<MedicationDispenseDosageInstructionComponent> dosageInstruction;
1169
1170    /**
1171     * 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.
1172     */
1173    @Child(name = "substitution", type = {}, order=15, min=0, max=1, modifier=false, summary=true)
1174    @Description(shortDefinition="Deals with substitution of one medicine for another", 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." )
1175    protected MedicationDispenseSubstitutionComponent substitution;
1176
1177    private static final long serialVersionUID = -2071218407L;
1178
1179  /*
1180   * Constructor
1181   */
1182    public MedicationDispense() {
1183      super();
1184    }
1185
1186  /*
1187   * Constructor
1188   */
1189    public MedicationDispense(Type medication) {
1190      super();
1191      this.medication = medication;
1192    }
1193
1194    /**
1195     * @return {@link #identifier} (Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.)
1196     */
1197    public Identifier getIdentifier() { 
1198      if (this.identifier == null)
1199        if (Configuration.errorOnAutoCreate())
1200          throw new Error("Attempt to auto-create MedicationDispense.identifier");
1201        else if (Configuration.doAutoCreate())
1202          this.identifier = new Identifier(); // cc
1203      return this.identifier;
1204    }
1205
1206    public boolean hasIdentifier() { 
1207      return this.identifier != null && !this.identifier.isEmpty();
1208    }
1209
1210    /**
1211     * @param value {@link #identifier} (Identifier assigned by the dispensing facility - this is an identifier assigned outside FHIR.)
1212     */
1213    public MedicationDispense setIdentifier(Identifier value) { 
1214      this.identifier = value;
1215      return this;
1216    }
1217
1218    /**
1219     * @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
1220     */
1221    public Enumeration<MedicationDispenseStatus> getStatusElement() { 
1222      if (this.status == null)
1223        if (Configuration.errorOnAutoCreate())
1224          throw new Error("Attempt to auto-create MedicationDispense.status");
1225        else if (Configuration.doAutoCreate())
1226          this.status = new Enumeration<MedicationDispenseStatus>(new MedicationDispenseStatusEnumFactory()); // bb
1227      return this.status;
1228    }
1229
1230    public boolean hasStatusElement() { 
1231      return this.status != null && !this.status.isEmpty();
1232    }
1233
1234    public boolean hasStatus() { 
1235      return this.status != null && !this.status.isEmpty();
1236    }
1237
1238    /**
1239     * @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
1240     */
1241    public MedicationDispense setStatusElement(Enumeration<MedicationDispenseStatus> value) { 
1242      this.status = value;
1243      return this;
1244    }
1245
1246    /**
1247     * @return A code specifying the state of the set of dispense events.
1248     */
1249    public MedicationDispenseStatus getStatus() { 
1250      return this.status == null ? null : this.status.getValue();
1251    }
1252
1253    /**
1254     * @param value A code specifying the state of the set of dispense events.
1255     */
1256    public MedicationDispense setStatus(MedicationDispenseStatus value) { 
1257      if (value == null)
1258        this.status = null;
1259      else {
1260        if (this.status == null)
1261          this.status = new Enumeration<MedicationDispenseStatus>(new MedicationDispenseStatusEnumFactory());
1262        this.status.setValue(value);
1263      }
1264      return this;
1265    }
1266
1267    /**
1268     * @return {@link #patient} (A link to a resource representing the person to whom the medication will be given.)
1269     */
1270    public Reference getPatient() { 
1271      if (this.patient == null)
1272        if (Configuration.errorOnAutoCreate())
1273          throw new Error("Attempt to auto-create MedicationDispense.patient");
1274        else if (Configuration.doAutoCreate())
1275          this.patient = new Reference(); // cc
1276      return this.patient;
1277    }
1278
1279    public boolean hasPatient() { 
1280      return this.patient != null && !this.patient.isEmpty();
1281    }
1282
1283    /**
1284     * @param value {@link #patient} (A link to a resource representing the person to whom the medication will be given.)
1285     */
1286    public MedicationDispense setPatient(Reference value) { 
1287      this.patient = value;
1288      return this;
1289    }
1290
1291    /**
1292     * @return {@link #patient} 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 to whom the medication will be given.)
1293     */
1294    public Patient getPatientTarget() { 
1295      if (this.patientTarget == null)
1296        if (Configuration.errorOnAutoCreate())
1297          throw new Error("Attempt to auto-create MedicationDispense.patient");
1298        else if (Configuration.doAutoCreate())
1299          this.patientTarget = new Patient(); // aa
1300      return this.patientTarget;
1301    }
1302
1303    /**
1304     * @param value {@link #patient} 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 to whom the medication will be given.)
1305     */
1306    public MedicationDispense setPatientTarget(Patient value) { 
1307      this.patientTarget = value;
1308      return this;
1309    }
1310
1311    /**
1312     * @return {@link #dispenser} (The individual responsible for dispensing the medication.)
1313     */
1314    public Reference getDispenser() { 
1315      if (this.dispenser == null)
1316        if (Configuration.errorOnAutoCreate())
1317          throw new Error("Attempt to auto-create MedicationDispense.dispenser");
1318        else if (Configuration.doAutoCreate())
1319          this.dispenser = new Reference(); // cc
1320      return this.dispenser;
1321    }
1322
1323    public boolean hasDispenser() { 
1324      return this.dispenser != null && !this.dispenser.isEmpty();
1325    }
1326
1327    /**
1328     * @param value {@link #dispenser} (The individual responsible for dispensing the medication.)
1329     */
1330    public MedicationDispense setDispenser(Reference value) { 
1331      this.dispenser = value;
1332      return this;
1333    }
1334
1335    /**
1336     * @return {@link #dispenser} 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 individual responsible for dispensing the medication.)
1337     */
1338    public Practitioner getDispenserTarget() { 
1339      if (this.dispenserTarget == null)
1340        if (Configuration.errorOnAutoCreate())
1341          throw new Error("Attempt to auto-create MedicationDispense.dispenser");
1342        else if (Configuration.doAutoCreate())
1343          this.dispenserTarget = new Practitioner(); // aa
1344      return this.dispenserTarget;
1345    }
1346
1347    /**
1348     * @param value {@link #dispenser} 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 individual responsible for dispensing the medication.)
1349     */
1350    public MedicationDispense setDispenserTarget(Practitioner value) { 
1351      this.dispenserTarget = value;
1352      return this;
1353    }
1354
1355    /**
1356     * @return {@link #authorizingPrescription} (Indicates the medication order that is being dispensed against.)
1357     */
1358    public List<Reference> getAuthorizingPrescription() { 
1359      if (this.authorizingPrescription == null)
1360        this.authorizingPrescription = new ArrayList<Reference>();
1361      return this.authorizingPrescription;
1362    }
1363
1364    public boolean hasAuthorizingPrescription() { 
1365      if (this.authorizingPrescription == null)
1366        return false;
1367      for (Reference item : this.authorizingPrescription)
1368        if (!item.isEmpty())
1369          return true;
1370      return false;
1371    }
1372
1373    /**
1374     * @return {@link #authorizingPrescription} (Indicates the medication order that is being dispensed against.)
1375     */
1376    // syntactic sugar
1377    public Reference addAuthorizingPrescription() { //3
1378      Reference t = new Reference();
1379      if (this.authorizingPrescription == null)
1380        this.authorizingPrescription = new ArrayList<Reference>();
1381      this.authorizingPrescription.add(t);
1382      return t;
1383    }
1384
1385    // syntactic sugar
1386    public MedicationDispense addAuthorizingPrescription(Reference t) { //3
1387      if (t == null)
1388        return this;
1389      if (this.authorizingPrescription == null)
1390        this.authorizingPrescription = new ArrayList<Reference>();
1391      this.authorizingPrescription.add(t);
1392      return this;
1393    }
1394
1395    /**
1396     * @return {@link #authorizingPrescription} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. Indicates the medication order that is being dispensed against.)
1397     */
1398    public List<MedicationOrder> getAuthorizingPrescriptionTarget() { 
1399      if (this.authorizingPrescriptionTarget == null)
1400        this.authorizingPrescriptionTarget = new ArrayList<MedicationOrder>();
1401      return this.authorizingPrescriptionTarget;
1402    }
1403
1404    // syntactic sugar
1405    /**
1406     * @return {@link #authorizingPrescription} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. Indicates the medication order that is being dispensed against.)
1407     */
1408    public MedicationOrder addAuthorizingPrescriptionTarget() { 
1409      MedicationOrder r = new MedicationOrder();
1410      if (this.authorizingPrescriptionTarget == null)
1411        this.authorizingPrescriptionTarget = new ArrayList<MedicationOrder>();
1412      this.authorizingPrescriptionTarget.add(r);
1413      return r;
1414    }
1415
1416    /**
1417     * @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.)
1418     */
1419    public CodeableConcept getType() { 
1420      if (this.type == null)
1421        if (Configuration.errorOnAutoCreate())
1422          throw new Error("Attempt to auto-create MedicationDispense.type");
1423        else if (Configuration.doAutoCreate())
1424          this.type = new CodeableConcept(); // cc
1425      return this.type;
1426    }
1427
1428    public boolean hasType() { 
1429      return this.type != null && !this.type.isEmpty();
1430    }
1431
1432    /**
1433     * @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.)
1434     */
1435    public MedicationDispense setType(CodeableConcept value) { 
1436      this.type = value;
1437      return this;
1438    }
1439
1440    /**
1441     * @return {@link #quantity} (The amount of medication that has been dispensed. Includes unit of measure.)
1442     */
1443    public SimpleQuantity getQuantity() { 
1444      if (this.quantity == null)
1445        if (Configuration.errorOnAutoCreate())
1446          throw new Error("Attempt to auto-create MedicationDispense.quantity");
1447        else if (Configuration.doAutoCreate())
1448          this.quantity = new SimpleQuantity(); // cc
1449      return this.quantity;
1450    }
1451
1452    public boolean hasQuantity() { 
1453      return this.quantity != null && !this.quantity.isEmpty();
1454    }
1455
1456    /**
1457     * @param value {@link #quantity} (The amount of medication that has been dispensed. Includes unit of measure.)
1458     */
1459    public MedicationDispense setQuantity(SimpleQuantity value) { 
1460      this.quantity = value;
1461      return this;
1462    }
1463
1464    /**
1465     * @return {@link #daysSupply} (The amount of medication expressed as a timing amount.)
1466     */
1467    public SimpleQuantity getDaysSupply() { 
1468      if (this.daysSupply == null)
1469        if (Configuration.errorOnAutoCreate())
1470          throw new Error("Attempt to auto-create MedicationDispense.daysSupply");
1471        else if (Configuration.doAutoCreate())
1472          this.daysSupply = new SimpleQuantity(); // cc
1473      return this.daysSupply;
1474    }
1475
1476    public boolean hasDaysSupply() { 
1477      return this.daysSupply != null && !this.daysSupply.isEmpty();
1478    }
1479
1480    /**
1481     * @param value {@link #daysSupply} (The amount of medication expressed as a timing amount.)
1482     */
1483    public MedicationDispense setDaysSupply(SimpleQuantity value) { 
1484      this.daysSupply = value;
1485      return this;
1486    }
1487
1488    /**
1489     * @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.)
1490     */
1491    public Type getMedication() { 
1492      return this.medication;
1493    }
1494
1495    /**
1496     * @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.)
1497     */
1498    public CodeableConcept getMedicationCodeableConcept() throws FHIRException { 
1499      if (!(this.medication instanceof CodeableConcept))
1500        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.medication.getClass().getName()+" was encountered");
1501      return (CodeableConcept) this.medication;
1502    }
1503
1504    public boolean hasMedicationCodeableConcept() { 
1505      return this.medication instanceof CodeableConcept;
1506    }
1507
1508    /**
1509     * @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.)
1510     */
1511    public Reference getMedicationReference() throws FHIRException { 
1512      if (!(this.medication instanceof Reference))
1513        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.medication.getClass().getName()+" was encountered");
1514      return (Reference) this.medication;
1515    }
1516
1517    public boolean hasMedicationReference() { 
1518      return this.medication instanceof Reference;
1519    }
1520
1521    public boolean hasMedication() { 
1522      return this.medication != null && !this.medication.isEmpty();
1523    }
1524
1525    /**
1526     * @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.)
1527     */
1528    public MedicationDispense setMedication(Type value) { 
1529      this.medication = value;
1530      return this;
1531    }
1532
1533    /**
1534     * @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
1535     */
1536    public DateTimeType getWhenPreparedElement() { 
1537      if (this.whenPrepared == null)
1538        if (Configuration.errorOnAutoCreate())
1539          throw new Error("Attempt to auto-create MedicationDispense.whenPrepared");
1540        else if (Configuration.doAutoCreate())
1541          this.whenPrepared = new DateTimeType(); // bb
1542      return this.whenPrepared;
1543    }
1544
1545    public boolean hasWhenPreparedElement() { 
1546      return this.whenPrepared != null && !this.whenPrepared.isEmpty();
1547    }
1548
1549    public boolean hasWhenPrepared() { 
1550      return this.whenPrepared != null && !this.whenPrepared.isEmpty();
1551    }
1552
1553    /**
1554     * @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
1555     */
1556    public MedicationDispense setWhenPreparedElement(DateTimeType value) { 
1557      this.whenPrepared = value;
1558      return this;
1559    }
1560
1561    /**
1562     * @return The time when the dispensed product was packaged and reviewed.
1563     */
1564    public Date getWhenPrepared() { 
1565      return this.whenPrepared == null ? null : this.whenPrepared.getValue();
1566    }
1567
1568    /**
1569     * @param value The time when the dispensed product was packaged and reviewed.
1570     */
1571    public MedicationDispense setWhenPrepared(Date value) { 
1572      if (value == null)
1573        this.whenPrepared = null;
1574      else {
1575        if (this.whenPrepared == null)
1576          this.whenPrepared = new DateTimeType();
1577        this.whenPrepared.setValue(value);
1578      }
1579      return this;
1580    }
1581
1582    /**
1583     * @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
1584     */
1585    public DateTimeType getWhenHandedOverElement() { 
1586      if (this.whenHandedOver == null)
1587        if (Configuration.errorOnAutoCreate())
1588          throw new Error("Attempt to auto-create MedicationDispense.whenHandedOver");
1589        else if (Configuration.doAutoCreate())
1590          this.whenHandedOver = new DateTimeType(); // bb
1591      return this.whenHandedOver;
1592    }
1593
1594    public boolean hasWhenHandedOverElement() { 
1595      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1596    }
1597
1598    public boolean hasWhenHandedOver() { 
1599      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1600    }
1601
1602    /**
1603     * @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
1604     */
1605    public MedicationDispense setWhenHandedOverElement(DateTimeType value) { 
1606      this.whenHandedOver = value;
1607      return this;
1608    }
1609
1610    /**
1611     * @return The time the dispensed product was provided to the patient or their representative.
1612     */
1613    public Date getWhenHandedOver() { 
1614      return this.whenHandedOver == null ? null : this.whenHandedOver.getValue();
1615    }
1616
1617    /**
1618     * @param value The time the dispensed product was provided to the patient or their representative.
1619     */
1620    public MedicationDispense setWhenHandedOver(Date value) { 
1621      if (value == null)
1622        this.whenHandedOver = null;
1623      else {
1624        if (this.whenHandedOver == null)
1625          this.whenHandedOver = new DateTimeType();
1626        this.whenHandedOver.setValue(value);
1627      }
1628      return this;
1629    }
1630
1631    /**
1632     * @return {@link #destination} (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1633     */
1634    public Reference getDestination() { 
1635      if (this.destination == null)
1636        if (Configuration.errorOnAutoCreate())
1637          throw new Error("Attempt to auto-create MedicationDispense.destination");
1638        else if (Configuration.doAutoCreate())
1639          this.destination = new Reference(); // cc
1640      return this.destination;
1641    }
1642
1643    public boolean hasDestination() { 
1644      return this.destination != null && !this.destination.isEmpty();
1645    }
1646
1647    /**
1648     * @param value {@link #destination} (Identification of the facility/location where the medication was shipped to, as part of the dispense event.)
1649     */
1650    public MedicationDispense setDestination(Reference value) { 
1651      this.destination = value;
1652      return this;
1653    }
1654
1655    /**
1656     * @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.)
1657     */
1658    public Location getDestinationTarget() { 
1659      if (this.destinationTarget == null)
1660        if (Configuration.errorOnAutoCreate())
1661          throw new Error("Attempt to auto-create MedicationDispense.destination");
1662        else if (Configuration.doAutoCreate())
1663          this.destinationTarget = new Location(); // aa
1664      return this.destinationTarget;
1665    }
1666
1667    /**
1668     * @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.)
1669     */
1670    public MedicationDispense setDestinationTarget(Location value) { 
1671      this.destinationTarget = value;
1672      return this;
1673    }
1674
1675    /**
1676     * @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.)
1677     */
1678    public List<Reference> getReceiver() { 
1679      if (this.receiver == null)
1680        this.receiver = new ArrayList<Reference>();
1681      return this.receiver;
1682    }
1683
1684    public boolean hasReceiver() { 
1685      if (this.receiver == null)
1686        return false;
1687      for (Reference item : this.receiver)
1688        if (!item.isEmpty())
1689          return true;
1690      return false;
1691    }
1692
1693    /**
1694     * @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.)
1695     */
1696    // syntactic sugar
1697    public Reference addReceiver() { //3
1698      Reference t = new Reference();
1699      if (this.receiver == null)
1700        this.receiver = new ArrayList<Reference>();
1701      this.receiver.add(t);
1702      return t;
1703    }
1704
1705    // syntactic sugar
1706    public MedicationDispense addReceiver(Reference t) { //3
1707      if (t == null)
1708        return this;
1709      if (this.receiver == null)
1710        this.receiver = new ArrayList<Reference>();
1711      this.receiver.add(t);
1712      return this;
1713    }
1714
1715    /**
1716     * @return {@link #receiver} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. 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.)
1717     */
1718    public List<Resource> getReceiverTarget() { 
1719      if (this.receiverTarget == null)
1720        this.receiverTarget = new ArrayList<Resource>();
1721      return this.receiverTarget;
1722    }
1723
1724    /**
1725     * @return {@link #note} (Extra information about the dispense that could not be conveyed in the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1726     */
1727    public StringType getNoteElement() { 
1728      if (this.note == null)
1729        if (Configuration.errorOnAutoCreate())
1730          throw new Error("Attempt to auto-create MedicationDispense.note");
1731        else if (Configuration.doAutoCreate())
1732          this.note = new StringType(); // bb
1733      return this.note;
1734    }
1735
1736    public boolean hasNoteElement() { 
1737      return this.note != null && !this.note.isEmpty();
1738    }
1739
1740    public boolean hasNote() { 
1741      return this.note != null && !this.note.isEmpty();
1742    }
1743
1744    /**
1745     * @param value {@link #note} (Extra information about the dispense that could not be conveyed in the other attributes.). This is the underlying object with id, value and extensions. The accessor "getNote" gives direct access to the value
1746     */
1747    public MedicationDispense setNoteElement(StringType value) { 
1748      this.note = value;
1749      return this;
1750    }
1751
1752    /**
1753     * @return Extra information about the dispense that could not be conveyed in the other attributes.
1754     */
1755    public String getNote() { 
1756      return this.note == null ? null : this.note.getValue();
1757    }
1758
1759    /**
1760     * @param value Extra information about the dispense that could not be conveyed in the other attributes.
1761     */
1762    public MedicationDispense setNote(String value) { 
1763      if (Utilities.noString(value))
1764        this.note = null;
1765      else {
1766        if (this.note == null)
1767          this.note = new StringType();
1768        this.note.setValue(value);
1769      }
1770      return this;
1771    }
1772
1773    /**
1774     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
1775     */
1776    public List<MedicationDispenseDosageInstructionComponent> getDosageInstruction() { 
1777      if (this.dosageInstruction == null)
1778        this.dosageInstruction = new ArrayList<MedicationDispenseDosageInstructionComponent>();
1779      return this.dosageInstruction;
1780    }
1781
1782    public boolean hasDosageInstruction() { 
1783      if (this.dosageInstruction == null)
1784        return false;
1785      for (MedicationDispenseDosageInstructionComponent item : this.dosageInstruction)
1786        if (!item.isEmpty())
1787          return true;
1788      return false;
1789    }
1790
1791    /**
1792     * @return {@link #dosageInstruction} (Indicates how the medication is to be used by the patient.)
1793     */
1794    // syntactic sugar
1795    public MedicationDispenseDosageInstructionComponent addDosageInstruction() { //3
1796      MedicationDispenseDosageInstructionComponent t = new MedicationDispenseDosageInstructionComponent();
1797      if (this.dosageInstruction == null)
1798        this.dosageInstruction = new ArrayList<MedicationDispenseDosageInstructionComponent>();
1799      this.dosageInstruction.add(t);
1800      return t;
1801    }
1802
1803    // syntactic sugar
1804    public MedicationDispense addDosageInstruction(MedicationDispenseDosageInstructionComponent t) { //3
1805      if (t == null)
1806        return this;
1807      if (this.dosageInstruction == null)
1808        this.dosageInstruction = new ArrayList<MedicationDispenseDosageInstructionComponent>();
1809      this.dosageInstruction.add(t);
1810      return this;
1811    }
1812
1813    /**
1814     * @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.)
1815     */
1816    public MedicationDispenseSubstitutionComponent getSubstitution() { 
1817      if (this.substitution == null)
1818        if (Configuration.errorOnAutoCreate())
1819          throw new Error("Attempt to auto-create MedicationDispense.substitution");
1820        else if (Configuration.doAutoCreate())
1821          this.substitution = new MedicationDispenseSubstitutionComponent(); // cc
1822      return this.substitution;
1823    }
1824
1825    public boolean hasSubstitution() { 
1826      return this.substitution != null && !this.substitution.isEmpty();
1827    }
1828
1829    /**
1830     * @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.)
1831     */
1832    public MedicationDispense setSubstitution(MedicationDispenseSubstitutionComponent value) { 
1833      this.substitution = value;
1834      return this;
1835    }
1836
1837      protected void listChildren(List<Property> childrenList) {
1838        super.listChildren(childrenList);
1839        childrenList.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));
1840        childrenList.add(new Property("status", "code", "A code specifying the state of the set of dispense events.", 0, java.lang.Integer.MAX_VALUE, status));
1841        childrenList.add(new Property("patient", "Reference(Patient)", "A link to a resource representing the person to whom the medication will be given.", 0, java.lang.Integer.MAX_VALUE, patient));
1842        childrenList.add(new Property("dispenser", "Reference(Practitioner)", "The individual responsible for dispensing the medication.", 0, java.lang.Integer.MAX_VALUE, dispenser));
1843        childrenList.add(new Property("authorizingPrescription", "Reference(MedicationOrder)", "Indicates the medication order that is being dispensed against.", 0, java.lang.Integer.MAX_VALUE, authorizingPrescription));
1844        childrenList.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, java.lang.Integer.MAX_VALUE, type));
1845        childrenList.add(new Property("quantity", "SimpleQuantity", "The amount of medication that has been dispensed. Includes unit of measure.", 0, java.lang.Integer.MAX_VALUE, quantity));
1846        childrenList.add(new Property("daysSupply", "SimpleQuantity", "The amount of medication expressed as a timing amount.", 0, java.lang.Integer.MAX_VALUE, daysSupply));
1847        childrenList.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, java.lang.Integer.MAX_VALUE, medication));
1848        childrenList.add(new Property("whenPrepared", "dateTime", "The time when the dispensed product was packaged and reviewed.", 0, java.lang.Integer.MAX_VALUE, whenPrepared));
1849        childrenList.add(new Property("whenHandedOver", "dateTime", "The time the dispensed product was provided to the patient or their representative.", 0, java.lang.Integer.MAX_VALUE, whenHandedOver));
1850        childrenList.add(new Property("destination", "Reference(Location)", "Identification of the facility/location where the medication was shipped to, as part of the dispense event.", 0, java.lang.Integer.MAX_VALUE, destination));
1851        childrenList.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));
1852        childrenList.add(new Property("note", "string", "Extra information about the dispense that could not be conveyed in the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
1853        childrenList.add(new Property("dosageInstruction", "", "Indicates how the medication is to be used by the patient.", 0, java.lang.Integer.MAX_VALUE, dosageInstruction));
1854        childrenList.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.", 0, java.lang.Integer.MAX_VALUE, substitution));
1855      }
1856
1857      @Override
1858      public void setProperty(String name, Base value) throws FHIRException {
1859        if (name.equals("identifier"))
1860          this.identifier = castToIdentifier(value); // Identifier
1861        else if (name.equals("status"))
1862          this.status = new MedicationDispenseStatusEnumFactory().fromType(value); // Enumeration<MedicationDispenseStatus>
1863        else if (name.equals("patient"))
1864          this.patient = castToReference(value); // Reference
1865        else if (name.equals("dispenser"))
1866          this.dispenser = castToReference(value); // Reference
1867        else if (name.equals("authorizingPrescription"))
1868          this.getAuthorizingPrescription().add(castToReference(value));
1869        else if (name.equals("type"))
1870          this.type = castToCodeableConcept(value); // CodeableConcept
1871        else if (name.equals("quantity"))
1872          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
1873        else if (name.equals("daysSupply"))
1874          this.daysSupply = castToSimpleQuantity(value); // SimpleQuantity
1875        else if (name.equals("medication[x]"))
1876          this.medication = (Type) value; // Type
1877        else if (name.equals("whenPrepared"))
1878          this.whenPrepared = castToDateTime(value); // DateTimeType
1879        else if (name.equals("whenHandedOver"))
1880          this.whenHandedOver = castToDateTime(value); // DateTimeType
1881        else if (name.equals("destination"))
1882          this.destination = castToReference(value); // Reference
1883        else if (name.equals("receiver"))
1884          this.getReceiver().add(castToReference(value));
1885        else if (name.equals("note"))
1886          this.note = castToString(value); // StringType
1887        else if (name.equals("dosageInstruction"))
1888          this.getDosageInstruction().add((MedicationDispenseDosageInstructionComponent) value);
1889        else if (name.equals("substitution"))
1890          this.substitution = (MedicationDispenseSubstitutionComponent) value; // MedicationDispenseSubstitutionComponent
1891        else
1892          super.setProperty(name, value);
1893      }
1894
1895      @Override
1896      public Base addChild(String name) throws FHIRException {
1897        if (name.equals("identifier")) {
1898          this.identifier = new Identifier();
1899          return this.identifier;
1900        }
1901        else if (name.equals("status")) {
1902          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.status");
1903        }
1904        else if (name.equals("patient")) {
1905          this.patient = new Reference();
1906          return this.patient;
1907        }
1908        else if (name.equals("dispenser")) {
1909          this.dispenser = new Reference();
1910          return this.dispenser;
1911        }
1912        else if (name.equals("authorizingPrescription")) {
1913          return addAuthorizingPrescription();
1914        }
1915        else if (name.equals("type")) {
1916          this.type = new CodeableConcept();
1917          return this.type;
1918        }
1919        else if (name.equals("quantity")) {
1920          this.quantity = new SimpleQuantity();
1921          return this.quantity;
1922        }
1923        else if (name.equals("daysSupply")) {
1924          this.daysSupply = new SimpleQuantity();
1925          return this.daysSupply;
1926        }
1927        else if (name.equals("medicationCodeableConcept")) {
1928          this.medication = new CodeableConcept();
1929          return this.medication;
1930        }
1931        else if (name.equals("medicationReference")) {
1932          this.medication = new Reference();
1933          return this.medication;
1934        }
1935        else if (name.equals("whenPrepared")) {
1936          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.whenPrepared");
1937        }
1938        else if (name.equals("whenHandedOver")) {
1939          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.whenHandedOver");
1940        }
1941        else if (name.equals("destination")) {
1942          this.destination = new Reference();
1943          return this.destination;
1944        }
1945        else if (name.equals("receiver")) {
1946          return addReceiver();
1947        }
1948        else if (name.equals("note")) {
1949          throw new FHIRException("Cannot call addChild on a primitive type MedicationDispense.note");
1950        }
1951        else if (name.equals("dosageInstruction")) {
1952          return addDosageInstruction();
1953        }
1954        else if (name.equals("substitution")) {
1955          this.substitution = new MedicationDispenseSubstitutionComponent();
1956          return this.substitution;
1957        }
1958        else
1959          return super.addChild(name);
1960      }
1961
1962  public String fhirType() {
1963    return "MedicationDispense";
1964
1965  }
1966
1967      public MedicationDispense copy() {
1968        MedicationDispense dst = new MedicationDispense();
1969        copyValues(dst);
1970        dst.identifier = identifier == null ? null : identifier.copy();
1971        dst.status = status == null ? null : status.copy();
1972        dst.patient = patient == null ? null : patient.copy();
1973        dst.dispenser = dispenser == null ? null : dispenser.copy();
1974        if (authorizingPrescription != null) {
1975          dst.authorizingPrescription = new ArrayList<Reference>();
1976          for (Reference i : authorizingPrescription)
1977            dst.authorizingPrescription.add(i.copy());
1978        };
1979        dst.type = type == null ? null : type.copy();
1980        dst.quantity = quantity == null ? null : quantity.copy();
1981        dst.daysSupply = daysSupply == null ? null : daysSupply.copy();
1982        dst.medication = medication == null ? null : medication.copy();
1983        dst.whenPrepared = whenPrepared == null ? null : whenPrepared.copy();
1984        dst.whenHandedOver = whenHandedOver == null ? null : whenHandedOver.copy();
1985        dst.destination = destination == null ? null : destination.copy();
1986        if (receiver != null) {
1987          dst.receiver = new ArrayList<Reference>();
1988          for (Reference i : receiver)
1989            dst.receiver.add(i.copy());
1990        };
1991        dst.note = note == null ? null : note.copy();
1992        if (dosageInstruction != null) {
1993          dst.dosageInstruction = new ArrayList<MedicationDispenseDosageInstructionComponent>();
1994          for (MedicationDispenseDosageInstructionComponent i : dosageInstruction)
1995            dst.dosageInstruction.add(i.copy());
1996        };
1997        dst.substitution = substitution == null ? null : substitution.copy();
1998        return dst;
1999      }
2000
2001      protected MedicationDispense typedCopy() {
2002        return copy();
2003      }
2004
2005      @Override
2006      public boolean equalsDeep(Base other) {
2007        if (!super.equalsDeep(other))
2008          return false;
2009        if (!(other instanceof MedicationDispense))
2010          return false;
2011        MedicationDispense o = (MedicationDispense) other;
2012        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(patient, o.patient, true)
2013           && compareDeep(dispenser, o.dispenser, true) && compareDeep(authorizingPrescription, o.authorizingPrescription, true)
2014           && compareDeep(type, o.type, true) && compareDeep(quantity, o.quantity, true) && compareDeep(daysSupply, o.daysSupply, true)
2015           && compareDeep(medication, o.medication, true) && compareDeep(whenPrepared, o.whenPrepared, true)
2016           && compareDeep(whenHandedOver, o.whenHandedOver, true) && compareDeep(destination, o.destination, true)
2017           && compareDeep(receiver, o.receiver, true) && compareDeep(note, o.note, true) && compareDeep(dosageInstruction, o.dosageInstruction, true)
2018           && compareDeep(substitution, o.substitution, true);
2019      }
2020
2021      @Override
2022      public boolean equalsShallow(Base other) {
2023        if (!super.equalsShallow(other))
2024          return false;
2025        if (!(other instanceof MedicationDispense))
2026          return false;
2027        MedicationDispense o = (MedicationDispense) other;
2028        return compareValues(status, o.status, true) && compareValues(whenPrepared, o.whenPrepared, true) && compareValues(whenHandedOver, o.whenHandedOver, true)
2029           && compareValues(note, o.note, true);
2030      }
2031
2032      public boolean isEmpty() {
2033        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
2034           && (patient == null || patient.isEmpty()) && (dispenser == null || dispenser.isEmpty()) && (authorizingPrescription == null || authorizingPrescription.isEmpty())
2035           && (type == null || type.isEmpty()) && (quantity == null || quantity.isEmpty()) && (daysSupply == null || daysSupply.isEmpty())
2036           && (medication == null || medication.isEmpty()) && (whenPrepared == null || whenPrepared.isEmpty())
2037           && (whenHandedOver == null || whenHandedOver.isEmpty()) && (destination == null || destination.isEmpty())
2038           && (receiver == null || receiver.isEmpty()) && (note == null || note.isEmpty()) && (dosageInstruction == null || dosageInstruction.isEmpty())
2039           && (substitution == null || substitution.isEmpty());
2040      }
2041
2042  @Override
2043  public ResourceType getResourceType() {
2044    return ResourceType.MedicationDispense;
2045   }
2046
2047  @SearchParamDefinition(name="identifier", path="MedicationDispense.identifier", description="Return dispenses with this external identifier", type="token" )
2048  public static final String SP_IDENTIFIER = "identifier";
2049  @SearchParamDefinition(name="code", path="MedicationDispense.medicationCodeableConcept", description="Return dispenses of this medicine code", type="token" )
2050  public static final String SP_CODE = "code";
2051  @SearchParamDefinition(name="receiver", path="MedicationDispense.receiver", description="Who collected the medication", type="reference" )
2052  public static final String SP_RECEIVER = "receiver";
2053  @SearchParamDefinition(name="destination", path="MedicationDispense.destination", description="Return dispenses that should be sent to a specific destination", type="reference" )
2054  public static final String SP_DESTINATION = "destination";
2055  @SearchParamDefinition(name="medication", path="MedicationDispense.medicationReference", description="Return dispenses of this medicine resource", type="reference" )
2056  public static final String SP_MEDICATION = "medication";
2057  @SearchParamDefinition(name="responsibleparty", path="MedicationDispense.substitution.responsibleParty", description="Return all dispenses with the specified responsible party", type="reference" )
2058  public static final String SP_RESPONSIBLEPARTY = "responsibleparty";
2059  @SearchParamDefinition(name="type", path="MedicationDispense.type", description="Return all dispenses of a specific type", type="token" )
2060  public static final String SP_TYPE = "type";
2061  @SearchParamDefinition(name="whenhandedover", path="MedicationDispense.whenHandedOver", description="Date when medication handed over to patient (outpatient setting), or supplied to ward or clinic (inpatient setting)", type="date" )
2062  public static final String SP_WHENHANDEDOVER = "whenhandedover";
2063  @SearchParamDefinition(name="whenprepared", path="MedicationDispense.whenPrepared", description="Date when medication prepared", type="date" )
2064  public static final String SP_WHENPREPARED = "whenprepared";
2065  @SearchParamDefinition(name="dispenser", path="MedicationDispense.dispenser", description="Return all dispenses performed by a specific individual", type="reference" )
2066  public static final String SP_DISPENSER = "dispenser";
2067  @SearchParamDefinition(name="prescription", path="MedicationDispense.authorizingPrescription", description="The identity of a prescription to list dispenses from", type="reference" )
2068  public static final String SP_PRESCRIPTION = "prescription";
2069  @SearchParamDefinition(name="patient", path="MedicationDispense.patient", description="The identity of a patient to list dispenses  for", type="reference" )
2070  public static final String SP_PATIENT = "patient";
2071  @SearchParamDefinition(name="status", path="MedicationDispense.status", description="Status of the dispense", type="token" )
2072  public static final String SP_STATUS = "status";
2073
2074}