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