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