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