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