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