001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.Description;
042import ca.uhn.fhir.model.api.annotation.ResourceDef;
043import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
044import org.hl7.fhir.exceptions.FHIRException;
045/**
046 * Record of delivery of what is supplied.
047 */
048@ResourceDef(name="SupplyDelivery", profile="http://hl7.org/fhir/Profile/SupplyDelivery")
049public class SupplyDelivery extends DomainResource {
050
051    public enum SupplyDeliveryStatus {
052        /**
053         * Supply has been requested, but not delivered.
054         */
055        INPROGRESS, 
056        /**
057         * Supply has been delivered ("completed").
058         */
059        COMPLETED, 
060        /**
061         * Dispensing was not completed.
062         */
063        ABANDONED, 
064        /**
065         * added to help the parsers
066         */
067        NULL;
068        public static SupplyDeliveryStatus fromCode(String codeString) throws FHIRException {
069            if (codeString == null || "".equals(codeString))
070                return null;
071        if ("in-progress".equals(codeString))
072          return INPROGRESS;
073        if ("completed".equals(codeString))
074          return COMPLETED;
075        if ("abandoned".equals(codeString))
076          return ABANDONED;
077        throw new FHIRException("Unknown SupplyDeliveryStatus code '"+codeString+"'");
078        }
079        public String toCode() {
080          switch (this) {
081            case INPROGRESS: return "in-progress";
082            case COMPLETED: return "completed";
083            case ABANDONED: return "abandoned";
084            case NULL: return null;
085            default: return "?";
086          }
087        }
088        public String getSystem() {
089          switch (this) {
090            case INPROGRESS: return "http://hl7.org/fhir/supplydelivery-status";
091            case COMPLETED: return "http://hl7.org/fhir/supplydelivery-status";
092            case ABANDONED: return "http://hl7.org/fhir/supplydelivery-status";
093            case NULL: return null;
094            default: return "?";
095          }
096        }
097        public String getDefinition() {
098          switch (this) {
099            case INPROGRESS: return "Supply has been requested, but not delivered.";
100            case COMPLETED: return "Supply has been delivered (\"completed\").";
101            case ABANDONED: return "Dispensing was not completed.";
102            case NULL: return null;
103            default: return "?";
104          }
105        }
106        public String getDisplay() {
107          switch (this) {
108            case INPROGRESS: return "In Progress";
109            case COMPLETED: return "Delivered";
110            case ABANDONED: return "Abandoned";
111            case NULL: return null;
112            default: return "?";
113          }
114        }
115    }
116
117  public static class SupplyDeliveryStatusEnumFactory implements EnumFactory<SupplyDeliveryStatus> {
118    public SupplyDeliveryStatus fromCode(String codeString) throws IllegalArgumentException {
119      if (codeString == null || "".equals(codeString))
120            if (codeString == null || "".equals(codeString))
121                return null;
122        if ("in-progress".equals(codeString))
123          return SupplyDeliveryStatus.INPROGRESS;
124        if ("completed".equals(codeString))
125          return SupplyDeliveryStatus.COMPLETED;
126        if ("abandoned".equals(codeString))
127          return SupplyDeliveryStatus.ABANDONED;
128        throw new IllegalArgumentException("Unknown SupplyDeliveryStatus code '"+codeString+"'");
129        }
130        public Enumeration<SupplyDeliveryStatus> fromType(Base code) throws FHIRException {
131          if (code == null || code.isEmpty())
132            return null;
133          String codeString = ((PrimitiveType) code).asStringValue();
134          if (codeString == null || "".equals(codeString))
135            return null;
136        if ("in-progress".equals(codeString))
137          return new Enumeration<SupplyDeliveryStatus>(this, SupplyDeliveryStatus.INPROGRESS);
138        if ("completed".equals(codeString))
139          return new Enumeration<SupplyDeliveryStatus>(this, SupplyDeliveryStatus.COMPLETED);
140        if ("abandoned".equals(codeString))
141          return new Enumeration<SupplyDeliveryStatus>(this, SupplyDeliveryStatus.ABANDONED);
142        throw new FHIRException("Unknown SupplyDeliveryStatus code '"+codeString+"'");
143        }
144    public String toCode(SupplyDeliveryStatus code) {
145      if (code == SupplyDeliveryStatus.INPROGRESS)
146        return "in-progress";
147      if (code == SupplyDeliveryStatus.COMPLETED)
148        return "completed";
149      if (code == SupplyDeliveryStatus.ABANDONED)
150        return "abandoned";
151      return "?";
152      }
153    }
154
155    /**
156     * Identifier assigned by the dispensing facility when the item(s) is dispensed.
157     */
158    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=1, modifier=false, summary=true)
159    @Description(shortDefinition="External identifier", formalDefinition="Identifier assigned by the dispensing facility when the item(s) is dispensed." )
160    protected Identifier identifier;
161
162    /**
163     * A code specifying the state of the dispense event.
164     */
165    @Child(name = "status", type = {CodeType.class}, order=1, min=0, max=1, modifier=true, summary=true)
166    @Description(shortDefinition="in-progress | completed | abandoned", formalDefinition="A code specifying the state of the dispense event." )
167    protected Enumeration<SupplyDeliveryStatus> status;
168
169    /**
170     * A link to a resource representing the person whom the delivered item is for.
171     */
172    @Child(name = "patient", type = {Patient.class}, order=2, min=0, max=1, modifier=false, summary=true)
173    @Description(shortDefinition="Patient for whom the item is supplied", formalDefinition="A link to a resource representing the person whom the delivered item is for." )
174    protected Reference patient;
175
176    /**
177     * The actual object that is the target of the reference (A link to a resource representing the person whom the delivered item is for.)
178     */
179    protected Patient patientTarget;
180
181    /**
182     * Indicates the type of dispensing event that is performed. Examples include: Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.
183     */
184    @Child(name = "type", type = {CodeableConcept.class}, order=3, min=0, max=1, modifier=false, summary=true)
185    @Description(shortDefinition="Category of dispense event", formalDefinition="Indicates the type of dispensing event that is performed. Examples include: Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc." )
186    protected CodeableConcept type;
187
188    /**
189     * The amount of supply that has been dispensed. Includes unit of measure.
190     */
191    @Child(name = "quantity", type = {SimpleQuantity.class}, order=4, min=0, max=1, modifier=false, summary=true)
192    @Description(shortDefinition="Amount dispensed", formalDefinition="The amount of supply that has been dispensed. Includes unit of measure." )
193    protected SimpleQuantity quantity;
194
195    /**
196     * Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.
197     */
198    @Child(name = "suppliedItem", type = {Medication.class, Substance.class, Device.class}, order=5, min=0, max=1, modifier=false, summary=true)
199    @Description(shortDefinition="Medication, Substance, or Device supplied", formalDefinition="Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list." )
200    protected Reference suppliedItem;
201
202    /**
203     * The actual object that is the target of the reference (Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.)
204     */
205    protected Resource suppliedItemTarget;
206
207    /**
208     * The individual responsible for dispensing the medication, supplier or device.
209     */
210    @Child(name = "supplier", type = {Practitioner.class}, order=6, min=0, max=1, modifier=false, summary=true)
211    @Description(shortDefinition="Dispenser", formalDefinition="The individual responsible for dispensing the medication, supplier or device." )
212    protected Reference supplier;
213
214    /**
215     * The actual object that is the target of the reference (The individual responsible for dispensing the medication, supplier or device.)
216     */
217    protected Practitioner supplierTarget;
218
219    /**
220     * The time the dispense event occurred.
221     */
222    @Child(name = "whenPrepared", type = {Period.class}, order=7, min=0, max=1, modifier=false, summary=true)
223    @Description(shortDefinition="Dispensing time", formalDefinition="The time the dispense event occurred." )
224    protected Period whenPrepared;
225
226    /**
227     * The time the dispensed item was sent or handed to the patient (or agent).
228     */
229    @Child(name = "time", type = {DateTimeType.class}, order=8, min=0, max=1, modifier=false, summary=true)
230    @Description(shortDefinition="Handover time", formalDefinition="The time the dispensed item was sent or handed to the patient (or agent)." )
231    protected DateTimeType time;
232
233    /**
234     * Identification of the facility/location where the Supply was shipped to, as part of the dispense event.
235     */
236    @Child(name = "destination", type = {Location.class}, order=9, min=0, max=1, modifier=false, summary=true)
237    @Description(shortDefinition="Where the Supply was sent", formalDefinition="Identification of the facility/location where the Supply was shipped to, as part of the dispense event." )
238    protected Reference destination;
239
240    /**
241     * The actual object that is the target of the reference (Identification of the facility/location where the Supply was shipped to, as part of the dispense event.)
242     */
243    protected Location destinationTarget;
244
245    /**
246     * Identifies the person who picked up the Supply.
247     */
248    @Child(name = "receiver", type = {Practitioner.class}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
249    @Description(shortDefinition="Who collected the Supply", formalDefinition="Identifies the person who picked up the Supply." )
250    protected List<Reference> receiver;
251    /**
252     * The actual objects that are the target of the reference (Identifies the person who picked up the Supply.)
253     */
254    protected List<Practitioner> receiverTarget;
255
256
257    private static final long serialVersionUID = -1520129707L;
258
259  /*
260   * Constructor
261   */
262    public SupplyDelivery() {
263      super();
264    }
265
266    /**
267     * @return {@link #identifier} (Identifier assigned by the dispensing facility when the item(s) is dispensed.)
268     */
269    public Identifier getIdentifier() { 
270      if (this.identifier == null)
271        if (Configuration.errorOnAutoCreate())
272          throw new Error("Attempt to auto-create SupplyDelivery.identifier");
273        else if (Configuration.doAutoCreate())
274          this.identifier = new Identifier(); // cc
275      return this.identifier;
276    }
277
278    public boolean hasIdentifier() { 
279      return this.identifier != null && !this.identifier.isEmpty();
280    }
281
282    /**
283     * @param value {@link #identifier} (Identifier assigned by the dispensing facility when the item(s) is dispensed.)
284     */
285    public SupplyDelivery setIdentifier(Identifier value) { 
286      this.identifier = value;
287      return this;
288    }
289
290    /**
291     * @return {@link #status} (A code specifying the state of the dispense event.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
292     */
293    public Enumeration<SupplyDeliveryStatus> getStatusElement() { 
294      if (this.status == null)
295        if (Configuration.errorOnAutoCreate())
296          throw new Error("Attempt to auto-create SupplyDelivery.status");
297        else if (Configuration.doAutoCreate())
298          this.status = new Enumeration<SupplyDeliveryStatus>(new SupplyDeliveryStatusEnumFactory()); // bb
299      return this.status;
300    }
301
302    public boolean hasStatusElement() { 
303      return this.status != null && !this.status.isEmpty();
304    }
305
306    public boolean hasStatus() { 
307      return this.status != null && !this.status.isEmpty();
308    }
309
310    /**
311     * @param value {@link #status} (A code specifying the state of the dispense event.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
312     */
313    public SupplyDelivery setStatusElement(Enumeration<SupplyDeliveryStatus> value) { 
314      this.status = value;
315      return this;
316    }
317
318    /**
319     * @return A code specifying the state of the dispense event.
320     */
321    public SupplyDeliveryStatus getStatus() { 
322      return this.status == null ? null : this.status.getValue();
323    }
324
325    /**
326     * @param value A code specifying the state of the dispense event.
327     */
328    public SupplyDelivery setStatus(SupplyDeliveryStatus value) { 
329      if (value == null)
330        this.status = null;
331      else {
332        if (this.status == null)
333          this.status = new Enumeration<SupplyDeliveryStatus>(new SupplyDeliveryStatusEnumFactory());
334        this.status.setValue(value);
335      }
336      return this;
337    }
338
339    /**
340     * @return {@link #patient} (A link to a resource representing the person whom the delivered item is for.)
341     */
342    public Reference getPatient() { 
343      if (this.patient == null)
344        if (Configuration.errorOnAutoCreate())
345          throw new Error("Attempt to auto-create SupplyDelivery.patient");
346        else if (Configuration.doAutoCreate())
347          this.patient = new Reference(); // cc
348      return this.patient;
349    }
350
351    public boolean hasPatient() { 
352      return this.patient != null && !this.patient.isEmpty();
353    }
354
355    /**
356     * @param value {@link #patient} (A link to a resource representing the person whom the delivered item is for.)
357     */
358    public SupplyDelivery setPatient(Reference value) { 
359      this.patient = value;
360      return this;
361    }
362
363    /**
364     * @return {@link #patient} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person whom the delivered item is for.)
365     */
366    public Patient getPatientTarget() { 
367      if (this.patientTarget == null)
368        if (Configuration.errorOnAutoCreate())
369          throw new Error("Attempt to auto-create SupplyDelivery.patient");
370        else if (Configuration.doAutoCreate())
371          this.patientTarget = new Patient(); // aa
372      return this.patientTarget;
373    }
374
375    /**
376     * @param value {@link #patient} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (A link to a resource representing the person whom the delivered item is for.)
377     */
378    public SupplyDelivery setPatientTarget(Patient value) { 
379      this.patientTarget = value;
380      return this;
381    }
382
383    /**
384     * @return {@link #type} (Indicates the type of dispensing event that is performed. Examples include: Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.)
385     */
386    public CodeableConcept getType() { 
387      if (this.type == null)
388        if (Configuration.errorOnAutoCreate())
389          throw new Error("Attempt to auto-create SupplyDelivery.type");
390        else if (Configuration.doAutoCreate())
391          this.type = new CodeableConcept(); // cc
392      return this.type;
393    }
394
395    public boolean hasType() { 
396      return this.type != null && !this.type.isEmpty();
397    }
398
399    /**
400     * @param value {@link #type} (Indicates the type of dispensing event that is performed. Examples include: Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.)
401     */
402    public SupplyDelivery setType(CodeableConcept value) { 
403      this.type = value;
404      return this;
405    }
406
407    /**
408     * @return {@link #quantity} (The amount of supply that has been dispensed. Includes unit of measure.)
409     */
410    public SimpleQuantity getQuantity() { 
411      if (this.quantity == null)
412        if (Configuration.errorOnAutoCreate())
413          throw new Error("Attempt to auto-create SupplyDelivery.quantity");
414        else if (Configuration.doAutoCreate())
415          this.quantity = new SimpleQuantity(); // cc
416      return this.quantity;
417    }
418
419    public boolean hasQuantity() { 
420      return this.quantity != null && !this.quantity.isEmpty();
421    }
422
423    /**
424     * @param value {@link #quantity} (The amount of supply that has been dispensed. Includes unit of measure.)
425     */
426    public SupplyDelivery setQuantity(SimpleQuantity value) { 
427      this.quantity = value;
428      return this;
429    }
430
431    /**
432     * @return {@link #suppliedItem} (Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.)
433     */
434    public Reference getSuppliedItem() { 
435      if (this.suppliedItem == null)
436        if (Configuration.errorOnAutoCreate())
437          throw new Error("Attempt to auto-create SupplyDelivery.suppliedItem");
438        else if (Configuration.doAutoCreate())
439          this.suppliedItem = new Reference(); // cc
440      return this.suppliedItem;
441    }
442
443    public boolean hasSuppliedItem() { 
444      return this.suppliedItem != null && !this.suppliedItem.isEmpty();
445    }
446
447    /**
448     * @param value {@link #suppliedItem} (Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.)
449     */
450    public SupplyDelivery setSuppliedItem(Reference value) { 
451      this.suppliedItem = value;
452      return this;
453    }
454
455    /**
456     * @return {@link #suppliedItem} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.)
457     */
458    public Resource getSuppliedItemTarget() { 
459      return this.suppliedItemTarget;
460    }
461
462    /**
463     * @param value {@link #suppliedItem} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.)
464     */
465    public SupplyDelivery setSuppliedItemTarget(Resource value) { 
466      this.suppliedItemTarget = value;
467      return this;
468    }
469
470    /**
471     * @return {@link #supplier} (The individual responsible for dispensing the medication, supplier or device.)
472     */
473    public Reference getSupplier() { 
474      if (this.supplier == null)
475        if (Configuration.errorOnAutoCreate())
476          throw new Error("Attempt to auto-create SupplyDelivery.supplier");
477        else if (Configuration.doAutoCreate())
478          this.supplier = new Reference(); // cc
479      return this.supplier;
480    }
481
482    public boolean hasSupplier() { 
483      return this.supplier != null && !this.supplier.isEmpty();
484    }
485
486    /**
487     * @param value {@link #supplier} (The individual responsible for dispensing the medication, supplier or device.)
488     */
489    public SupplyDelivery setSupplier(Reference value) { 
490      this.supplier = value;
491      return this;
492    }
493
494    /**
495     * @return {@link #supplier} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The individual responsible for dispensing the medication, supplier or device.)
496     */
497    public Practitioner getSupplierTarget() { 
498      if (this.supplierTarget == null)
499        if (Configuration.errorOnAutoCreate())
500          throw new Error("Attempt to auto-create SupplyDelivery.supplier");
501        else if (Configuration.doAutoCreate())
502          this.supplierTarget = new Practitioner(); // aa
503      return this.supplierTarget;
504    }
505
506    /**
507     * @param value {@link #supplier} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The individual responsible for dispensing the medication, supplier or device.)
508     */
509    public SupplyDelivery setSupplierTarget(Practitioner value) { 
510      this.supplierTarget = value;
511      return this;
512    }
513
514    /**
515     * @return {@link #whenPrepared} (The time the dispense event occurred.)
516     */
517    public Period getWhenPrepared() { 
518      if (this.whenPrepared == null)
519        if (Configuration.errorOnAutoCreate())
520          throw new Error("Attempt to auto-create SupplyDelivery.whenPrepared");
521        else if (Configuration.doAutoCreate())
522          this.whenPrepared = new Period(); // cc
523      return this.whenPrepared;
524    }
525
526    public boolean hasWhenPrepared() { 
527      return this.whenPrepared != null && !this.whenPrepared.isEmpty();
528    }
529
530    /**
531     * @param value {@link #whenPrepared} (The time the dispense event occurred.)
532     */
533    public SupplyDelivery setWhenPrepared(Period value) { 
534      this.whenPrepared = value;
535      return this;
536    }
537
538    /**
539     * @return {@link #time} (The time the dispensed item was sent or handed to the patient (or agent).). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value
540     */
541    public DateTimeType getTimeElement() { 
542      if (this.time == null)
543        if (Configuration.errorOnAutoCreate())
544          throw new Error("Attempt to auto-create SupplyDelivery.time");
545        else if (Configuration.doAutoCreate())
546          this.time = new DateTimeType(); // bb
547      return this.time;
548    }
549
550    public boolean hasTimeElement() { 
551      return this.time != null && !this.time.isEmpty();
552    }
553
554    public boolean hasTime() { 
555      return this.time != null && !this.time.isEmpty();
556    }
557
558    /**
559     * @param value {@link #time} (The time the dispensed item was sent or handed to the patient (or agent).). This is the underlying object with id, value and extensions. The accessor "getTime" gives direct access to the value
560     */
561    public SupplyDelivery setTimeElement(DateTimeType value) { 
562      this.time = value;
563      return this;
564    }
565
566    /**
567     * @return The time the dispensed item was sent or handed to the patient (or agent).
568     */
569    public Date getTime() { 
570      return this.time == null ? null : this.time.getValue();
571    }
572
573    /**
574     * @param value The time the dispensed item was sent or handed to the patient (or agent).
575     */
576    public SupplyDelivery setTime(Date value) { 
577      if (value == null)
578        this.time = null;
579      else {
580        if (this.time == null)
581          this.time = new DateTimeType();
582        this.time.setValue(value);
583      }
584      return this;
585    }
586
587    /**
588     * @return {@link #destination} (Identification of the facility/location where the Supply was shipped to, as part of the dispense event.)
589     */
590    public Reference getDestination() { 
591      if (this.destination == null)
592        if (Configuration.errorOnAutoCreate())
593          throw new Error("Attempt to auto-create SupplyDelivery.destination");
594        else if (Configuration.doAutoCreate())
595          this.destination = new Reference(); // cc
596      return this.destination;
597    }
598
599    public boolean hasDestination() { 
600      return this.destination != null && !this.destination.isEmpty();
601    }
602
603    /**
604     * @param value {@link #destination} (Identification of the facility/location where the Supply was shipped to, as part of the dispense event.)
605     */
606    public SupplyDelivery setDestination(Reference value) { 
607      this.destination = value;
608      return this;
609    }
610
611    /**
612     * @return {@link #destination} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (Identification of the facility/location where the Supply was shipped to, as part of the dispense event.)
613     */
614    public Location getDestinationTarget() { 
615      if (this.destinationTarget == null)
616        if (Configuration.errorOnAutoCreate())
617          throw new Error("Attempt to auto-create SupplyDelivery.destination");
618        else if (Configuration.doAutoCreate())
619          this.destinationTarget = new Location(); // aa
620      return this.destinationTarget;
621    }
622
623    /**
624     * @param value {@link #destination} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (Identification of the facility/location where the Supply was shipped to, as part of the dispense event.)
625     */
626    public SupplyDelivery setDestinationTarget(Location value) { 
627      this.destinationTarget = value;
628      return this;
629    }
630
631    /**
632     * @return {@link #receiver} (Identifies the person who picked up the Supply.)
633     */
634    public List<Reference> getReceiver() { 
635      if (this.receiver == null)
636        this.receiver = new ArrayList<Reference>();
637      return this.receiver;
638    }
639
640    public boolean hasReceiver() { 
641      if (this.receiver == null)
642        return false;
643      for (Reference item : this.receiver)
644        if (!item.isEmpty())
645          return true;
646      return false;
647    }
648
649    /**
650     * @return {@link #receiver} (Identifies the person who picked up the Supply.)
651     */
652    // syntactic sugar
653    public Reference addReceiver() { //3
654      Reference t = new Reference();
655      if (this.receiver == null)
656        this.receiver = new ArrayList<Reference>();
657      this.receiver.add(t);
658      return t;
659    }
660
661    // syntactic sugar
662    public SupplyDelivery addReceiver(Reference t) { //3
663      if (t == null)
664        return this;
665      if (this.receiver == null)
666        this.receiver = new ArrayList<Reference>();
667      this.receiver.add(t);
668      return this;
669    }
670
671    /**
672     * @return {@link #receiver} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. Identifies the person who picked up the Supply.)
673     */
674    public List<Practitioner> getReceiverTarget() { 
675      if (this.receiverTarget == null)
676        this.receiverTarget = new ArrayList<Practitioner>();
677      return this.receiverTarget;
678    }
679
680    // syntactic sugar
681    /**
682     * @return {@link #receiver} (Add an actual object that is the target of the reference. The reference library doesn't use these, but you can use this to hold the resources if you resolvethemt. Identifies the person who picked up the Supply.)
683     */
684    public Practitioner addReceiverTarget() { 
685      Practitioner r = new Practitioner();
686      if (this.receiverTarget == null)
687        this.receiverTarget = new ArrayList<Practitioner>();
688      this.receiverTarget.add(r);
689      return r;
690    }
691
692      protected void listChildren(List<Property> childrenList) {
693        super.listChildren(childrenList);
694        childrenList.add(new Property("identifier", "Identifier", "Identifier assigned by the dispensing facility when the item(s) is dispensed.", 0, java.lang.Integer.MAX_VALUE, identifier));
695        childrenList.add(new Property("status", "code", "A code specifying the state of the dispense event.", 0, java.lang.Integer.MAX_VALUE, status));
696        childrenList.add(new Property("patient", "Reference(Patient)", "A link to a resource representing the person whom the delivered item is for.", 0, java.lang.Integer.MAX_VALUE, patient));
697        childrenList.add(new Property("type", "CodeableConcept", "Indicates the type of dispensing event that is performed. Examples include: Trial Fill, Completion of Trial, Partial Fill, Emergency Fill, Samples, etc.", 0, java.lang.Integer.MAX_VALUE, type));
698        childrenList.add(new Property("quantity", "SimpleQuantity", "The amount of supply that has been dispensed. Includes unit of measure.", 0, java.lang.Integer.MAX_VALUE, quantity));
699        childrenList.add(new Property("suppliedItem", "Reference(Medication|Substance|Device)", "Identifies the medication, substance or device being dispensed. This is either a link to a resource representing the details of the item or a simple attribute carrying a code that identifies the item from a known list.", 0, java.lang.Integer.MAX_VALUE, suppliedItem));
700        childrenList.add(new Property("supplier", "Reference(Practitioner)", "The individual responsible for dispensing the medication, supplier or device.", 0, java.lang.Integer.MAX_VALUE, supplier));
701        childrenList.add(new Property("whenPrepared", "Period", "The time the dispense event occurred.", 0, java.lang.Integer.MAX_VALUE, whenPrepared));
702        childrenList.add(new Property("time", "dateTime", "The time the dispensed item was sent or handed to the patient (or agent).", 0, java.lang.Integer.MAX_VALUE, time));
703        childrenList.add(new Property("destination", "Reference(Location)", "Identification of the facility/location where the Supply was shipped to, as part of the dispense event.", 0, java.lang.Integer.MAX_VALUE, destination));
704        childrenList.add(new Property("receiver", "Reference(Practitioner)", "Identifies the person who picked up the Supply.", 0, java.lang.Integer.MAX_VALUE, receiver));
705      }
706
707      @Override
708      public void setProperty(String name, Base value) throws FHIRException {
709        if (name.equals("identifier"))
710          this.identifier = castToIdentifier(value); // Identifier
711        else if (name.equals("status"))
712          this.status = new SupplyDeliveryStatusEnumFactory().fromType(value); // Enumeration<SupplyDeliveryStatus>
713        else if (name.equals("patient"))
714          this.patient = castToReference(value); // Reference
715        else if (name.equals("type"))
716          this.type = castToCodeableConcept(value); // CodeableConcept
717        else if (name.equals("quantity"))
718          this.quantity = castToSimpleQuantity(value); // SimpleQuantity
719        else if (name.equals("suppliedItem"))
720          this.suppliedItem = castToReference(value); // Reference
721        else if (name.equals("supplier"))
722          this.supplier = castToReference(value); // Reference
723        else if (name.equals("whenPrepared"))
724          this.whenPrepared = castToPeriod(value); // Period
725        else if (name.equals("time"))
726          this.time = castToDateTime(value); // DateTimeType
727        else if (name.equals("destination"))
728          this.destination = castToReference(value); // Reference
729        else if (name.equals("receiver"))
730          this.getReceiver().add(castToReference(value));
731        else
732          super.setProperty(name, value);
733      }
734
735      @Override
736      public Base addChild(String name) throws FHIRException {
737        if (name.equals("identifier")) {
738          this.identifier = new Identifier();
739          return this.identifier;
740        }
741        else if (name.equals("status")) {
742          throw new FHIRException("Cannot call addChild on a primitive type SupplyDelivery.status");
743        }
744        else if (name.equals("patient")) {
745          this.patient = new Reference();
746          return this.patient;
747        }
748        else if (name.equals("type")) {
749          this.type = new CodeableConcept();
750          return this.type;
751        }
752        else if (name.equals("quantity")) {
753          this.quantity = new SimpleQuantity();
754          return this.quantity;
755        }
756        else if (name.equals("suppliedItem")) {
757          this.suppliedItem = new Reference();
758          return this.suppliedItem;
759        }
760        else if (name.equals("supplier")) {
761          this.supplier = new Reference();
762          return this.supplier;
763        }
764        else if (name.equals("whenPrepared")) {
765          this.whenPrepared = new Period();
766          return this.whenPrepared;
767        }
768        else if (name.equals("time")) {
769          throw new FHIRException("Cannot call addChild on a primitive type SupplyDelivery.time");
770        }
771        else if (name.equals("destination")) {
772          this.destination = new Reference();
773          return this.destination;
774        }
775        else if (name.equals("receiver")) {
776          return addReceiver();
777        }
778        else
779          return super.addChild(name);
780      }
781
782  public String fhirType() {
783    return "SupplyDelivery";
784
785  }
786
787      public SupplyDelivery copy() {
788        SupplyDelivery dst = new SupplyDelivery();
789        copyValues(dst);
790        dst.identifier = identifier == null ? null : identifier.copy();
791        dst.status = status == null ? null : status.copy();
792        dst.patient = patient == null ? null : patient.copy();
793        dst.type = type == null ? null : type.copy();
794        dst.quantity = quantity == null ? null : quantity.copy();
795        dst.suppliedItem = suppliedItem == null ? null : suppliedItem.copy();
796        dst.supplier = supplier == null ? null : supplier.copy();
797        dst.whenPrepared = whenPrepared == null ? null : whenPrepared.copy();
798        dst.time = time == null ? null : time.copy();
799        dst.destination = destination == null ? null : destination.copy();
800        if (receiver != null) {
801          dst.receiver = new ArrayList<Reference>();
802          for (Reference i : receiver)
803            dst.receiver.add(i.copy());
804        };
805        return dst;
806      }
807
808      protected SupplyDelivery typedCopy() {
809        return copy();
810      }
811
812      @Override
813      public boolean equalsDeep(Base other) {
814        if (!super.equalsDeep(other))
815          return false;
816        if (!(other instanceof SupplyDelivery))
817          return false;
818        SupplyDelivery o = (SupplyDelivery) other;
819        return compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(patient, o.patient, true)
820           && compareDeep(type, o.type, true) && compareDeep(quantity, o.quantity, true) && compareDeep(suppliedItem, o.suppliedItem, true)
821           && compareDeep(supplier, o.supplier, true) && compareDeep(whenPrepared, o.whenPrepared, true) && compareDeep(time, o.time, true)
822           && compareDeep(destination, o.destination, true) && compareDeep(receiver, o.receiver, true);
823      }
824
825      @Override
826      public boolean equalsShallow(Base other) {
827        if (!super.equalsShallow(other))
828          return false;
829        if (!(other instanceof SupplyDelivery))
830          return false;
831        SupplyDelivery o = (SupplyDelivery) other;
832        return compareValues(status, o.status, true) && compareValues(time, o.time, true);
833      }
834
835      public boolean isEmpty() {
836        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
837           && (patient == null || patient.isEmpty()) && (type == null || type.isEmpty()) && (quantity == null || quantity.isEmpty())
838           && (suppliedItem == null || suppliedItem.isEmpty()) && (supplier == null || supplier.isEmpty())
839           && (whenPrepared == null || whenPrepared.isEmpty()) && (time == null || time.isEmpty()) && (destination == null || destination.isEmpty())
840           && (receiver == null || receiver.isEmpty());
841      }
842
843  @Override
844  public ResourceType getResourceType() {
845    return ResourceType.SupplyDelivery;
846   }
847
848  @SearchParamDefinition(name="identifier", path="SupplyDelivery.identifier", description="External identifier", type="token" )
849  public static final String SP_IDENTIFIER = "identifier";
850  @SearchParamDefinition(name="receiver", path="SupplyDelivery.receiver", description="Who collected the Supply", type="reference" )
851  public static final String SP_RECEIVER = "receiver";
852  @SearchParamDefinition(name="patient", path="SupplyDelivery.patient", description="Patient for whom the item is supplied", type="reference" )
853  public static final String SP_PATIENT = "patient";
854  @SearchParamDefinition(name="supplier", path="SupplyDelivery.supplier", description="Dispenser", type="reference" )
855  public static final String SP_SUPPLIER = "supplier";
856  @SearchParamDefinition(name="status", path="SupplyDelivery.status", description="in-progress | completed | abandoned", type="token" )
857  public static final String SP_STATUS = "status";
858
859}