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