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