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