001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import ca.uhn.fhir.model.api.annotation.ResourceDef;
041import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
042import ca.uhn.fhir.model.api.annotation.Child;
043import ca.uhn.fhir.model.api.annotation.ChildOrder;
044import ca.uhn.fhir.model.api.annotation.Description;
045import ca.uhn.fhir.model.api.annotation.Block;
046import org.hl7.fhir.instance.model.api.*;
047import org.hl7.fhir.exceptions.FHIRException;
048/**
049 * A record of a device being used by a patient where the record is the result of a report from the patient or another clinician.
050 */
051@ResourceDef(name="DeviceUseStatement", profile="http://hl7.org/fhir/StructureDefinition/DeviceUseStatement")
052public class DeviceUseStatement extends DomainResource {
053
054    public enum DeviceUseStatementStatus {
055        /**
056         * The device is still being used.
057         */
058        ACTIVE, 
059        /**
060         * The device is no longer being used.
061         */
062        COMPLETED, 
063        /**
064         * The statement was recorded incorrectly.
065         */
066        ENTEREDINERROR, 
067        /**
068         * The device may be used at some time in the future.
069         */
070        INTENDED, 
071        /**
072         * Actions implied by the statement have been permanently halted, before all of them occurred.
073         */
074        STOPPED, 
075        /**
076         * Actions implied by the statement have been temporarily halted, but are expected to continue later. May also be called "suspended".
077         */
078        ONHOLD, 
079        /**
080         * added to help the parsers with the generic types
081         */
082        NULL;
083        public static DeviceUseStatementStatus fromCode(String codeString) throws FHIRException {
084            if (codeString == null || "".equals(codeString))
085                return null;
086        if ("active".equals(codeString))
087          return ACTIVE;
088        if ("completed".equals(codeString))
089          return COMPLETED;
090        if ("entered-in-error".equals(codeString))
091          return ENTEREDINERROR;
092        if ("intended".equals(codeString))
093          return INTENDED;
094        if ("stopped".equals(codeString))
095          return STOPPED;
096        if ("on-hold".equals(codeString))
097          return ONHOLD;
098        if (Configuration.isAcceptInvalidEnums())
099          return null;
100        else
101          throw new FHIRException("Unknown DeviceUseStatementStatus code '"+codeString+"'");
102        }
103        public String toCode() {
104          switch (this) {
105            case ACTIVE: return "active";
106            case COMPLETED: return "completed";
107            case ENTEREDINERROR: return "entered-in-error";
108            case INTENDED: return "intended";
109            case STOPPED: return "stopped";
110            case ONHOLD: return "on-hold";
111            case NULL: return null;
112            default: return "?";
113          }
114        }
115        public String getSystem() {
116          switch (this) {
117            case ACTIVE: return "http://hl7.org/fhir/device-statement-status";
118            case COMPLETED: return "http://hl7.org/fhir/device-statement-status";
119            case ENTEREDINERROR: return "http://hl7.org/fhir/device-statement-status";
120            case INTENDED: return "http://hl7.org/fhir/device-statement-status";
121            case STOPPED: return "http://hl7.org/fhir/device-statement-status";
122            case ONHOLD: return "http://hl7.org/fhir/device-statement-status";
123            case NULL: return null;
124            default: return "?";
125          }
126        }
127        public String getDefinition() {
128          switch (this) {
129            case ACTIVE: return "The device is still being used.";
130            case COMPLETED: return "The device is no longer being used.";
131            case ENTEREDINERROR: return "The statement was recorded incorrectly.";
132            case INTENDED: return "The device may be used at some time in the future.";
133            case STOPPED: return "Actions implied by the statement have been permanently halted, before all of them occurred.";
134            case ONHOLD: return "Actions implied by the statement have been temporarily halted, but are expected to continue later. May also be called \"suspended\".";
135            case NULL: return null;
136            default: return "?";
137          }
138        }
139        public String getDisplay() {
140          switch (this) {
141            case ACTIVE: return "Active";
142            case COMPLETED: return "Completed";
143            case ENTEREDINERROR: return "Entered in Error";
144            case INTENDED: return "Intended";
145            case STOPPED: return "Stopped";
146            case ONHOLD: return "On Hold";
147            case NULL: return null;
148            default: return "?";
149          }
150        }
151    }
152
153  public static class DeviceUseStatementStatusEnumFactory implements EnumFactory<DeviceUseStatementStatus> {
154    public DeviceUseStatementStatus fromCode(String codeString) throws IllegalArgumentException {
155      if (codeString == null || "".equals(codeString))
156            if (codeString == null || "".equals(codeString))
157                return null;
158        if ("active".equals(codeString))
159          return DeviceUseStatementStatus.ACTIVE;
160        if ("completed".equals(codeString))
161          return DeviceUseStatementStatus.COMPLETED;
162        if ("entered-in-error".equals(codeString))
163          return DeviceUseStatementStatus.ENTEREDINERROR;
164        if ("intended".equals(codeString))
165          return DeviceUseStatementStatus.INTENDED;
166        if ("stopped".equals(codeString))
167          return DeviceUseStatementStatus.STOPPED;
168        if ("on-hold".equals(codeString))
169          return DeviceUseStatementStatus.ONHOLD;
170        throw new IllegalArgumentException("Unknown DeviceUseStatementStatus code '"+codeString+"'");
171        }
172        public Enumeration<DeviceUseStatementStatus> fromType(Base code) throws FHIRException {
173          if (code == null)
174            return null;
175          if (code.isEmpty())
176            return new Enumeration<DeviceUseStatementStatus>(this);
177          String codeString = ((PrimitiveType) code).asStringValue();
178          if (codeString == null || "".equals(codeString))
179            return null;
180        if ("active".equals(codeString))
181          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.ACTIVE);
182        if ("completed".equals(codeString))
183          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.COMPLETED);
184        if ("entered-in-error".equals(codeString))
185          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.ENTEREDINERROR);
186        if ("intended".equals(codeString))
187          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.INTENDED);
188        if ("stopped".equals(codeString))
189          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.STOPPED);
190        if ("on-hold".equals(codeString))
191          return new Enumeration<DeviceUseStatementStatus>(this, DeviceUseStatementStatus.ONHOLD);
192        throw new FHIRException("Unknown DeviceUseStatementStatus code '"+codeString+"'");
193        }
194    public String toCode(DeviceUseStatementStatus code) {
195      if (code == DeviceUseStatementStatus.ACTIVE)
196        return "active";
197      if (code == DeviceUseStatementStatus.COMPLETED)
198        return "completed";
199      if (code == DeviceUseStatementStatus.ENTEREDINERROR)
200        return "entered-in-error";
201      if (code == DeviceUseStatementStatus.INTENDED)
202        return "intended";
203      if (code == DeviceUseStatementStatus.STOPPED)
204        return "stopped";
205      if (code == DeviceUseStatementStatus.ONHOLD)
206        return "on-hold";
207      return "?";
208      }
209    public String toSystem(DeviceUseStatementStatus code) {
210      return code.getSystem();
211      }
212    }
213
214    /**
215     * An external identifier for this statement such as an IRI.
216     */
217    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
218    @Description(shortDefinition="External identifier for this record", formalDefinition="An external identifier for this statement such as an IRI." )
219    protected List<Identifier> identifier;
220
221    /**
222     * A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement.
223     */
224    @Child(name = "basedOn", type = {ServiceRequest.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
225    @Description(shortDefinition="Fulfills plan, proposal or order", formalDefinition="A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement." )
226    protected List<Reference> basedOn;
227    /**
228     * The actual objects that are the target of the reference (A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement.)
229     */
230    protected List<ServiceRequest> basedOnTarget;
231
232
233    /**
234     * A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.
235     */
236    @Child(name = "status", type = {CodeType.class}, order=2, min=1, max=1, modifier=true, summary=true)
237    @Description(shortDefinition="active | completed | entered-in-error +", formalDefinition="A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed." )
238    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/device-statement-status")
239    protected Enumeration<DeviceUseStatementStatus> status;
240
241    /**
242     * The patient who used the device.
243     */
244    @Child(name = "subject", type = {Patient.class, Group.class}, order=3, min=1, max=1, modifier=false, summary=true)
245    @Description(shortDefinition="Patient using device", formalDefinition="The patient who used the device." )
246    protected Reference subject;
247
248    /**
249     * The actual object that is the target of the reference (The patient who used the device.)
250     */
251    protected Resource subjectTarget;
252
253    /**
254     * Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement.
255     */
256    @Child(name = "derivedFrom", type = {ServiceRequest.class, Procedure.class, Claim.class, Observation.class, QuestionnaireResponse.class, DocumentReference.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
257    @Description(shortDefinition="Supporting information", formalDefinition="Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement." )
258    protected List<Reference> derivedFrom;
259    /**
260     * The actual objects that are the target of the reference (Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement.)
261     */
262    protected List<Resource> derivedFromTarget;
263
264
265    /**
266     * How often the device was used.
267     */
268    @Child(name = "timing", type = {Timing.class, Period.class, DateTimeType.class}, order=5, min=0, max=1, modifier=false, summary=true)
269    @Description(shortDefinition="How often  the device was used", formalDefinition="How often the device was used." )
270    protected Type timing;
271
272    /**
273     * The time at which the statement was made/recorded.
274     */
275    @Child(name = "recordedOn", type = {DateTimeType.class}, order=6, min=0, max=1, modifier=false, summary=true)
276    @Description(shortDefinition="When statement was recorded", formalDefinition="The time at which the statement was made/recorded." )
277    protected DateTimeType recordedOn;
278
279    /**
280     * Who reported the device was being used by the patient.
281     */
282    @Child(name = "source", type = {Patient.class, Practitioner.class, PractitionerRole.class, RelatedPerson.class}, order=7, min=0, max=1, modifier=false, summary=true)
283    @Description(shortDefinition="Who made the statement", formalDefinition="Who reported the device was being used by the patient." )
284    protected Reference source;
285
286    /**
287     * The actual object that is the target of the reference (Who reported the device was being used by the patient.)
288     */
289    protected Resource sourceTarget;
290
291    /**
292     * The details of the device used.
293     */
294    @Child(name = "device", type = {Device.class}, order=8, min=1, max=1, modifier=false, summary=true)
295    @Description(shortDefinition="Reference to device used", formalDefinition="The details of the device used." )
296    protected Reference device;
297
298    /**
299     * The actual object that is the target of the reference (The details of the device used.)
300     */
301    protected Device deviceTarget;
302
303    /**
304     * Reason or justification for the use of the device.
305     */
306    @Child(name = "reasonCode", type = {CodeableConcept.class}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
307    @Description(shortDefinition="Why device was used", formalDefinition="Reason or justification for the use of the device." )
308    protected List<CodeableConcept> reasonCode;
309
310    /**
311     * Indicates another resource whose existence justifies this DeviceUseStatement.
312     */
313    @Child(name = "reasonReference", type = {Condition.class, Observation.class, DiagnosticReport.class, DocumentReference.class, Media.class}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
314    @Description(shortDefinition="Why was DeviceUseStatement performed?", formalDefinition="Indicates another resource whose existence justifies this DeviceUseStatement." )
315    protected List<Reference> reasonReference;
316    /**
317     * The actual objects that are the target of the reference (Indicates another resource whose existence justifies this DeviceUseStatement.)
318     */
319    protected List<Resource> reasonReferenceTarget;
320
321
322    /**
323     * Indicates the anotomic location on the subject's body where the device was used ( i.e. the target).
324     */
325    @Child(name = "bodySite", type = {CodeableConcept.class}, order=11, min=0, max=1, modifier=false, summary=true)
326    @Description(shortDefinition="Target body site", formalDefinition="Indicates the anotomic location on the subject's body where the device was used ( i.e. the target)." )
327    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/body-site")
328    protected CodeableConcept bodySite;
329
330    /**
331     * Details about the device statement that were not represented at all or sufficiently in one of the attributes provided in a class. These may include for example a comment, an instruction, or a note associated with the statement.
332     */
333    @Child(name = "note", type = {Annotation.class}, order=12, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
334    @Description(shortDefinition="Addition details (comments, instructions)", formalDefinition="Details about the device statement that were not represented at all or sufficiently in one of the attributes provided in a class. These may include for example a comment, an instruction, or a note associated with the statement." )
335    protected List<Annotation> note;
336
337    private static final long serialVersionUID = -968330048L;
338
339  /**
340   * Constructor
341   */
342    public DeviceUseStatement() {
343      super();
344    }
345
346  /**
347   * Constructor
348   */
349    public DeviceUseStatement(Enumeration<DeviceUseStatementStatus> status, Reference subject, Reference device) {
350      super();
351      this.status = status;
352      this.subject = subject;
353      this.device = device;
354    }
355
356    /**
357     * @return {@link #identifier} (An external identifier for this statement such as an IRI.)
358     */
359    public List<Identifier> getIdentifier() { 
360      if (this.identifier == null)
361        this.identifier = new ArrayList<Identifier>();
362      return this.identifier;
363    }
364
365    /**
366     * @return Returns a reference to <code>this</code> for easy method chaining
367     */
368    public DeviceUseStatement setIdentifier(List<Identifier> theIdentifier) { 
369      this.identifier = theIdentifier;
370      return this;
371    }
372
373    public boolean hasIdentifier() { 
374      if (this.identifier == null)
375        return false;
376      for (Identifier item : this.identifier)
377        if (!item.isEmpty())
378          return true;
379      return false;
380    }
381
382    public Identifier addIdentifier() { //3
383      Identifier t = new Identifier();
384      if (this.identifier == null)
385        this.identifier = new ArrayList<Identifier>();
386      this.identifier.add(t);
387      return t;
388    }
389
390    public DeviceUseStatement addIdentifier(Identifier t) { //3
391      if (t == null)
392        return this;
393      if (this.identifier == null)
394        this.identifier = new ArrayList<Identifier>();
395      this.identifier.add(t);
396      return this;
397    }
398
399    /**
400     * @return The first repetition of repeating field {@link #identifier}, creating it if it does not already exist
401     */
402    public Identifier getIdentifierFirstRep() { 
403      if (getIdentifier().isEmpty()) {
404        addIdentifier();
405      }
406      return getIdentifier().get(0);
407    }
408
409    /**
410     * @return {@link #basedOn} (A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement.)
411     */
412    public List<Reference> getBasedOn() { 
413      if (this.basedOn == null)
414        this.basedOn = new ArrayList<Reference>();
415      return this.basedOn;
416    }
417
418    /**
419     * @return Returns a reference to <code>this</code> for easy method chaining
420     */
421    public DeviceUseStatement setBasedOn(List<Reference> theBasedOn) { 
422      this.basedOn = theBasedOn;
423      return this;
424    }
425
426    public boolean hasBasedOn() { 
427      if (this.basedOn == null)
428        return false;
429      for (Reference item : this.basedOn)
430        if (!item.isEmpty())
431          return true;
432      return false;
433    }
434
435    public Reference addBasedOn() { //3
436      Reference t = new Reference();
437      if (this.basedOn == null)
438        this.basedOn = new ArrayList<Reference>();
439      this.basedOn.add(t);
440      return t;
441    }
442
443    public DeviceUseStatement addBasedOn(Reference t) { //3
444      if (t == null)
445        return this;
446      if (this.basedOn == null)
447        this.basedOn = new ArrayList<Reference>();
448      this.basedOn.add(t);
449      return this;
450    }
451
452    /**
453     * @return The first repetition of repeating field {@link #basedOn}, creating it if it does not already exist
454     */
455    public Reference getBasedOnFirstRep() { 
456      if (getBasedOn().isEmpty()) {
457        addBasedOn();
458      }
459      return getBasedOn().get(0);
460    }
461
462    /**
463     * @deprecated Use Reference#setResource(IBaseResource) instead
464     */
465    @Deprecated
466    public List<ServiceRequest> getBasedOnTarget() { 
467      if (this.basedOnTarget == null)
468        this.basedOnTarget = new ArrayList<ServiceRequest>();
469      return this.basedOnTarget;
470    }
471
472    /**
473     * @deprecated Use Reference#setResource(IBaseResource) instead
474     */
475    @Deprecated
476    public ServiceRequest addBasedOnTarget() { 
477      ServiceRequest r = new ServiceRequest();
478      if (this.basedOnTarget == null)
479        this.basedOnTarget = new ArrayList<ServiceRequest>();
480      this.basedOnTarget.add(r);
481      return r;
482    }
483
484    /**
485     * @return {@link #status} (A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
486     */
487    public Enumeration<DeviceUseStatementStatus> getStatusElement() { 
488      if (this.status == null)
489        if (Configuration.errorOnAutoCreate())
490          throw new Error("Attempt to auto-create DeviceUseStatement.status");
491        else if (Configuration.doAutoCreate())
492          this.status = new Enumeration<DeviceUseStatementStatus>(new DeviceUseStatementStatusEnumFactory()); // bb
493      return this.status;
494    }
495
496    public boolean hasStatusElement() { 
497      return this.status != null && !this.status.isEmpty();
498    }
499
500    public boolean hasStatus() { 
501      return this.status != null && !this.status.isEmpty();
502    }
503
504    /**
505     * @param value {@link #status} (A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
506     */
507    public DeviceUseStatement setStatusElement(Enumeration<DeviceUseStatementStatus> value) { 
508      this.status = value;
509      return this;
510    }
511
512    /**
513     * @return A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.
514     */
515    public DeviceUseStatementStatus getStatus() { 
516      return this.status == null ? null : this.status.getValue();
517    }
518
519    /**
520     * @param value A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.
521     */
522    public DeviceUseStatement setStatus(DeviceUseStatementStatus value) { 
523        if (this.status == null)
524          this.status = new Enumeration<DeviceUseStatementStatus>(new DeviceUseStatementStatusEnumFactory());
525        this.status.setValue(value);
526      return this;
527    }
528
529    /**
530     * @return {@link #subject} (The patient who used the device.)
531     */
532    public Reference getSubject() { 
533      if (this.subject == null)
534        if (Configuration.errorOnAutoCreate())
535          throw new Error("Attempt to auto-create DeviceUseStatement.subject");
536        else if (Configuration.doAutoCreate())
537          this.subject = new Reference(); // cc
538      return this.subject;
539    }
540
541    public boolean hasSubject() { 
542      return this.subject != null && !this.subject.isEmpty();
543    }
544
545    /**
546     * @param value {@link #subject} (The patient who used the device.)
547     */
548    public DeviceUseStatement setSubject(Reference value) { 
549      this.subject = value;
550      return this;
551    }
552
553    /**
554     * @return {@link #subject} 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 patient who used the device.)
555     */
556    public Resource getSubjectTarget() { 
557      return this.subjectTarget;
558    }
559
560    /**
561     * @param value {@link #subject} 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 patient who used the device.)
562     */
563    public DeviceUseStatement setSubjectTarget(Resource value) { 
564      this.subjectTarget = value;
565      return this;
566    }
567
568    /**
569     * @return {@link #derivedFrom} (Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement.)
570     */
571    public List<Reference> getDerivedFrom() { 
572      if (this.derivedFrom == null)
573        this.derivedFrom = new ArrayList<Reference>();
574      return this.derivedFrom;
575    }
576
577    /**
578     * @return Returns a reference to <code>this</code> for easy method chaining
579     */
580    public DeviceUseStatement setDerivedFrom(List<Reference> theDerivedFrom) { 
581      this.derivedFrom = theDerivedFrom;
582      return this;
583    }
584
585    public boolean hasDerivedFrom() { 
586      if (this.derivedFrom == null)
587        return false;
588      for (Reference item : this.derivedFrom)
589        if (!item.isEmpty())
590          return true;
591      return false;
592    }
593
594    public Reference addDerivedFrom() { //3
595      Reference t = new Reference();
596      if (this.derivedFrom == null)
597        this.derivedFrom = new ArrayList<Reference>();
598      this.derivedFrom.add(t);
599      return t;
600    }
601
602    public DeviceUseStatement addDerivedFrom(Reference t) { //3
603      if (t == null)
604        return this;
605      if (this.derivedFrom == null)
606        this.derivedFrom = new ArrayList<Reference>();
607      this.derivedFrom.add(t);
608      return this;
609    }
610
611    /**
612     * @return The first repetition of repeating field {@link #derivedFrom}, creating it if it does not already exist
613     */
614    public Reference getDerivedFromFirstRep() { 
615      if (getDerivedFrom().isEmpty()) {
616        addDerivedFrom();
617      }
618      return getDerivedFrom().get(0);
619    }
620
621    /**
622     * @deprecated Use Reference#setResource(IBaseResource) instead
623     */
624    @Deprecated
625    public List<Resource> getDerivedFromTarget() { 
626      if (this.derivedFromTarget == null)
627        this.derivedFromTarget = new ArrayList<Resource>();
628      return this.derivedFromTarget;
629    }
630
631    /**
632     * @return {@link #timing} (How often the device was used.)
633     */
634    public Type getTiming() { 
635      return this.timing;
636    }
637
638    /**
639     * @return {@link #timing} (How often the device was used.)
640     */
641    public Timing getTimingTiming() throws FHIRException { 
642      if (this.timing == null)
643        this.timing = new Timing();
644      if (!(this.timing instanceof Timing))
645        throw new FHIRException("Type mismatch: the type Timing was expected, but "+this.timing.getClass().getName()+" was encountered");
646      return (Timing) this.timing;
647    }
648
649    public boolean hasTimingTiming() { 
650      return this != null && this.timing instanceof Timing;
651    }
652
653    /**
654     * @return {@link #timing} (How often the device was used.)
655     */
656    public Period getTimingPeriod() throws FHIRException { 
657      if (this.timing == null)
658        this.timing = new Period();
659      if (!(this.timing instanceof Period))
660        throw new FHIRException("Type mismatch: the type Period was expected, but "+this.timing.getClass().getName()+" was encountered");
661      return (Period) this.timing;
662    }
663
664    public boolean hasTimingPeriod() { 
665      return this != null && this.timing instanceof Period;
666    }
667
668    /**
669     * @return {@link #timing} (How often the device was used.)
670     */
671    public DateTimeType getTimingDateTimeType() throws FHIRException { 
672      if (this.timing == null)
673        this.timing = new DateTimeType();
674      if (!(this.timing instanceof DateTimeType))
675        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.timing.getClass().getName()+" was encountered");
676      return (DateTimeType) this.timing;
677    }
678
679    public boolean hasTimingDateTimeType() { 
680      return this != null && this.timing instanceof DateTimeType;
681    }
682
683    public boolean hasTiming() { 
684      return this.timing != null && !this.timing.isEmpty();
685    }
686
687    /**
688     * @param value {@link #timing} (How often the device was used.)
689     */
690    public DeviceUseStatement setTiming(Type value) { 
691      if (value != null && !(value instanceof Timing || value instanceof Period || value instanceof DateTimeType))
692        throw new Error("Not the right type for DeviceUseStatement.timing[x]: "+value.fhirType());
693      this.timing = value;
694      return this;
695    }
696
697    /**
698     * @return {@link #recordedOn} (The time at which the statement was made/recorded.). This is the underlying object with id, value and extensions. The accessor "getRecordedOn" gives direct access to the value
699     */
700    public DateTimeType getRecordedOnElement() { 
701      if (this.recordedOn == null)
702        if (Configuration.errorOnAutoCreate())
703          throw new Error("Attempt to auto-create DeviceUseStatement.recordedOn");
704        else if (Configuration.doAutoCreate())
705          this.recordedOn = new DateTimeType(); // bb
706      return this.recordedOn;
707    }
708
709    public boolean hasRecordedOnElement() { 
710      return this.recordedOn != null && !this.recordedOn.isEmpty();
711    }
712
713    public boolean hasRecordedOn() { 
714      return this.recordedOn != null && !this.recordedOn.isEmpty();
715    }
716
717    /**
718     * @param value {@link #recordedOn} (The time at which the statement was made/recorded.). This is the underlying object with id, value and extensions. The accessor "getRecordedOn" gives direct access to the value
719     */
720    public DeviceUseStatement setRecordedOnElement(DateTimeType value) { 
721      this.recordedOn = value;
722      return this;
723    }
724
725    /**
726     * @return The time at which the statement was made/recorded.
727     */
728    public Date getRecordedOn() { 
729      return this.recordedOn == null ? null : this.recordedOn.getValue();
730    }
731
732    /**
733     * @param value The time at which the statement was made/recorded.
734     */
735    public DeviceUseStatement setRecordedOn(Date value) { 
736      if (value == null)
737        this.recordedOn = null;
738      else {
739        if (this.recordedOn == null)
740          this.recordedOn = new DateTimeType();
741        this.recordedOn.setValue(value);
742      }
743      return this;
744    }
745
746    /**
747     * @return {@link #source} (Who reported the device was being used by the patient.)
748     */
749    public Reference getSource() { 
750      if (this.source == null)
751        if (Configuration.errorOnAutoCreate())
752          throw new Error("Attempt to auto-create DeviceUseStatement.source");
753        else if (Configuration.doAutoCreate())
754          this.source = new Reference(); // cc
755      return this.source;
756    }
757
758    public boolean hasSource() { 
759      return this.source != null && !this.source.isEmpty();
760    }
761
762    /**
763     * @param value {@link #source} (Who reported the device was being used by the patient.)
764     */
765    public DeviceUseStatement setSource(Reference value) { 
766      this.source = value;
767      return this;
768    }
769
770    /**
771     * @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. (Who reported the device was being used by the patient.)
772     */
773    public Resource getSourceTarget() { 
774      return this.sourceTarget;
775    }
776
777    /**
778     * @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. (Who reported the device was being used by the patient.)
779     */
780    public DeviceUseStatement setSourceTarget(Resource value) { 
781      this.sourceTarget = value;
782      return this;
783    }
784
785    /**
786     * @return {@link #device} (The details of the device used.)
787     */
788    public Reference getDevice() { 
789      if (this.device == null)
790        if (Configuration.errorOnAutoCreate())
791          throw new Error("Attempt to auto-create DeviceUseStatement.device");
792        else if (Configuration.doAutoCreate())
793          this.device = new Reference(); // cc
794      return this.device;
795    }
796
797    public boolean hasDevice() { 
798      return this.device != null && !this.device.isEmpty();
799    }
800
801    /**
802     * @param value {@link #device} (The details of the device used.)
803     */
804    public DeviceUseStatement setDevice(Reference value) { 
805      this.device = value;
806      return this;
807    }
808
809    /**
810     * @return {@link #device} 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 details of the device used.)
811     */
812    public Device getDeviceTarget() { 
813      if (this.deviceTarget == null)
814        if (Configuration.errorOnAutoCreate())
815          throw new Error("Attempt to auto-create DeviceUseStatement.device");
816        else if (Configuration.doAutoCreate())
817          this.deviceTarget = new Device(); // aa
818      return this.deviceTarget;
819    }
820
821    /**
822     * @param value {@link #device} 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 details of the device used.)
823     */
824    public DeviceUseStatement setDeviceTarget(Device value) { 
825      this.deviceTarget = value;
826      return this;
827    }
828
829    /**
830     * @return {@link #reasonCode} (Reason or justification for the use of the device.)
831     */
832    public List<CodeableConcept> getReasonCode() { 
833      if (this.reasonCode == null)
834        this.reasonCode = new ArrayList<CodeableConcept>();
835      return this.reasonCode;
836    }
837
838    /**
839     * @return Returns a reference to <code>this</code> for easy method chaining
840     */
841    public DeviceUseStatement setReasonCode(List<CodeableConcept> theReasonCode) { 
842      this.reasonCode = theReasonCode;
843      return this;
844    }
845
846    public boolean hasReasonCode() { 
847      if (this.reasonCode == null)
848        return false;
849      for (CodeableConcept item : this.reasonCode)
850        if (!item.isEmpty())
851          return true;
852      return false;
853    }
854
855    public CodeableConcept addReasonCode() { //3
856      CodeableConcept t = new CodeableConcept();
857      if (this.reasonCode == null)
858        this.reasonCode = new ArrayList<CodeableConcept>();
859      this.reasonCode.add(t);
860      return t;
861    }
862
863    public DeviceUseStatement addReasonCode(CodeableConcept t) { //3
864      if (t == null)
865        return this;
866      if (this.reasonCode == null)
867        this.reasonCode = new ArrayList<CodeableConcept>();
868      this.reasonCode.add(t);
869      return this;
870    }
871
872    /**
873     * @return The first repetition of repeating field {@link #reasonCode}, creating it if it does not already exist
874     */
875    public CodeableConcept getReasonCodeFirstRep() { 
876      if (getReasonCode().isEmpty()) {
877        addReasonCode();
878      }
879      return getReasonCode().get(0);
880    }
881
882    /**
883     * @return {@link #reasonReference} (Indicates another resource whose existence justifies this DeviceUseStatement.)
884     */
885    public List<Reference> getReasonReference() { 
886      if (this.reasonReference == null)
887        this.reasonReference = new ArrayList<Reference>();
888      return this.reasonReference;
889    }
890
891    /**
892     * @return Returns a reference to <code>this</code> for easy method chaining
893     */
894    public DeviceUseStatement setReasonReference(List<Reference> theReasonReference) { 
895      this.reasonReference = theReasonReference;
896      return this;
897    }
898
899    public boolean hasReasonReference() { 
900      if (this.reasonReference == null)
901        return false;
902      for (Reference item : this.reasonReference)
903        if (!item.isEmpty())
904          return true;
905      return false;
906    }
907
908    public Reference addReasonReference() { //3
909      Reference t = new Reference();
910      if (this.reasonReference == null)
911        this.reasonReference = new ArrayList<Reference>();
912      this.reasonReference.add(t);
913      return t;
914    }
915
916    public DeviceUseStatement addReasonReference(Reference t) { //3
917      if (t == null)
918        return this;
919      if (this.reasonReference == null)
920        this.reasonReference = new ArrayList<Reference>();
921      this.reasonReference.add(t);
922      return this;
923    }
924
925    /**
926     * @return The first repetition of repeating field {@link #reasonReference}, creating it if it does not already exist
927     */
928    public Reference getReasonReferenceFirstRep() { 
929      if (getReasonReference().isEmpty()) {
930        addReasonReference();
931      }
932      return getReasonReference().get(0);
933    }
934
935    /**
936     * @deprecated Use Reference#setResource(IBaseResource) instead
937     */
938    @Deprecated
939    public List<Resource> getReasonReferenceTarget() { 
940      if (this.reasonReferenceTarget == null)
941        this.reasonReferenceTarget = new ArrayList<Resource>();
942      return this.reasonReferenceTarget;
943    }
944
945    /**
946     * @return {@link #bodySite} (Indicates the anotomic location on the subject's body where the device was used ( i.e. the target).)
947     */
948    public CodeableConcept getBodySite() { 
949      if (this.bodySite == null)
950        if (Configuration.errorOnAutoCreate())
951          throw new Error("Attempt to auto-create DeviceUseStatement.bodySite");
952        else if (Configuration.doAutoCreate())
953          this.bodySite = new CodeableConcept(); // cc
954      return this.bodySite;
955    }
956
957    public boolean hasBodySite() { 
958      return this.bodySite != null && !this.bodySite.isEmpty();
959    }
960
961    /**
962     * @param value {@link #bodySite} (Indicates the anotomic location on the subject's body where the device was used ( i.e. the target).)
963     */
964    public DeviceUseStatement setBodySite(CodeableConcept value) { 
965      this.bodySite = value;
966      return this;
967    }
968
969    /**
970     * @return {@link #note} (Details about the device statement that were not represented at all or sufficiently in one of the attributes provided in a class. These may include for example a comment, an instruction, or a note associated with the statement.)
971     */
972    public List<Annotation> getNote() { 
973      if (this.note == null)
974        this.note = new ArrayList<Annotation>();
975      return this.note;
976    }
977
978    /**
979     * @return Returns a reference to <code>this</code> for easy method chaining
980     */
981    public DeviceUseStatement setNote(List<Annotation> theNote) { 
982      this.note = theNote;
983      return this;
984    }
985
986    public boolean hasNote() { 
987      if (this.note == null)
988        return false;
989      for (Annotation item : this.note)
990        if (!item.isEmpty())
991          return true;
992      return false;
993    }
994
995    public Annotation addNote() { //3
996      Annotation t = new Annotation();
997      if (this.note == null)
998        this.note = new ArrayList<Annotation>();
999      this.note.add(t);
1000      return t;
1001    }
1002
1003    public DeviceUseStatement addNote(Annotation t) { //3
1004      if (t == null)
1005        return this;
1006      if (this.note == null)
1007        this.note = new ArrayList<Annotation>();
1008      this.note.add(t);
1009      return this;
1010    }
1011
1012    /**
1013     * @return The first repetition of repeating field {@link #note}, creating it if it does not already exist
1014     */
1015    public Annotation getNoteFirstRep() { 
1016      if (getNote().isEmpty()) {
1017        addNote();
1018      }
1019      return getNote().get(0);
1020    }
1021
1022      protected void listChildren(List<Property> children) {
1023        super.listChildren(children);
1024        children.add(new Property("identifier", "Identifier", "An external identifier for this statement such as an IRI.", 0, java.lang.Integer.MAX_VALUE, identifier));
1025        children.add(new Property("basedOn", "Reference(ServiceRequest)", "A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, basedOn));
1026        children.add(new Property("status", "code", "A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.", 0, 1, status));
1027        children.add(new Property("subject", "Reference(Patient|Group)", "The patient who used the device.", 0, 1, subject));
1028        children.add(new Property("derivedFrom", "Reference(ServiceRequest|Procedure|Claim|Observation|QuestionnaireResponse|DocumentReference)", "Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, derivedFrom));
1029        children.add(new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing));
1030        children.add(new Property("recordedOn", "dateTime", "The time at which the statement was made/recorded.", 0, 1, recordedOn));
1031        children.add(new Property("source", "Reference(Patient|Practitioner|PractitionerRole|RelatedPerson)", "Who reported the device was being used by the patient.", 0, 1, source));
1032        children.add(new Property("device", "Reference(Device)", "The details of the device used.", 0, 1, device));
1033        children.add(new Property("reasonCode", "CodeableConcept", "Reason or justification for the use of the device.", 0, java.lang.Integer.MAX_VALUE, reasonCode));
1034        children.add(new Property("reasonReference", "Reference(Condition|Observation|DiagnosticReport|DocumentReference|Media)", "Indicates another resource whose existence justifies this DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, reasonReference));
1035        children.add(new Property("bodySite", "CodeableConcept", "Indicates the anotomic location on the subject's body where the device was used ( i.e. the target).", 0, 1, bodySite));
1036        children.add(new Property("note", "Annotation", "Details about the device statement that were not represented at all or sufficiently in one of the attributes provided in a class. These may include for example a comment, an instruction, or a note associated with the statement.", 0, java.lang.Integer.MAX_VALUE, note));
1037      }
1038
1039      @Override
1040      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1041        switch (_hash) {
1042        case -1618432855: /*identifier*/  return new Property("identifier", "Identifier", "An external identifier for this statement such as an IRI.", 0, java.lang.Integer.MAX_VALUE, identifier);
1043        case -332612366: /*basedOn*/  return new Property("basedOn", "Reference(ServiceRequest)", "A plan, proposal or order that is fulfilled in whole or in part by this DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, basedOn);
1044        case -892481550: /*status*/  return new Property("status", "code", "A code representing the patient or other source's judgment about the state of the device used that this statement is about.  Generally this will be active or completed.", 0, 1, status);
1045        case -1867885268: /*subject*/  return new Property("subject", "Reference(Patient|Group)", "The patient who used the device.", 0, 1, subject);
1046        case 1077922663: /*derivedFrom*/  return new Property("derivedFrom", "Reference(ServiceRequest|Procedure|Claim|Observation|QuestionnaireResponse|DocumentReference)", "Allows linking the DeviceUseStatement to the underlying Request, or to other information that supports or is used to derive the DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, derivedFrom);
1047        case 164632566: /*timing[x]*/  return new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing);
1048        case -873664438: /*timing*/  return new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing);
1049        case -497554124: /*timingTiming*/  return new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing);
1050        case -615615829: /*timingPeriod*/  return new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing);
1051        case -1837458939: /*timingDateTime*/  return new Property("timing[x]", "Timing|Period|dateTime", "How often the device was used.", 0, 1, timing);
1052        case 735397551: /*recordedOn*/  return new Property("recordedOn", "dateTime", "The time at which the statement was made/recorded.", 0, 1, recordedOn);
1053        case -896505829: /*source*/  return new Property("source", "Reference(Patient|Practitioner|PractitionerRole|RelatedPerson)", "Who reported the device was being used by the patient.", 0, 1, source);
1054        case -1335157162: /*device*/  return new Property("device", "Reference(Device)", "The details of the device used.", 0, 1, device);
1055        case 722137681: /*reasonCode*/  return new Property("reasonCode", "CodeableConcept", "Reason or justification for the use of the device.", 0, java.lang.Integer.MAX_VALUE, reasonCode);
1056        case -1146218137: /*reasonReference*/  return new Property("reasonReference", "Reference(Condition|Observation|DiagnosticReport|DocumentReference|Media)", "Indicates another resource whose existence justifies this DeviceUseStatement.", 0, java.lang.Integer.MAX_VALUE, reasonReference);
1057        case 1702620169: /*bodySite*/  return new Property("bodySite", "CodeableConcept", "Indicates the anotomic location on the subject's body where the device was used ( i.e. the target).", 0, 1, bodySite);
1058        case 3387378: /*note*/  return new Property("note", "Annotation", "Details about the device statement that were not represented at all or sufficiently in one of the attributes provided in a class. These may include for example a comment, an instruction, or a note associated with the statement.", 0, java.lang.Integer.MAX_VALUE, note);
1059        default: return super.getNamedProperty(_hash, _name, _checkValid);
1060        }
1061
1062      }
1063
1064      @Override
1065      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1066        switch (hash) {
1067        case -1618432855: /*identifier*/ return this.identifier == null ? new Base[0] : this.identifier.toArray(new Base[this.identifier.size()]); // Identifier
1068        case -332612366: /*basedOn*/ return this.basedOn == null ? new Base[0] : this.basedOn.toArray(new Base[this.basedOn.size()]); // Reference
1069        case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<DeviceUseStatementStatus>
1070        case -1867885268: /*subject*/ return this.subject == null ? new Base[0] : new Base[] {this.subject}; // Reference
1071        case 1077922663: /*derivedFrom*/ return this.derivedFrom == null ? new Base[0] : this.derivedFrom.toArray(new Base[this.derivedFrom.size()]); // Reference
1072        case -873664438: /*timing*/ return this.timing == null ? new Base[0] : new Base[] {this.timing}; // Type
1073        case 735397551: /*recordedOn*/ return this.recordedOn == null ? new Base[0] : new Base[] {this.recordedOn}; // DateTimeType
1074        case -896505829: /*source*/ return this.source == null ? new Base[0] : new Base[] {this.source}; // Reference
1075        case -1335157162: /*device*/ return this.device == null ? new Base[0] : new Base[] {this.device}; // Reference
1076        case 722137681: /*reasonCode*/ return this.reasonCode == null ? new Base[0] : this.reasonCode.toArray(new Base[this.reasonCode.size()]); // CodeableConcept
1077        case -1146218137: /*reasonReference*/ return this.reasonReference == null ? new Base[0] : this.reasonReference.toArray(new Base[this.reasonReference.size()]); // Reference
1078        case 1702620169: /*bodySite*/ return this.bodySite == null ? new Base[0] : new Base[] {this.bodySite}; // CodeableConcept
1079        case 3387378: /*note*/ return this.note == null ? new Base[0] : this.note.toArray(new Base[this.note.size()]); // Annotation
1080        default: return super.getProperty(hash, name, checkValid);
1081        }
1082
1083      }
1084
1085      @Override
1086      public Base setProperty(int hash, String name, Base value) throws FHIRException {
1087        switch (hash) {
1088        case -1618432855: // identifier
1089          this.getIdentifier().add(castToIdentifier(value)); // Identifier
1090          return value;
1091        case -332612366: // basedOn
1092          this.getBasedOn().add(castToReference(value)); // Reference
1093          return value;
1094        case -892481550: // status
1095          value = new DeviceUseStatementStatusEnumFactory().fromType(castToCode(value));
1096          this.status = (Enumeration) value; // Enumeration<DeviceUseStatementStatus>
1097          return value;
1098        case -1867885268: // subject
1099          this.subject = castToReference(value); // Reference
1100          return value;
1101        case 1077922663: // derivedFrom
1102          this.getDerivedFrom().add(castToReference(value)); // Reference
1103          return value;
1104        case -873664438: // timing
1105          this.timing = castToType(value); // Type
1106          return value;
1107        case 735397551: // recordedOn
1108          this.recordedOn = castToDateTime(value); // DateTimeType
1109          return value;
1110        case -896505829: // source
1111          this.source = castToReference(value); // Reference
1112          return value;
1113        case -1335157162: // device
1114          this.device = castToReference(value); // Reference
1115          return value;
1116        case 722137681: // reasonCode
1117          this.getReasonCode().add(castToCodeableConcept(value)); // CodeableConcept
1118          return value;
1119        case -1146218137: // reasonReference
1120          this.getReasonReference().add(castToReference(value)); // Reference
1121          return value;
1122        case 1702620169: // bodySite
1123          this.bodySite = castToCodeableConcept(value); // CodeableConcept
1124          return value;
1125        case 3387378: // note
1126          this.getNote().add(castToAnnotation(value)); // Annotation
1127          return value;
1128        default: return super.setProperty(hash, name, value);
1129        }
1130
1131      }
1132
1133      @Override
1134      public Base setProperty(String name, Base value) throws FHIRException {
1135        if (name.equals("identifier")) {
1136          this.getIdentifier().add(castToIdentifier(value));
1137        } else if (name.equals("basedOn")) {
1138          this.getBasedOn().add(castToReference(value));
1139        } else if (name.equals("status")) {
1140          value = new DeviceUseStatementStatusEnumFactory().fromType(castToCode(value));
1141          this.status = (Enumeration) value; // Enumeration<DeviceUseStatementStatus>
1142        } else if (name.equals("subject")) {
1143          this.subject = castToReference(value); // Reference
1144        } else if (name.equals("derivedFrom")) {
1145          this.getDerivedFrom().add(castToReference(value));
1146        } else if (name.equals("timing[x]")) {
1147          this.timing = castToType(value); // Type
1148        } else if (name.equals("recordedOn")) {
1149          this.recordedOn = castToDateTime(value); // DateTimeType
1150        } else if (name.equals("source")) {
1151          this.source = castToReference(value); // Reference
1152        } else if (name.equals("device")) {
1153          this.device = castToReference(value); // Reference
1154        } else if (name.equals("reasonCode")) {
1155          this.getReasonCode().add(castToCodeableConcept(value));
1156        } else if (name.equals("reasonReference")) {
1157          this.getReasonReference().add(castToReference(value));
1158        } else if (name.equals("bodySite")) {
1159          this.bodySite = castToCodeableConcept(value); // CodeableConcept
1160        } else if (name.equals("note")) {
1161          this.getNote().add(castToAnnotation(value));
1162        } else
1163          return super.setProperty(name, value);
1164        return value;
1165      }
1166
1167      @Override
1168      public Base makeProperty(int hash, String name) throws FHIRException {
1169        switch (hash) {
1170        case -1618432855:  return addIdentifier(); 
1171        case -332612366:  return addBasedOn(); 
1172        case -892481550:  return getStatusElement();
1173        case -1867885268:  return getSubject(); 
1174        case 1077922663:  return addDerivedFrom(); 
1175        case 164632566:  return getTiming(); 
1176        case -873664438:  return getTiming(); 
1177        case 735397551:  return getRecordedOnElement();
1178        case -896505829:  return getSource(); 
1179        case -1335157162:  return getDevice(); 
1180        case 722137681:  return addReasonCode(); 
1181        case -1146218137:  return addReasonReference(); 
1182        case 1702620169:  return getBodySite(); 
1183        case 3387378:  return addNote(); 
1184        default: return super.makeProperty(hash, name);
1185        }
1186
1187      }
1188
1189      @Override
1190      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1191        switch (hash) {
1192        case -1618432855: /*identifier*/ return new String[] {"Identifier"};
1193        case -332612366: /*basedOn*/ return new String[] {"Reference"};
1194        case -892481550: /*status*/ return new String[] {"code"};
1195        case -1867885268: /*subject*/ return new String[] {"Reference"};
1196        case 1077922663: /*derivedFrom*/ return new String[] {"Reference"};
1197        case -873664438: /*timing*/ return new String[] {"Timing", "Period", "dateTime"};
1198        case 735397551: /*recordedOn*/ return new String[] {"dateTime"};
1199        case -896505829: /*source*/ return new String[] {"Reference"};
1200        case -1335157162: /*device*/ return new String[] {"Reference"};
1201        case 722137681: /*reasonCode*/ return new String[] {"CodeableConcept"};
1202        case -1146218137: /*reasonReference*/ return new String[] {"Reference"};
1203        case 1702620169: /*bodySite*/ return new String[] {"CodeableConcept"};
1204        case 3387378: /*note*/ return new String[] {"Annotation"};
1205        default: return super.getTypesForProperty(hash, name);
1206        }
1207
1208      }
1209
1210      @Override
1211      public Base addChild(String name) throws FHIRException {
1212        if (name.equals("identifier")) {
1213          return addIdentifier();
1214        }
1215        else if (name.equals("basedOn")) {
1216          return addBasedOn();
1217        }
1218        else if (name.equals("status")) {
1219          throw new FHIRException("Cannot call addChild on a primitive type DeviceUseStatement.status");
1220        }
1221        else if (name.equals("subject")) {
1222          this.subject = new Reference();
1223          return this.subject;
1224        }
1225        else if (name.equals("derivedFrom")) {
1226          return addDerivedFrom();
1227        }
1228        else if (name.equals("timingTiming")) {
1229          this.timing = new Timing();
1230          return this.timing;
1231        }
1232        else if (name.equals("timingPeriod")) {
1233          this.timing = new Period();
1234          return this.timing;
1235        }
1236        else if (name.equals("timingDateTime")) {
1237          this.timing = new DateTimeType();
1238          return this.timing;
1239        }
1240        else if (name.equals("recordedOn")) {
1241          throw new FHIRException("Cannot call addChild on a primitive type DeviceUseStatement.recordedOn");
1242        }
1243        else if (name.equals("source")) {
1244          this.source = new Reference();
1245          return this.source;
1246        }
1247        else if (name.equals("device")) {
1248          this.device = new Reference();
1249          return this.device;
1250        }
1251        else if (name.equals("reasonCode")) {
1252          return addReasonCode();
1253        }
1254        else if (name.equals("reasonReference")) {
1255          return addReasonReference();
1256        }
1257        else if (name.equals("bodySite")) {
1258          this.bodySite = new CodeableConcept();
1259          return this.bodySite;
1260        }
1261        else if (name.equals("note")) {
1262          return addNote();
1263        }
1264        else
1265          return super.addChild(name);
1266      }
1267
1268  public String fhirType() {
1269    return "DeviceUseStatement";
1270
1271  }
1272
1273      public DeviceUseStatement copy() {
1274        DeviceUseStatement dst = new DeviceUseStatement();
1275        copyValues(dst);
1276        return dst;
1277      }
1278
1279      public void copyValues(DeviceUseStatement dst) {
1280        super.copyValues(dst);
1281        if (identifier != null) {
1282          dst.identifier = new ArrayList<Identifier>();
1283          for (Identifier i : identifier)
1284            dst.identifier.add(i.copy());
1285        };
1286        if (basedOn != null) {
1287          dst.basedOn = new ArrayList<Reference>();
1288          for (Reference i : basedOn)
1289            dst.basedOn.add(i.copy());
1290        };
1291        dst.status = status == null ? null : status.copy();
1292        dst.subject = subject == null ? null : subject.copy();
1293        if (derivedFrom != null) {
1294          dst.derivedFrom = new ArrayList<Reference>();
1295          for (Reference i : derivedFrom)
1296            dst.derivedFrom.add(i.copy());
1297        };
1298        dst.timing = timing == null ? null : timing.copy();
1299        dst.recordedOn = recordedOn == null ? null : recordedOn.copy();
1300        dst.source = source == null ? null : source.copy();
1301        dst.device = device == null ? null : device.copy();
1302        if (reasonCode != null) {
1303          dst.reasonCode = new ArrayList<CodeableConcept>();
1304          for (CodeableConcept i : reasonCode)
1305            dst.reasonCode.add(i.copy());
1306        };
1307        if (reasonReference != null) {
1308          dst.reasonReference = new ArrayList<Reference>();
1309          for (Reference i : reasonReference)
1310            dst.reasonReference.add(i.copy());
1311        };
1312        dst.bodySite = bodySite == null ? null : bodySite.copy();
1313        if (note != null) {
1314          dst.note = new ArrayList<Annotation>();
1315          for (Annotation i : note)
1316            dst.note.add(i.copy());
1317        };
1318      }
1319
1320      protected DeviceUseStatement typedCopy() {
1321        return copy();
1322      }
1323
1324      @Override
1325      public boolean equalsDeep(Base other_) {
1326        if (!super.equalsDeep(other_))
1327          return false;
1328        if (!(other_ instanceof DeviceUseStatement))
1329          return false;
1330        DeviceUseStatement o = (DeviceUseStatement) other_;
1331        return compareDeep(identifier, o.identifier, true) && compareDeep(basedOn, o.basedOn, true) && compareDeep(status, o.status, true)
1332           && compareDeep(subject, o.subject, true) && compareDeep(derivedFrom, o.derivedFrom, true) && compareDeep(timing, o.timing, true)
1333           && compareDeep(recordedOn, o.recordedOn, true) && compareDeep(source, o.source, true) && compareDeep(device, o.device, true)
1334           && compareDeep(reasonCode, o.reasonCode, true) && compareDeep(reasonReference, o.reasonReference, true)
1335           && compareDeep(bodySite, o.bodySite, true) && compareDeep(note, o.note, true);
1336      }
1337
1338      @Override
1339      public boolean equalsShallow(Base other_) {
1340        if (!super.equalsShallow(other_))
1341          return false;
1342        if (!(other_ instanceof DeviceUseStatement))
1343          return false;
1344        DeviceUseStatement o = (DeviceUseStatement) other_;
1345        return compareValues(status, o.status, true) && compareValues(recordedOn, o.recordedOn, true);
1346      }
1347
1348      public boolean isEmpty() {
1349        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(identifier, basedOn, status
1350          , subject, derivedFrom, timing, recordedOn, source, device, reasonCode, reasonReference
1351          , bodySite, note);
1352      }
1353
1354  @Override
1355  public ResourceType getResourceType() {
1356    return ResourceType.DeviceUseStatement;
1357   }
1358
1359 /**
1360   * Search parameter: <b>identifier</b>
1361   * <p>
1362   * Description: <b>Search by identifier</b><br>
1363   * Type: <b>token</b><br>
1364   * Path: <b>DeviceUseStatement.identifier</b><br>
1365   * </p>
1366   */
1367  @SearchParamDefinition(name="identifier", path="DeviceUseStatement.identifier", description="Search by identifier", type="token" )
1368  public static final String SP_IDENTIFIER = "identifier";
1369 /**
1370   * <b>Fluent Client</b> search parameter constant for <b>identifier</b>
1371   * <p>
1372   * Description: <b>Search by identifier</b><br>
1373   * Type: <b>token</b><br>
1374   * Path: <b>DeviceUseStatement.identifier</b><br>
1375   * </p>
1376   */
1377  public static final ca.uhn.fhir.rest.gclient.TokenClientParam IDENTIFIER = new ca.uhn.fhir.rest.gclient.TokenClientParam(SP_IDENTIFIER);
1378
1379 /**
1380   * Search parameter: <b>subject</b>
1381   * <p>
1382   * Description: <b>Search by subject</b><br>
1383   * Type: <b>reference</b><br>
1384   * Path: <b>DeviceUseStatement.subject</b><br>
1385   * </p>
1386   */
1387  @SearchParamDefinition(name="subject", path="DeviceUseStatement.subject", description="Search by subject", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Patient") }, target={Group.class, Patient.class } )
1388  public static final String SP_SUBJECT = "subject";
1389 /**
1390   * <b>Fluent Client</b> search parameter constant for <b>subject</b>
1391   * <p>
1392   * Description: <b>Search by subject</b><br>
1393   * Type: <b>reference</b><br>
1394   * Path: <b>DeviceUseStatement.subject</b><br>
1395   * </p>
1396   */
1397  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam SUBJECT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_SUBJECT);
1398
1399/**
1400   * Constant for fluent queries to be used to add include statements. Specifies
1401   * the path value of "<b>DeviceUseStatement:subject</b>".
1402   */
1403  public static final ca.uhn.fhir.model.api.Include INCLUDE_SUBJECT = new ca.uhn.fhir.model.api.Include("DeviceUseStatement:subject").toLocked();
1404
1405 /**
1406   * Search parameter: <b>patient</b>
1407   * <p>
1408   * Description: <b>Search by subject - a patient</b><br>
1409   * Type: <b>reference</b><br>
1410   * Path: <b>DeviceUseStatement.subject</b><br>
1411   * </p>
1412   */
1413  @SearchParamDefinition(name="patient", path="DeviceUseStatement.subject", description="Search by subject - a patient", type="reference", target={Group.class, Patient.class } )
1414  public static final String SP_PATIENT = "patient";
1415 /**
1416   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
1417   * <p>
1418   * Description: <b>Search by subject - a patient</b><br>
1419   * Type: <b>reference</b><br>
1420   * Path: <b>DeviceUseStatement.subject</b><br>
1421   * </p>
1422   */
1423  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_PATIENT);
1424
1425/**
1426   * Constant for fluent queries to be used to add include statements. Specifies
1427   * the path value of "<b>DeviceUseStatement:patient</b>".
1428   */
1429  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include("DeviceUseStatement:patient").toLocked();
1430
1431 /**
1432   * Search parameter: <b>device</b>
1433   * <p>
1434   * Description: <b>Search by device</b><br>
1435   * Type: <b>reference</b><br>
1436   * Path: <b>DeviceUseStatement.device</b><br>
1437   * </p>
1438   */
1439  @SearchParamDefinition(name="device", path="DeviceUseStatement.device", description="Search by device", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Device") }, target={Device.class } )
1440  public static final String SP_DEVICE = "device";
1441 /**
1442   * <b>Fluent Client</b> search parameter constant for <b>device</b>
1443   * <p>
1444   * Description: <b>Search by device</b><br>
1445   * Type: <b>reference</b><br>
1446   * Path: <b>DeviceUseStatement.device</b><br>
1447   * </p>
1448   */
1449  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam DEVICE = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(SP_DEVICE);
1450
1451/**
1452   * Constant for fluent queries to be used to add include statements. Specifies
1453   * the path value of "<b>DeviceUseStatement:device</b>".
1454   */
1455  public static final ca.uhn.fhir.model.api.Include INCLUDE_DEVICE = new ca.uhn.fhir.model.api.Include("DeviceUseStatement:device").toLocked();
1456
1457
1458}