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