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