001package org.hl7.fhir.dstu2016may.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 Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
042
043import ca.uhn.fhir.model.api.annotation.Block;
044import ca.uhn.fhir.model.api.annotation.Child;
045import ca.uhn.fhir.model.api.annotation.Description;
046import ca.uhn.fhir.model.api.annotation.ResourceDef;
047import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
048/**
049 * A record of a request for a medication, substance or device used in the healthcare setting.
050 */
051@ResourceDef(name="SupplyRequest", profile="http://hl7.org/fhir/Profile/SupplyRequest")
052public class SupplyRequest extends DomainResource {
053
054    public enum SupplyRequestStatus {
055        /**
056         * Supply has been requested, but not dispensed.
057         */
058        REQUESTED, 
059        /**
060         * Supply has been received by the requestor.
061         */
062        COMPLETED, 
063        /**
064         * The supply will not be completed because the supplier was unable or unwilling to supply the item.
065         */
066        FAILED, 
067        /**
068         * The orderer of the supply cancelled the request.
069         */
070        CANCELLED, 
071        /**
072         * added to help the parsers
073         */
074        NULL;
075        public static SupplyRequestStatus fromCode(String codeString) throws FHIRException {
076            if (codeString == null || "".equals(codeString))
077                return null;
078        if ("requested".equals(codeString))
079          return REQUESTED;
080        if ("completed".equals(codeString))
081          return COMPLETED;
082        if ("failed".equals(codeString))
083          return FAILED;
084        if ("cancelled".equals(codeString))
085          return CANCELLED;
086        throw new FHIRException("Unknown SupplyRequestStatus code '"+codeString+"'");
087        }
088        public String toCode() {
089          switch (this) {
090            case REQUESTED: return "requested";
091            case COMPLETED: return "completed";
092            case FAILED: return "failed";
093            case CANCELLED: return "cancelled";
094            case NULL: return null;
095            default: return "?";
096          }
097        }
098        public String getSystem() {
099          switch (this) {
100            case REQUESTED: return "http://hl7.org/fhir/supplyrequest-status";
101            case COMPLETED: return "http://hl7.org/fhir/supplyrequest-status";
102            case FAILED: return "http://hl7.org/fhir/supplyrequest-status";
103            case CANCELLED: return "http://hl7.org/fhir/supplyrequest-status";
104            case NULL: return null;
105            default: return "?";
106          }
107        }
108        public String getDefinition() {
109          switch (this) {
110            case REQUESTED: return "Supply has been requested, but not dispensed.";
111            case COMPLETED: return "Supply has been received by the requestor.";
112            case FAILED: return "The supply will not be completed because the supplier was unable or unwilling to supply the item.";
113            case CANCELLED: return "The orderer of the supply cancelled the request.";
114            case NULL: return null;
115            default: return "?";
116          }
117        }
118        public String getDisplay() {
119          switch (this) {
120            case REQUESTED: return "Requested";
121            case COMPLETED: return "Received";
122            case FAILED: return "Failed";
123            case CANCELLED: return "Cancelled";
124            case NULL: return null;
125            default: return "?";
126          }
127        }
128    }
129
130  public static class SupplyRequestStatusEnumFactory implements EnumFactory<SupplyRequestStatus> {
131    public SupplyRequestStatus fromCode(String codeString) throws IllegalArgumentException {
132      if (codeString == null || "".equals(codeString))
133            if (codeString == null || "".equals(codeString))
134                return null;
135        if ("requested".equals(codeString))
136          return SupplyRequestStatus.REQUESTED;
137        if ("completed".equals(codeString))
138          return SupplyRequestStatus.COMPLETED;
139        if ("failed".equals(codeString))
140          return SupplyRequestStatus.FAILED;
141        if ("cancelled".equals(codeString))
142          return SupplyRequestStatus.CANCELLED;
143        throw new IllegalArgumentException("Unknown SupplyRequestStatus code '"+codeString+"'");
144        }
145        public Enumeration<SupplyRequestStatus> fromType(Base code) throws FHIRException {
146          if (code == null || code.isEmpty())
147            return null;
148          String codeString = ((PrimitiveType) code).asStringValue();
149          if (codeString == null || "".equals(codeString))
150            return null;
151        if ("requested".equals(codeString))
152          return new Enumeration<SupplyRequestStatus>(this, SupplyRequestStatus.REQUESTED);
153        if ("completed".equals(codeString))
154          return new Enumeration<SupplyRequestStatus>(this, SupplyRequestStatus.COMPLETED);
155        if ("failed".equals(codeString))
156          return new Enumeration<SupplyRequestStatus>(this, SupplyRequestStatus.FAILED);
157        if ("cancelled".equals(codeString))
158          return new Enumeration<SupplyRequestStatus>(this, SupplyRequestStatus.CANCELLED);
159        throw new FHIRException("Unknown SupplyRequestStatus code '"+codeString+"'");
160        }
161    public String toCode(SupplyRequestStatus code) {
162      if (code == SupplyRequestStatus.REQUESTED)
163        return "requested";
164      if (code == SupplyRequestStatus.COMPLETED)
165        return "completed";
166      if (code == SupplyRequestStatus.FAILED)
167        return "failed";
168      if (code == SupplyRequestStatus.CANCELLED)
169        return "cancelled";
170      return "?";
171      }
172    public String toSystem(SupplyRequestStatus code) {
173      return code.getSystem();
174      }
175    }
176
177    @Block()
178    public static class SupplyRequestWhenComponent extends BackboneElement implements IBaseBackboneElement {
179        /**
180         * Code indicating when the request should be fulfilled.
181         */
182        @Child(name = "code", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=true)
183        @Description(shortDefinition="Fulfilment code", formalDefinition="Code indicating when the request should be fulfilled." )
184        protected CodeableConcept code;
185
186        /**
187         * Formal fulfillment schedule.
188         */
189        @Child(name = "schedule", type = {Timing.class}, order=2, min=0, max=1, modifier=false, summary=true)
190        @Description(shortDefinition="Formal fulfillment schedule", formalDefinition="Formal fulfillment schedule." )
191        protected Timing schedule;
192
193        private static final long serialVersionUID = 307115287L;
194
195    /**
196     * Constructor
197     */
198      public SupplyRequestWhenComponent() {
199        super();
200      }
201
202        /**
203         * @return {@link #code} (Code indicating when the request should be fulfilled.)
204         */
205        public CodeableConcept getCode() { 
206          if (this.code == null)
207            if (Configuration.errorOnAutoCreate())
208              throw new Error("Attempt to auto-create SupplyRequestWhenComponent.code");
209            else if (Configuration.doAutoCreate())
210              this.code = new CodeableConcept(); // cc
211          return this.code;
212        }
213
214        public boolean hasCode() { 
215          return this.code != null && !this.code.isEmpty();
216        }
217
218        /**
219         * @param value {@link #code} (Code indicating when the request should be fulfilled.)
220         */
221        public SupplyRequestWhenComponent setCode(CodeableConcept value) { 
222          this.code = value;
223          return this;
224        }
225
226        /**
227         * @return {@link #schedule} (Formal fulfillment schedule.)
228         */
229        public Timing getSchedule() { 
230          if (this.schedule == null)
231            if (Configuration.errorOnAutoCreate())
232              throw new Error("Attempt to auto-create SupplyRequestWhenComponent.schedule");
233            else if (Configuration.doAutoCreate())
234              this.schedule = new Timing(); // cc
235          return this.schedule;
236        }
237
238        public boolean hasSchedule() { 
239          return this.schedule != null && !this.schedule.isEmpty();
240        }
241
242        /**
243         * @param value {@link #schedule} (Formal fulfillment schedule.)
244         */
245        public SupplyRequestWhenComponent setSchedule(Timing value) { 
246          this.schedule = value;
247          return this;
248        }
249
250        protected void listChildren(List<Property> childrenList) {
251          super.listChildren(childrenList);
252          childrenList.add(new Property("code", "CodeableConcept", "Code indicating when the request should be fulfilled.", 0, java.lang.Integer.MAX_VALUE, code));
253          childrenList.add(new Property("schedule", "Timing", "Formal fulfillment schedule.", 0, java.lang.Integer.MAX_VALUE, schedule));
254        }
255
256      @Override
257      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
258        switch (hash) {
259        case 3059181: /*code*/ return this.code == null ? new Base[0] : new Base[] {this.code}; // CodeableConcept
260        case -697920873: /*schedule*/ return this.schedule == null ? new Base[0] : new Base[] {this.schedule}; // Timing
261        default: return super.getProperty(hash, name, checkValid);
262        }
263
264      }
265
266      @Override
267      public void setProperty(int hash, String name, Base value) throws FHIRException {
268        switch (hash) {
269        case 3059181: // code
270          this.code = castToCodeableConcept(value); // CodeableConcept
271          break;
272        case -697920873: // schedule
273          this.schedule = castToTiming(value); // Timing
274          break;
275        default: super.setProperty(hash, name, value);
276        }
277
278      }
279
280      @Override
281      public void setProperty(String name, Base value) throws FHIRException {
282        if (name.equals("code"))
283          this.code = castToCodeableConcept(value); // CodeableConcept
284        else if (name.equals("schedule"))
285          this.schedule = castToTiming(value); // Timing
286        else
287          super.setProperty(name, value);
288      }
289
290      @Override
291      public Base makeProperty(int hash, String name) throws FHIRException {
292        switch (hash) {
293        case 3059181:  return getCode(); // CodeableConcept
294        case -697920873:  return getSchedule(); // Timing
295        default: return super.makeProperty(hash, name);
296        }
297
298      }
299
300      @Override
301      public Base addChild(String name) throws FHIRException {
302        if (name.equals("code")) {
303          this.code = new CodeableConcept();
304          return this.code;
305        }
306        else if (name.equals("schedule")) {
307          this.schedule = new Timing();
308          return this.schedule;
309        }
310        else
311          return super.addChild(name);
312      }
313
314      public SupplyRequestWhenComponent copy() {
315        SupplyRequestWhenComponent dst = new SupplyRequestWhenComponent();
316        copyValues(dst);
317        dst.code = code == null ? null : code.copy();
318        dst.schedule = schedule == null ? null : schedule.copy();
319        return dst;
320      }
321
322      @Override
323      public boolean equalsDeep(Base other) {
324        if (!super.equalsDeep(other))
325          return false;
326        if (!(other instanceof SupplyRequestWhenComponent))
327          return false;
328        SupplyRequestWhenComponent o = (SupplyRequestWhenComponent) other;
329        return compareDeep(code, o.code, true) && compareDeep(schedule, o.schedule, true);
330      }
331
332      @Override
333      public boolean equalsShallow(Base other) {
334        if (!super.equalsShallow(other))
335          return false;
336        if (!(other instanceof SupplyRequestWhenComponent))
337          return false;
338        SupplyRequestWhenComponent o = (SupplyRequestWhenComponent) other;
339        return true;
340      }
341
342      public boolean isEmpty() {
343        return super.isEmpty() && (code == null || code.isEmpty()) && (schedule == null || schedule.isEmpty())
344          ;
345      }
346
347  public String fhirType() {
348    return "SupplyRequest.when";
349
350  }
351
352  }
353
354    /**
355     * A link to a resource representing the person whom the ordered item is for.
356     */
357    @Child(name = "patient", type = {Patient.class}, order=0, min=0, max=1, modifier=false, summary=true)
358    @Description(shortDefinition="Patient for whom the item is supplied", formalDefinition="A link to a resource representing the person whom the ordered item is for." )
359    protected Reference patient;
360
361    /**
362     * The actual object that is the target of the reference (A link to a resource representing the person whom the ordered item is for.)
363     */
364    protected Patient patientTarget;
365
366    /**
367     * The Practitioner , Organization or Patient who initiated this order for the supply.
368     */
369    @Child(name = "source", type = {Practitioner.class, Organization.class, Patient.class}, order=1, min=0, max=1, modifier=false, summary=true)
370    @Description(shortDefinition="Who initiated this order", formalDefinition="The Practitioner , Organization or Patient who initiated this order for the supply." )
371    protected Reference source;
372
373    /**
374     * The actual object that is the target of the reference (The Practitioner , Organization or Patient who initiated this order for the supply.)
375     */
376    protected Resource sourceTarget;
377
378    /**
379     * When the request was made.
380     */
381    @Child(name = "date", type = {DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
382    @Description(shortDefinition="When the request was made", formalDefinition="When the request was made." )
383    protected DateTimeType date;
384
385    /**
386     * Unique identifier for this supply request.
387     */
388    @Child(name = "identifier", type = {Identifier.class}, order=3, min=0, max=1, modifier=false, summary=true)
389    @Description(shortDefinition="Unique identifier", formalDefinition="Unique identifier for this supply request." )
390    protected Identifier identifier;
391
392    /**
393     * Status of the supply request.
394     */
395    @Child(name = "status", type = {CodeType.class}, order=4, min=0, max=1, modifier=true, summary=true)
396    @Description(shortDefinition="requested | completed | failed | cancelled", formalDefinition="Status of the supply request." )
397    protected Enumeration<SupplyRequestStatus> status;
398
399    /**
400     * Category of supply, e.g.  central, non-stock, etc. This is used to support work flows associated with the supply process.
401     */
402    @Child(name = "kind", type = {CodeableConcept.class}, order=5, min=0, max=1, modifier=false, summary=true)
403    @Description(shortDefinition="The kind of supply (central, non-stock, etc.)", formalDefinition="Category of supply, e.g.  central, non-stock, etc. This is used to support work flows associated with the supply process." )
404    protected CodeableConcept kind;
405
406    /**
407     * The item that is requested to be supplied.
408     */
409    @Child(name = "orderedItem", type = {Medication.class, Substance.class, Device.class}, order=6, min=0, max=1, modifier=false, summary=true)
410    @Description(shortDefinition="Medication, Substance, or Device requested to be supplied", formalDefinition="The item that is requested to be supplied." )
411    protected Reference orderedItem;
412
413    /**
414     * The actual object that is the target of the reference (The item that is requested to be supplied.)
415     */
416    protected Resource orderedItemTarget;
417
418    /**
419     * Who is intended to fulfill the request.
420     */
421    @Child(name = "supplier", type = {Organization.class}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
422    @Description(shortDefinition="Who is intended to fulfill the request", formalDefinition="Who is intended to fulfill the request." )
423    protected List<Reference> supplier;
424    /**
425     * The actual objects that are the target of the reference (Who is intended to fulfill the request.)
426     */
427    protected List<Organization> supplierTarget;
428
429
430    /**
431     * Why the supply item was requested.
432     */
433    @Child(name = "reason", type = {CodeableConcept.class}, order=8, min=0, max=1, modifier=false, summary=true)
434    @Description(shortDefinition="Why the supply item was requested", formalDefinition="Why the supply item was requested." )
435    protected Type reason;
436
437    /**
438     * When the request should be fulfilled.
439     */
440    @Child(name = "when", type = {}, order=9, min=0, max=1, modifier=false, summary=true)
441    @Description(shortDefinition="When the request should be fulfilled", formalDefinition="When the request should be fulfilled." )
442    protected SupplyRequestWhenComponent when;
443
444    private static final long serialVersionUID = 1649766198L;
445
446  /**
447   * Constructor
448   */
449    public SupplyRequest() {
450      super();
451    }
452
453    /**
454     * @return {@link #patient} (A link to a resource representing the person whom the ordered item is for.)
455     */
456    public Reference getPatient() { 
457      if (this.patient == null)
458        if (Configuration.errorOnAutoCreate())
459          throw new Error("Attempt to auto-create SupplyRequest.patient");
460        else if (Configuration.doAutoCreate())
461          this.patient = new Reference(); // cc
462      return this.patient;
463    }
464
465    public boolean hasPatient() { 
466      return this.patient != null && !this.patient.isEmpty();
467    }
468
469    /**
470     * @param value {@link #patient} (A link to a resource representing the person whom the ordered item is for.)
471     */
472    public SupplyRequest setPatient(Reference value) { 
473      this.patient = value;
474      return this;
475    }
476
477    /**
478     * @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 ordered item is for.)
479     */
480    public Patient getPatientTarget() { 
481      if (this.patientTarget == null)
482        if (Configuration.errorOnAutoCreate())
483          throw new Error("Attempt to auto-create SupplyRequest.patient");
484        else if (Configuration.doAutoCreate())
485          this.patientTarget = new Patient(); // aa
486      return this.patientTarget;
487    }
488
489    /**
490     * @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 ordered item is for.)
491     */
492    public SupplyRequest setPatientTarget(Patient value) { 
493      this.patientTarget = value;
494      return this;
495    }
496
497    /**
498     * @return {@link #source} (The Practitioner , Organization or Patient who initiated this order for the supply.)
499     */
500    public Reference getSource() { 
501      if (this.source == null)
502        if (Configuration.errorOnAutoCreate())
503          throw new Error("Attempt to auto-create SupplyRequest.source");
504        else if (Configuration.doAutoCreate())
505          this.source = new Reference(); // cc
506      return this.source;
507    }
508
509    public boolean hasSource() { 
510      return this.source != null && !this.source.isEmpty();
511    }
512
513    /**
514     * @param value {@link #source} (The Practitioner , Organization or Patient who initiated this order for the supply.)
515     */
516    public SupplyRequest setSource(Reference value) { 
517      this.source = value;
518      return this;
519    }
520
521    /**
522     * @return {@link #source} 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 Practitioner , Organization or Patient who initiated this order for the supply.)
523     */
524    public Resource getSourceTarget() { 
525      return this.sourceTarget;
526    }
527
528    /**
529     * @param value {@link #source} 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 Practitioner , Organization or Patient who initiated this order for the supply.)
530     */
531    public SupplyRequest setSourceTarget(Resource value) { 
532      this.sourceTarget = value;
533      return this;
534    }
535
536    /**
537     * @return {@link #date} (When the request was made.). This is the underlying object with id, value and extensions. The accessor "getDate" gives direct access to the value
538     */
539    public DateTimeType getDateElement() { 
540      if (this.date == null)
541        if (Configuration.errorOnAutoCreate())
542          throw new Error("Attempt to auto-create SupplyRequest.date");
543        else if (Configuration.doAutoCreate())
544          this.date = new DateTimeType(); // bb
545      return this.date;
546    }
547
548    public boolean hasDateElement() { 
549      return this.date != null && !this.date.isEmpty();
550    }
551
552    public boolean hasDate() { 
553      return this.date != null && !this.date.isEmpty();
554    }
555
556    /**
557     * @param value {@link #date} (When the request was made.). This is the underlying object with id, value and extensions. The accessor "getDate" gives direct access to the value
558     */
559    public SupplyRequest setDateElement(DateTimeType value) { 
560      this.date = value;
561      return this;
562    }
563
564    /**
565     * @return When the request was made.
566     */
567    public Date getDate() { 
568      return this.date == null ? null : this.date.getValue();
569    }
570
571    /**
572     * @param value When the request was made.
573     */
574    public SupplyRequest setDate(Date value) { 
575      if (value == null)
576        this.date = null;
577      else {
578        if (this.date == null)
579          this.date = new DateTimeType();
580        this.date.setValue(value);
581      }
582      return this;
583    }
584
585    /**
586     * @return {@link #identifier} (Unique identifier for this supply request.)
587     */
588    public Identifier getIdentifier() { 
589      if (this.identifier == null)
590        if (Configuration.errorOnAutoCreate())
591          throw new Error("Attempt to auto-create SupplyRequest.identifier");
592        else if (Configuration.doAutoCreate())
593          this.identifier = new Identifier(); // cc
594      return this.identifier;
595    }
596
597    public boolean hasIdentifier() { 
598      return this.identifier != null && !this.identifier.isEmpty();
599    }
600
601    /**
602     * @param value {@link #identifier} (Unique identifier for this supply request.)
603     */
604    public SupplyRequest setIdentifier(Identifier value) { 
605      this.identifier = value;
606      return this;
607    }
608
609    /**
610     * @return {@link #status} (Status of the supply request.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
611     */
612    public Enumeration<SupplyRequestStatus> getStatusElement() { 
613      if (this.status == null)
614        if (Configuration.errorOnAutoCreate())
615          throw new Error("Attempt to auto-create SupplyRequest.status");
616        else if (Configuration.doAutoCreate())
617          this.status = new Enumeration<SupplyRequestStatus>(new SupplyRequestStatusEnumFactory()); // bb
618      return this.status;
619    }
620
621    public boolean hasStatusElement() { 
622      return this.status != null && !this.status.isEmpty();
623    }
624
625    public boolean hasStatus() { 
626      return this.status != null && !this.status.isEmpty();
627    }
628
629    /**
630     * @param value {@link #status} (Status of the supply request.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
631     */
632    public SupplyRequest setStatusElement(Enumeration<SupplyRequestStatus> value) { 
633      this.status = value;
634      return this;
635    }
636
637    /**
638     * @return Status of the supply request.
639     */
640    public SupplyRequestStatus getStatus() { 
641      return this.status == null ? null : this.status.getValue();
642    }
643
644    /**
645     * @param value Status of the supply request.
646     */
647    public SupplyRequest setStatus(SupplyRequestStatus value) { 
648      if (value == null)
649        this.status = null;
650      else {
651        if (this.status == null)
652          this.status = new Enumeration<SupplyRequestStatus>(new SupplyRequestStatusEnumFactory());
653        this.status.setValue(value);
654      }
655      return this;
656    }
657
658    /**
659     * @return {@link #kind} (Category of supply, e.g.  central, non-stock, etc. This is used to support work flows associated with the supply process.)
660     */
661    public CodeableConcept getKind() { 
662      if (this.kind == null)
663        if (Configuration.errorOnAutoCreate())
664          throw new Error("Attempt to auto-create SupplyRequest.kind");
665        else if (Configuration.doAutoCreate())
666          this.kind = new CodeableConcept(); // cc
667      return this.kind;
668    }
669
670    public boolean hasKind() { 
671      return this.kind != null && !this.kind.isEmpty();
672    }
673
674    /**
675     * @param value {@link #kind} (Category of supply, e.g.  central, non-stock, etc. This is used to support work flows associated with the supply process.)
676     */
677    public SupplyRequest setKind(CodeableConcept value) { 
678      this.kind = value;
679      return this;
680    }
681
682    /**
683     * @return {@link #orderedItem} (The item that is requested to be supplied.)
684     */
685    public Reference getOrderedItem() { 
686      if (this.orderedItem == null)
687        if (Configuration.errorOnAutoCreate())
688          throw new Error("Attempt to auto-create SupplyRequest.orderedItem");
689        else if (Configuration.doAutoCreate())
690          this.orderedItem = new Reference(); // cc
691      return this.orderedItem;
692    }
693
694    public boolean hasOrderedItem() { 
695      return this.orderedItem != null && !this.orderedItem.isEmpty();
696    }
697
698    /**
699     * @param value {@link #orderedItem} (The item that is requested to be supplied.)
700     */
701    public SupplyRequest setOrderedItem(Reference value) { 
702      this.orderedItem = value;
703      return this;
704    }
705
706    /**
707     * @return {@link #orderedItem} 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 item that is requested to be supplied.)
708     */
709    public Resource getOrderedItemTarget() { 
710      return this.orderedItemTarget;
711    }
712
713    /**
714     * @param value {@link #orderedItem} 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 item that is requested to be supplied.)
715     */
716    public SupplyRequest setOrderedItemTarget(Resource value) { 
717      this.orderedItemTarget = value;
718      return this;
719    }
720
721    /**
722     * @return {@link #supplier} (Who is intended to fulfill the request.)
723     */
724    public List<Reference> getSupplier() { 
725      if (this.supplier == null)
726        this.supplier = new ArrayList<Reference>();
727      return this.supplier;
728    }
729
730    public boolean hasSupplier() { 
731      if (this.supplier == null)
732        return false;
733      for (Reference item : this.supplier)
734        if (!item.isEmpty())
735          return true;
736      return false;
737    }
738
739    /**
740     * @return {@link #supplier} (Who is intended to fulfill the request.)
741     */
742    // syntactic sugar
743    public Reference addSupplier() { //3
744      Reference t = new Reference();
745      if (this.supplier == null)
746        this.supplier = new ArrayList<Reference>();
747      this.supplier.add(t);
748      return t;
749    }
750
751    // syntactic sugar
752    public SupplyRequest addSupplier(Reference t) { //3
753      if (t == null)
754        return this;
755      if (this.supplier == null)
756        this.supplier = new ArrayList<Reference>();
757      this.supplier.add(t);
758      return this;
759    }
760
761    /**
762     * @return {@link #supplier} (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. Who is intended to fulfill the request.)
763     */
764    public List<Organization> getSupplierTarget() { 
765      if (this.supplierTarget == null)
766        this.supplierTarget = new ArrayList<Organization>();
767      return this.supplierTarget;
768    }
769
770    // syntactic sugar
771    /**
772     * @return {@link #supplier} (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. Who is intended to fulfill the request.)
773     */
774    public Organization addSupplierTarget() { 
775      Organization r = new Organization();
776      if (this.supplierTarget == null)
777        this.supplierTarget = new ArrayList<Organization>();
778      this.supplierTarget.add(r);
779      return r;
780    }
781
782    /**
783     * @return {@link #reason} (Why the supply item was requested.)
784     */
785    public Type getReason() { 
786      return this.reason;
787    }
788
789    /**
790     * @return {@link #reason} (Why the supply item was requested.)
791     */
792    public CodeableConcept getReasonCodeableConcept() throws FHIRException { 
793      if (!(this.reason instanceof CodeableConcept))
794        throw new FHIRException("Type mismatch: the type CodeableConcept was expected, but "+this.reason.getClass().getName()+" was encountered");
795      return (CodeableConcept) this.reason;
796    }
797
798    public boolean hasReasonCodeableConcept() { 
799      return this.reason instanceof CodeableConcept;
800    }
801
802    /**
803     * @return {@link #reason} (Why the supply item was requested.)
804     */
805    public Reference getReasonReference() throws FHIRException { 
806      if (!(this.reason instanceof Reference))
807        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.reason.getClass().getName()+" was encountered");
808      return (Reference) this.reason;
809    }
810
811    public boolean hasReasonReference() { 
812      return this.reason instanceof Reference;
813    }
814
815    public boolean hasReason() { 
816      return this.reason != null && !this.reason.isEmpty();
817    }
818
819    /**
820     * @param value {@link #reason} (Why the supply item was requested.)
821     */
822    public SupplyRequest setReason(Type value) { 
823      this.reason = value;
824      return this;
825    }
826
827    /**
828     * @return {@link #when} (When the request should be fulfilled.)
829     */
830    public SupplyRequestWhenComponent getWhen() { 
831      if (this.when == null)
832        if (Configuration.errorOnAutoCreate())
833          throw new Error("Attempt to auto-create SupplyRequest.when");
834        else if (Configuration.doAutoCreate())
835          this.when = new SupplyRequestWhenComponent(); // cc
836      return this.when;
837    }
838
839    public boolean hasWhen() { 
840      return this.when != null && !this.when.isEmpty();
841    }
842
843    /**
844     * @param value {@link #when} (When the request should be fulfilled.)
845     */
846    public SupplyRequest setWhen(SupplyRequestWhenComponent value) { 
847      this.when = value;
848      return this;
849    }
850
851      protected void listChildren(List<Property> childrenList) {
852        super.listChildren(childrenList);
853        childrenList.add(new Property("patient", "Reference(Patient)", "A link to a resource representing the person whom the ordered item is for.", 0, java.lang.Integer.MAX_VALUE, patient));
854        childrenList.add(new Property("source", "Reference(Practitioner|Organization|Patient)", "The Practitioner , Organization or Patient who initiated this order for the supply.", 0, java.lang.Integer.MAX_VALUE, source));
855        childrenList.add(new Property("date", "dateTime", "When the request was made.", 0, java.lang.Integer.MAX_VALUE, date));
856        childrenList.add(new Property("identifier", "Identifier", "Unique identifier for this supply request.", 0, java.lang.Integer.MAX_VALUE, identifier));
857        childrenList.add(new Property("status", "code", "Status of the supply request.", 0, java.lang.Integer.MAX_VALUE, status));
858        childrenList.add(new Property("kind", "CodeableConcept", "Category of supply, e.g.  central, non-stock, etc. This is used to support work flows associated with the supply process.", 0, java.lang.Integer.MAX_VALUE, kind));
859        childrenList.add(new Property("orderedItem", "Reference(Medication|Substance|Device)", "The item that is requested to be supplied.", 0, java.lang.Integer.MAX_VALUE, orderedItem));
860        childrenList.add(new Property("supplier", "Reference(Organization)", "Who is intended to fulfill the request.", 0, java.lang.Integer.MAX_VALUE, supplier));
861        childrenList.add(new Property("reason[x]", "CodeableConcept|Reference(Any)", "Why the supply item was requested.", 0, java.lang.Integer.MAX_VALUE, reason));
862        childrenList.add(new Property("when", "", "When the request should be fulfilled.", 0, java.lang.Integer.MAX_VALUE, when));
863      }
864
865      @Override
866      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
867        switch (hash) {
868        case -791418107: /*patient*/ return this.patient == null ? new Base[0] : new Base[] {this.patient}; // Reference
869        case -896505829: /*source*/ return this.source == null ? new Base[0] : new Base[] {this.source}; // Reference
870        case 3076014: /*date*/ return this.date == null ? new Base[0] : new Base[] {this.date}; // DateTimeType
871        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : new Base[] {this.identifier}; // Identifier
872        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<SupplyRequestStatus>
873        case 3292052: /*kind*/ return this.kind == null ? new Base[0] : new Base[] {this.kind}; // CodeableConcept
874        case 2129914144: /*orderedItem*/ return this.orderedItem == null ? new Base[0] : new Base[] {this.orderedItem}; // Reference
875        case -1663305268: /*supplier*/ return this.supplier == null ? new Base[0] : this.supplier.toArray(new Base[this.supplier.size()]); // Reference
876        case -934964668: /*reason*/ return this.reason == null ? new Base[0] : new Base[] {this.reason}; // Type
877        case 3648314: /*when*/ return this.when == null ? new Base[0] : new Base[] {this.when}; // SupplyRequestWhenComponent
878        default: return super.getProperty(hash, name, checkValid);
879        }
880
881      }
882
883      @Override
884      public void setProperty(int hash, String name, Base value) throws FHIRException {
885        switch (hash) {
886        case -791418107: // patient
887          this.patient = castToReference(value); // Reference
888          break;
889        case -896505829: // source
890          this.source = castToReference(value); // Reference
891          break;
892        case 3076014: // date
893          this.date = castToDateTime(value); // DateTimeType
894          break;
895        case -1618432855: // identifier
896          this.identifier = castToIdentifier(value); // Identifier
897          break;
898        case -892481550: // status
899          this.status = new SupplyRequestStatusEnumFactory().fromType(value); // Enumeration<SupplyRequestStatus>
900          break;
901        case 3292052: // kind
902          this.kind = castToCodeableConcept(value); // CodeableConcept
903          break;
904        case 2129914144: // orderedItem
905          this.orderedItem = castToReference(value); // Reference
906          break;
907        case -1663305268: // supplier
908          this.getSupplier().add(castToReference(value)); // Reference
909          break;
910        case -934964668: // reason
911          this.reason = (Type) value; // Type
912          break;
913        case 3648314: // when
914          this.when = (SupplyRequestWhenComponent) value; // SupplyRequestWhenComponent
915          break;
916        default: super.setProperty(hash, name, value);
917        }
918
919      }
920
921      @Override
922      public void setProperty(String name, Base value) throws FHIRException {
923        if (name.equals("patient"))
924          this.patient = castToReference(value); // Reference
925        else if (name.equals("source"))
926          this.source = castToReference(value); // Reference
927        else if (name.equals("date"))
928          this.date = castToDateTime(value); // DateTimeType
929        else if (name.equals("identifier"))
930          this.identifier = castToIdentifier(value); // Identifier
931        else if (name.equals("status"))
932          this.status = new SupplyRequestStatusEnumFactory().fromType(value); // Enumeration<SupplyRequestStatus>
933        else if (name.equals("kind"))
934          this.kind = castToCodeableConcept(value); // CodeableConcept
935        else if (name.equals("orderedItem"))
936          this.orderedItem = castToReference(value); // Reference
937        else if (name.equals("supplier"))
938          this.getSupplier().add(castToReference(value));
939        else if (name.equals("reason[x]"))
940          this.reason = (Type) value; // Type
941        else if (name.equals("when"))
942          this.when = (SupplyRequestWhenComponent) value; // SupplyRequestWhenComponent
943        else
944          super.setProperty(name, value);
945      }
946
947      @Override
948      public Base makeProperty(int hash, String name) throws FHIRException {
949        switch (hash) {
950        case -791418107:  return getPatient(); // Reference
951        case -896505829:  return getSource(); // Reference
952        case 3076014: throw new FHIRException("Cannot make property date as it is not a complex type"); // DateTimeType
953        case -1618432855:  return getIdentifier(); // Identifier
954        case -892481550: throw new FHIRException("Cannot make property status as it is not a complex type"); // Enumeration<SupplyRequestStatus>
955        case 3292052:  return getKind(); // CodeableConcept
956        case 2129914144:  return getOrderedItem(); // Reference
957        case -1663305268:  return addSupplier(); // Reference
958        case -669418564:  return getReason(); // Type
959        case 3648314:  return getWhen(); // SupplyRequestWhenComponent
960        default: return super.makeProperty(hash, name);
961        }
962
963      }
964
965      @Override
966      public Base addChild(String name) throws FHIRException {
967        if (name.equals("patient")) {
968          this.patient = new Reference();
969          return this.patient;
970        }
971        else if (name.equals("source")) {
972          this.source = new Reference();
973          return this.source;
974        }
975        else if (name.equals("date")) {
976          throw new FHIRException("Cannot call addChild on a primitive type SupplyRequest.date");
977        }
978        else if (name.equals("identifier")) {
979          this.identifier = new Identifier();
980          return this.identifier;
981        }
982        else if (name.equals("status")) {
983          throw new FHIRException("Cannot call addChild on a primitive type SupplyRequest.status");
984        }
985        else if (name.equals("kind")) {
986          this.kind = new CodeableConcept();
987          return this.kind;
988        }
989        else if (name.equals("orderedItem")) {
990          this.orderedItem = new Reference();
991          return this.orderedItem;
992        }
993        else if (name.equals("supplier")) {
994          return addSupplier();
995        }
996        else if (name.equals("reasonCodeableConcept")) {
997          this.reason = new CodeableConcept();
998          return this.reason;
999        }
1000        else if (name.equals("reasonReference")) {
1001          this.reason = new Reference();
1002          return this.reason;
1003        }
1004        else if (name.equals("when")) {
1005          this.when = new SupplyRequestWhenComponent();
1006          return this.when;
1007        }
1008        else
1009          return super.addChild(name);
1010      }
1011
1012  public String fhirType() {
1013    return "SupplyRequest";
1014
1015  }
1016
1017      public SupplyRequest copy() {
1018        SupplyRequest dst = new SupplyRequest();
1019        copyValues(dst);
1020        dst.patient = patient == null ? null : patient.copy();
1021        dst.source = source == null ? null : source.copy();
1022        dst.date = date == null ? null : date.copy();
1023        dst.identifier = identifier == null ? null : identifier.copy();
1024        dst.status = status == null ? null : status.copy();
1025        dst.kind = kind == null ? null : kind.copy();
1026        dst.orderedItem = orderedItem == null ? null : orderedItem.copy();
1027        if (supplier != null) {
1028          dst.supplier = new ArrayList<Reference>();
1029          for (Reference i : supplier)
1030            dst.supplier.add(i.copy());
1031        };
1032        dst.reason = reason == null ? null : reason.copy();
1033        dst.when = when == null ? null : when.copy();
1034        return dst;
1035      }
1036
1037      protected SupplyRequest typedCopy() {
1038        return copy();
1039      }
1040
1041      @Override
1042      public boolean equalsDeep(Base other) {
1043        if (!super.equalsDeep(other))
1044          return false;
1045        if (!(other instanceof SupplyRequest))
1046          return false;
1047        SupplyRequest o = (SupplyRequest) other;
1048        return compareDeep(patient, o.patient, true) && compareDeep(source, o.source, true) && compareDeep(date, o.date, true)
1049           && compareDeep(identifier, o.identifier, true) && compareDeep(status, o.status, true) && compareDeep(kind, o.kind, true)
1050           && compareDeep(orderedItem, o.orderedItem, true) && compareDeep(supplier, o.supplier, true) && compareDeep(reason, o.reason, true)
1051           && compareDeep(when, o.when, true);
1052      }
1053
1054      @Override
1055      public boolean equalsShallow(Base other) {
1056        if (!super.equalsShallow(other))
1057          return false;
1058        if (!(other instanceof SupplyRequest))
1059          return false;
1060        SupplyRequest o = (SupplyRequest) other;
1061        return compareValues(date, o.date, true) && compareValues(status, o.status, true);
1062      }
1063
1064      public boolean isEmpty() {
1065        return super.isEmpty() && (patient == null || patient.isEmpty()) && (source == null || source.isEmpty())
1066           && (date == null || date.isEmpty()) && (identifier == null || identifier.isEmpty()) && (status == null || status.isEmpty())
1067           && (kind == null || kind.isEmpty()) && (orderedItem == null || orderedItem.isEmpty()) && (supplier == null || supplier.isEmpty())
1068           && (reason == null || reason.isEmpty()) && (when == null || when.isEmpty());
1069      }
1070
1071  @Override
1072  public ResourceType getResourceType() {
1073    return ResourceType.SupplyRequest;
1074   }
1075
1076 /**
1077   * Search parameter: <b>patient</b>
1078   * <p>
1079   * Description: <b>Patient for whom the item is supplied</b><br>
1080   * Type: <b>reference</b><br>
1081   * Path: <b>SupplyRequest.patient</b><br>
1082   * </p>
1083   */
1084  @SearchParamDefinition(name="patient", path="SupplyRequest.patient", description="Patient for whom the item is supplied", type="reference" )
1085  public static final String SP_PATIENT = "patient";
1086 /**
1087   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
1088   * <p>
1089   * Description: <b>Patient for whom the item is supplied</b><br>
1090   * Type: <b>reference</b><br>
1091   * Path: <b>SupplyRequest.patient</b><br>
1092   * </p>
1093   */
1094  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
1095
1096/**
1097   * Constant for fluent queries to be used to add include statements. Specifies
1098   * the path value of "<b>SupplyRequest:patient</b>".
1099   */
1100  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("SupplyRequest:patient").toLocked();
1101
1102 /**
1103   * Search parameter: <b>source</b>
1104   * <p>
1105   * Description: <b>Who initiated this order</b><br>
1106   * Type: <b>reference</b><br>
1107   * Path: <b>SupplyRequest.source</b><br>
1108   * </p>
1109   */
1110  @SearchParamDefinition(name="source", path="SupplyRequest.source", description="Who initiated this order", type="reference" )
1111  public static final String SP_SOURCE = "source";
1112 /**
1113   * <b>Fluent Client</b> search parameter constant for <b>source</b>
1114   * <p>
1115   * Description: <b>Who initiated this order</b><br>
1116   * Type: <b>reference</b><br>
1117   * Path: <b>SupplyRequest.source</b><br>
1118   * </p>
1119   */
1120  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SOURCE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SOURCE);
1121
1122/**
1123   * Constant for fluent queries to be used to add include statements. Specifies
1124   * the path value of "<b>SupplyRequest:source</b>".
1125   */
1126  public static final ca.uhn.fhir.model.api.Include INCLUDE_SOURCE = new ca.uhn.fhir.model.api.Include("SupplyRequest:source").toLocked();
1127
1128 /**
1129   * Search parameter: <b>status</b>
1130   * <p>
1131   * Description: <b>requested | completed | failed | cancelled</b><br>
1132   * Type: <b>token</b><br>
1133   * Path: <b>SupplyRequest.status</b><br>
1134   * </p>
1135   */
1136  @SearchParamDefinition(name="status", path="SupplyRequest.status", description="requested | completed | failed | cancelled", type="token" )
1137  public static final String SP_STATUS = "status";
1138 /**
1139   * <b>Fluent Client</b> search parameter constant for <b>status</b>
1140   * <p>
1141   * Description: <b>requested | completed | failed | cancelled</b><br>
1142   * Type: <b>token</b><br>
1143   * Path: <b>SupplyRequest.status</b><br>
1144   * </p>
1145   */
1146  public static final ca.uhn.fhir.rest.gclient.TokenClientParam STATUS = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_STATUS);
1147
1148 /**
1149   * Search parameter: <b>date</b>
1150   * <p>
1151   * Description: <b>When the request was made</b><br>
1152   * Type: <b>date</b><br>
1153   * Path: <b>SupplyRequest.date</b><br>
1154   * </p>
1155   */
1156  @SearchParamDefinition(name="date", path="SupplyRequest.date", description="When the request was made", type="date" )
1157  public static final String SP_DATE = "date";
1158 /**
1159   * <b>Fluent Client</b> search parameter constant for <b>date</b>
1160   * <p>
1161   * Description: <b>When the request was made</b><br>
1162   * Type: <b>date</b><br>
1163   * Path: <b>SupplyRequest.date</b><br>
1164   * </p>
1165   */
1166  public static final ca.uhn.fhir.rest.gclient.DateClientParam DATE = new ca.uhn.fhir.rest.gclient.DateClientParam(SP_DATE);
1167
1168 /**
1169   * Search parameter: <b>identifier</b>
1170   * <p>
1171   * Description: <b>Unique identifier</b><br>
1172   * Type: <b>token</b><br>
1173   * Path: <b>SupplyRequest.identifier</b><br>
1174   * </p>
1175   */
1176  @SearchParamDefinition(name="identifier", path="SupplyRequest.identifier", description="Unique identifier", type="token" )
1177  public static final String SP_IDENTIFIER = "identifier";
1178 /**
1179   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1180   * <p>
1181   * Description: <b>Unique identifier</b><br>
1182   * Type: <b>token</b><br>
1183   * Path: <b>SupplyRequest.identifier</b><br>
1184   * </p>
1185   */
1186  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1187
1188 /**
1189   * Search parameter: <b>supplier</b>
1190   * <p>
1191   * Description: <b>Who is intended to fulfill the request</b><br>
1192   * Type: <b>reference</b><br>
1193   * Path: <b>SupplyRequest.supplier</b><br>
1194   * </p>
1195   */
1196  @SearchParamDefinition(name="supplier", path="SupplyRequest.supplier", description="Who is intended to fulfill the request", type="reference" )
1197  public static final String SP_SUPPLIER = "supplier";
1198 /**
1199   * <b>Fluent Client</b> search parameter constant for <b>supplier</b>
1200   * <p>
1201   * Description: <b>Who is intended to fulfill the request</b><br>
1202   * Type: <b>reference</b><br>
1203   * Path: <b>SupplyRequest.supplier</b><br>
1204   * </p>
1205   */
1206  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUPPLIER = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUPPLIER);
1207
1208/**
1209   * Constant for fluent queries to be used to add include statements. Specifies
1210   * the path value of "<b>SupplyRequest:supplier</b>".
1211   */
1212  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUPPLIER = new ca.uhn.fhir.model.api.Include("SupplyRequest:supplier").toLocked();
1213
1214 /**
1215   * Search parameter: <b>kind</b>
1216   * <p>
1217   * Description: <b>The kind of supply (central, non-stock, etc.)</b><br>
1218   * Type: <b>token</b><br>
1219   * Path: <b>SupplyRequest.kind</b><br>
1220   * </p>
1221   */
1222  @SearchParamDefinition(name="kind", path="SupplyRequest.kind", description="The kind of supply (central, non-stock, etc.)", type="token" )
1223  public static final String SP_KIND = "kind";
1224 /**
1225   * <b>Fluent Client</b> search parameter constant for <b>kind</b>
1226   * <p>
1227   * Description: <b>The kind of supply (central, non-stock, etc.)</b><br>
1228   * Type: <b>token</b><br>
1229   * Path: <b>SupplyRequest.kind</b><br>
1230   * </p>
1231   */
1232  public static final ca.uhn.fhir.rest.gclient.TokenClientParam KIND = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_KIND);
1233
1234
1235}