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;
038import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045
046/**
047 * Provenance of a resource is a record that describes entities and processes
048 * involved in producing and delivering or otherwise influencing that resource.
049 * Provenance provides a critical foundation for assessing authenticity,
050 * enabling trust, and allowing reproducibility. Provenance assertions are a
051 * form of contextual metadata and can themselves become important records with
052 * their own provenance. Provenance statement indicates clinical significance in
053 * terms of confidence in authenticity, reliability, and trustworthiness,
054 * integrity, and stage in lifecycle (e.g. Document Completion - has the
055 * artifact been legally authenticated), all of which may impact security,
056 * privacy, and trust policies.
057 */
058@ResourceDef(name = "Provenance", profile = "http://hl7.org/fhir/StructureDefinition/Provenance")
059public class Provenance extends DomainResource {
060
061  public enum ProvenanceEntityRole {
062    /**
063     * A transformation of an entity into another, an update of an entity resulting
064     * in a new one, or the construction of a new entity based on a pre-existing
065     * entity.
066     */
067    DERIVATION,
068    /**
069     * A derivation for which the resulting entity is a revised version of some
070     * original.
071     */
072    REVISION,
073    /**
074     * The repeat of (some or all of) an entity, such as text or image, by someone
075     * who might or might not be its original author.
076     */
077    QUOTATION,
078    /**
079     * A primary source for a topic refers to something produced by some agent with
080     * direct experience and knowledge about the topic, at the time of the topic's
081     * study, without benefit from hindsight.
082     */
083    SOURCE,
084    /**
085     * A derivation for which the entity is removed from accessibility usually
086     * through the use of the Delete operation.
087     */
088    REMOVAL,
089    /**
090     * added to help the parsers with the generic types
091     */
092    NULL;
093
094    public static ProvenanceEntityRole fromCode(String codeString) throws FHIRException {
095      if (codeString == null || "".equals(codeString))
096        return null;
097      if ("derivation".equals(codeString))
098        return DERIVATION;
099      if ("revision".equals(codeString))
100        return REVISION;
101      if ("quotation".equals(codeString))
102        return QUOTATION;
103      if ("source".equals(codeString))
104        return SOURCE;
105      if ("removal".equals(codeString))
106        return REMOVAL;
107      if (Configuration.isAcceptInvalidEnums())
108        return null;
109      else
110        throw new FHIRException("Unknown ProvenanceEntityRole code '" + codeString + "'");
111    }
112
113    public String toCode() {
114      switch (this) {
115      case DERIVATION:
116        return "derivation";
117      case REVISION:
118        return "revision";
119      case QUOTATION:
120        return "quotation";
121      case SOURCE:
122        return "source";
123      case REMOVAL:
124        return "removal";
125      case NULL:
126        return null;
127      default:
128        return "?";
129      }
130    }
131
132    public String getSystem() {
133      switch (this) {
134      case DERIVATION:
135        return "http://hl7.org/fhir/provenance-entity-role";
136      case REVISION:
137        return "http://hl7.org/fhir/provenance-entity-role";
138      case QUOTATION:
139        return "http://hl7.org/fhir/provenance-entity-role";
140      case SOURCE:
141        return "http://hl7.org/fhir/provenance-entity-role";
142      case REMOVAL:
143        return "http://hl7.org/fhir/provenance-entity-role";
144      case NULL:
145        return null;
146      default:
147        return "?";
148      }
149    }
150
151    public String getDefinition() {
152      switch (this) {
153      case DERIVATION:
154        return "A transformation of an entity into another, an update of an entity resulting in a new one, or the construction of a new entity based on a pre-existing entity.";
155      case REVISION:
156        return "A derivation for which the resulting entity is a revised version of some original.";
157      case QUOTATION:
158        return "The repeat of (some or all of) an entity, such as text or image, by someone who might or might not be its original author.";
159      case SOURCE:
160        return "A primary source for a topic refers to something produced by some agent with direct experience and knowledge about the topic, at the time of the topic's study, without benefit from hindsight.";
161      case REMOVAL:
162        return "A derivation for which the entity is removed from accessibility usually through the use of the Delete operation.";
163      case NULL:
164        return null;
165      default:
166        return "?";
167      }
168    }
169
170    public String getDisplay() {
171      switch (this) {
172      case DERIVATION:
173        return "Derivation";
174      case REVISION:
175        return "Revision";
176      case QUOTATION:
177        return "Quotation";
178      case SOURCE:
179        return "Source";
180      case REMOVAL:
181        return "Removal";
182      case NULL:
183        return null;
184      default:
185        return "?";
186      }
187    }
188  }
189
190  public static class ProvenanceEntityRoleEnumFactory implements EnumFactory<ProvenanceEntityRole> {
191    public ProvenanceEntityRole fromCode(String codeString) throws IllegalArgumentException {
192      if (codeString == null || "".equals(codeString))
193        if (codeString == null || "".equals(codeString))
194          return null;
195      if ("derivation".equals(codeString))
196        return ProvenanceEntityRole.DERIVATION;
197      if ("revision".equals(codeString))
198        return ProvenanceEntityRole.REVISION;
199      if ("quotation".equals(codeString))
200        return ProvenanceEntityRole.QUOTATION;
201      if ("source".equals(codeString))
202        return ProvenanceEntityRole.SOURCE;
203      if ("removal".equals(codeString))
204        return ProvenanceEntityRole.REMOVAL;
205      throw new IllegalArgumentException("Unknown ProvenanceEntityRole code '" + codeString + "'");
206    }
207
208    public Enumeration<ProvenanceEntityRole> fromType(PrimitiveType<?> code) throws FHIRException {
209      if (code == null)
210        return null;
211      if (code.isEmpty())
212        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.NULL, code);
213      String codeString = code.asStringValue();
214      if (codeString == null || "".equals(codeString))
215        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.NULL, code);
216      if ("derivation".equals(codeString))
217        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.DERIVATION, code);
218      if ("revision".equals(codeString))
219        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.REVISION, code);
220      if ("quotation".equals(codeString))
221        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.QUOTATION, code);
222      if ("source".equals(codeString))
223        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.SOURCE, code);
224      if ("removal".equals(codeString))
225        return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.REMOVAL, code);
226      throw new FHIRException("Unknown ProvenanceEntityRole code '" + codeString + "'");
227    }
228
229    public String toCode(ProvenanceEntityRole code) {
230      if (code == ProvenanceEntityRole.DERIVATION)
231        return "derivation";
232      if (code == ProvenanceEntityRole.REVISION)
233        return "revision";
234      if (code == ProvenanceEntityRole.QUOTATION)
235        return "quotation";
236      if (code == ProvenanceEntityRole.SOURCE)
237        return "source";
238      if (code == ProvenanceEntityRole.REMOVAL)
239        return "removal";
240      return "?";
241    }
242
243    public String toSystem(ProvenanceEntityRole code) {
244      return code.getSystem();
245    }
246  }
247
248  @Block()
249  public static class ProvenanceAgentComponent extends BackboneElement implements IBaseBackboneElement {
250    /**
251     * The participation the agent had with respect to the activity.
252     */
253    @Child(name = "type", type = {
254        CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
255    @Description(shortDefinition = "How the agent participated", formalDefinition = "The participation the agent had with respect to the activity.")
256    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/provenance-agent-type")
257    protected CodeableConcept type;
258
259    /**
260     * The function of the agent with respect to the activity. The security role
261     * enabling the agent with respect to the activity.
262     */
263    @Child(name = "role", type = {
264        CodeableConcept.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
265    @Description(shortDefinition = "What the agents role was", formalDefinition = "The function of the agent with respect to the activity. The security role enabling the agent with respect to the activity.")
266    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/security-role-type")
267    protected List<CodeableConcept> role;
268
269    /**
270     * The individual, device or organization that participated in the event.
271     */
272    @Child(name = "who", type = { Practitioner.class, PractitionerRole.class, RelatedPerson.class, Patient.class,
273        Device.class, Organization.class }, order = 3, min = 1, max = 1, modifier = false, summary = true)
274    @Description(shortDefinition = "Who participated", formalDefinition = "The individual, device or organization that participated in the event.")
275    protected Reference who;
276
277    /**
278     * The actual object that is the target of the reference (The individual, device
279     * or organization that participated in the event.)
280     */
281    protected Resource whoTarget;
282
283    /**
284     * The individual, device, or organization for whom the change was made.
285     */
286    @Child(name = "onBehalfOf", type = { Practitioner.class, PractitionerRole.class, RelatedPerson.class, Patient.class,
287        Device.class, Organization.class }, order = 4, min = 0, max = 1, modifier = false, summary = false)
288    @Description(shortDefinition = "Who the agent is representing", formalDefinition = "The individual, device, or organization for whom the change was made.")
289    protected Reference onBehalfOf;
290
291    /**
292     * The actual object that is the target of the reference (The individual,
293     * device, or organization for whom the change was made.)
294     */
295    protected Resource onBehalfOfTarget;
296
297    private static final long serialVersionUID = -1363252586L;
298
299    /**
300     * Constructor
301     */
302    public ProvenanceAgentComponent() {
303      super();
304    }
305
306    /**
307     * Constructor
308     */
309    public ProvenanceAgentComponent(Reference who) {
310      super();
311      this.who = who;
312    }
313
314    /**
315     * @return {@link #type} (The participation the agent had with respect to the
316     *         activity.)
317     */
318    public CodeableConcept getType() {
319      if (this.type == null)
320        if (Configuration.errorOnAutoCreate())
321          throw new Error("Attempt to auto-create ProvenanceAgentComponent.type");
322        else if (Configuration.doAutoCreate())
323          this.type = new CodeableConcept(); // cc
324      return this.type;
325    }
326
327    public boolean hasType() {
328      return this.type != null && !this.type.isEmpty();
329    }
330
331    /**
332     * @param value {@link #type} (The participation the agent had with respect to
333     *              the activity.)
334     */
335    public ProvenanceAgentComponent setType(CodeableConcept value) {
336      this.type = value;
337      return this;
338    }
339
340    /**
341     * @return {@link #role} (The function of the agent with respect to the
342     *         activity. The security role enabling the agent with respect to the
343     *         activity.)
344     */
345    public List<CodeableConcept> getRole() {
346      if (this.role == null)
347        this.role = new ArrayList<CodeableConcept>();
348      return this.role;
349    }
350
351    /**
352     * @return Returns a reference to <code>this</code> for easy method chaining
353     */
354    public ProvenanceAgentComponent setRole(List<CodeableConcept> theRole) {
355      this.role = theRole;
356      return this;
357    }
358
359    public boolean hasRole() {
360      if (this.role == null)
361        return false;
362      for (CodeableConcept item : this.role)
363        if (!item.isEmpty())
364          return true;
365      return false;
366    }
367
368    public CodeableConcept addRole() { // 3
369      CodeableConcept t = new CodeableConcept();
370      if (this.role == null)
371        this.role = new ArrayList<CodeableConcept>();
372      this.role.add(t);
373      return t;
374    }
375
376    public ProvenanceAgentComponent addRole(CodeableConcept t) { // 3
377      if (t == null)
378        return this;
379      if (this.role == null)
380        this.role = new ArrayList<CodeableConcept>();
381      this.role.add(t);
382      return this;
383    }
384
385    /**
386     * @return The first repetition of repeating field {@link #role}, creating it if
387     *         it does not already exist
388     */
389    public CodeableConcept getRoleFirstRep() {
390      if (getRole().isEmpty()) {
391        addRole();
392      }
393      return getRole().get(0);
394    }
395
396    /**
397     * @return {@link #who} (The individual, device or organization that
398     *         participated in the event.)
399     */
400    public Reference getWho() {
401      if (this.who == null)
402        if (Configuration.errorOnAutoCreate())
403          throw new Error("Attempt to auto-create ProvenanceAgentComponent.who");
404        else if (Configuration.doAutoCreate())
405          this.who = new Reference(); // cc
406      return this.who;
407    }
408
409    public boolean hasWho() {
410      return this.who != null && !this.who.isEmpty();
411    }
412
413    /**
414     * @param value {@link #who} (The individual, device or organization that
415     *              participated in the event.)
416     */
417    public ProvenanceAgentComponent setWho(Reference value) {
418      this.who = value;
419      return this;
420    }
421
422    /**
423     * @return {@link #who} The actual object that is the target of the reference.
424     *         The reference library doesn't populate this, but you can use it to
425     *         hold the resource if you resolve it. (The individual, device or
426     *         organization that participated in the event.)
427     */
428    public Resource getWhoTarget() {
429      return this.whoTarget;
430    }
431
432    /**
433     * @param value {@link #who} The actual object that is the target of the
434     *              reference. The reference library doesn't use these, but you can
435     *              use it to hold the resource if you resolve it. (The individual,
436     *              device or organization that participated in the event.)
437     */
438    public ProvenanceAgentComponent setWhoTarget(Resource value) {
439      this.whoTarget = value;
440      return this;
441    }
442
443    /**
444     * @return {@link #onBehalfOf} (The individual, device, or organization for whom
445     *         the change was made.)
446     */
447    public Reference getOnBehalfOf() {
448      if (this.onBehalfOf == null)
449        if (Configuration.errorOnAutoCreate())
450          throw new Error("Attempt to auto-create ProvenanceAgentComponent.onBehalfOf");
451        else if (Configuration.doAutoCreate())
452          this.onBehalfOf = new Reference(); // cc
453      return this.onBehalfOf;
454    }
455
456    public boolean hasOnBehalfOf() {
457      return this.onBehalfOf != null && !this.onBehalfOf.isEmpty();
458    }
459
460    /**
461     * @param value {@link #onBehalfOf} (The individual, device, or organization for
462     *              whom the change was made.)
463     */
464    public ProvenanceAgentComponent setOnBehalfOf(Reference value) {
465      this.onBehalfOf = value;
466      return this;
467    }
468
469    /**
470     * @return {@link #onBehalfOf} The actual object that is the target of the
471     *         reference. The reference library doesn't populate this, but you can
472     *         use it to hold the resource if you resolve it. (The individual,
473     *         device, or organization for whom the change was made.)
474     */
475    public Resource getOnBehalfOfTarget() {
476      return this.onBehalfOfTarget;
477    }
478
479    /**
480     * @param value {@link #onBehalfOf} The actual object that is the target of the
481     *              reference. The reference library doesn't use these, but you can
482     *              use it to hold the resource if you resolve it. (The individual,
483     *              device, or organization for whom the change was made.)
484     */
485    public ProvenanceAgentComponent setOnBehalfOfTarget(Resource value) {
486      this.onBehalfOfTarget = value;
487      return this;
488    }
489
490    protected void listChildren(List<Property> children) {
491      super.listChildren(children);
492      children.add(new Property("type", "CodeableConcept",
493          "The participation the agent had with respect to the activity.", 0, 1, type));
494      children.add(new Property("role", "CodeableConcept",
495          "The function of the agent with respect to the activity. The security role enabling the agent with respect to the activity.",
496          0, java.lang.Integer.MAX_VALUE, role));
497      children
498          .add(new Property("who", "Reference(Practitioner|PractitionerRole|RelatedPerson|Patient|Device|Organization)",
499              "The individual, device or organization that participated in the event.", 0, 1, who));
500      children.add(new Property("onBehalfOf",
501          "Reference(Practitioner|PractitionerRole|RelatedPerson|Patient|Device|Organization)",
502          "The individual, device, or organization for whom the change was made.", 0, 1, onBehalfOf));
503    }
504
505    @Override
506    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
507      switch (_hash) {
508      case 3575610:
509        /* type */ return new Property("type", "CodeableConcept",
510            "The participation the agent had with respect to the activity.", 0, 1, type);
511      case 3506294:
512        /* role */ return new Property("role", "CodeableConcept",
513            "The function of the agent with respect to the activity. The security role enabling the agent with respect to the activity.",
514            0, java.lang.Integer.MAX_VALUE, role);
515      case 117694:
516        /* who */ return new Property("who",
517            "Reference(Practitioner|PractitionerRole|RelatedPerson|Patient|Device|Organization)",
518            "The individual, device or organization that participated in the event.", 0, 1, who);
519      case -14402964:
520        /* onBehalfOf */ return new Property("onBehalfOf",
521            "Reference(Practitioner|PractitionerRole|RelatedPerson|Patient|Device|Organization)",
522            "The individual, device, or organization for whom the change was made.", 0, 1, onBehalfOf);
523      default:
524        return super.getNamedProperty(_hash, _name, _checkValid);
525      }
526
527    }
528
529    @Override
530    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
531      switch (hash) {
532      case 3575610:
533        /* type */ return this.type == null ? new Base[0] : new Base[] { this.type }; // CodeableConcept
534      case 3506294:
535        /* role */ return this.role == null ? new Base[0] : this.role.toArray(new Base[this.role.size()]); // CodeableConcept
536      case 117694:
537        /* who */ return this.who == null ? new Base[0] : new Base[] { this.who }; // Reference
538      case -14402964:
539        /* onBehalfOf */ return this.onBehalfOf == null ? new Base[0] : new Base[] { this.onBehalfOf }; // Reference
540      default:
541        return super.getProperty(hash, name, checkValid);
542      }
543
544    }
545
546    @Override
547    public Base setProperty(int hash, String name, Base value) throws FHIRException {
548      switch (hash) {
549      case 3575610: // type
550        this.type = castToCodeableConcept(value); // CodeableConcept
551        return value;
552      case 3506294: // role
553        this.getRole().add(castToCodeableConcept(value)); // CodeableConcept
554        return value;
555      case 117694: // who
556        this.who = castToReference(value); // Reference
557        return value;
558      case -14402964: // onBehalfOf
559        this.onBehalfOf = castToReference(value); // Reference
560        return value;
561      default:
562        return super.setProperty(hash, name, value);
563      }
564
565    }
566
567    @Override
568    public Base setProperty(String name, Base value) throws FHIRException {
569      if (name.equals("type")) {
570        this.type = castToCodeableConcept(value); // CodeableConcept
571      } else if (name.equals("role")) {
572        this.getRole().add(castToCodeableConcept(value));
573      } else if (name.equals("who")) {
574        this.who = castToReference(value); // Reference
575      } else if (name.equals("onBehalfOf")) {
576        this.onBehalfOf = castToReference(value); // Reference
577      } else
578        return super.setProperty(name, value);
579      return value;
580    }
581
582  @Override
583  public void removeChild(String name, Base value) throws FHIRException {
584      if (name.equals("type")) {
585        this.type = null;
586      } else if (name.equals("role")) {
587        this.getRole().remove(castToCodeableConcept(value));
588      } else if (name.equals("who")) {
589        this.who = null;
590      } else if (name.equals("onBehalfOf")) {
591        this.onBehalfOf = null;
592      } else
593        super.removeChild(name, value);
594      
595    }
596
597    @Override
598    public Base makeProperty(int hash, String name) throws FHIRException {
599      switch (hash) {
600      case 3575610:
601        return getType();
602      case 3506294:
603        return addRole();
604      case 117694:
605        return getWho();
606      case -14402964:
607        return getOnBehalfOf();
608      default:
609        return super.makeProperty(hash, name);
610      }
611
612    }
613
614    @Override
615    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
616      switch (hash) {
617      case 3575610:
618        /* type */ return new String[] { "CodeableConcept" };
619      case 3506294:
620        /* role */ return new String[] { "CodeableConcept" };
621      case 117694:
622        /* who */ return new String[] { "Reference" };
623      case -14402964:
624        /* onBehalfOf */ return new String[] { "Reference" };
625      default:
626        return super.getTypesForProperty(hash, name);
627      }
628
629    }
630
631    @Override
632    public Base addChild(String name) throws FHIRException {
633      if (name.equals("type")) {
634        this.type = new CodeableConcept();
635        return this.type;
636      } else if (name.equals("role")) {
637        return addRole();
638      } else if (name.equals("who")) {
639        this.who = new Reference();
640        return this.who;
641      } else if (name.equals("onBehalfOf")) {
642        this.onBehalfOf = new Reference();
643        return this.onBehalfOf;
644      } else
645        return super.addChild(name);
646    }
647
648    public ProvenanceAgentComponent copy() {
649      ProvenanceAgentComponent dst = new ProvenanceAgentComponent();
650      copyValues(dst);
651      return dst;
652    }
653
654    public void copyValues(ProvenanceAgentComponent dst) {
655      super.copyValues(dst);
656      dst.type = type == null ? null : type.copy();
657      if (role != null) {
658        dst.role = new ArrayList<CodeableConcept>();
659        for (CodeableConcept i : role)
660          dst.role.add(i.copy());
661      }
662      ;
663      dst.who = who == null ? null : who.copy();
664      dst.onBehalfOf = onBehalfOf == null ? null : onBehalfOf.copy();
665    }
666
667    @Override
668    public boolean equalsDeep(Base other_) {
669      if (!super.equalsDeep(other_))
670        return false;
671      if (!(other_ instanceof ProvenanceAgentComponent))
672        return false;
673      ProvenanceAgentComponent o = (ProvenanceAgentComponent) other_;
674      return compareDeep(type, o.type, true) && compareDeep(role, o.role, true) && compareDeep(who, o.who, true)
675          && compareDeep(onBehalfOf, o.onBehalfOf, true);
676    }
677
678    @Override
679    public boolean equalsShallow(Base other_) {
680      if (!super.equalsShallow(other_))
681        return false;
682      if (!(other_ instanceof ProvenanceAgentComponent))
683        return false;
684      ProvenanceAgentComponent o = (ProvenanceAgentComponent) other_;
685      return true;
686    }
687
688    public boolean isEmpty() {
689      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, role, who, onBehalfOf);
690    }
691
692    public String fhirType() {
693      return "Provenance.agent";
694
695    }
696
697  }
698
699  @Block()
700  public static class ProvenanceEntityComponent extends BackboneElement implements IBaseBackboneElement {
701    /**
702     * How the entity was used during the activity.
703     */
704    @Child(name = "role", type = { CodeType.class }, order = 1, min = 1, max = 1, modifier = false, summary = true)
705    @Description(shortDefinition = "derivation | revision | quotation | source | removal", formalDefinition = "How the entity was used during the activity.")
706    @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/provenance-entity-role")
707    protected Enumeration<ProvenanceEntityRole> role;
708
709    /**
710     * Identity of the Entity used. May be a logical or physical uri and maybe
711     * absolute or relative.
712     */
713    @Child(name = "what", type = { Reference.class }, order = 2, min = 1, max = 1, modifier = false, summary = true)
714    @Description(shortDefinition = "Identity of entity", formalDefinition = "Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.")
715    protected Reference what;
716
717    /**
718     * The actual object that is the target of the reference (Identity of the Entity
719     * used. May be a logical or physical uri and maybe absolute or relative.)
720     */
721    protected Resource whatTarget;
722
723    /**
724     * The entity is attributed to an agent to express the agent's responsibility
725     * for that entity, possibly along with other agents. This description can be
726     * understood as shorthand for saying that the agent was responsible for the
727     * activity which generated the entity.
728     */
729    @Child(name = "agent", type = {
730        ProvenanceAgentComponent.class }, order = 3, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
731    @Description(shortDefinition = "Entity is attributed to this agent", formalDefinition = "The entity is attributed to an agent to express the agent's responsibility for that entity, possibly along with other agents. This description can be understood as shorthand for saying that the agent was responsible for the activity which generated the entity.")
732    protected List<ProvenanceAgentComponent> agent;
733
734    private static final long serialVersionUID = 144967401L;
735
736    /**
737     * Constructor
738     */
739    public ProvenanceEntityComponent() {
740      super();
741    }
742
743    /**
744     * Constructor
745     */
746    public ProvenanceEntityComponent(Enumeration<ProvenanceEntityRole> role, Reference what) {
747      super();
748      this.role = role;
749      this.what = what;
750    }
751
752    /**
753     * @return {@link #role} (How the entity was used during the activity.). This is
754     *         the underlying object with id, value and extensions. The accessor
755     *         "getRole" gives direct access to the value
756     */
757    public Enumeration<ProvenanceEntityRole> getRoleElement() {
758      if (this.role == null)
759        if (Configuration.errorOnAutoCreate())
760          throw new Error("Attempt to auto-create ProvenanceEntityComponent.role");
761        else if (Configuration.doAutoCreate())
762          this.role = new Enumeration<ProvenanceEntityRole>(new ProvenanceEntityRoleEnumFactory()); // bb
763      return this.role;
764    }
765
766    public boolean hasRoleElement() {
767      return this.role != null && !this.role.isEmpty();
768    }
769
770    public boolean hasRole() {
771      return this.role != null && !this.role.isEmpty();
772    }
773
774    /**
775     * @param value {@link #role} (How the entity was used during the activity.).
776     *              This is the underlying object with id, value and extensions. The
777     *              accessor "getRole" gives direct access to the value
778     */
779    public ProvenanceEntityComponent setRoleElement(Enumeration<ProvenanceEntityRole> value) {
780      this.role = value;
781      return this;
782    }
783
784    /**
785     * @return How the entity was used during the activity.
786     */
787    public ProvenanceEntityRole getRole() {
788      return this.role == null ? null : this.role.getValue();
789    }
790
791    /**
792     * @param value How the entity was used during the activity.
793     */
794    public ProvenanceEntityComponent setRole(ProvenanceEntityRole value) {
795      if (this.role == null)
796        this.role = new Enumeration<ProvenanceEntityRole>(new ProvenanceEntityRoleEnumFactory());
797      this.role.setValue(value);
798      return this;
799    }
800
801    /**
802     * @return {@link #what} (Identity of the Entity used. May be a logical or
803     *         physical uri and maybe absolute or relative.)
804     */
805    public Reference getWhat() {
806      if (this.what == null)
807        if (Configuration.errorOnAutoCreate())
808          throw new Error("Attempt to auto-create ProvenanceEntityComponent.what");
809        else if (Configuration.doAutoCreate())
810          this.what = new Reference(); // cc
811      return this.what;
812    }
813
814    public boolean hasWhat() {
815      return this.what != null && !this.what.isEmpty();
816    }
817
818    /**
819     * @param value {@link #what} (Identity of the Entity used. May be a logical or
820     *              physical uri and maybe absolute or relative.)
821     */
822    public ProvenanceEntityComponent setWhat(Reference value) {
823      this.what = value;
824      return this;
825    }
826
827    /**
828     * @return {@link #what} The actual object that is the target of the reference.
829     *         The reference library doesn't populate this, but you can use it to
830     *         hold the resource if you resolve it. (Identity of the Entity used.
831     *         May be a logical or physical uri and maybe absolute or relative.)
832     */
833    public Resource getWhatTarget() {
834      return this.whatTarget;
835    }
836
837    /**
838     * @param value {@link #what} The actual object that is the target of the
839     *              reference. The reference library doesn't use these, but you can
840     *              use it to hold the resource if you resolve it. (Identity of the
841     *              Entity used. May be a logical or physical uri and maybe absolute
842     *              or relative.)
843     */
844    public ProvenanceEntityComponent setWhatTarget(Resource value) {
845      this.whatTarget = value;
846      return this;
847    }
848
849    /**
850     * @return {@link #agent} (The entity is attributed to an agent to express the
851     *         agent's responsibility for that entity, possibly along with other
852     *         agents. This description can be understood as shorthand for saying
853     *         that the agent was responsible for the activity which generated the
854     *         entity.)
855     */
856    public List<ProvenanceAgentComponent> getAgent() {
857      if (this.agent == null)
858        this.agent = new ArrayList<ProvenanceAgentComponent>();
859      return this.agent;
860    }
861
862    /**
863     * @return Returns a reference to <code>this</code> for easy method chaining
864     */
865    public ProvenanceEntityComponent setAgent(List<ProvenanceAgentComponent> theAgent) {
866      this.agent = theAgent;
867      return this;
868    }
869
870    public boolean hasAgent() {
871      if (this.agent == null)
872        return false;
873      for (ProvenanceAgentComponent item : this.agent)
874        if (!item.isEmpty())
875          return true;
876      return false;
877    }
878
879    public ProvenanceAgentComponent addAgent() { // 3
880      ProvenanceAgentComponent t = new ProvenanceAgentComponent();
881      if (this.agent == null)
882        this.agent = new ArrayList<ProvenanceAgentComponent>();
883      this.agent.add(t);
884      return t;
885    }
886
887    public ProvenanceEntityComponent addAgent(ProvenanceAgentComponent t) { // 3
888      if (t == null)
889        return this;
890      if (this.agent == null)
891        this.agent = new ArrayList<ProvenanceAgentComponent>();
892      this.agent.add(t);
893      return this;
894    }
895
896    /**
897     * @return The first repetition of repeating field {@link #agent}, creating it
898     *         if it does not already exist
899     */
900    public ProvenanceAgentComponent getAgentFirstRep() {
901      if (getAgent().isEmpty()) {
902        addAgent();
903      }
904      return getAgent().get(0);
905    }
906
907    protected void listChildren(List<Property> children) {
908      super.listChildren(children);
909      children.add(new Property("role", "code", "How the entity was used during the activity.", 0, 1, role));
910      children.add(new Property("what", "Reference(Any)",
911          "Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.", 0, 1,
912          what));
913      children.add(new Property("agent", "@Provenance.agent",
914          "The entity is attributed to an agent to express the agent's responsibility for that entity, possibly along with other agents. This description can be understood as shorthand for saying that the agent was responsible for the activity which generated the entity.",
915          0, java.lang.Integer.MAX_VALUE, agent));
916    }
917
918    @Override
919    public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
920      switch (_hash) {
921      case 3506294:
922        /* role */ return new Property("role", "code", "How the entity was used during the activity.", 0, 1, role);
923      case 3648196:
924        /* what */ return new Property("what", "Reference(Any)",
925            "Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.", 0, 1,
926            what);
927      case 92750597:
928        /* agent */ return new Property("agent", "@Provenance.agent",
929            "The entity is attributed to an agent to express the agent's responsibility for that entity, possibly along with other agents. This description can be understood as shorthand for saying that the agent was responsible for the activity which generated the entity.",
930            0, java.lang.Integer.MAX_VALUE, agent);
931      default:
932        return super.getNamedProperty(_hash, _name, _checkValid);
933      }
934
935    }
936
937    @Override
938    public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
939      switch (hash) {
940      case 3506294:
941        /* role */ return this.role == null ? new Base[0] : new Base[] { this.role }; // Enumeration<ProvenanceEntityRole>
942      case 3648196:
943        /* what */ return this.what == null ? new Base[0] : new Base[] { this.what }; // Reference
944      case 92750597:
945        /* agent */ return this.agent == null ? new Base[0] : this.agent.toArray(new Base[this.agent.size()]); // ProvenanceAgentComponent
946      default:
947        return super.getProperty(hash, name, checkValid);
948      }
949
950    }
951
952    @Override
953    public Base setProperty(int hash, String name, Base value) throws FHIRException {
954      switch (hash) {
955      case 3506294: // role
956        value = new ProvenanceEntityRoleEnumFactory().fromType(castToCode(value));
957        this.role = (Enumeration) value; // Enumeration<ProvenanceEntityRole>
958        return value;
959      case 3648196: // what
960        this.what = castToReference(value); // Reference
961        return value;
962      case 92750597: // agent
963        this.getAgent().add((ProvenanceAgentComponent) value); // ProvenanceAgentComponent
964        return value;
965      default:
966        return super.setProperty(hash, name, value);
967      }
968
969    }
970
971    @Override
972    public Base setProperty(String name, Base value) throws FHIRException {
973      if (name.equals("role")) {
974        value = new ProvenanceEntityRoleEnumFactory().fromType(castToCode(value));
975        this.role = (Enumeration) value; // Enumeration<ProvenanceEntityRole>
976      } else if (name.equals("what")) {
977        this.what = castToReference(value); // Reference
978      } else if (name.equals("agent")) {
979        this.getAgent().add((ProvenanceAgentComponent) value);
980      } else
981        return super.setProperty(name, value);
982      return value;
983    }
984
985  @Override
986  public void removeChild(String name, Base value) throws FHIRException {
987      if (name.equals("role")) {
988        this.role = null;
989      } else if (name.equals("what")) {
990        this.what = null;
991      } else if (name.equals("agent")) {
992        this.getAgent().remove((ProvenanceAgentComponent) value);
993      } else
994        super.removeChild(name, value);
995      
996    }
997
998    @Override
999    public Base makeProperty(int hash, String name) throws FHIRException {
1000      switch (hash) {
1001      case 3506294:
1002        return getRoleElement();
1003      case 3648196:
1004        return getWhat();
1005      case 92750597:
1006        return addAgent();
1007      default:
1008        return super.makeProperty(hash, name);
1009      }
1010
1011    }
1012
1013    @Override
1014    public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1015      switch (hash) {
1016      case 3506294:
1017        /* role */ return new String[] { "code" };
1018      case 3648196:
1019        /* what */ return new String[] { "Reference" };
1020      case 92750597:
1021        /* agent */ return new String[] { "@Provenance.agent" };
1022      default:
1023        return super.getTypesForProperty(hash, name);
1024      }
1025
1026    }
1027
1028    @Override
1029    public Base addChild(String name) throws FHIRException {
1030      if (name.equals("role")) {
1031        throw new FHIRException("Cannot call addChild on a singleton property Provenance.role");
1032      } else if (name.equals("what")) {
1033        this.what = new Reference();
1034        return this.what;
1035      } else if (name.equals("agent")) {
1036        return addAgent();
1037      } else
1038        return super.addChild(name);
1039    }
1040
1041    public ProvenanceEntityComponent copy() {
1042      ProvenanceEntityComponent dst = new ProvenanceEntityComponent();
1043      copyValues(dst);
1044      return dst;
1045    }
1046
1047    public void copyValues(ProvenanceEntityComponent dst) {
1048      super.copyValues(dst);
1049      dst.role = role == null ? null : role.copy();
1050      dst.what = what == null ? null : what.copy();
1051      if (agent != null) {
1052        dst.agent = new ArrayList<ProvenanceAgentComponent>();
1053        for (ProvenanceAgentComponent i : agent)
1054          dst.agent.add(i.copy());
1055      }
1056      ;
1057    }
1058
1059    @Override
1060    public boolean equalsDeep(Base other_) {
1061      if (!super.equalsDeep(other_))
1062        return false;
1063      if (!(other_ instanceof ProvenanceEntityComponent))
1064        return false;
1065      ProvenanceEntityComponent o = (ProvenanceEntityComponent) other_;
1066      return compareDeep(role, o.role, true) && compareDeep(what, o.what, true) && compareDeep(agent, o.agent, true);
1067    }
1068
1069    @Override
1070    public boolean equalsShallow(Base other_) {
1071      if (!super.equalsShallow(other_))
1072        return false;
1073      if (!(other_ instanceof ProvenanceEntityComponent))
1074        return false;
1075      ProvenanceEntityComponent o = (ProvenanceEntityComponent) other_;
1076      return compareValues(role, o.role, true);
1077    }
1078
1079    public boolean isEmpty() {
1080      return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(role, what, agent);
1081    }
1082
1083    public String fhirType() {
1084      return "Provenance.entity";
1085
1086    }
1087
1088  }
1089
1090  /**
1091   * The Reference(s) that were generated or updated by the activity described in
1092   * this resource. A provenance can point to more than one target if multiple
1093   * resources were created/updated by the same activity.
1094   */
1095  @Child(name = "target", type = {
1096      Reference.class }, order = 0, min = 1, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
1097  @Description(shortDefinition = "Target Reference(s) (usually version specific)", formalDefinition = "The Reference(s) that were generated or updated by  the activity described in this resource. A provenance can point to more than one target if multiple resources were created/updated by the same activity.")
1098  protected List<Reference> target;
1099  /**
1100   * The actual objects that are the target of the reference (The Reference(s)
1101   * that were generated or updated by the activity described in this resource. A
1102   * provenance can point to more than one target if multiple resources were
1103   * created/updated by the same activity.)
1104   */
1105  protected List<Resource> targetTarget;
1106
1107  /**
1108   * The period during which the activity occurred.
1109   */
1110  @Child(name = "occurred", type = { Period.class,
1111      DateTimeType.class }, order = 1, min = 0, max = 1, modifier = false, summary = false)
1112  @Description(shortDefinition = "When the activity occurred", formalDefinition = "The period during which the activity occurred.")
1113  protected Type occurred;
1114
1115  /**
1116   * The instant of time at which the activity was recorded.
1117   */
1118  @Child(name = "recorded", type = { InstantType.class }, order = 2, min = 1, max = 1, modifier = false, summary = true)
1119  @Description(shortDefinition = "When the activity was recorded / updated", formalDefinition = "The instant of time at which the activity was recorded.")
1120  protected InstantType recorded;
1121
1122  /**
1123   * Policy or plan the activity was defined by. Typically, a single activity may
1124   * have multiple applicable policy documents, such as patient consent, guarantor
1125   * funding, etc.
1126   */
1127  @Child(name = "policy", type = {
1128      UriType.class }, order = 3, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
1129  @Description(shortDefinition = "Policy or plan the activity was defined by", formalDefinition = "Policy or plan the activity was defined by. Typically, a single activity may have multiple applicable policy documents, such as patient consent, guarantor funding, etc.")
1130  protected List<UriType> policy;
1131
1132  /**
1133   * Where the activity occurred, if relevant.
1134   */
1135  @Child(name = "location", type = { Location.class }, order = 4, min = 0, max = 1, modifier = false, summary = false)
1136  @Description(shortDefinition = "Where the activity occurred, if relevant", formalDefinition = "Where the activity occurred, if relevant.")
1137  protected Reference location;
1138
1139  /**
1140   * The actual object that is the target of the reference (Where the activity
1141   * occurred, if relevant.)
1142   */
1143  protected Location locationTarget;
1144
1145  /**
1146   * The reason that the activity was taking place.
1147   */
1148  @Child(name = "reason", type = {
1149      CodeableConcept.class }, order = 5, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
1150  @Description(shortDefinition = "Reason the activity is occurring", formalDefinition = "The reason that the activity was taking place.")
1151  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://terminology.hl7.org/ValueSet/v3-PurposeOfUse")
1152  protected List<CodeableConcept> reason;
1153
1154  /**
1155   * An activity is something that occurs over a period of time and acts upon or
1156   * with entities; it may include consuming, processing, transforming, modifying,
1157   * relocating, using, or generating entities.
1158   */
1159  @Child(name = "activity", type = {
1160      CodeableConcept.class }, order = 6, min = 0, max = 1, modifier = false, summary = false)
1161  @Description(shortDefinition = "Activity that occurred", formalDefinition = "An activity is something that occurs over a period of time and acts upon or with entities; it may include consuming, processing, transforming, modifying, relocating, using, or generating entities.")
1162  @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/provenance-activity-type")
1163  protected CodeableConcept activity;
1164
1165  /**
1166   * An actor taking a role in an activity for which it can be assigned some
1167   * degree of responsibility for the activity taking place.
1168   */
1169  @Child(name = "agent", type = {}, order = 7, min = 1, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
1170  @Description(shortDefinition = "Actor involved", formalDefinition = "An actor taking a role in an activity  for which it can be assigned some degree of responsibility for the activity taking place.")
1171  protected List<ProvenanceAgentComponent> agent;
1172
1173  /**
1174   * An entity used in this activity.
1175   */
1176  @Child(name = "entity", type = {}, order = 8, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
1177  @Description(shortDefinition = "An entity used in this activity", formalDefinition = "An entity used in this activity.")
1178  protected List<ProvenanceEntityComponent> entity;
1179
1180  /**
1181   * A digital signature on the target Reference(s). The signer should match a
1182   * Provenance.agent. The purpose of the signature is indicated.
1183   */
1184  @Child(name = "signature", type = {
1185      Signature.class }, order = 9, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
1186  @Description(shortDefinition = "Signature on target", formalDefinition = "A digital signature on the target Reference(s). The signer should match a Provenance.agent. The purpose of the signature is indicated.")
1187  protected List<Signature> signature;
1188
1189  private static final long serialVersionUID = -1991881518L;
1190
1191  /**
1192   * Constructor
1193   */
1194  public Provenance() {
1195    super();
1196  }
1197
1198  /**
1199   * Constructor
1200   */
1201  public Provenance(InstantType recorded) {
1202    super();
1203    this.recorded = recorded;
1204  }
1205
1206  /**
1207   * @return {@link #target} (The Reference(s) that were generated or updated by
1208   *         the activity described in this resource. A provenance can point to
1209   *         more than one target if multiple resources were created/updated by
1210   *         the same activity.)
1211   */
1212  public List<Reference> getTarget() {
1213    if (this.target == null)
1214      this.target = new ArrayList<Reference>();
1215    return this.target;
1216  }
1217
1218  /**
1219   * @return Returns a reference to <code>this</code> for easy method chaining
1220   */
1221  public Provenance setTarget(List<Reference> theTarget) {
1222    this.target = theTarget;
1223    return this;
1224  }
1225
1226  public boolean hasTarget() {
1227    if (this.target == null)
1228      return false;
1229    for (Reference item : this.target)
1230      if (!item.isEmpty())
1231        return true;
1232    return false;
1233  }
1234
1235  public Reference addTarget() { // 3
1236    Reference t = new Reference();
1237    if (this.target == null)
1238      this.target = new ArrayList<Reference>();
1239    this.target.add(t);
1240    return t;
1241  }
1242
1243  public Provenance addTarget(Reference t) { // 3
1244    if (t == null)
1245      return this;
1246    if (this.target == null)
1247      this.target = new ArrayList<Reference>();
1248    this.target.add(t);
1249    return this;
1250  }
1251
1252  /**
1253   * @return The first repetition of repeating field {@link #target}, creating it
1254   *         if it does not already exist
1255   */
1256  public Reference getTargetFirstRep() {
1257    if (getTarget().isEmpty()) {
1258      addTarget();
1259    }
1260    return getTarget().get(0);
1261  }
1262
1263  /**
1264   * @deprecated Use Reference#setResource(IBaseResource) instead
1265   */
1266  @Deprecated
1267  public List<Resource> getTargetTarget() {
1268    if (this.targetTarget == null)
1269      this.targetTarget = new ArrayList<Resource>();
1270    return this.targetTarget;
1271  }
1272
1273  /**
1274   * @return {@link #occurred} (The period during which the activity occurred.)
1275   */
1276  public Type getOccurred() {
1277    return this.occurred;
1278  }
1279
1280  /**
1281   * @return {@link #occurred} (The period during which the activity occurred.)
1282   */
1283  public Period getOccurredPeriod() throws FHIRException {
1284    if (this.occurred == null)
1285      this.occurred = new Period();
1286    if (!(this.occurred instanceof Period))
1287      throw new FHIRException("Type mismatch: the type Period was expected, but " + this.occurred.getClass().getName()
1288          + " was encountered");
1289    return (Period) this.occurred;
1290  }
1291
1292  public boolean hasOccurredPeriod() {
1293    return this != null && this.occurred instanceof Period;
1294  }
1295
1296  /**
1297   * @return {@link #occurred} (The period during which the activity occurred.)
1298   */
1299  public DateTimeType getOccurredDateTimeType() throws FHIRException {
1300    if (this.occurred == null)
1301      this.occurred = new DateTimeType();
1302    if (!(this.occurred instanceof DateTimeType))
1303      throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "
1304          + this.occurred.getClass().getName() + " was encountered");
1305    return (DateTimeType) this.occurred;
1306  }
1307
1308  public boolean hasOccurredDateTimeType() {
1309    return this != null && this.occurred instanceof DateTimeType;
1310  }
1311
1312  public boolean hasOccurred() {
1313    return this.occurred != null && !this.occurred.isEmpty();
1314  }
1315
1316  /**
1317   * @param value {@link #occurred} (The period during which the activity
1318   *              occurred.)
1319   */
1320  public Provenance setOccurred(Type value) {
1321    if (value != null && !(value instanceof Period || value instanceof DateTimeType))
1322      throw new Error("Not the right type for Provenance.occurred[x]: " + value.fhirType());
1323    this.occurred = value;
1324    return this;
1325  }
1326
1327  /**
1328   * @return {@link #recorded} (The instant of time at which the activity was
1329   *         recorded.). This is the underlying object with id, value and
1330   *         extensions. The accessor "getRecorded" gives direct access to the
1331   *         value
1332   */
1333  public InstantType getRecordedElement() {
1334    if (this.recorded == null)
1335      if (Configuration.errorOnAutoCreate())
1336        throw new Error("Attempt to auto-create Provenance.recorded");
1337      else if (Configuration.doAutoCreate())
1338        this.recorded = new InstantType(); // bb
1339    return this.recorded;
1340  }
1341
1342  public boolean hasRecordedElement() {
1343    return this.recorded != null && !this.recorded.isEmpty();
1344  }
1345
1346  public boolean hasRecorded() {
1347    return this.recorded != null && !this.recorded.isEmpty();
1348  }
1349
1350  /**
1351   * @param value {@link #recorded} (The instant of time at which the activity was
1352   *              recorded.). This is the underlying object with id, value and
1353   *              extensions. The accessor "getRecorded" gives direct access to
1354   *              the value
1355   */
1356  public Provenance setRecordedElement(InstantType value) {
1357    this.recorded = value;
1358    return this;
1359  }
1360
1361  /**
1362   * @return The instant of time at which the activity was recorded.
1363   */
1364  public Date getRecorded() {
1365    return this.recorded == null ? null : this.recorded.getValue();
1366  }
1367
1368  /**
1369   * @param value The instant of time at which the activity was recorded.
1370   */
1371  public Provenance setRecorded(Date value) {
1372    if (this.recorded == null)
1373      this.recorded = new InstantType();
1374    this.recorded.setValue(value);
1375    return this;
1376  }
1377
1378  /**
1379   * @return {@link #policy} (Policy or plan the activity was defined by.
1380   *         Typically, a single activity may have multiple applicable policy
1381   *         documents, such as patient consent, guarantor funding, etc.)
1382   */
1383  public List<UriType> getPolicy() {
1384    if (this.policy == null)
1385      this.policy = new ArrayList<UriType>();
1386    return this.policy;
1387  }
1388
1389  /**
1390   * @return Returns a reference to <code>this</code> for easy method chaining
1391   */
1392  public Provenance setPolicy(List<UriType> thePolicy) {
1393    this.policy = thePolicy;
1394    return this;
1395  }
1396
1397  public boolean hasPolicy() {
1398    if (this.policy == null)
1399      return false;
1400    for (UriType item : this.policy)
1401      if (!item.isEmpty())
1402        return true;
1403    return false;
1404  }
1405
1406  /**
1407   * @return {@link #policy} (Policy or plan the activity was defined by.
1408   *         Typically, a single activity may have multiple applicable policy
1409   *         documents, such as patient consent, guarantor funding, etc.)
1410   */
1411  public UriType addPolicyElement() {// 2
1412    UriType t = new UriType();
1413    if (this.policy == null)
1414      this.policy = new ArrayList<UriType>();
1415    this.policy.add(t);
1416    return t;
1417  }
1418
1419  /**
1420   * @param value {@link #policy} (Policy or plan the activity was defined by.
1421   *              Typically, a single activity may have multiple applicable policy
1422   *              documents, such as patient consent, guarantor funding, etc.)
1423   */
1424  public Provenance addPolicy(String value) { // 1
1425    UriType t = new UriType();
1426    t.setValue(value);
1427    if (this.policy == null)
1428      this.policy = new ArrayList<UriType>();
1429    this.policy.add(t);
1430    return this;
1431  }
1432
1433  /**
1434   * @param value {@link #policy} (Policy or plan the activity was defined by.
1435   *              Typically, a single activity may have multiple applicable policy
1436   *              documents, such as patient consent, guarantor funding, etc.)
1437   */
1438  public boolean hasPolicy(String value) {
1439    if (this.policy == null)
1440      return false;
1441    for (UriType v : this.policy)
1442      if (v.getValue().equals(value)) // uri
1443        return true;
1444    return false;
1445  }
1446
1447  /**
1448   * @return {@link #location} (Where the activity occurred, if relevant.)
1449   */
1450  public Reference getLocation() {
1451    if (this.location == null)
1452      if (Configuration.errorOnAutoCreate())
1453        throw new Error("Attempt to auto-create Provenance.location");
1454      else if (Configuration.doAutoCreate())
1455        this.location = new Reference(); // cc
1456    return this.location;
1457  }
1458
1459  public boolean hasLocation() {
1460    return this.location != null && !this.location.isEmpty();
1461  }
1462
1463  /**
1464   * @param value {@link #location} (Where the activity occurred, if relevant.)
1465   */
1466  public Provenance setLocation(Reference value) {
1467    this.location = value;
1468    return this;
1469  }
1470
1471  /**
1472   * @return {@link #location} The actual object that is the target of the
1473   *         reference. The reference library doesn't populate this, but you can
1474   *         use it to hold the resource if you resolve it. (Where the activity
1475   *         occurred, if relevant.)
1476   */
1477  public Location getLocationTarget() {
1478    if (this.locationTarget == null)
1479      if (Configuration.errorOnAutoCreate())
1480        throw new Error("Attempt to auto-create Provenance.location");
1481      else if (Configuration.doAutoCreate())
1482        this.locationTarget = new Location(); // aa
1483    return this.locationTarget;
1484  }
1485
1486  /**
1487   * @param value {@link #location} The actual object that is the target of the
1488   *              reference. The reference library doesn't use these, but you can
1489   *              use it to hold the resource if you resolve it. (Where the
1490   *              activity occurred, if relevant.)
1491   */
1492  public Provenance setLocationTarget(Location value) {
1493    this.locationTarget = value;
1494    return this;
1495  }
1496
1497  /**
1498   * @return {@link #reason} (The reason that the activity was taking place.)
1499   */
1500  public List<CodeableConcept> getReason() {
1501    if (this.reason == null)
1502      this.reason = new ArrayList<CodeableConcept>();
1503    return this.reason;
1504  }
1505
1506  /**
1507   * @return Returns a reference to <code>this</code> for easy method chaining
1508   */
1509  public Provenance setReason(List<CodeableConcept> theReason) {
1510    this.reason = theReason;
1511    return this;
1512  }
1513
1514  public boolean hasReason() {
1515    if (this.reason == null)
1516      return false;
1517    for (CodeableConcept item : this.reason)
1518      if (!item.isEmpty())
1519        return true;
1520    return false;
1521  }
1522
1523  public CodeableConcept addReason() { // 3
1524    CodeableConcept t = new CodeableConcept();
1525    if (this.reason == null)
1526      this.reason = new ArrayList<CodeableConcept>();
1527    this.reason.add(t);
1528    return t;
1529  }
1530
1531  public Provenance addReason(CodeableConcept t) { // 3
1532    if (t == null)
1533      return this;
1534    if (this.reason == null)
1535      this.reason = new ArrayList<CodeableConcept>();
1536    this.reason.add(t);
1537    return this;
1538  }
1539
1540  /**
1541   * @return The first repetition of repeating field {@link #reason}, creating it
1542   *         if it does not already exist
1543   */
1544  public CodeableConcept getReasonFirstRep() {
1545    if (getReason().isEmpty()) {
1546      addReason();
1547    }
1548    return getReason().get(0);
1549  }
1550
1551  /**
1552   * @return {@link #activity} (An activity is something that occurs over a period
1553   *         of time and acts upon or with entities; it may include consuming,
1554   *         processing, transforming, modifying, relocating, using, or generating
1555   *         entities.)
1556   */
1557  public CodeableConcept getActivity() {
1558    if (this.activity == null)
1559      if (Configuration.errorOnAutoCreate())
1560        throw new Error("Attempt to auto-create Provenance.activity");
1561      else if (Configuration.doAutoCreate())
1562        this.activity = new CodeableConcept(); // cc
1563    return this.activity;
1564  }
1565
1566  public boolean hasActivity() {
1567    return this.activity != null && !this.activity.isEmpty();
1568  }
1569
1570  /**
1571   * @param value {@link #activity} (An activity is something that occurs over a
1572   *              period of time and acts upon or with entities; it may include
1573   *              consuming, processing, transforming, modifying, relocating,
1574   *              using, or generating entities.)
1575   */
1576  public Provenance setActivity(CodeableConcept value) {
1577    this.activity = value;
1578    return this;
1579  }
1580
1581  /**
1582   * @return {@link #agent} (An actor taking a role in an activity for which it
1583   *         can be assigned some degree of responsibility for the activity taking
1584   *         place.)
1585   */
1586  public List<ProvenanceAgentComponent> getAgent() {
1587    if (this.agent == null)
1588      this.agent = new ArrayList<ProvenanceAgentComponent>();
1589    return this.agent;
1590  }
1591
1592  /**
1593   * @return Returns a reference to <code>this</code> for easy method chaining
1594   */
1595  public Provenance setAgent(List<ProvenanceAgentComponent> theAgent) {
1596    this.agent = theAgent;
1597    return this;
1598  }
1599
1600  public boolean hasAgent() {
1601    if (this.agent == null)
1602      return false;
1603    for (ProvenanceAgentComponent item : this.agent)
1604      if (!item.isEmpty())
1605        return true;
1606    return false;
1607  }
1608
1609  public ProvenanceAgentComponent addAgent() { // 3
1610    ProvenanceAgentComponent t = new ProvenanceAgentComponent();
1611    if (this.agent == null)
1612      this.agent = new ArrayList<ProvenanceAgentComponent>();
1613    this.agent.add(t);
1614    return t;
1615  }
1616
1617  public Provenance addAgent(ProvenanceAgentComponent t) { // 3
1618    if (t == null)
1619      return this;
1620    if (this.agent == null)
1621      this.agent = new ArrayList<ProvenanceAgentComponent>();
1622    this.agent.add(t);
1623    return this;
1624  }
1625
1626  /**
1627   * @return The first repetition of repeating field {@link #agent}, creating it
1628   *         if it does not already exist
1629   */
1630  public ProvenanceAgentComponent getAgentFirstRep() {
1631    if (getAgent().isEmpty()) {
1632      addAgent();
1633    }
1634    return getAgent().get(0);
1635  }
1636
1637  /**
1638   * @return {@link #entity} (An entity used in this activity.)
1639   */
1640  public List<ProvenanceEntityComponent> getEntity() {
1641    if (this.entity == null)
1642      this.entity = new ArrayList<ProvenanceEntityComponent>();
1643    return this.entity;
1644  }
1645
1646  /**
1647   * @return Returns a reference to <code>this</code> for easy method chaining
1648   */
1649  public Provenance setEntity(List<ProvenanceEntityComponent> theEntity) {
1650    this.entity = theEntity;
1651    return this;
1652  }
1653
1654  public boolean hasEntity() {
1655    if (this.entity == null)
1656      return false;
1657    for (ProvenanceEntityComponent item : this.entity)
1658      if (!item.isEmpty())
1659        return true;
1660    return false;
1661  }
1662
1663  public ProvenanceEntityComponent addEntity() { // 3
1664    ProvenanceEntityComponent t = new ProvenanceEntityComponent();
1665    if (this.entity == null)
1666      this.entity = new ArrayList<ProvenanceEntityComponent>();
1667    this.entity.add(t);
1668    return t;
1669  }
1670
1671  public Provenance addEntity(ProvenanceEntityComponent t) { // 3
1672    if (t == null)
1673      return this;
1674    if (this.entity == null)
1675      this.entity = new ArrayList<ProvenanceEntityComponent>();
1676    this.entity.add(t);
1677    return this;
1678  }
1679
1680  /**
1681   * @return The first repetition of repeating field {@link #entity}, creating it
1682   *         if it does not already exist
1683   */
1684  public ProvenanceEntityComponent getEntityFirstRep() {
1685    if (getEntity().isEmpty()) {
1686      addEntity();
1687    }
1688    return getEntity().get(0);
1689  }
1690
1691  /**
1692   * @return {@link #signature} (A digital signature on the target Reference(s).
1693   *         The signer should match a Provenance.agent. The purpose of the
1694   *         signature is indicated.)
1695   */
1696  public List<Signature> getSignature() {
1697    if (this.signature == null)
1698      this.signature = new ArrayList<Signature>();
1699    return this.signature;
1700  }
1701
1702  /**
1703   * @return Returns a reference to <code>this</code> for easy method chaining
1704   */
1705  public Provenance setSignature(List<Signature> theSignature) {
1706    this.signature = theSignature;
1707    return this;
1708  }
1709
1710  public boolean hasSignature() {
1711    if (this.signature == null)
1712      return false;
1713    for (Signature item : this.signature)
1714      if (!item.isEmpty())
1715        return true;
1716    return false;
1717  }
1718
1719  public Signature addSignature() { // 3
1720    Signature t = new Signature();
1721    if (this.signature == null)
1722      this.signature = new ArrayList<Signature>();
1723    this.signature.add(t);
1724    return t;
1725  }
1726
1727  public Provenance addSignature(Signature t) { // 3
1728    if (t == null)
1729      return this;
1730    if (this.signature == null)
1731      this.signature = new ArrayList<Signature>();
1732    this.signature.add(t);
1733    return this;
1734  }
1735
1736  /**
1737   * @return The first repetition of repeating field {@link #signature}, creating
1738   *         it if it does not already exist
1739   */
1740  public Signature getSignatureFirstRep() {
1741    if (getSignature().isEmpty()) {
1742      addSignature();
1743    }
1744    return getSignature().get(0);
1745  }
1746
1747  protected void listChildren(List<Property> children) {
1748    super.listChildren(children);
1749    children.add(new Property("target", "Reference(Any)",
1750        "The Reference(s) that were generated or updated by  the activity described in this resource. A provenance can point to more than one target if multiple resources were created/updated by the same activity.",
1751        0, java.lang.Integer.MAX_VALUE, target));
1752    children.add(new Property("occurred[x]", "Period|dateTime", "The period during which the activity occurred.", 0, 1,
1753        occurred));
1754    children.add(
1755        new Property("recorded", "instant", "The instant of time at which the activity was recorded.", 0, 1, recorded));
1756    children.add(new Property("policy", "uri",
1757        "Policy or plan the activity was defined by. Typically, a single activity may have multiple applicable policy documents, such as patient consent, guarantor funding, etc.",
1758        0, java.lang.Integer.MAX_VALUE, policy));
1759    children.add(
1760        new Property("location", "Reference(Location)", "Where the activity occurred, if relevant.", 0, 1, location));
1761    children.add(new Property("reason", "CodeableConcept", "The reason that the activity was taking place.", 0,
1762        java.lang.Integer.MAX_VALUE, reason));
1763    children.add(new Property("activity", "CodeableConcept",
1764        "An activity is something that occurs over a period of time and acts upon or with entities; it may include consuming, processing, transforming, modifying, relocating, using, or generating entities.",
1765        0, 1, activity));
1766    children.add(new Property("agent", "",
1767        "An actor taking a role in an activity  for which it can be assigned some degree of responsibility for the activity taking place.",
1768        0, java.lang.Integer.MAX_VALUE, agent));
1769    children
1770        .add(new Property("entity", "", "An entity used in this activity.", 0, java.lang.Integer.MAX_VALUE, entity));
1771    children.add(new Property("signature", "Signature",
1772        "A digital signature on the target Reference(s). The signer should match a Provenance.agent. The purpose of the signature is indicated.",
1773        0, java.lang.Integer.MAX_VALUE, signature));
1774  }
1775
1776  @Override
1777  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
1778    switch (_hash) {
1779    case -880905839:
1780      /* target */ return new Property("target", "Reference(Any)",
1781          "The Reference(s) that were generated or updated by  the activity described in this resource. A provenance can point to more than one target if multiple resources were created/updated by the same activity.",
1782          0, java.lang.Integer.MAX_VALUE, target);
1783    case 784181563:
1784      /* occurred[x] */ return new Property("occurred[x]", "Period|dateTime",
1785          "The period during which the activity occurred.", 0, 1, occurred);
1786    case 792816933:
1787      /* occurred */ return new Property("occurred[x]", "Period|dateTime",
1788          "The period during which the activity occurred.", 0, 1, occurred);
1789    case 894082886:
1790      /* occurredPeriod */ return new Property("occurred[x]", "Period|dateTime",
1791          "The period during which the activity occurred.", 0, 1, occurred);
1792    case 1579027424:
1793      /* occurredDateTime */ return new Property("occurred[x]", "Period|dateTime",
1794          "The period during which the activity occurred.", 0, 1, occurred);
1795    case -799233872:
1796      /* recorded */ return new Property("recorded", "instant",
1797          "The instant of time at which the activity was recorded.", 0, 1, recorded);
1798    case -982670030:
1799      /* policy */ return new Property("policy", "uri",
1800          "Policy or plan the activity was defined by. Typically, a single activity may have multiple applicable policy documents, such as patient consent, guarantor funding, etc.",
1801          0, java.lang.Integer.MAX_VALUE, policy);
1802    case 1901043637:
1803      /* location */ return new Property("location", "Reference(Location)", "Where the activity occurred, if relevant.",
1804          0, 1, location);
1805    case -934964668:
1806      /* reason */ return new Property("reason", "CodeableConcept", "The reason that the activity was taking place.", 0,
1807          java.lang.Integer.MAX_VALUE, reason);
1808    case -1655966961:
1809      /* activity */ return new Property("activity", "CodeableConcept",
1810          "An activity is something that occurs over a period of time and acts upon or with entities; it may include consuming, processing, transforming, modifying, relocating, using, or generating entities.",
1811          0, 1, activity);
1812    case 92750597:
1813      /* agent */ return new Property("agent", "",
1814          "An actor taking a role in an activity  for which it can be assigned some degree of responsibility for the activity taking place.",
1815          0, java.lang.Integer.MAX_VALUE, agent);
1816    case -1298275357:
1817      /* entity */ return new Property("entity", "", "An entity used in this activity.", 0, java.lang.Integer.MAX_VALUE,
1818          entity);
1819    case 1073584312:
1820      /* signature */ return new Property("signature", "Signature",
1821          "A digital signature on the target Reference(s). The signer should match a Provenance.agent. The purpose of the signature is indicated.",
1822          0, java.lang.Integer.MAX_VALUE, signature);
1823    default:
1824      return super.getNamedProperty(_hash, _name, _checkValid);
1825    }
1826
1827  }
1828
1829  @Override
1830  public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
1831    switch (hash) {
1832    case -880905839:
1833      /* target */ return this.target == null ? new Base[0] : this.target.toArray(new Base[this.target.size()]); // Reference
1834    case 792816933:
1835      /* occurred */ return this.occurred == null ? new Base[0] : new Base[] { this.occurred }; // Type
1836    case -799233872:
1837      /* recorded */ return this.recorded == null ? new Base[0] : new Base[] { this.recorded }; // InstantType
1838    case -982670030:
1839      /* policy */ return this.policy == null ? new Base[0] : this.policy.toArray(new Base[this.policy.size()]); // UriType
1840    case 1901043637:
1841      /* location */ return this.location == null ? new Base[0] : new Base[] { this.location }; // Reference
1842    case -934964668:
1843      /* reason */ return this.reason == null ? new Base[0] : this.reason.toArray(new Base[this.reason.size()]); // CodeableConcept
1844    case -1655966961:
1845      /* activity */ return this.activity == null ? new Base[0] : new Base[] { this.activity }; // CodeableConcept
1846    case 92750597:
1847      /* agent */ return this.agent == null ? new Base[0] : this.agent.toArray(new Base[this.agent.size()]); // ProvenanceAgentComponent
1848    case -1298275357:
1849      /* entity */ return this.entity == null ? new Base[0] : this.entity.toArray(new Base[this.entity.size()]); // ProvenanceEntityComponent
1850    case 1073584312:
1851      /* signature */ return this.signature == null ? new Base[0]
1852          : this.signature.toArray(new Base[this.signature.size()]); // Signature
1853    default:
1854      return super.getProperty(hash, name, checkValid);
1855    }
1856
1857  }
1858
1859  @Override
1860  public Base setProperty(int hash, String name, Base value) throws FHIRException {
1861    switch (hash) {
1862    case -880905839: // target
1863      this.getTarget().add(castToReference(value)); // Reference
1864      return value;
1865    case 792816933: // occurred
1866      this.occurred = castToType(value); // Type
1867      return value;
1868    case -799233872: // recorded
1869      this.recorded = castToInstant(value); // InstantType
1870      return value;
1871    case -982670030: // policy
1872      this.getPolicy().add(castToUri(value)); // UriType
1873      return value;
1874    case 1901043637: // location
1875      this.location = castToReference(value); // Reference
1876      return value;
1877    case -934964668: // reason
1878      this.getReason().add(castToCodeableConcept(value)); // CodeableConcept
1879      return value;
1880    case -1655966961: // activity
1881      this.activity = castToCodeableConcept(value); // CodeableConcept
1882      return value;
1883    case 92750597: // agent
1884      this.getAgent().add((ProvenanceAgentComponent) value); // ProvenanceAgentComponent
1885      return value;
1886    case -1298275357: // entity
1887      this.getEntity().add((ProvenanceEntityComponent) value); // ProvenanceEntityComponent
1888      return value;
1889    case 1073584312: // signature
1890      this.getSignature().add(castToSignature(value)); // Signature
1891      return value;
1892    default:
1893      return super.setProperty(hash, name, value);
1894    }
1895
1896  }
1897
1898  @Override
1899  public Base setProperty(String name, Base value) throws FHIRException {
1900    if (name.equals("target")) {
1901      this.getTarget().add(castToReference(value));
1902    } else if (name.equals("occurred[x]")) {
1903      this.occurred = castToType(value); // Type
1904    } else if (name.equals("recorded")) {
1905      this.recorded = castToInstant(value); // InstantType
1906    } else if (name.equals("policy")) {
1907      this.getPolicy().add(castToUri(value));
1908    } else if (name.equals("location")) {
1909      this.location = castToReference(value); // Reference
1910    } else if (name.equals("reason")) {
1911      this.getReason().add(castToCodeableConcept(value));
1912    } else if (name.equals("activity")) {
1913      this.activity = castToCodeableConcept(value); // CodeableConcept
1914    } else if (name.equals("agent")) {
1915      this.getAgent().add((ProvenanceAgentComponent) value);
1916    } else if (name.equals("entity")) {
1917      this.getEntity().add((ProvenanceEntityComponent) value);
1918    } else if (name.equals("signature")) {
1919      this.getSignature().add(castToSignature(value));
1920    } else
1921      return super.setProperty(name, value);
1922    return value;
1923  }
1924
1925  @Override
1926  public void removeChild(String name, Base value) throws FHIRException {
1927    if (name.equals("target")) {
1928      this.getTarget().remove(castToReference(value));
1929    } else if (name.equals("occurred[x]")) {
1930      this.occurred = null;
1931    } else if (name.equals("recorded")) {
1932      this.recorded = null;
1933    } else if (name.equals("policy")) {
1934      this.getPolicy().remove(castToUri(value));
1935    } else if (name.equals("location")) {
1936      this.location = null;
1937    } else if (name.equals("reason")) {
1938      this.getReason().remove(castToCodeableConcept(value));
1939    } else if (name.equals("activity")) {
1940      this.activity = null;
1941    } else if (name.equals("agent")) {
1942      this.getAgent().remove((ProvenanceAgentComponent) value);
1943    } else if (name.equals("entity")) {
1944      this.getEntity().remove((ProvenanceEntityComponent) value);
1945    } else if (name.equals("signature")) {
1946      this.getSignature().remove(castToSignature(value));
1947    } else
1948      super.removeChild(name, value);
1949    
1950  }
1951
1952  @Override
1953  public Base makeProperty(int hash, String name) throws FHIRException {
1954    switch (hash) {
1955    case -880905839:
1956      return addTarget();
1957    case 784181563:
1958      return getOccurred();
1959    case 792816933:
1960      return getOccurred();
1961    case -799233872:
1962      return getRecordedElement();
1963    case -982670030:
1964      return addPolicyElement();
1965    case 1901043637:
1966      return getLocation();
1967    case -934964668:
1968      return addReason();
1969    case -1655966961:
1970      return getActivity();
1971    case 92750597:
1972      return addAgent();
1973    case -1298275357:
1974      return addEntity();
1975    case 1073584312:
1976      return addSignature();
1977    default:
1978      return super.makeProperty(hash, name);
1979    }
1980
1981  }
1982
1983  @Override
1984  public String[] getTypesForProperty(int hash, String name) throws FHIRException {
1985    switch (hash) {
1986    case -880905839:
1987      /* target */ return new String[] { "Reference" };
1988    case 792816933:
1989      /* occurred */ return new String[] { "Period", "dateTime" };
1990    case -799233872:
1991      /* recorded */ return new String[] { "instant" };
1992    case -982670030:
1993      /* policy */ return new String[] { "uri" };
1994    case 1901043637:
1995      /* location */ return new String[] { "Reference" };
1996    case -934964668:
1997      /* reason */ return new String[] { "CodeableConcept" };
1998    case -1655966961:
1999      /* activity */ return new String[] { "CodeableConcept" };
2000    case 92750597:
2001      /* agent */ return new String[] {};
2002    case -1298275357:
2003      /* entity */ return new String[] {};
2004    case 1073584312:
2005      /* signature */ return new String[] { "Signature" };
2006    default:
2007      return super.getTypesForProperty(hash, name);
2008    }
2009
2010  }
2011
2012  @Override
2013  public Base addChild(String name) throws FHIRException {
2014    if (name.equals("target")) {
2015      return addTarget();
2016    } else if (name.equals("occurredPeriod")) {
2017      this.occurred = new Period();
2018      return this.occurred;
2019    } else if (name.equals("occurredDateTime")) {
2020      this.occurred = new DateTimeType();
2021      return this.occurred;
2022    } else if (name.equals("recorded")) {
2023      throw new FHIRException("Cannot call addChild on a singleton property Provenance.recorded");
2024    } else if (name.equals("policy")) {
2025      throw new FHIRException("Cannot call addChild on a singleton property Provenance.policy");
2026    } else if (name.equals("location")) {
2027      this.location = new Reference();
2028      return this.location;
2029    } else if (name.equals("reason")) {
2030      return addReason();
2031    } else if (name.equals("activity")) {
2032      this.activity = new CodeableConcept();
2033      return this.activity;
2034    } else if (name.equals("agent")) {
2035      return addAgent();
2036    } else if (name.equals("entity")) {
2037      return addEntity();
2038    } else if (name.equals("signature")) {
2039      return addSignature();
2040    } else
2041      return super.addChild(name);
2042  }
2043
2044  public String fhirType() {
2045    return "Provenance";
2046
2047  }
2048
2049  public Provenance copy() {
2050    Provenance dst = new Provenance();
2051    copyValues(dst);
2052    return dst;
2053  }
2054
2055  public void copyValues(Provenance dst) {
2056    super.copyValues(dst);
2057    if (target != null) {
2058      dst.target = new ArrayList<Reference>();
2059      for (Reference i : target)
2060        dst.target.add(i.copy());
2061    }
2062    ;
2063    dst.occurred = occurred == null ? null : occurred.copy();
2064    dst.recorded = recorded == null ? null : recorded.copy();
2065    if (policy != null) {
2066      dst.policy = new ArrayList<UriType>();
2067      for (UriType i : policy)
2068        dst.policy.add(i.copy());
2069    }
2070    ;
2071    dst.location = location == null ? null : location.copy();
2072    if (reason != null) {
2073      dst.reason = new ArrayList<CodeableConcept>();
2074      for (CodeableConcept i : reason)
2075        dst.reason.add(i.copy());
2076    }
2077    ;
2078    dst.activity = activity == null ? null : activity.copy();
2079    if (agent != null) {
2080      dst.agent = new ArrayList<ProvenanceAgentComponent>();
2081      for (ProvenanceAgentComponent i : agent)
2082        dst.agent.add(i.copy());
2083    }
2084    ;
2085    if (entity != null) {
2086      dst.entity = new ArrayList<ProvenanceEntityComponent>();
2087      for (ProvenanceEntityComponent i : entity)
2088        dst.entity.add(i.copy());
2089    }
2090    ;
2091    if (signature != null) {
2092      dst.signature = new ArrayList<Signature>();
2093      for (Signature i : signature)
2094        dst.signature.add(i.copy());
2095    }
2096    ;
2097  }
2098
2099  protected Provenance typedCopy() {
2100    return copy();
2101  }
2102
2103  @Override
2104  public boolean equalsDeep(Base other_) {
2105    if (!super.equalsDeep(other_))
2106      return false;
2107    if (!(other_ instanceof Provenance))
2108      return false;
2109    Provenance o = (Provenance) other_;
2110    return compareDeep(target, o.target, true) && compareDeep(occurred, o.occurred, true)
2111        && compareDeep(recorded, o.recorded, true) && compareDeep(policy, o.policy, true)
2112        && compareDeep(location, o.location, true) && compareDeep(reason, o.reason, true)
2113        && compareDeep(activity, o.activity, true) && compareDeep(agent, o.agent, true)
2114        && compareDeep(entity, o.entity, true) && compareDeep(signature, o.signature, true);
2115  }
2116
2117  @Override
2118  public boolean equalsShallow(Base other_) {
2119    if (!super.equalsShallow(other_))
2120      return false;
2121    if (!(other_ instanceof Provenance))
2122      return false;
2123    Provenance o = (Provenance) other_;
2124    return compareValues(recorded, o.recorded, true) && compareValues(policy, o.policy, true);
2125  }
2126
2127  public boolean isEmpty() {
2128    return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(target, occurred, recorded, policy, location, reason,
2129        activity, agent, entity, signature);
2130  }
2131
2132  @Override
2133  public ResourceType getResourceType() {
2134    return ResourceType.Provenance;
2135  }
2136
2137  /**
2138   * Search parameter: <b>agent-type</b>
2139   * <p>
2140   * Description: <b>How the agent participated</b><br>
2141   * Type: <b>token</b><br>
2142   * Path: <b>Provenance.agent.type</b><br>
2143   * </p>
2144   */
2145  @SearchParamDefinition(name = "agent-type", path = "Provenance.agent.type", description = "How the agent participated", type = "token")
2146  public static final String SP_AGENT_TYPE = "agent-type";
2147  /**
2148   * <b>Fluent Client</b> search parameter constant for <b>agent-type</b>
2149   * <p>
2150   * Description: <b>How the agent participated</b><br>
2151   * Type: <b>token</b><br>
2152   * Path: <b>Provenance.agent.type</b><br>
2153   * </p>
2154   */
2155  public static final ca.uhn.fhir.rest.gclient.TokenClientParam AGENT_TYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(
2156      SP_AGENT_TYPE);
2157
2158  /**
2159   * Search parameter: <b>agent</b>
2160   * <p>
2161   * Description: <b>Who participated</b><br>
2162   * Type: <b>reference</b><br>
2163   * Path: <b>Provenance.agent.who</b><br>
2164   * </p>
2165   */
2166  @SearchParamDefinition(name = "agent", path = "Provenance.agent.who", description = "Who participated", type = "reference", providesMembershipIn = {
2167      @ca.uhn.fhir.model.api.annotation.Compartment(name = "Device"),
2168      @ca.uhn.fhir.model.api.annotation.Compartment(name = "Practitioner"),
2169      @ca.uhn.fhir.model.api.annotation.Compartment(name = "RelatedPerson") }, target = { Device.class,
2170          Organization.class, Patient.class, Practitioner.class, PractitionerRole.class, RelatedPerson.class })
2171  public static final String SP_AGENT = "agent";
2172  /**
2173   * <b>Fluent Client</b> search parameter constant for <b>agent</b>
2174   * <p>
2175   * Description: <b>Who participated</b><br>
2176   * Type: <b>reference</b><br>
2177   * Path: <b>Provenance.agent.who</b><br>
2178   * </p>
2179   */
2180  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam AGENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
2181      SP_AGENT);
2182
2183  /**
2184   * Constant for fluent queries to be used to add include statements. Specifies
2185   * the path value of "<b>Provenance:agent</b>".
2186   */
2187  public static final ca.uhn.fhir.model.api.Include INCLUDE_AGENT = new ca.uhn.fhir.model.api.Include(
2188      "Provenance:agent").toLocked();
2189
2190  /**
2191   * Search parameter: <b>signature-type</b>
2192   * <p>
2193   * Description: <b>Indication of the reason the entity signed the
2194   * object(s)</b><br>
2195   * Type: <b>token</b><br>
2196   * Path: <b>Provenance.signature.type</b><br>
2197   * </p>
2198   */
2199  @SearchParamDefinition(name = "signature-type", path = "Provenance.signature.type", description = "Indication of the reason the entity signed the object(s)", type = "token")
2200  public static final String SP_SIGNATURE_TYPE = "signature-type";
2201  /**
2202   * <b>Fluent Client</b> search parameter constant for <b>signature-type</b>
2203   * <p>
2204   * Description: <b>Indication of the reason the entity signed the
2205   * object(s)</b><br>
2206   * Type: <b>token</b><br>
2207   * Path: <b>Provenance.signature.type</b><br>
2208   * </p>
2209   */
2210  public static final ca.uhn.fhir.rest.gclient.TokenClientParam SIGNATURE_TYPE = new ca.uhn.fhir.rest.gclient.TokenClientParam(
2211      SP_SIGNATURE_TYPE);
2212
2213  /**
2214   * Search parameter: <b>patient</b>
2215   * <p>
2216   * Description: <b>Target Reference(s) (usually version specific)</b><br>
2217   * Type: <b>reference</b><br>
2218   * Path: <b>Provenance.target</b><br>
2219   * </p>
2220   */
2221  @SearchParamDefinition(name = "patient", path = "Provenance.target.where(resolve() is Patient)", description = "Target Reference(s) (usually version specific)", type = "reference", providesMembershipIn = {
2222      @ca.uhn.fhir.model.api.annotation.Compartment(name = "Patient") }, target = { Patient.class })
2223  public static final String SP_PATIENT = "patient";
2224  /**
2225   * <b>Fluent Client</b> search parameter constant for <b>patient</b>
2226   * <p>
2227   * Description: <b>Target Reference(s) (usually version specific)</b><br>
2228   * Type: <b>reference</b><br>
2229   * Path: <b>Provenance.target</b><br>
2230   * </p>
2231   */
2232  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam PATIENT = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
2233      SP_PATIENT);
2234
2235  /**
2236   * Constant for fluent queries to be used to add include statements. Specifies
2237   * the path value of "<b>Provenance:patient</b>".
2238   */
2239  public static final ca.uhn.fhir.model.api.Include INCLUDE_PATIENT = new ca.uhn.fhir.model.api.Include(
2240      "Provenance:patient").toLocked();
2241
2242  /**
2243   * Search parameter: <b>location</b>
2244   * <p>
2245   * Description: <b>Where the activity occurred, if relevant</b><br>
2246   * Type: <b>reference</b><br>
2247   * Path: <b>Provenance.location</b><br>
2248   * </p>
2249   */
2250  @SearchParamDefinition(name = "location", path = "Provenance.location", description = "Where the activity occurred, if relevant", type = "reference", target = {
2251      Location.class })
2252  public static final String SP_LOCATION = "location";
2253  /**
2254   * <b>Fluent Client</b> search parameter constant for <b>location</b>
2255   * <p>
2256   * Description: <b>Where the activity occurred, if relevant</b><br>
2257   * Type: <b>reference</b><br>
2258   * Path: <b>Provenance.location</b><br>
2259   * </p>
2260   */
2261  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam LOCATION = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
2262      SP_LOCATION);
2263
2264  /**
2265   * Constant for fluent queries to be used to add include statements. Specifies
2266   * the path value of "<b>Provenance:location</b>".
2267   */
2268  public static final ca.uhn.fhir.model.api.Include INCLUDE_LOCATION = new ca.uhn.fhir.model.api.Include(
2269      "Provenance:location").toLocked();
2270
2271  /**
2272   * Search parameter: <b>recorded</b>
2273   * <p>
2274   * Description: <b>When the activity was recorded / updated</b><br>
2275   * Type: <b>date</b><br>
2276   * Path: <b>Provenance.recorded</b><br>
2277   * </p>
2278   */
2279  @SearchParamDefinition(name = "recorded", path = "Provenance.recorded", description = "When the activity was recorded / updated", type = "date")
2280  public static final String SP_RECORDED = "recorded";
2281  /**
2282   * <b>Fluent Client</b> search parameter constant for <b>recorded</b>
2283   * <p>
2284   * Description: <b>When the activity was recorded / updated</b><br>
2285   * Type: <b>date</b><br>
2286   * Path: <b>Provenance.recorded</b><br>
2287   * </p>
2288   */
2289  public static final ca.uhn.fhir.rest.gclient.DateClientParam RECORDED = new ca.uhn.fhir.rest.gclient.DateClientParam(
2290      SP_RECORDED);
2291
2292  /**
2293   * Search parameter: <b>agent-role</b>
2294   * <p>
2295   * Description: <b>What the agents role was</b><br>
2296   * Type: <b>token</b><br>
2297   * Path: <b>Provenance.agent.role</b><br>
2298   * </p>
2299   */
2300  @SearchParamDefinition(name = "agent-role", path = "Provenance.agent.role", description = "What the agents role was", type = "token")
2301  public static final String SP_AGENT_ROLE = "agent-role";
2302  /**
2303   * <b>Fluent Client</b> search parameter constant for <b>agent-role</b>
2304   * <p>
2305   * Description: <b>What the agents role was</b><br>
2306   * Type: <b>token</b><br>
2307   * Path: <b>Provenance.agent.role</b><br>
2308   * </p>
2309   */
2310  public static final ca.uhn.fhir.rest.gclient.TokenClientParam AGENT_ROLE = new ca.uhn.fhir.rest.gclient.TokenClientParam(
2311      SP_AGENT_ROLE);
2312
2313  /**
2314   * Search parameter: <b>when</b>
2315   * <p>
2316   * Description: <b>When the activity occurred</b><br>
2317   * Type: <b>date</b><br>
2318   * Path: <b>Provenance.occurredDateTime</b><br>
2319   * </p>
2320   */
2321  @SearchParamDefinition(name = "when", path = "(Provenance.occurred as dateTime)", description = "When the activity occurred", type = "date")
2322  public static final String SP_WHEN = "when";
2323  /**
2324   * <b>Fluent Client</b> search parameter constant for <b>when</b>
2325   * <p>
2326   * Description: <b>When the activity occurred</b><br>
2327   * Type: <b>date</b><br>
2328   * Path: <b>Provenance.occurredDateTime</b><br>
2329   * </p>
2330   */
2331  public static final ca.uhn.fhir.rest.gclient.DateClientParam WHEN = new ca.uhn.fhir.rest.gclient.DateClientParam(
2332      SP_WHEN);
2333
2334  /**
2335   * Search parameter: <b>entity</b>
2336   * <p>
2337   * Description: <b>Identity of entity</b><br>
2338   * Type: <b>reference</b><br>
2339   * Path: <b>Provenance.entity.what</b><br>
2340   * </p>
2341   */
2342  @SearchParamDefinition(name = "entity", path = "Provenance.entity.what", description = "Identity of entity", type = "reference")
2343  public static final String SP_ENTITY = "entity";
2344  /**
2345   * <b>Fluent Client</b> search parameter constant for <b>entity</b>
2346   * <p>
2347   * Description: <b>Identity of entity</b><br>
2348   * Type: <b>reference</b><br>
2349   * Path: <b>Provenance.entity.what</b><br>
2350   * </p>
2351   */
2352  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam ENTITY = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
2353      SP_ENTITY);
2354
2355  /**
2356   * Constant for fluent queries to be used to add include statements. Specifies
2357   * the path value of "<b>Provenance:entity</b>".
2358   */
2359  public static final ca.uhn.fhir.model.api.Include INCLUDE_ENTITY = new ca.uhn.fhir.model.api.Include(
2360      "Provenance:entity").toLocked();
2361
2362  /**
2363   * Search parameter: <b>target</b>
2364   * <p>
2365   * Description: <b>Target Reference(s) (usually version specific)</b><br>
2366   * Type: <b>reference</b><br>
2367   * Path: <b>Provenance.target</b><br>
2368   * </p>
2369   */
2370  @SearchParamDefinition(name = "target", path = "Provenance.target", description = "Target Reference(s) (usually version specific)", type = "reference")
2371  public static final String SP_TARGET = "target";
2372  /**
2373   * <b>Fluent Client</b> search parameter constant for <b>target</b>
2374   * <p>
2375   * Description: <b>Target Reference(s) (usually version specific)</b><br>
2376   * Type: <b>reference</b><br>
2377   * Path: <b>Provenance.target</b><br>
2378   * </p>
2379   */
2380  public static final ca.uhn.fhir.rest.gclient.ReferenceClientParam TARGET = new ca.uhn.fhir.rest.gclient.ReferenceClientParam(
2381      SP_TARGET);
2382
2383  /**
2384   * Constant for fluent queries to be used to add include statements. Specifies
2385   * the path value of "<b>Provenance:target</b>".
2386   */
2387  public static final ca.uhn.fhir.model.api.Include INCLUDE_TARGET = new ca.uhn.fhir.model.api.Include(
2388      "Provenance:target").toLocked();
2389
2390}