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