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