001package org.hl7.fhir.r5.model;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Tue, Dec 28, 2021 07:16+1100 for FHIR v5.0.0-snapshot1
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.utilities.Utilities;
038import org.hl7.fhir.r5.model.Enumerations.*;
039import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.ICompositeType;
042import ca.uhn.fhir.model.api.annotation.ResourceDef;
043import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
044import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
045import ca.uhn.fhir.model.api.annotation.Child;
046import ca.uhn.fhir.model.api.annotation.ChildOrder;
047import ca.uhn.fhir.model.api.annotation.Description;
048import ca.uhn.fhir.model.api.annotation.Block;
049
050/**
051 * Indicates that a device is to be or has been dispensed for a named person/patient.  This includes a description of the product (supply) provided and the instructions for using the device.
052 */
053@ResourceDef(name="DeviceDispense", profile="http://hl7.org/fhir/StructureDefinition/DeviceDispense")
054public class DeviceDispense extends DomainResource {
055
056    public enum DeviceDispenseStatusCodes {
057        /**
058         * The core event has not started yet, but some staging activities have begun (e.g. initial preparing of the device. Preparation stages may be tracked e.g. for planning, supply or billing purposes.
059         */
060        PREPARATION, 
061        /**
062         * The dispensed product is ready for pickup.
063         */
064        INPROGRESS, 
065        /**
066         * The dispensed product was not and will never be picked up by the patient.
067         */
068        CANCELLED, 
069        /**
070         * The dispense process is paused while waiting for an external event to reactivate the dispense.  For example, new stock has arrived or the prescriber has called.
071         */
072        ONHOLD, 
073        /**
074         * The dispensed product has been picked up.
075         */
076        COMPLETED, 
077        /**
078         * The dispense was entered in error and therefore nullified.
079         */
080        ENTEREDINERROR, 
081        /**
082         * Actions implied by the dispense have been permanently halted, before all of them occurred.
083         */
084        STOPPED, 
085        /**
086         * The dispense was declined and not performed.
087         */
088        DECLINED, 
089        /**
090         * The authoring system does not know which of the status values applies for this dispense.  Note: this concept is not to be used for other - one of the listed statuses is presumed to apply, it's just now known which one.
091         */
092        UNKNOWN, 
093        /**
094         * added to help the parsers with the generic types
095         */
096        NULL;
097        public static DeviceDispenseStatusCodes fromCode(String codeString) throws FHIRException {
098            if (codeString == null || "".equals(codeString))
099                return null;
100        if ("preparation".equals(codeString))
101          return PREPARATION;
102        if ("in-progress".equals(codeString))
103          return INPROGRESS;
104        if ("cancelled".equals(codeString))
105          return CANCELLED;
106        if ("on-hold".equals(codeString))
107          return ONHOLD;
108        if ("completed".equals(codeString))
109          return COMPLETED;
110        if ("entered-in-error".equals(codeString))
111          return ENTEREDINERROR;
112        if ("stopped".equals(codeString))
113          return STOPPED;
114        if ("declined".equals(codeString))
115          return DECLINED;
116        if ("unknown".equals(codeString))
117          return UNKNOWN;
118        if (Configuration.isAcceptInvalidEnums())
119          return null;
120        else
121          throw new FHIRException("Unknown DeviceDispenseStatusCodes code '"+codeString+"'");
122        }
123        public String toCode() {
124          switch (this) {
125            case PREPARATION: return "preparation";
126            case INPROGRESS: return "in-progress";
127            case CANCELLED: return "cancelled";
128            case ONHOLD: return "on-hold";
129            case COMPLETED: return "completed";
130            case ENTEREDINERROR: return "entered-in-error";
131            case STOPPED: return "stopped";
132            case DECLINED: return "declined";
133            case UNKNOWN: return "unknown";
134            default: return "?";
135          }
136        }
137        public String getSystem() {
138          switch (this) {
139            case PREPARATION: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
140            case INPROGRESS: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
141            case CANCELLED: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
142            case ONHOLD: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
143            case COMPLETED: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
144            case ENTEREDINERROR: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
145            case STOPPED: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
146            case DECLINED: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
147            case UNKNOWN: return "http://terminology.hl7.org/CodeSystem/devicedispense-status";
148            default: return "?";
149          }
150        }
151        public String getDefinition() {
152          switch (this) {
153            case PREPARATION: return "The core event has not started yet, but some staging activities have begun (e.g. initial preparing of the device. Preparation stages may be tracked e.g. for planning, supply or billing purposes.";
154            case INPROGRESS: return "The dispensed product is ready for pickup.";
155            case CANCELLED: return "The dispensed product was not and will never be picked up by the patient.";
156            case ONHOLD: return "The dispense process is paused while waiting for an external event to reactivate the dispense.  For example, new stock has arrived or the prescriber has called.";
157            case COMPLETED: return "The dispensed product has been picked up.";
158            case ENTEREDINERROR: return "The dispense was entered in error and therefore nullified.";
159            case STOPPED: return "Actions implied by the dispense have been permanently halted, before all of them occurred.";
160            case DECLINED: return "The dispense was declined and not performed.";
161            case UNKNOWN: return "The authoring system does not know which of the status values applies for this dispense.  Note: this concept is not to be used for other - one of the listed statuses is presumed to apply, it's just now known which one.";
162            default: return "?";
163          }
164        }
165        public String getDisplay() {
166          switch (this) {
167            case PREPARATION: return "Preparation";
168            case INPROGRESS: return "In Progress";
169            case CANCELLED: return "Cancelled";
170            case ONHOLD: return "On Hold";
171            case COMPLETED: return "Completed";
172            case ENTEREDINERROR: return "Entered in Error";
173            case STOPPED: return "Stopped";
174            case DECLINED: return "Declined";
175            case UNKNOWN: return "Unknown";
176            default: return "?";
177          }
178        }
179    }
180
181  public static class DeviceDispenseStatusCodesEnumFactory implements EnumFactory<DeviceDispenseStatusCodes> {
182    public DeviceDispenseStatusCodes fromCode(String codeString) throws IllegalArgumentException {
183      if (codeString == null || "".equals(codeString))
184            if (codeString == null || "".equals(codeString))
185                return null;
186        if ("preparation".equals(codeString))
187          return DeviceDispenseStatusCodes.PREPARATION;
188        if ("in-progress".equals(codeString))
189          return DeviceDispenseStatusCodes.INPROGRESS;
190        if ("cancelled".equals(codeString))
191          return DeviceDispenseStatusCodes.CANCELLED;
192        if ("on-hold".equals(codeString))
193          return DeviceDispenseStatusCodes.ONHOLD;
194        if ("completed".equals(codeString))
195          return DeviceDispenseStatusCodes.COMPLETED;
196        if ("entered-in-error".equals(codeString))
197          return DeviceDispenseStatusCodes.ENTEREDINERROR;
198        if ("stopped".equals(codeString))
199          return DeviceDispenseStatusCodes.STOPPED;
200        if ("declined".equals(codeString))
201          return DeviceDispenseStatusCodes.DECLINED;
202        if ("unknown".equals(codeString))
203          return DeviceDispenseStatusCodes.UNKNOWN;
204        throw new IllegalArgumentException("Unknown DeviceDispenseStatusCodes code '"+codeString+"'");
205        }
206        public Enumeration<DeviceDispenseStatusCodes> fromType(Base code) throws FHIRException {
207          if (code == null)
208            return null;
209          if (code.isEmpty())
210            return new Enumeration<DeviceDispenseStatusCodes>(this);
211          String codeString = ((PrimitiveType) code).asStringValue();
212          if (codeString == null || "".equals(codeString))
213            return null;
214        if ("preparation".equals(codeString))
215          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.PREPARATION);
216        if ("in-progress".equals(codeString))
217          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.INPROGRESS);
218        if ("cancelled".equals(codeString))
219          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.CANCELLED);
220        if ("on-hold".equals(codeString))
221          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.ONHOLD);
222        if ("completed".equals(codeString))
223          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.COMPLETED);
224        if ("entered-in-error".equals(codeString))
225          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.ENTEREDINERROR);
226        if ("stopped".equals(codeString))
227          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.STOPPED);
228        if ("declined".equals(codeString))
229          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.DECLINED);
230        if ("unknown".equals(codeString))
231          return new Enumeration<DeviceDispenseStatusCodes>(this, DeviceDispenseStatusCodes.UNKNOWN);
232        throw new FHIRException("Unknown DeviceDispenseStatusCodes code '"+codeString+"'");
233        }
234    public String toCode(DeviceDispenseStatusCodes code) {
235      if (code == DeviceDispenseStatusCodes.PREPARATION)
236        return "preparation";
237      if (code == DeviceDispenseStatusCodes.INPROGRESS)
238        return "in-progress";
239      if (code == DeviceDispenseStatusCodes.CANCELLED)
240        return "cancelled";
241      if (code == DeviceDispenseStatusCodes.ONHOLD)
242        return "on-hold";
243      if (code == DeviceDispenseStatusCodes.COMPLETED)
244        return "completed";
245      if (code == DeviceDispenseStatusCodes.ENTEREDINERROR)
246        return "entered-in-error";
247      if (code == DeviceDispenseStatusCodes.STOPPED)
248        return "stopped";
249      if (code == DeviceDispenseStatusCodes.DECLINED)
250        return "declined";
251      if (code == DeviceDispenseStatusCodes.UNKNOWN)
252        return "unknown";
253      return "?";
254      }
255    public String toSystem(DeviceDispenseStatusCodes code) {
256      return code.getSystem();
257      }
258    }
259
260    @Block()
261    public static class DeviceDispensePerformerComponent extends BackboneElement implements IBaseBackboneElement {
262        /**
263         * Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker.
264         */
265        @Child(name = "function", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=false)
266        @Description(shortDefinition="Who performed the dispense and what they did", formalDefinition="Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker." )
267        protected CodeableConcept function;
268
269        /**
270         * The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device.
271         */
272        @Child(name = "actor", type = {Practitioner.class, PractitionerRole.class, Organization.class, Patient.class, Device.class, RelatedPerson.class, CareTeam.class}, order=2, min=1, max=1, modifier=false, summary=false)
273        @Description(shortDefinition="Individual who was performing", formalDefinition="The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device." )
274        protected Reference actor;
275
276        private static final long serialVersionUID = -576943815L;
277
278    /**
279     * Constructor
280     */
281      public DeviceDispensePerformerComponent() {
282        super();
283      }
284
285    /**
286     * Constructor
287     */
288      public DeviceDispensePerformerComponent(Reference actor) {
289        super();
290        this.setActor(actor);
291      }
292
293        /**
294         * @return {@link #function} (Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker.)
295         */
296        public CodeableConcept getFunction() { 
297          if (this.function == null)
298            if (Configuration.errorOnAutoCreate())
299              throw new Error("Attempt to auto-create DeviceDispensePerformerComponent.function");
300            else if (Configuration.doAutoCreate())
301              this.function = new CodeableConcept(); // cc
302          return this.function;
303        }
304
305        public boolean hasFunction() { 
306          return this.function != null && !this.function.isEmpty();
307        }
308
309        /**
310         * @param value {@link #function} (Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker.)
311         */
312        public DeviceDispensePerformerComponent setFunction(CodeableConcept value) { 
313          this.function = value;
314          return this;
315        }
316
317        /**
318         * @return {@link #actor} (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device.)
319         */
320        public Reference getActor() { 
321          if (this.actor == null)
322            if (Configuration.errorOnAutoCreate())
323              throw new Error("Attempt to auto-create DeviceDispensePerformerComponent.actor");
324            else if (Configuration.doAutoCreate())
325              this.actor = new Reference(); // cc
326          return this.actor;
327        }
328
329        public boolean hasActor() { 
330          return this.actor != null && !this.actor.isEmpty();
331        }
332
333        /**
334         * @param value {@link #actor} (The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device.)
335         */
336        public DeviceDispensePerformerComponent setActor(Reference value) { 
337          this.actor = value;
338          return this;
339        }
340
341        protected void listChildren(List<Property> children) {
342          super.listChildren(children);
343          children.add(new Property("function", "CodeableConcept", "Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker.", 0, 1, function));
344          children.add(new Property("actor", "Reference(Practitioner|PractitionerRole|Organization|Patient|Device|RelatedPerson|CareTeam)", "The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device.", 0, 1, actor));
345        }
346
347        @Override
348        public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
349          switch (_hash) {
350          case 1380938712: /*function*/  return new Property("function", "CodeableConcept", "Distinguishes the type of performer in the dispense.  For example, date enterer, packager, final checker.", 0, 1, function);
351          case 92645877: /*actor*/  return new Property("actor", "Reference(Practitioner|PractitionerRole|Organization|Patient|Device|RelatedPerson|CareTeam)", "The device, practitioner, etc. who performed the action.  It should be assumed that the actor is the dispenser of the device.", 0, 1, actor);
352          default: return super.getNamedProperty(_hash, _name, _checkValid);
353          }
354
355        }
356
357      @Override
358      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
359        switch (hash) {
360        case 1380938712: /*function*/ return this.function == null ? new Base[0] : new Base[] {this.function}; // CodeableConcept
361        case 92645877: /*actor*/ return this.actor == null ? new Base[0] : new Base[] {this.actor}; // Reference
362        default: return super.getProperty(hash, name, checkValid);
363        }
364
365      }
366
367      @Override
368      public Base setProperty(int hash, String name, Base value) throws FHIRException {
369        switch (hash) {
370        case 1380938712: // function
371          this.function = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
372          return value;
373        case 92645877: // actor
374          this.actor = TypeConvertor.castToReference(value); // Reference
375          return value;
376        default: return super.setProperty(hash, name, value);
377        }
378
379      }
380
381      @Override
382      public Base setProperty(String name, Base value) throws FHIRException {
383        if (name.equals("function")) {
384          this.function = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
385        } else if (name.equals("actor")) {
386          this.actor = TypeConvertor.castToReference(value); // Reference
387        } else
388          return super.setProperty(name, value);
389        return value;
390      }
391
392      @Override
393      public Base makeProperty(int hash, String name) throws FHIRException {
394        switch (hash) {
395        case 1380938712:  return getFunction();
396        case 92645877:  return getActor();
397        default: return super.makeProperty(hash, name);
398        }
399
400      }
401
402      @Override
403      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
404        switch (hash) {
405        case 1380938712: /*function*/ return new String[] {"CodeableConcept"};
406        case 92645877: /*actor*/ return new String[] {"Reference"};
407        default: return super.getTypesForProperty(hash, name);
408        }
409
410      }
411
412      @Override
413      public Base addChild(String name) throws FHIRException {
414        if (name.equals("function")) {
415          this.function = new CodeableConcept();
416          return this.function;
417        }
418        else if (name.equals("actor")) {
419          this.actor = new Reference();
420          return this.actor;
421        }
422        else
423          return super.addChild(name);
424      }
425
426      public DeviceDispensePerformerComponent copy() {
427        DeviceDispensePerformerComponent dst = new DeviceDispensePerformerComponent();
428        copyValues(dst);
429        return dst;
430      }
431
432      public void copyValues(DeviceDispensePerformerComponent dst) {
433        super.copyValues(dst);
434        dst.function = function == null ? null : function.copy();
435        dst.actor = actor == null ? null : actor.copy();
436      }
437
438      @Override
439      public boolean equalsDeep(Base other_) {
440        if (!super.equalsDeep(other_))
441          return false;
442        if (!(other_ instanceof DeviceDispensePerformerComponent))
443          return false;
444        DeviceDispensePerformerComponent o = (DeviceDispensePerformerComponent) other_;
445        return compareDeep(function, o.function, true) && compareDeep(actor, o.actor, true);
446      }
447
448      @Override
449      public boolean equalsShallow(Base other_) {
450        if (!super.equalsShallow(other_))
451          return false;
452        if (!(other_ instanceof DeviceDispensePerformerComponent))
453          return false;
454        DeviceDispensePerformerComponent o = (DeviceDispensePerformerComponent) other_;
455        return true;
456      }
457
458      public boolean isEmpty() {
459        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(function, actor);
460      }
461
462  public String fhirType() {
463    return "DeviceDispense.performer";
464
465  }
466
467  }
468
469    /**
470     * Business identifier for this dispensation.
471     */
472    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
473    @Description(shortDefinition="Business identifier for this dispensation", formalDefinition="Business identifier for this dispensation." )
474    protected List<Identifier> identifier;
475
476    /**
477     * The order or request that this dispense is fulfilling.
478     */
479    @Child(name = "basedOn", type = {CarePlan.class, DeviceRequest.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
480    @Description(shortDefinition="The order or request that this dispense is fulfilling", formalDefinition="The order or request that this dispense is fulfilling." )
481    protected List<Reference> basedOn;
482
483    /**
484     * The bigger event that this dispense is a part of.
485     */
486    @Child(name = "partOf", type = {Procedure.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
487    @Description(shortDefinition="The bigger event that this dispense is a part of", formalDefinition="The bigger event that this dispense is a part of." )
488    protected List<Reference> partOf;
489
490    /**
491     * A code specifying the state of the set of dispense events.
492     */
493    @Child(name = "status", type = {CodeType.class}, order=3, min=1, max=1, modifier=true, summary=true)
494    @Description(shortDefinition="preparation | in-progress | cancelled | on-hold | completed | entered-in-error | stopped | declined | unknown", formalDefinition="A code specifying the state of the set of dispense events." )
495    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/devicedispense-status")
496    protected Enumeration<DeviceDispenseStatusCodes> status;
497
498    /**
499     * Indicates the reason why a dispense was or was not performed.
500     */
501    @Child(name = "statusReason", type = {CodeableReference.class}, order=4, min=0, max=1, modifier=false, summary=false)
502    @Description(shortDefinition="Why a dispense was or was not performed", formalDefinition="Indicates the reason why a dispense was or was not performed." )
503    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/devicedispense-status-reason")
504    protected CodeableReference statusReason;
505
506    /**
507     * Indicates the type of device dispense.
508     */
509    @Child(name = "category", type = {CodeableConcept.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
510    @Description(shortDefinition="Type of device dispense", formalDefinition="Indicates the type of device dispense." )
511    protected List<CodeableConcept> category;
512
513    /**
514     * Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices.
515     */
516    @Child(name = "device", type = {CodeableReference.class}, order=6, min=1, max=1, modifier=false, summary=true)
517    @Description(shortDefinition="What device was supplied", formalDefinition="Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices." )
518    protected CodeableReference device;
519
520    /**
521     * A link to a resource representing the person to whom the device is intended.
522     */
523    @Child(name = "subject", type = {Patient.class}, order=7, min=1, max=1, modifier=false, summary=true)
524    @Description(shortDefinition="Who the dispense is for", formalDefinition="A link to a resource representing the person to whom the device is intended." )
525    protected Reference subject;
526
527    /**
528     * The encounter that establishes the context for this event.
529     */
530    @Child(name = "encounter", type = {Encounter.class}, order=8, min=0, max=1, modifier=false, summary=false)
531    @Description(shortDefinition="Encounter associated with event", formalDefinition="The encounter that establishes the context for this event." )
532    protected Reference encounter;
533
534    /**
535     * Additional information that supports the device being dispensed.
536     */
537    @Child(name = "supportingInformation", type = {Reference.class}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
538    @Description(shortDefinition="Information that supports the dispensing of the device", formalDefinition="Additional information that supports the device being dispensed." )
539    protected List<Reference> supportingInformation;
540
541    /**
542     * Indicates who or what performed the event.
543     */
544    @Child(name = "performer", type = {}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
545    @Description(shortDefinition="Who performed event", formalDefinition="Indicates who or what performed the event." )
546    protected List<DeviceDispensePerformerComponent> performer;
547
548    /**
549     * The principal physical location where the dispense was performed.
550     */
551    @Child(name = "location", type = {Location.class}, order=11, min=0, max=1, modifier=false, summary=false)
552    @Description(shortDefinition="Where the dispense occurred", formalDefinition="The principal physical location where the dispense was performed." )
553    protected Reference location;
554
555    /**
556     * Indicates the type of dispensing event that is performed.
557     */
558    @Child(name = "type", type = {CodeableConcept.class}, order=12, min=0, max=1, modifier=false, summary=false)
559    @Description(shortDefinition="Trial fill, partial fill, emergency fill, etc.", formalDefinition="Indicates the type of dispensing event that is performed." )
560    protected CodeableConcept type;
561
562    /**
563     * The number of devices that have been dispensed.
564     */
565    @Child(name = "quantity", type = {Quantity.class}, order=13, min=0, max=1, modifier=false, summary=false)
566    @Description(shortDefinition="Amount dispensed", formalDefinition="The number of devices that have been dispensed." )
567    protected Quantity quantity;
568
569    /**
570     * The time when the dispensed product was packaged and reviewed.
571     */
572    @Child(name = "preparedDate", type = {DateTimeType.class}, order=14, min=0, max=1, modifier=false, summary=true)
573    @Description(shortDefinition="When product was packaged and reviewed", formalDefinition="The time when the dispensed product was packaged and reviewed." )
574    protected DateTimeType preparedDate;
575
576    /**
577     * The time the dispensed product was made available to the patient or their representative.
578     */
579    @Child(name = "whenHandedOver", type = {DateTimeType.class}, order=15, min=0, max=1, modifier=false, summary=false)
580    @Description(shortDefinition="When product was given out", formalDefinition="The time the dispensed product was made available to the patient or their representative." )
581    protected DateTimeType whenHandedOver;
582
583    /**
584     * Identification of the facility/location where the device was /should be shipped to, as part of the dispense process.
585     */
586    @Child(name = "destination", type = {Location.class}, order=16, min=0, max=1, modifier=false, summary=false)
587    @Description(shortDefinition="Where the device was sent or should be sent", formalDefinition="Identification of the facility/location where the device was /should be shipped to, as part of the dispense process." )
588    protected Reference destination;
589
590    /**
591     * Extra information about the dispense that could not be conveyed in the other attributes.
592     */
593    @Child(name = "note", type = {Annotation.class}, order=17, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
594    @Description(shortDefinition="Information about the dispense", formalDefinition="Extra information about the dispense that could not be conveyed in the other attributes." )
595    protected List<Annotation> note;
596
597    /**
598     * The full representation of the instructions.
599     */
600    @Child(name = "usageInstruction", type = {StringType.class}, order=18, min=0, max=1, modifier=false, summary=false)
601    @Description(shortDefinition="Full representation of the usage instructions", formalDefinition="The full representation of the instructions." )
602    protected StringType usageInstruction;
603
604    /**
605     * A summary of the events of interest that have occurred, such as when the dispense was verified.
606     */
607    @Child(name = "eventHistory", type = {Provenance.class}, order=19, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
608    @Description(shortDefinition="A list of relevant lifecycle events", formalDefinition="A summary of the events of interest that have occurred, such as when the dispense was verified." )
609    protected List<Reference> eventHistory;
610
611    private static final long serialVersionUID = -1613459109L;
612
613  /**
614   * Constructor
615   */
616    public DeviceDispense() {
617      super();
618    }
619
620  /**
621   * Constructor
622   */
623    public DeviceDispense(DeviceDispenseStatusCodes status, CodeableReference device, Reference subject) {
624      super();
625      this.setStatus(status);
626      this.setDevice(device);
627      this.setSubject(subject);
628    }
629
630    /**
631     * @return {@link #identifier} (Business identifier for this dispensation.)
632     */
633    public List<Identifier> getIdentifier() { 
634      if (this.identifier == null)
635        this.identifier = new ArrayList<Identifier>();
636      return this.identifier;
637    }
638
639    /**
640     * @return Returns a reference to <code>this</code> for easy method chaining
641     */
642    public DeviceDispense setIdentifier(List<Identifier> theIdentifier) { 
643      this.identifier = theIdentifier;
644      return this;
645    }
646
647    public boolean hasIdentifier() { 
648      if (this.identifier == null)
649        return false;
650      for (Identifier item : this.identifier)
651        if (!item.isEmpty())
652          return true;
653      return false;
654    }
655
656    public Identifier addIdentifier() { //3
657      Identifier t = new Identifier();
658      if (this.identifier == null)
659        this.identifier = new ArrayList<Identifier>();
660      this.identifier.add(t);
661      return t;
662    }
663
664    public DeviceDispense addIdentifier(Identifier t) { //3
665      if (t == null)
666        return this;
667      if (this.identifier == null)
668        this.identifier = new ArrayList<Identifier>();
669      this.identifier.add(t);
670      return this;
671    }
672
673    /**
674     * @return The first repetition of repeating field {@link #identifier}, creating it if it does not already exist {3}
675     */
676    public Identifier getIdentifierFirstRep() { 
677      if (getIdentifier().isEmpty()) {
678        addIdentifier();
679      }
680      return getIdentifier().get(0);
681    }
682
683    /**
684     * @return {@link #basedOn} (The order or request that this dispense is fulfilling.)
685     */
686    public List<Reference> getBasedOn() { 
687      if (this.basedOn == null)
688        this.basedOn = new ArrayList<Reference>();
689      return this.basedOn;
690    }
691
692    /**
693     * @return Returns a reference to <code>this</code> for easy method chaining
694     */
695    public DeviceDispense setBasedOn(List<Reference> theBasedOn) { 
696      this.basedOn = theBasedOn;
697      return this;
698    }
699
700    public boolean hasBasedOn() { 
701      if (this.basedOn == null)
702        return false;
703      for (Reference item : this.basedOn)
704        if (!item.isEmpty())
705          return true;
706      return false;
707    }
708
709    public Reference addBasedOn() { //3
710      Reference t = new Reference();
711      if (this.basedOn == null)
712        this.basedOn = new ArrayList<Reference>();
713      this.basedOn.add(t);
714      return t;
715    }
716
717    public DeviceDispense addBasedOn(Reference t) { //3
718      if (t == null)
719        return this;
720      if (this.basedOn == null)
721        this.basedOn = new ArrayList<Reference>();
722      this.basedOn.add(t);
723      return this;
724    }
725
726    /**
727     * @return The first repetition of repeating field {@link #basedOn}, creating it if it does not already exist {3}
728     */
729    public Reference getBasedOnFirstRep() { 
730      if (getBasedOn().isEmpty()) {
731        addBasedOn();
732      }
733      return getBasedOn().get(0);
734    }
735
736    /**
737     * @return {@link #partOf} (The bigger event that this dispense is a part of.)
738     */
739    public List<Reference> getPartOf() { 
740      if (this.partOf == null)
741        this.partOf = new ArrayList<Reference>();
742      return this.partOf;
743    }
744
745    /**
746     * @return Returns a reference to <code>this</code> for easy method chaining
747     */
748    public DeviceDispense setPartOf(List<Reference> thePartOf) { 
749      this.partOf = thePartOf;
750      return this;
751    }
752
753    public boolean hasPartOf() { 
754      if (this.partOf == null)
755        return false;
756      for (Reference item : this.partOf)
757        if (!item.isEmpty())
758          return true;
759      return false;
760    }
761
762    public Reference addPartOf() { //3
763      Reference t = new Reference();
764      if (this.partOf == null)
765        this.partOf = new ArrayList<Reference>();
766      this.partOf.add(t);
767      return t;
768    }
769
770    public DeviceDispense addPartOf(Reference t) { //3
771      if (t == null)
772        return this;
773      if (this.partOf == null)
774        this.partOf = new ArrayList<Reference>();
775      this.partOf.add(t);
776      return this;
777    }
778
779    /**
780     * @return The first repetition of repeating field {@link #partOf}, creating it if it does not already exist {3}
781     */
782    public Reference getPartOfFirstRep() { 
783      if (getPartOf().isEmpty()) {
784        addPartOf();
785      }
786      return getPartOf().get(0);
787    }
788
789    /**
790     * @return {@link #status} (A code specifying the state of the set of dispense events.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
791     */
792    public Enumeration<DeviceDispenseStatusCodes> getStatusElement() { 
793      if (this.status == null)
794        if (Configuration.errorOnAutoCreate())
795          throw new Error("Attempt to auto-create DeviceDispense.status");
796        else if (Configuration.doAutoCreate())
797          this.status = new Enumeration<DeviceDispenseStatusCodes>(new DeviceDispenseStatusCodesEnumFactory()); // bb
798      return this.status;
799    }
800
801    public boolean hasStatusElement() { 
802      return this.status != null && !this.status.isEmpty();
803    }
804
805    public boolean hasStatus() { 
806      return this.status != null && !this.status.isEmpty();
807    }
808
809    /**
810     * @param value {@link #status} (A code specifying the state of the set of dispense events.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
811     */
812    public DeviceDispense setStatusElement(Enumeration<DeviceDispenseStatusCodes> value) { 
813      this.status = value;
814      return this;
815    }
816
817    /**
818     * @return A code specifying the state of the set of dispense events.
819     */
820    public DeviceDispenseStatusCodes getStatus() { 
821      return this.status == null ? null : this.status.getValue();
822    }
823
824    /**
825     * @param value A code specifying the state of the set of dispense events.
826     */
827    public DeviceDispense setStatus(DeviceDispenseStatusCodes value) { 
828        if (this.status == null)
829          this.status = new Enumeration<DeviceDispenseStatusCodes>(new DeviceDispenseStatusCodesEnumFactory());
830        this.status.setValue(value);
831      return this;
832    }
833
834    /**
835     * @return {@link #statusReason} (Indicates the reason why a dispense was or was not performed.)
836     */
837    public CodeableReference getStatusReason() { 
838      if (this.statusReason == null)
839        if (Configuration.errorOnAutoCreate())
840          throw new Error("Attempt to auto-create DeviceDispense.statusReason");
841        else if (Configuration.doAutoCreate())
842          this.statusReason = new CodeableReference(); // cc
843      return this.statusReason;
844    }
845
846    public boolean hasStatusReason() { 
847      return this.statusReason != null && !this.statusReason.isEmpty();
848    }
849
850    /**
851     * @param value {@link #statusReason} (Indicates the reason why a dispense was or was not performed.)
852     */
853    public DeviceDispense setStatusReason(CodeableReference value) { 
854      this.statusReason = value;
855      return this;
856    }
857
858    /**
859     * @return {@link #category} (Indicates the type of device dispense.)
860     */
861    public List<CodeableConcept> getCategory() { 
862      if (this.category == null)
863        this.category = new ArrayList<CodeableConcept>();
864      return this.category;
865    }
866
867    /**
868     * @return Returns a reference to <code>this</code> for easy method chaining
869     */
870    public DeviceDispense setCategory(List<CodeableConcept> theCategory) { 
871      this.category = theCategory;
872      return this;
873    }
874
875    public boolean hasCategory() { 
876      if (this.category == null)
877        return false;
878      for (CodeableConcept item : this.category)
879        if (!item.isEmpty())
880          return true;
881      return false;
882    }
883
884    public CodeableConcept addCategory() { //3
885      CodeableConcept t = new CodeableConcept();
886      if (this.category == null)
887        this.category = new ArrayList<CodeableConcept>();
888      this.category.add(t);
889      return t;
890    }
891
892    public DeviceDispense addCategory(CodeableConcept t) { //3
893      if (t == null)
894        return this;
895      if (this.category == null)
896        this.category = new ArrayList<CodeableConcept>();
897      this.category.add(t);
898      return this;
899    }
900
901    /**
902     * @return The first repetition of repeating field {@link #category}, creating it if it does not already exist {3}
903     */
904    public CodeableConcept getCategoryFirstRep() { 
905      if (getCategory().isEmpty()) {
906        addCategory();
907      }
908      return getCategory().get(0);
909    }
910
911    /**
912     * @return {@link #device} (Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices.)
913     */
914    public CodeableReference getDevice() { 
915      if (this.device == null)
916        if (Configuration.errorOnAutoCreate())
917          throw new Error("Attempt to auto-create DeviceDispense.device");
918        else if (Configuration.doAutoCreate())
919          this.device = new CodeableReference(); // cc
920      return this.device;
921    }
922
923    public boolean hasDevice() { 
924      return this.device != null && !this.device.isEmpty();
925    }
926
927    /**
928     * @param value {@link #device} (Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices.)
929     */
930    public DeviceDispense setDevice(CodeableReference value) { 
931      this.device = value;
932      return this;
933    }
934
935    /**
936     * @return {@link #subject} (A link to a resource representing the person to whom the device is intended.)
937     */
938    public Reference getSubject() { 
939      if (this.subject == null)
940        if (Configuration.errorOnAutoCreate())
941          throw new Error("Attempt to auto-create DeviceDispense.subject");
942        else if (Configuration.doAutoCreate())
943          this.subject = new Reference(); // cc
944      return this.subject;
945    }
946
947    public boolean hasSubject() { 
948      return this.subject != null && !this.subject.isEmpty();
949    }
950
951    /**
952     * @param value {@link #subject} (A link to a resource representing the person to whom the device is intended.)
953     */
954    public DeviceDispense setSubject(Reference value) { 
955      this.subject = value;
956      return this;
957    }
958
959    /**
960     * @return {@link #encounter} (The encounter that establishes the context for this event.)
961     */
962    public Reference getEncounter() { 
963      if (this.encounter == null)
964        if (Configuration.errorOnAutoCreate())
965          throw new Error("Attempt to auto-create DeviceDispense.encounter");
966        else if (Configuration.doAutoCreate())
967          this.encounter = new Reference(); // cc
968      return this.encounter;
969    }
970
971    public boolean hasEncounter() { 
972      return this.encounter != null && !this.encounter.isEmpty();
973    }
974
975    /**
976     * @param value {@link #encounter} (The encounter that establishes the context for this event.)
977     */
978    public DeviceDispense setEncounter(Reference value) { 
979      this.encounter = value;
980      return this;
981    }
982
983    /**
984     * @return {@link #supportingInformation} (Additional information that supports the device being dispensed.)
985     */
986    public List<Reference> getSupportingInformation() { 
987      if (this.supportingInformation == null)
988        this.supportingInformation = new ArrayList<Reference>();
989      return this.supportingInformation;
990    }
991
992    /**
993     * @return Returns a reference to <code>this</code> for easy method chaining
994     */
995    public DeviceDispense setSupportingInformation(List<Reference> theSupportingInformation) { 
996      this.supportingInformation = theSupportingInformation;
997      return this;
998    }
999
1000    public boolean hasSupportingInformation() { 
1001      if (this.supportingInformation == null)
1002        return false;
1003      for (Reference item : this.supportingInformation)
1004        if (!item.isEmpty())
1005          return true;
1006      return false;
1007    }
1008
1009    public Reference addSupportingInformation() { //3
1010      Reference t = new Reference();
1011      if (this.supportingInformation == null)
1012        this.supportingInformation = new ArrayList<Reference>();
1013      this.supportingInformation.add(t);
1014      return t;
1015    }
1016
1017    public DeviceDispense addSupportingInformation(Reference t) { //3
1018      if (t == null)
1019        return this;
1020      if (this.supportingInformation == null)
1021        this.supportingInformation = new ArrayList<Reference>();
1022      this.supportingInformation.add(t);
1023      return this;
1024    }
1025
1026    /**
1027     * @return The first repetition of repeating field {@link #supportingInformation}, creating it if it does not already exist {3}
1028     */
1029    public Reference getSupportingInformationFirstRep() { 
1030      if (getSupportingInformation().isEmpty()) {
1031        addSupportingInformation();
1032      }
1033      return getSupportingInformation().get(0);
1034    }
1035
1036    /**
1037     * @return {@link #performer} (Indicates who or what performed the event.)
1038     */
1039    public List<DeviceDispensePerformerComponent> getPerformer() { 
1040      if (this.performer == null)
1041        this.performer = new ArrayList<DeviceDispensePerformerComponent>();
1042      return this.performer;
1043    }
1044
1045    /**
1046     * @return Returns a reference to <code>this</code> for easy method chaining
1047     */
1048    public DeviceDispense setPerformer(List<DeviceDispensePerformerComponent> thePerformer) { 
1049      this.performer = thePerformer;
1050      return this;
1051    }
1052
1053    public boolean hasPerformer() { 
1054      if (this.performer == null)
1055        return false;
1056      for (DeviceDispensePerformerComponent item : this.performer)
1057        if (!item.isEmpty())
1058          return true;
1059      return false;
1060    }
1061
1062    public DeviceDispensePerformerComponent addPerformer() { //3
1063      DeviceDispensePerformerComponent t = new DeviceDispensePerformerComponent();
1064      if (this.performer == null)
1065        this.performer = new ArrayList<DeviceDispensePerformerComponent>();
1066      this.performer.add(t);
1067      return t;
1068    }
1069
1070    public DeviceDispense addPerformer(DeviceDispensePerformerComponent t) { //3
1071      if (t == null)
1072        return this;
1073      if (this.performer == null)
1074        this.performer = new ArrayList<DeviceDispensePerformerComponent>();
1075      this.performer.add(t);
1076      return this;
1077    }
1078
1079    /**
1080     * @return The first repetition of repeating field {@link #performer}, creating it if it does not already exist {3}
1081     */
1082    public DeviceDispensePerformerComponent getPerformerFirstRep() { 
1083      if (getPerformer().isEmpty()) {
1084        addPerformer();
1085      }
1086      return getPerformer().get(0);
1087    }
1088
1089    /**
1090     * @return {@link #location} (The principal physical location where the dispense was performed.)
1091     */
1092    public Reference getLocation() { 
1093      if (this.location == null)
1094        if (Configuration.errorOnAutoCreate())
1095          throw new Error("Attempt to auto-create DeviceDispense.location");
1096        else if (Configuration.doAutoCreate())
1097          this.location = new Reference(); // cc
1098      return this.location;
1099    }
1100
1101    public boolean hasLocation() { 
1102      return this.location != null && !this.location.isEmpty();
1103    }
1104
1105    /**
1106     * @param value {@link #location} (The principal physical location where the dispense was performed.)
1107     */
1108    public DeviceDispense setLocation(Reference value) { 
1109      this.location = value;
1110      return this;
1111    }
1112
1113    /**
1114     * @return {@link #type} (Indicates the type of dispensing event that is performed.)
1115     */
1116    public CodeableConcept getType() { 
1117      if (this.type == null)
1118        if (Configuration.errorOnAutoCreate())
1119          throw new Error("Attempt to auto-create DeviceDispense.type");
1120        else if (Configuration.doAutoCreate())
1121          this.type = new CodeableConcept(); // cc
1122      return this.type;
1123    }
1124
1125    public boolean hasType() { 
1126      return this.type != null && !this.type.isEmpty();
1127    }
1128
1129    /**
1130     * @param value {@link #type} (Indicates the type of dispensing event that is performed.)
1131     */
1132    public DeviceDispense setType(CodeableConcept value) { 
1133      this.type = value;
1134      return this;
1135    }
1136
1137    /**
1138     * @return {@link #quantity} (The number of devices that have been dispensed.)
1139     */
1140    public Quantity getQuantity() { 
1141      if (this.quantity == null)
1142        if (Configuration.errorOnAutoCreate())
1143          throw new Error("Attempt to auto-create DeviceDispense.quantity");
1144        else if (Configuration.doAutoCreate())
1145          this.quantity = new Quantity(); // cc
1146      return this.quantity;
1147    }
1148
1149    public boolean hasQuantity() { 
1150      return this.quantity != null && !this.quantity.isEmpty();
1151    }
1152
1153    /**
1154     * @param value {@link #quantity} (The number of devices that have been dispensed.)
1155     */
1156    public DeviceDispense setQuantity(Quantity value) { 
1157      this.quantity = value;
1158      return this;
1159    }
1160
1161    /**
1162     * @return {@link #preparedDate} (The time when the dispensed product was packaged and reviewed.). This is the underlying object with id, value and extensions. The accessor "getPreparedDate" gives direct access to the value
1163     */
1164    public DateTimeType getPreparedDateElement() { 
1165      if (this.preparedDate == null)
1166        if (Configuration.errorOnAutoCreate())
1167          throw new Error("Attempt to auto-create DeviceDispense.preparedDate");
1168        else if (Configuration.doAutoCreate())
1169          this.preparedDate = new DateTimeType(); // bb
1170      return this.preparedDate;
1171    }
1172
1173    public boolean hasPreparedDateElement() { 
1174      return this.preparedDate != null && !this.preparedDate.isEmpty();
1175    }
1176
1177    public boolean hasPreparedDate() { 
1178      return this.preparedDate != null && !this.preparedDate.isEmpty();
1179    }
1180
1181    /**
1182     * @param value {@link #preparedDate} (The time when the dispensed product was packaged and reviewed.). This is the underlying object with id, value and extensions. The accessor "getPreparedDate" gives direct access to the value
1183     */
1184    public DeviceDispense setPreparedDateElement(DateTimeType value) { 
1185      this.preparedDate = value;
1186      return this;
1187    }
1188
1189    /**
1190     * @return The time when the dispensed product was packaged and reviewed.
1191     */
1192    public Date getPreparedDate() { 
1193      return this.preparedDate == null ? null : this.preparedDate.getValue();
1194    }
1195
1196    /**
1197     * @param value The time when the dispensed product was packaged and reviewed.
1198     */
1199    public DeviceDispense setPreparedDate(Date value) { 
1200      if (value == null)
1201        this.preparedDate = null;
1202      else {
1203        if (this.preparedDate == null)
1204          this.preparedDate = new DateTimeType();
1205        this.preparedDate.setValue(value);
1206      }
1207      return this;
1208    }
1209
1210    /**
1211     * @return {@link #whenHandedOver} (The time the dispensed product was made available to the patient or their representative.). This is the underlying object with id, value and extensions. The accessor "getWhenHandedOver" gives direct access to the value
1212     */
1213    public DateTimeType getWhenHandedOverElement() { 
1214      if (this.whenHandedOver == null)
1215        if (Configuration.errorOnAutoCreate())
1216          throw new Error("Attempt to auto-create DeviceDispense.whenHandedOver");
1217        else if (Configuration.doAutoCreate())
1218          this.whenHandedOver = new DateTimeType(); // bb
1219      return this.whenHandedOver;
1220    }
1221
1222    public boolean hasWhenHandedOverElement() { 
1223      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1224    }
1225
1226    public boolean hasWhenHandedOver() { 
1227      return this.whenHandedOver != null && !this.whenHandedOver.isEmpty();
1228    }
1229
1230    /**
1231     * @param value {@link #whenHandedOver} (The time the dispensed product was made available to the patient or their representative.). This is the underlying object with id, value and extensions. The accessor "getWhenHandedOver" gives direct access to the value
1232     */
1233    public DeviceDispense setWhenHandedOverElement(DateTimeType value) { 
1234      this.whenHandedOver = value;
1235      return this;
1236    }
1237
1238    /**
1239     * @return The time the dispensed product was made available to the patient or their representative.
1240     */
1241    public Date getWhenHandedOver() { 
1242      return this.whenHandedOver == null ? null : this.whenHandedOver.getValue();
1243    }
1244
1245    /**
1246     * @param value The time the dispensed product was made available to the patient or their representative.
1247     */
1248    public DeviceDispense setWhenHandedOver(Date value) { 
1249      if (value == null)
1250        this.whenHandedOver = null;
1251      else {
1252        if (this.whenHandedOver == null)
1253          this.whenHandedOver = new DateTimeType();
1254        this.whenHandedOver.setValue(value);
1255      }
1256      return this;
1257    }
1258
1259    /**
1260     * @return {@link #destination} (Identification of the facility/location where the device was /should be shipped to, as part of the dispense process.)
1261     */
1262    public Reference getDestination() { 
1263      if (this.destination == null)
1264        if (Configuration.errorOnAutoCreate())
1265          throw new Error("Attempt to auto-create DeviceDispense.destination");
1266        else if (Configuration.doAutoCreate())
1267          this.destination = new Reference(); // cc
1268      return this.destination;
1269    }
1270
1271    public boolean hasDestination() { 
1272      return this.destination != null && !this.destination.isEmpty();
1273    }
1274
1275    /**
1276     * @param value {@link #destination} (Identification of the facility/location where the device was /should be shipped to, as part of the dispense process.)
1277     */
1278    public DeviceDispense setDestination(Reference value) { 
1279      this.destination = value;
1280      return this;
1281    }
1282
1283    /**
1284     * @return {@link #note} (Extra information about the dispense that could not be conveyed in the other attributes.)
1285     */
1286    public List<Annotation> getNote() { 
1287      if (this.note == null)
1288        this.note = new ArrayList<Annotation>();
1289      return this.note;
1290    }
1291
1292    /**
1293     * @return Returns a reference to <code>this</code> for easy method chaining
1294     */
1295    public DeviceDispense setNote(List<Annotation> theNote) { 
1296      this.note = theNote;
1297      return this;
1298    }
1299
1300    public boolean hasNote() { 
1301      if (this.note == null)
1302        return false;
1303      for (Annotation item : this.note)
1304        if (!item.isEmpty())
1305          return true;
1306      return false;
1307    }
1308
1309    public Annotation addNote() { //3
1310      Annotation t = new Annotation();
1311      if (this.note == null)
1312        this.note = new ArrayList<Annotation>();
1313      this.note.add(t);
1314      return t;
1315    }
1316
1317    public DeviceDispense addNote(Annotation t) { //3
1318      if (t == null)
1319        return this;
1320      if (this.note == null)
1321        this.note = new ArrayList<Annotation>();
1322      this.note.add(t);
1323      return this;
1324    }
1325
1326    /**
1327     * @return The first repetition of repeating field {@link #note}, creating it if it does not already exist {3}
1328     */
1329    public Annotation getNoteFirstRep() { 
1330      if (getNote().isEmpty()) {
1331        addNote();
1332      }
1333      return getNote().get(0);
1334    }
1335
1336    /**
1337     * @return {@link #usageInstruction} (The full representation of the instructions.). This is the underlying object with id, value and extensions. The accessor "getUsageInstruction" gives direct access to the value
1338     */
1339    public StringType getUsageInstructionElement() { 
1340      if (this.usageInstruction == null)
1341        if (Configuration.errorOnAutoCreate())
1342          throw new Error("Attempt to auto-create DeviceDispense.usageInstruction");
1343        else if (Configuration.doAutoCreate())
1344          this.usageInstruction = new StringType(); // bb
1345      return this.usageInstruction;
1346    }
1347
1348    public boolean hasUsageInstructionElement() { 
1349      return this.usageInstruction != null && !this.usageInstruction.isEmpty();
1350    }
1351
1352    public boolean hasUsageInstruction() { 
1353      return this.usageInstruction != null && !this.usageInstruction.isEmpty();
1354    }
1355
1356    /**
1357     * @param value {@link #usageInstruction} (The full representation of the instructions.). This is the underlying object with id, value and extensions. The accessor "getUsageInstruction" gives direct access to the value
1358     */
1359    public DeviceDispense setUsageInstructionElement(StringType value) { 
1360      this.usageInstruction = value;
1361      return this;
1362    }
1363
1364    /**
1365     * @return The full representation of the instructions.
1366     */
1367    public String getUsageInstruction() { 
1368      return this.usageInstruction == null ? null : this.usageInstruction.getValue();
1369    }
1370
1371    /**
1372     * @param value The full representation of the instructions.
1373     */
1374    public DeviceDispense setUsageInstruction(String value) { 
1375      if (Utilities.noString(value))
1376        this.usageInstruction = null;
1377      else {
1378        if (this.usageInstruction == null)
1379          this.usageInstruction = new StringType();
1380        this.usageInstruction.setValue(value);
1381      }
1382      return this;
1383    }
1384
1385    /**
1386     * @return {@link #eventHistory} (A summary of the events of interest that have occurred, such as when the dispense was verified.)
1387     */
1388    public List<Reference> getEventHistory() { 
1389      if (this.eventHistory == null)
1390        this.eventHistory = new ArrayList<Reference>();
1391      return this.eventHistory;
1392    }
1393
1394    /**
1395     * @return Returns a reference to <code>this</code> for easy method chaining
1396     */
1397    public DeviceDispense setEventHistory(List<Reference> theEventHistory) { 
1398      this.eventHistory = theEventHistory;
1399      return this;
1400    }
1401
1402    public boolean hasEventHistory() { 
1403      if (this.eventHistory == null)
1404        return false;
1405      for (Reference item : this.eventHistory)
1406        if (!item.isEmpty())
1407          return true;
1408      return false;
1409    }
1410
1411    public Reference addEventHistory() { //3
1412      Reference t = new Reference();
1413      if (this.eventHistory == null)
1414        this.eventHistory = new ArrayList<Reference>();
1415      this.eventHistory.add(t);
1416      return t;
1417    }
1418
1419    public DeviceDispense addEventHistory(Reference t) { //3
1420      if (t == null)
1421        return this;
1422      if (this.eventHistory == null)
1423        this.eventHistory = new ArrayList<Reference>();
1424      this.eventHistory.add(t);
1425      return this;
1426    }
1427
1428    /**
1429     * @return The first repetition of repeating field {@link #eventHistory}, creating it if it does not already exist {3}
1430     */
1431    public Reference getEventHistoryFirstRep() { 
1432      if (getEventHistory().isEmpty()) {
1433        addEventHistory();
1434      }
1435      return getEventHistory().get(0);
1436    }
1437
1438      protected void listChildren(List<Property> children) {
1439        super.listChildren(children);
1440        children.add(new Property("identifier", "Identifier", "Business identifier for this dispensation.", 0, java.lang.Integer.MAX_VALUE, identifier));
1441        children.add(new Property("basedOn", "Reference(CarePlan|DeviceRequest)", "The order or request that this dispense is fulfilling.", 0, java.lang.Integer.MAX_VALUE, basedOn));
1442        children.add(new Property("partOf", "Reference(Procedure)", "The bigger event that this dispense is a part of.", 0, java.lang.Integer.MAX_VALUE, partOf));
1443        children.add(new Property("status", "code", "A code specifying the state of the set of dispense events.", 0, 1, status));
1444        children.add(new Property("statusReason", "CodeableReference(DetectedIssue)", "Indicates the reason why a dispense was or was not performed.", 0, 1, statusReason));
1445        children.add(new Property("category", "CodeableConcept", "Indicates the type of device dispense.", 0, java.lang.Integer.MAX_VALUE, category));
1446        children.add(new Property("device", "CodeableReference(Device|DeviceDefinition)", "Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices.", 0, 1, device));
1447        children.add(new Property("subject", "Reference(Patient)", "A link to a resource representing the person to whom the device is intended.", 0, 1, subject));
1448        children.add(new Property("encounter", "Reference(Encounter)", "The encounter that establishes the context for this event.", 0, 1, encounter));
1449        children.add(new Property("supportingInformation", "Reference(Any)", "Additional information that supports the device being dispensed.", 0, java.lang.Integer.MAX_VALUE, supportingInformation));
1450        children.add(new Property("performer", "", "Indicates who or what performed the event.", 0, java.lang.Integer.MAX_VALUE, performer));
1451        children.add(new Property("location", "Reference(Location)", "The principal physical location where the dispense was performed.", 0, 1, location));
1452        children.add(new Property("type", "CodeableConcept", "Indicates the type of dispensing event that is performed.", 0, 1, type));
1453        children.add(new Property("quantity", "Quantity", "The number of devices that have been dispensed.", 0, 1, quantity));
1454        children.add(new Property("preparedDate", "dateTime", "The time when the dispensed product was packaged and reviewed.", 0, 1, preparedDate));
1455        children.add(new Property("whenHandedOver", "dateTime", "The time the dispensed product was made available to the patient or their representative.", 0, 1, whenHandedOver));
1456        children.add(new Property("destination", "Reference(Location)", "Identification of the facility/location where the device was /should be shipped to, as part of the dispense process.", 0, 1, destination));
1457        children.add(new Property("note", "Annotation", "Extra information about the dispense that could not be conveyed in the other attributes.", 0, java.lang.Integer.MAX_VALUE, note));
1458        children.add(new Property("usageInstruction", "string", "The full representation of the instructions.", 0, 1, usageInstruction));
1459        children.add(new Property("eventHistory", "Reference(Provenance)", "A summary of the events of interest that have occurred, such as when the dispense was verified.", 0, java.lang.Integer.MAX_VALUE, eventHistory));
1460      }
1461
1462      @Override
1463      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1464        switch (_hash) {
1465        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "Business identifier for this dispensation.", 0, java.lang.Integer.MAX_VALUE, identifier);
1466        case -332612366: /*basedOn*/  return new Property("basedOn", "Reference(CarePlan|DeviceRequest)", "The order or request that this dispense is fulfilling.", 0, java.lang.Integer.MAX_VALUE, basedOn);
1467        case -995410646: /*partOf*/  return new Property("partOf", "Reference(Procedure)", "The bigger event that this dispense is a part of.", 0, java.lang.Integer.MAX_VALUE, partOf);
1468        case -892481550: /*status*/  return new Property("status", "code", "A code specifying the state of the set of dispense events.", 0, 1, status);
1469        case 2051346646: /*statusReason*/  return new Property("statusReason", "CodeableReference(DetectedIssue)", "Indicates the reason why a dispense was or was not performed.", 0, 1, statusReason);
1470        case 50511102: /*category*/  return new Property("category", "CodeableConcept", "Indicates the type of device dispense.", 0, java.lang.Integer.MAX_VALUE, category);
1471        case -1335157162: /*device*/  return new Property("device", "CodeableReference(Device|DeviceDefinition)", "Identifies the device being dispensed. This is either a link to a resource representing the details of the device or a simple attribute carrying a code that identifies the device from a known list of devices.", 0, 1, device);
1472        case -1867885268: /*subject*/  return new Property("subject", "Reference(Patient)", "A link to a resource representing the person to whom the device is intended.", 0, 1, subject);
1473        case 1524132147: /*encounter*/  return new Property("encounter", "Reference(Encounter)", "The encounter that establishes the context for this event.", 0, 1, encounter);
1474        case -1248768647: /*supportingInformation*/  return new Property("supportingInformation", "Reference(Any)", "Additional information that supports the device being dispensed.", 0, java.lang.Integer.MAX_VALUE, supportingInformation);
1475        case 481140686: /*performer*/  return new Property("performer", "", "Indicates who or what performed the event.", 0, java.lang.Integer.MAX_VALUE, performer);
1476        case 1901043637: /*location*/  return new Property("location", "Reference(Location)", "The principal physical location where the dispense was performed.", 0, 1, location);
1477        case 3575610: /*type*/  return new Property("type", "CodeableConcept", "Indicates the type of dispensing event that is performed.", 0, 1, type);
1478        case -1285004149: /*quantity*/  return new Property("quantity", "Quantity", "The number of devices that have been dispensed.", 0, 1, quantity);
1479        case -2024959605: /*preparedDate*/  return new Property("preparedDate", "dateTime", "The time when the dispensed product was packaged and reviewed.", 0, 1, preparedDate);
1480        case -940241380: /*whenHandedOver*/  return new Property("whenHandedOver", "dateTime", "The time the dispensed product was made available to the patient or their representative.", 0, 1, whenHandedOver);
1481        case -1429847026: /*destination*/  return new Property("destination", "Reference(Location)", "Identification of the facility/location where the device was /should be shipped to, as part of the dispense process.", 0, 1, destination);
1482        case 3387378: /*note*/  return new Property("note", "Annotation", "Extra information about the dispense that could not be conveyed in the other attributes.", 0, java.lang.Integer.MAX_VALUE, note);
1483        case 2138372141: /*usageInstruction*/  return new Property("usageInstruction", "string", "The full representation of the instructions.", 0, 1, usageInstruction);
1484        case 1835190426: /*eventHistory*/  return new Property("eventHistory", "Reference(Provenance)", "A summary of the events of interest that have occurred, such as when the dispense was verified.", 0, java.lang.Integer.MAX_VALUE, eventHistory);
1485        default: return super.getNamedProperty(_hash, _name, _checkValid);
1486        }
1487
1488      }
1489
1490      @Override
1491      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1492        switch (hash) {
1493        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1494        case -332612366: /*basedOn*/ return this.basedOn == null ? new Base[0] : this.basedOn.toArray(new Base[this.basedOn.size()]); // Reference
1495        case -995410646: /*partOf*/ return this.partOf == null ? new Base[0] : this.partOf.toArray(new Base[this.partOf.size()]); // Reference
1496        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<DeviceDispenseStatusCodes>
1497        case 2051346646: /*statusReason*/ return this.statusReason == null ? new Base[0] : new Base[] {this.statusReason}; // CodeableReference
1498        case 50511102: /*category*/ return this.category == null ? new Base[0] : this.category.toArray(new Base[this.category.size()]); // CodeableConcept
1499        case -1335157162: /*device*/ return this.device == null ? new Base[0] : new Base[] {this.device}; // CodeableReference
1500        case -1867885268: /*subject*/ return this.subject == null ? new Base[0] : new Base[] {this.subject}; // Reference
1501        case 1524132147: /*encounter*/ return this.encounter == null ? new Base[0] : new Base[] {this.encounter}; // Reference
1502        case -1248768647: /*supportingInformation*/ return this.supportingInformation == null ? new Base[0] : this.supportingInformation.toArray(new Base[this.supportingInformation.size()]); // Reference
1503        case 481140686: /*performer*/ return this.performer == null ? new Base[0] : this.performer.toArray(new Base[this.performer.size()]); // DeviceDispensePerformerComponent
1504        case 1901043637: /*location*/ return this.location == null ? new Base[0] : new Base[] {this.location}; // Reference
1505        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // CodeableConcept
1506        case -1285004149: /*quantity*/ return this.quantity == null ? new Base[0] : new Base[] {this.quantity}; // Quantity
1507        case -2024959605: /*preparedDate*/ return this.preparedDate == null ? new Base[0] : new Base[] {this.preparedDate}; // DateTimeType
1508        case -940241380: /*whenHandedOver*/ return this.whenHandedOver == null ? new Base[0] : new Base[] {this.whenHandedOver}; // DateTimeType
1509        case -1429847026: /*destination*/ return this.destination == null ? new Base[0] : new Base[] {this.destination}; // Reference
1510        case 3387378: /*note*/ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
1511        case 2138372141: /*usageInstruction*/ return this.usageInstruction == null ? new Base[0] : new Base[] {this.usageInstruction}; // StringType
1512        case 1835190426: /*eventHistory*/ return this.eventHistory == null ? new Base[0] : this.eventHistory.toArray(new Base[this.eventHistory.size()]); // Reference
1513        default: return super.getProperty(hash, name, checkValid);
1514        }
1515
1516      }
1517
1518      @Override
1519      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1520        switch (hash) {
1521        case -1618432855: // identifier
1522          this.getIdentifier().add(TypeConvertor.castToIdentifier(value)); // Identifier
1523          return value;
1524        case -332612366: // basedOn
1525          this.getBasedOn().add(TypeConvertor.castToReference(value)); // Reference
1526          return value;
1527        case -995410646: // partOf
1528          this.getPartOf().add(TypeConvertor.castToReference(value)); // Reference
1529          return value;
1530        case -892481550: // status
1531          value = new DeviceDispenseStatusCodesEnumFactory().fromType(TypeConvertor.castToCode(value));
1532          this.status = (Enumeration) value; // Enumeration<DeviceDispenseStatusCodes>
1533          return value;
1534        case 2051346646: // statusReason
1535          this.statusReason = TypeConvertor.castToCodeableReference(value); // CodeableReference
1536          return value;
1537        case 50511102: // category
1538          this.getCategory().add(TypeConvertor.castToCodeableConcept(value)); // CodeableConcept
1539          return value;
1540        case -1335157162: // device
1541          this.device = TypeConvertor.castToCodeableReference(value); // CodeableReference
1542          return value;
1543        case -1867885268: // subject
1544          this.subject = TypeConvertor.castToReference(value); // Reference
1545          return value;
1546        case 1524132147: // encounter
1547          this.encounter = TypeConvertor.castToReference(value); // Reference
1548          return value;
1549        case -1248768647: // supportingInformation
1550          this.getSupportingInformation().add(TypeConvertor.castToReference(value)); // Reference
1551          return value;
1552        case 481140686: // performer
1553          this.getPerformer().add((DeviceDispensePerformerComponent) value); // DeviceDispensePerformerComponent
1554          return value;
1555        case 1901043637: // location
1556          this.location = TypeConvertor.castToReference(value); // Reference
1557          return value;
1558        case 3575610: // type
1559          this.type = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1560          return value;
1561        case -1285004149: // quantity
1562          this.quantity = TypeConvertor.castToQuantity(value); // Quantity
1563          return value;
1564        case -2024959605: // preparedDate
1565          this.preparedDate = TypeConvertor.castToDateTime(value); // DateTimeType
1566          return value;
1567        case -940241380: // whenHandedOver
1568          this.whenHandedOver = TypeConvertor.castToDateTime(value); // DateTimeType
1569          return value;
1570        case -1429847026: // destination
1571          this.destination = TypeConvertor.castToReference(value); // Reference
1572          return value;
1573        case 3387378: // note
1574          this.getNote().add(TypeConvertor.castToAnnotation(value)); // Annotation
1575          return value;
1576        case 2138372141: // usageInstruction
1577          this.usageInstruction = TypeConvertor.castToString(value); // StringType
1578          return value;
1579        case 1835190426: // eventHistory
1580          this.getEventHistory().add(TypeConvertor.castToReference(value)); // Reference
1581          return value;
1582        default: return super.setProperty(hash, name, value);
1583        }
1584
1585      }
1586
1587      @Override
1588      public Base setProperty(String name, Base value) throws FHIRException {
1589        if (name.equals("identifier")) {
1590          this.getIdentifier().add(TypeConvertor.castToIdentifier(value));
1591        } else if (name.equals("basedOn")) {
1592          this.getBasedOn().add(TypeConvertor.castToReference(value));
1593        } else if (name.equals("partOf")) {
1594          this.getPartOf().add(TypeConvertor.castToReference(value));
1595        } else if (name.equals("status")) {
1596          value = new DeviceDispenseStatusCodesEnumFactory().fromType(TypeConvertor.castToCode(value));
1597          this.status = (Enumeration) value; // Enumeration<DeviceDispenseStatusCodes>
1598        } else if (name.equals("statusReason")) {
1599          this.statusReason = TypeConvertor.castToCodeableReference(value); // CodeableReference
1600        } else if (name.equals("category")) {
1601          this.getCategory().add(TypeConvertor.castToCodeableConcept(value));
1602        } else if (name.equals("device")) {
1603          this.device = TypeConvertor.castToCodeableReference(value); // CodeableReference
1604        } else if (name.equals("subject")) {
1605          this.subject = TypeConvertor.castToReference(value); // Reference
1606        } else if (name.equals("encounter")) {
1607          this.encounter = TypeConvertor.castToReference(value); // Reference
1608        } else if (name.equals("supportingInformation")) {
1609          this.getSupportingInformation().add(TypeConvertor.castToReference(value));
1610        } else if (name.equals("performer")) {
1611          this.getPerformer().add((DeviceDispensePerformerComponent) value);
1612        } else if (name.equals("location")) {
1613          this.location = TypeConvertor.castToReference(value); // Reference
1614        } else if (name.equals("type")) {
1615          this.type = TypeConvertor.castToCodeableConcept(value); // CodeableConcept
1616        } else if (name.equals("quantity")) {
1617          this.quantity = TypeConvertor.castToQuantity(value); // Quantity
1618        } else if (name.equals("preparedDate")) {
1619          this.preparedDate = TypeConvertor.castToDateTime(value); // DateTimeType
1620        } else if (name.equals("whenHandedOver")) {
1621          this.whenHandedOver = TypeConvertor.castToDateTime(value); // DateTimeType
1622        } else if (name.equals("destination")) {
1623          this.destination = TypeConvertor.castToReference(value); // Reference
1624        } else if (name.equals("note")) {
1625          this.getNote().add(TypeConvertor.castToAnnotation(value));
1626        } else if (name.equals("usageInstruction")) {
1627          this.usageInstruction = TypeConvertor.castToString(value); // StringType
1628        } else if (name.equals("eventHistory")) {
1629          this.getEventHistory().add(TypeConvertor.castToReference(value));
1630        } else
1631          return super.setProperty(name, value);
1632        return value;
1633      }
1634
1635      @Override
1636      public Base makeProperty(int hash, String name) throws FHIRException {
1637        switch (hash) {
1638        case -1618432855:  return addIdentifier(); 
1639        case -332612366:  return addBasedOn(); 
1640        case -995410646:  return addPartOf(); 
1641        case -892481550:  return getStatusElement();
1642        case 2051346646:  return getStatusReason();
1643        case 50511102:  return addCategory(); 
1644        case -1335157162:  return getDevice();
1645        case -1867885268:  return getSubject();
1646        case 1524132147:  return getEncounter();
1647        case -1248768647:  return addSupportingInformation(); 
1648        case 481140686:  return addPerformer(); 
1649        case 1901043637:  return getLocation();
1650        case 3575610:  return getType();
1651        case -1285004149:  return getQuantity();
1652        case -2024959605:  return getPreparedDateElement();
1653        case -940241380:  return getWhenHandedOverElement();
1654        case -1429847026:  return getDestination();
1655        case 3387378:  return addNote(); 
1656        case 2138372141:  return getUsageInstructionElement();
1657        case 1835190426:  return addEventHistory(); 
1658        default: return super.makeProperty(hash, name);
1659        }
1660
1661      }
1662
1663      @Override
1664      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1665        switch (hash) {
1666        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
1667        case -332612366: /*basedOn*/ return new String[] {"Reference"};
1668        case -995410646: /*partOf*/ return new String[] {"Reference"};
1669        case -892481550: /*status*/ return new String[] {"code"};
1670        case 2051346646: /*statusReason*/ return new String[] {"CodeableReference"};
1671        case 50511102: /*category*/ return new String[] {"CodeableConcept"};
1672        case -1335157162: /*device*/ return new String[] {"CodeableReference"};
1673        case -1867885268: /*subject*/ return new String[] {"Reference"};
1674        case 1524132147: /*encounter*/ return new String[] {"Reference"};
1675        case -1248768647: /*supportingInformation*/ return new String[] {"Reference"};
1676        case 481140686: /*performer*/ return new String[] {};
1677        case 1901043637: /*location*/ return new String[] {"Reference"};
1678        case 3575610: /*type*/ return new String[] {"CodeableConcept"};
1679        case -1285004149: /*quantity*/ return new String[] {"Quantity"};
1680        case -2024959605: /*preparedDate*/ return new String[] {"dateTime"};
1681        case -940241380: /*whenHandedOver*/ return new String[] {"dateTime"};
1682        case -1429847026: /*destination*/ return new String[] {"Reference"};
1683        case 3387378: /*note*/ return new String[] {"Annotation"};
1684        case 2138372141: /*usageInstruction*/ return new String[] {"string"};
1685        case 1835190426: /*eventHistory*/ return new String[] {"Reference"};
1686        default: return super.getTypesForProperty(hash, name);
1687        }
1688
1689      }
1690
1691      @Override
1692      public Base addChild(String name) throws FHIRException {
1693        if (name.equals("identifier")) {
1694          return addIdentifier();
1695        }
1696        else if (name.equals("basedOn")) {
1697          return addBasedOn();
1698        }
1699        else if (name.equals("partOf")) {
1700          return addPartOf();
1701        }
1702        else if (name.equals("status")) {
1703          throw new FHIRException("Cannot call addChild on a primitive type DeviceDispense.status");
1704        }
1705        else if (name.equals("statusReason")) {
1706          this.statusReason = new CodeableReference();
1707          return this.statusReason;
1708        }
1709        else if (name.equals("category")) {
1710          return addCategory();
1711        }
1712        else if (name.equals("device")) {
1713          this.device = new CodeableReference();
1714          return this.device;
1715        }
1716        else if (name.equals("subject")) {
1717          this.subject = new Reference();
1718          return this.subject;
1719        }
1720        else if (name.equals("encounter")) {
1721          this.encounter = new Reference();
1722          return this.encounter;
1723        }
1724        else if (name.equals("supportingInformation")) {
1725          return addSupportingInformation();
1726        }
1727        else if (name.equals("performer")) {
1728          return addPerformer();
1729        }
1730        else if (name.equals("location")) {
1731          this.location = new Reference();
1732          return this.location;
1733        }
1734        else if (name.equals("type")) {
1735          this.type = new CodeableConcept();
1736          return this.type;
1737        }
1738        else if (name.equals("quantity")) {
1739          this.quantity = new Quantity();
1740          return this.quantity;
1741        }
1742        else if (name.equals("preparedDate")) {
1743          throw new FHIRException("Cannot call addChild on a primitive type DeviceDispense.preparedDate");
1744        }
1745        else if (name.equals("whenHandedOver")) {
1746          throw new FHIRException("Cannot call addChild on a primitive type DeviceDispense.whenHandedOver");
1747        }
1748        else if (name.equals("destination")) {
1749          this.destination = new Reference();
1750          return this.destination;
1751        }
1752        else if (name.equals("note")) {
1753          return addNote();
1754        }
1755        else if (name.equals("usageInstruction")) {
1756          throw new FHIRException("Cannot call addChild on a primitive type DeviceDispense.usageInstruction");
1757        }
1758        else if (name.equals("eventHistory")) {
1759          return addEventHistory();
1760        }
1761        else
1762          return super.addChild(name);
1763      }
1764
1765  public String fhirType() {
1766    return "DeviceDispense";
1767
1768  }
1769
1770      public DeviceDispense copy() {
1771        DeviceDispense dst = new DeviceDispense();
1772        copyValues(dst);
1773        return dst;
1774      }
1775
1776      public void copyValues(DeviceDispense dst) {
1777        super.copyValues(dst);
1778        if (identifier != null) {
1779          dst.identifier = new ArrayList<Identifier>();
1780          for (Identifier i : identifier)
1781            dst.identifier.add(i.copy());
1782        };
1783        if (basedOn != null) {
1784          dst.basedOn = new ArrayList<Reference>();
1785          for (Reference i : basedOn)
1786            dst.basedOn.add(i.copy());
1787        };
1788        if (partOf != null) {
1789          dst.partOf = new ArrayList<Reference>();
1790          for (Reference i : partOf)
1791            dst.partOf.add(i.copy());
1792        };
1793        dst.status = status == null ? null : status.copy();
1794        dst.statusReason = statusReason == null ? null : statusReason.copy();
1795        if (category != null) {
1796          dst.category = new ArrayList<CodeableConcept>();
1797          for (CodeableConcept i : category)
1798            dst.category.add(i.copy());
1799        };
1800        dst.device = device == null ? null : device.copy();
1801        dst.subject = subject == null ? null : subject.copy();
1802        dst.encounter = encounter == null ? null : encounter.copy();
1803        if (supportingInformation != null) {
1804          dst.supportingInformation = new ArrayList<Reference>();
1805          for (Reference i : supportingInformation)
1806            dst.supportingInformation.add(i.copy());
1807        };
1808        if (performer != null) {
1809          dst.performer = new ArrayList<DeviceDispensePerformerComponent>();
1810          for (DeviceDispensePerformerComponent i : performer)
1811            dst.performer.add(i.copy());
1812        };
1813        dst.location = location == null ? null : location.copy();
1814        dst.type = type == null ? null : type.copy();
1815        dst.quantity = quantity == null ? null : quantity.copy();
1816        dst.preparedDate = preparedDate == null ? null : preparedDate.copy();
1817        dst.whenHandedOver = whenHandedOver == null ? null : whenHandedOver.copy();
1818        dst.destination = destination == null ? null : destination.copy();
1819        if (note != null) {
1820          dst.note = new ArrayList<Annotation>();
1821          for (Annotation i : note)
1822            dst.note.add(i.copy());
1823        };
1824        dst.usageInstruction = usageInstruction == null ? null : usageInstruction.copy();
1825        if (eventHistory != null) {
1826          dst.eventHistory = new ArrayList<Reference>();
1827          for (Reference i : eventHistory)
1828            dst.eventHistory.add(i.copy());
1829        };
1830      }
1831
1832      protected DeviceDispense typedCopy() {
1833        return copy();
1834      }
1835
1836      @Override
1837      public boolean equalsDeep(Base other_) {
1838        if (!super.equalsDeep(other_))
1839          return false;
1840        if (!(other_ instanceof DeviceDispense))
1841          return false;
1842        DeviceDispense o = (DeviceDispense) other_;
1843        return compareDeep(identifier, o.identifier, true) && compareDeep(basedOn, o.basedOn, true) && compareDeep(partOf, o.partOf, true)
1844           && compareDeep(status, o.status, true) && compareDeep(statusReason, o.statusReason, true) && compareDeep(category, o.category, true)
1845           && compareDeep(device, o.device, true) && compareDeep(subject, o.subject, true) && compareDeep(encounter, o.encounter, true)
1846           && compareDeep(supportingInformation, o.supportingInformation, true) && compareDeep(performer, o.performer, true)
1847           && compareDeep(location, o.location, true) && compareDeep(type, o.type, true) && compareDeep(quantity, o.quantity, true)
1848           && compareDeep(preparedDate, o.preparedDate, true) && compareDeep(whenHandedOver, o.whenHandedOver, true)
1849           && compareDeep(destination, o.destination, true) && compareDeep(note, o.note, true) && compareDeep(usageInstruction, o.usageInstruction, true)
1850           && compareDeep(eventHistory, o.eventHistory, true);
1851      }
1852
1853      @Override
1854      public boolean equalsShallow(Base other_) {
1855        if (!super.equalsShallow(other_))
1856          return false;
1857        if (!(other_ instanceof DeviceDispense))
1858          return false;
1859        DeviceDispense o = (DeviceDispense) other_;
1860        return compareValues(status, o.status, true) && compareValues(preparedDate, o.preparedDate, true) && compareValues(whenHandedOver, o.whenHandedOver, true)
1861           && compareValues(usageInstruction, o.usageInstruction, true);
1862      }
1863
1864      public boolean isEmpty() {
1865        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, basedOn, partOf
1866          , status, statusReason, category, device, subject, encounter, supportingInformation
1867          , performer, location, type, quantity, preparedDate, whenHandedOver, destination
1868          , note, usageInstruction, eventHistory);
1869      }
1870
1871  @Override
1872  public ResourceType getResourceType() {
1873    return ResourceType.DeviceDispense;
1874   }
1875
1876 /**
1877   * Search parameter: <b>code</b>
1878   * <p>
1879   * Description: <b>Search for devices that match this code</b><br>
1880   * Type: <b>token</b><br>
1881   * Path: <b>DeviceDispense.device.concept</b><br>
1882   * </p>
1883   */
1884  @SearchParamDefinition(name="code", path="DeviceDispense.device.concept", description="Search for devices that match this code", type="token" )
1885  public static final String SP_CODE = "code";
1886 /**
1887   * <b>Fluent Client</b> search parameter constant for <b>code</b>
1888   * <p>
1889   * Description: <b>Search for devices that match this code</b><br>
1890   * Type: <b>token</b><br>
1891   * Path: <b>DeviceDispense.device.concept</b><br>
1892   * </p>
1893   */
1894  public static final ca.uhn.fhir.rest.gclient.TokenClientParam CODE = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_CODE);
1895
1896 /**
1897   * Search parameter: <b>subject</b>
1898   * <p>
1899   * Description: <b>The identity of a patient for whom to list dispenses</b><br>
1900   * Type: <b>reference</b><br>
1901   * Path: <b>DeviceDispense.subject</b><br>
1902   * </p>
1903   */
1904  @SearchParamDefinition(name="subject", path="DeviceDispense.subject", description="The identity of a patient for whom to list dispenses", type="reference", target={Patient.class } )
1905  public static final String SP_SUBJECT = "subject";
1906 /**
1907   * <b>Fluent Client</b> search parameter constant for <b>subject</b>
1908   * <p>
1909   * Description: <b>The identity of a patient for whom to list dispenses</b><br>
1910   * Type: <b>reference</b><br>
1911   * Path: <b>DeviceDispense.subject</b><br>
1912   * </p>
1913   */
1914  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBJECT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUBJECT);
1915
1916/**
1917   * Constant for fluent queries to be used to add include statements. Specifies
1918   * the path value of "<b>DeviceDispense:subject</b>".
1919   */
1920  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBJECT = new ca.uhn.fhir.model.api.Include("DeviceDispense:subject").toLocked();
1921
1922
1923}
1924