001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Block;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.ResourceDef;
044import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
045import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
046import org.hl7.fhir.exceptions.FHIRException;
047import org.hl7.fhir.utilities.Utilities;
048/**
049 * 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.
050 */
051@ResourceDef(name="Provenance", profile="http://hl7.org/fhir/Profile/Provenance")
052public class Provenance extends DomainResource {
053
054    public enum ProvenanceEntityRole {
055        /**
056         * 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.
057         */
058        DERIVATION, 
059        /**
060         * A derivation for which the resulting entity is a revised version of some original.
061         */
062        REVISION, 
063        /**
064         * The repeat of (some or all of) an entity, such as text or image, by someone who may or may not be its original author.
065         */
066        QUOTATION, 
067        /**
068         * 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.
069         */
070        SOURCE, 
071        /**
072         * added to help the parsers
073         */
074        NULL;
075        public static ProvenanceEntityRole fromCode(String codeString) throws FHIRException {
076            if (codeString == null || "".equals(codeString))
077                return null;
078        if ("derivation".equals(codeString))
079          return DERIVATION;
080        if ("revision".equals(codeString))
081          return REVISION;
082        if ("quotation".equals(codeString))
083          return QUOTATION;
084        if ("source".equals(codeString))
085          return SOURCE;
086        throw new FHIRException("Unknown ProvenanceEntityRole code '"+codeString+"'");
087        }
088        public String toCode() {
089          switch (this) {
090            case DERIVATION: return "derivation";
091            case REVISION: return "revision";
092            case QUOTATION: return "quotation";
093            case SOURCE: return "source";
094            default: return "?";
095          }
096        }
097        public String getSystem() {
098          switch (this) {
099            case DERIVATION: return "http://hl7.org/fhir/provenance-entity-role";
100            case REVISION: return "http://hl7.org/fhir/provenance-entity-role";
101            case QUOTATION: return "http://hl7.org/fhir/provenance-entity-role";
102            case SOURCE: return "http://hl7.org/fhir/provenance-entity-role";
103            default: return "?";
104          }
105        }
106        public String getDefinition() {
107          switch (this) {
108            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.";
109            case REVISION: return "A derivation for which the resulting entity is a revised version of some original.";
110            case QUOTATION: return "The repeat of (some or all of) an entity, such as text or image, by someone who may or may not be its original author.";
111            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.";
112            default: return "?";
113          }
114        }
115        public String getDisplay() {
116          switch (this) {
117            case DERIVATION: return "Derivation";
118            case REVISION: return "Revision";
119            case QUOTATION: return "Quotation";
120            case SOURCE: return "Source";
121            default: return "?";
122          }
123        }
124    }
125
126  public static class ProvenanceEntityRoleEnumFactory implements EnumFactory<ProvenanceEntityRole> {
127    public ProvenanceEntityRole fromCode(String codeString) throws IllegalArgumentException {
128      if (codeString == null || "".equals(codeString))
129            if (codeString == null || "".equals(codeString))
130                return null;
131        if ("derivation".equals(codeString))
132          return ProvenanceEntityRole.DERIVATION;
133        if ("revision".equals(codeString))
134          return ProvenanceEntityRole.REVISION;
135        if ("quotation".equals(codeString))
136          return ProvenanceEntityRole.QUOTATION;
137        if ("source".equals(codeString))
138          return ProvenanceEntityRole.SOURCE;
139        throw new IllegalArgumentException("Unknown ProvenanceEntityRole code '"+codeString+"'");
140        }
141        public Enumeration<ProvenanceEntityRole> fromType(Base code) throws FHIRException {
142          if (code == null || code.isEmpty())
143            return null;
144          String codeString = ((PrimitiveType) code).asStringValue();
145          if (codeString == null || "".equals(codeString))
146            return null;
147        if ("derivation".equals(codeString))
148          return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.DERIVATION);
149        if ("revision".equals(codeString))
150          return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.REVISION);
151        if ("quotation".equals(codeString))
152          return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.QUOTATION);
153        if ("source".equals(codeString))
154          return new Enumeration<ProvenanceEntityRole>(this, ProvenanceEntityRole.SOURCE);
155        throw new FHIRException("Unknown ProvenanceEntityRole code '"+codeString+"'");
156        }
157    public String toCode(ProvenanceEntityRole code) {
158      if (code == ProvenanceEntityRole.DERIVATION)
159        return "derivation";
160      if (code == ProvenanceEntityRole.REVISION)
161        return "revision";
162      if (code == ProvenanceEntityRole.QUOTATION)
163        return "quotation";
164      if (code == ProvenanceEntityRole.SOURCE)
165        return "source";
166      return "?";
167      }
168    }
169
170    @Block()
171    public static class ProvenanceAgentComponent extends BackboneElement implements IBaseBackboneElement {
172        /**
173         * The function of the agent with respect to the activity.
174         */
175        @Child(name = "role", type = {Coding.class}, order=1, min=1, max=1, modifier=false, summary=true)
176        @Description(shortDefinition="What the agents involvement was", formalDefinition="The function of the agent with respect to the activity." )
177        protected Coding role;
178
179        /**
180         * The individual, device or organization that participated in the event.
181         */
182        @Child(name = "actor", type = {Practitioner.class, RelatedPerson.class, Patient.class, Device.class, Organization.class}, order=2, min=0, max=1, modifier=false, summary=true)
183        @Description(shortDefinition="Individual, device or organization playing role", formalDefinition="The individual, device or organization that participated in the event." )
184        protected Reference actor;
185
186        /**
187         * The actual object that is the target of the reference (The individual, device or organization that participated in the event.)
188         */
189        protected Resource actorTarget;
190
191        /**
192         * The identity of the agent as known by the authorization system.
193         */
194        @Child(name = "userId", type = {Identifier.class}, order=3, min=0, max=1, modifier=false, summary=true)
195        @Description(shortDefinition="Authorization-system identifier for the agent", formalDefinition="The identity of the agent as known by the authorization system." )
196        protected Identifier userId;
197
198        /**
199         * A relationship between two the agents referenced in this resource. This is defined to allow for explicit description of the delegation between agents.  For example, this human author used this device, or one person acted on another's behest.
200         */
201        @Child(name = "relatedAgent", type = {}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
202        @Description(shortDefinition="Track delegation between agents", formalDefinition="A relationship between two the agents referenced in this resource. This is defined to allow for explicit description of the delegation between agents.  For example, this human author used this device, or one person acted on another's behest." )
203        protected List<ProvenanceAgentRelatedAgentComponent> relatedAgent;
204
205        private static final long serialVersionUID = 1792758952L;
206
207    /*
208     * Constructor
209     */
210      public ProvenanceAgentComponent() {
211        super();
212      }
213
214    /*
215     * Constructor
216     */
217      public ProvenanceAgentComponent(Coding role) {
218        super();
219        this.role = role;
220      }
221
222        /**
223         * @return {@link #role} (The function of the agent with respect to the activity.)
224         */
225        public Coding getRole() { 
226          if (this.role == null)
227            if (Configuration.errorOnAutoCreate())
228              throw new Error("Attempt to auto-create ProvenanceAgentComponent.role");
229            else if (Configuration.doAutoCreate())
230              this.role = new Coding(); // cc
231          return this.role;
232        }
233
234        public boolean hasRole() { 
235          return this.role != null && !this.role.isEmpty();
236        }
237
238        /**
239         * @param value {@link #role} (The function of the agent with respect to the activity.)
240         */
241        public ProvenanceAgentComponent setRole(Coding value) { 
242          this.role = value;
243          return this;
244        }
245
246        /**
247         * @return {@link #actor} (The individual, device or organization that participated in the event.)
248         */
249        public Reference getActor() { 
250          if (this.actor == null)
251            if (Configuration.errorOnAutoCreate())
252              throw new Error("Attempt to auto-create ProvenanceAgentComponent.actor");
253            else if (Configuration.doAutoCreate())
254              this.actor = new Reference(); // cc
255          return this.actor;
256        }
257
258        public boolean hasActor() { 
259          return this.actor != null && !this.actor.isEmpty();
260        }
261
262        /**
263         * @param value {@link #actor} (The individual, device or organization that participated in the event.)
264         */
265        public ProvenanceAgentComponent setActor(Reference value) { 
266          this.actor = value;
267          return this;
268        }
269
270        /**
271         * @return {@link #actor} 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. (The individual, device or organization that participated in the event.)
272         */
273        public Resource getActorTarget() { 
274          return this.actorTarget;
275        }
276
277        /**
278         * @param value {@link #actor} 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. (The individual, device or organization that participated in the event.)
279         */
280        public ProvenanceAgentComponent setActorTarget(Resource value) { 
281          this.actorTarget = value;
282          return this;
283        }
284
285        /**
286         * @return {@link #userId} (The identity of the agent as known by the authorization system.)
287         */
288        public Identifier getUserId() { 
289          if (this.userId == null)
290            if (Configuration.errorOnAutoCreate())
291              throw new Error("Attempt to auto-create ProvenanceAgentComponent.userId");
292            else if (Configuration.doAutoCreate())
293              this.userId = new Identifier(); // cc
294          return this.userId;
295        }
296
297        public boolean hasUserId() { 
298          return this.userId != null && !this.userId.isEmpty();
299        }
300
301        /**
302         * @param value {@link #userId} (The identity of the agent as known by the authorization system.)
303         */
304        public ProvenanceAgentComponent setUserId(Identifier value) { 
305          this.userId = value;
306          return this;
307        }
308
309        /**
310         * @return {@link #relatedAgent} (A relationship between two the agents referenced in this resource. This is defined to allow for explicit description of the delegation between agents.  For example, this human author used this device, or one person acted on another's behest.)
311         */
312        public List<ProvenanceAgentRelatedAgentComponent> getRelatedAgent() { 
313          if (this.relatedAgent == null)
314            this.relatedAgent = new ArrayList<ProvenanceAgentRelatedAgentComponent>();
315          return this.relatedAgent;
316        }
317
318        public boolean hasRelatedAgent() { 
319          if (this.relatedAgent == null)
320            return false;
321          for (ProvenanceAgentRelatedAgentComponent item : this.relatedAgent)
322            if (!item.isEmpty())
323              return true;
324          return false;
325        }
326
327        /**
328         * @return {@link #relatedAgent} (A relationship between two the agents referenced in this resource. This is defined to allow for explicit description of the delegation between agents.  For example, this human author used this device, or one person acted on another's behest.)
329         */
330    // syntactic sugar
331        public ProvenanceAgentRelatedAgentComponent addRelatedAgent() { //3
332          ProvenanceAgentRelatedAgentComponent t = new ProvenanceAgentRelatedAgentComponent();
333          if (this.relatedAgent == null)
334            this.relatedAgent = new ArrayList<ProvenanceAgentRelatedAgentComponent>();
335          this.relatedAgent.add(t);
336          return t;
337        }
338
339    // syntactic sugar
340        public ProvenanceAgentComponent addRelatedAgent(ProvenanceAgentRelatedAgentComponent t) { //3
341          if (t == null)
342            return this;
343          if (this.relatedAgent == null)
344            this.relatedAgent = new ArrayList<ProvenanceAgentRelatedAgentComponent>();
345          this.relatedAgent.add(t);
346          return this;
347        }
348
349        protected void listChildren(List<Property> childrenList) {
350          super.listChildren(childrenList);
351          childrenList.add(new Property("role", "Coding", "The function of the agent with respect to the activity.", 0, java.lang.Integer.MAX_VALUE, role));
352          childrenList.add(new Property("actor", "Reference(Practitioner|RelatedPerson|Patient|Device|Organization)", "The individual, device or organization that participated in the event.", 0, java.lang.Integer.MAX_VALUE, actor));
353          childrenList.add(new Property("userId", "Identifier", "The identity of the agent as known by the authorization system.", 0, java.lang.Integer.MAX_VALUE, userId));
354          childrenList.add(new Property("relatedAgent", "", "A relationship between two the agents referenced in this resource. This is defined to allow for explicit description of the delegation between agents.  For example, this human author used this device, or one person acted on another's behest.", 0, java.lang.Integer.MAX_VALUE, relatedAgent));
355        }
356
357      @Override
358      public void setProperty(String name, Base value) throws FHIRException {
359        if (name.equals("role"))
360          this.role = castToCoding(value); // Coding
361        else if (name.equals("actor"))
362          this.actor = castToReference(value); // Reference
363        else if (name.equals("userId"))
364          this.userId = castToIdentifier(value); // Identifier
365        else if (name.equals("relatedAgent"))
366          this.getRelatedAgent().add((ProvenanceAgentRelatedAgentComponent) value);
367        else
368          super.setProperty(name, value);
369      }
370
371      @Override
372      public Base addChild(String name) throws FHIRException {
373        if (name.equals("role")) {
374          this.role = new Coding();
375          return this.role;
376        }
377        else if (name.equals("actor")) {
378          this.actor = new Reference();
379          return this.actor;
380        }
381        else if (name.equals("userId")) {
382          this.userId = new Identifier();
383          return this.userId;
384        }
385        else if (name.equals("relatedAgent")) {
386          return addRelatedAgent();
387        }
388        else
389          return super.addChild(name);
390      }
391
392      public ProvenanceAgentComponent copy() {
393        ProvenanceAgentComponent dst = new ProvenanceAgentComponent();
394        copyValues(dst);
395        dst.role = role == null ? null : role.copy();
396        dst.actor = actor == null ? null : actor.copy();
397        dst.userId = userId == null ? null : userId.copy();
398        if (relatedAgent != null) {
399          dst.relatedAgent = new ArrayList<ProvenanceAgentRelatedAgentComponent>();
400          for (ProvenanceAgentRelatedAgentComponent i : relatedAgent)
401            dst.relatedAgent.add(i.copy());
402        };
403        return dst;
404      }
405
406      @Override
407      public boolean equalsDeep(Base other) {
408        if (!super.equalsDeep(other))
409          return false;
410        if (!(other instanceof ProvenanceAgentComponent))
411          return false;
412        ProvenanceAgentComponent o = (ProvenanceAgentComponent) other;
413        return compareDeep(role, o.role, true) && compareDeep(actor, o.actor, true) && compareDeep(userId, o.userId, true)
414           && compareDeep(relatedAgent, o.relatedAgent, true);
415      }
416
417      @Override
418      public boolean equalsShallow(Base other) {
419        if (!super.equalsShallow(other))
420          return false;
421        if (!(other instanceof ProvenanceAgentComponent))
422          return false;
423        ProvenanceAgentComponent o = (ProvenanceAgentComponent) other;
424        return true;
425      }
426
427      public boolean isEmpty() {
428        return super.isEmpty() && (role == null || role.isEmpty()) && (actor == null || actor.isEmpty())
429           && (userId == null || userId.isEmpty()) && (relatedAgent == null || relatedAgent.isEmpty())
430          ;
431      }
432
433  public String fhirType() {
434    return "Provenance.agent";
435
436  }
437
438  }
439
440    @Block()
441    public static class ProvenanceAgentRelatedAgentComponent extends BackboneElement implements IBaseBackboneElement {
442        /**
443         * The type of relationship between agents.
444         */
445        @Child(name = "type", type = {CodeableConcept.class}, order=1, min=1, max=1, modifier=false, summary=true)
446        @Description(shortDefinition="Type of relationship between agents", formalDefinition="The type of relationship between agents." )
447        protected CodeableConcept type;
448
449        /**
450         * An internal reference to another agent listed in this provenance by its identifier.
451         */
452        @Child(name = "target", type = {UriType.class}, order=2, min=1, max=1, modifier=false, summary=true)
453        @Description(shortDefinition="Reference to other agent in this resource by identifier", formalDefinition="An internal reference to another agent listed in this provenance by its identifier." )
454        protected UriType target;
455
456        private static final long serialVersionUID = 794181198L;
457
458    /*
459     * Constructor
460     */
461      public ProvenanceAgentRelatedAgentComponent() {
462        super();
463      }
464
465    /*
466     * Constructor
467     */
468      public ProvenanceAgentRelatedAgentComponent(CodeableConcept type, UriType target) {
469        super();
470        this.type = type;
471        this.target = target;
472      }
473
474        /**
475         * @return {@link #type} (The type of relationship between agents.)
476         */
477        public CodeableConcept getType() { 
478          if (this.type == null)
479            if (Configuration.errorOnAutoCreate())
480              throw new Error("Attempt to auto-create ProvenanceAgentRelatedAgentComponent.type");
481            else if (Configuration.doAutoCreate())
482              this.type = new CodeableConcept(); // cc
483          return this.type;
484        }
485
486        public boolean hasType() { 
487          return this.type != null && !this.type.isEmpty();
488        }
489
490        /**
491         * @param value {@link #type} (The type of relationship between agents.)
492         */
493        public ProvenanceAgentRelatedAgentComponent setType(CodeableConcept value) { 
494          this.type = value;
495          return this;
496        }
497
498        /**
499         * @return {@link #target} (An internal reference to another agent listed in this provenance by its identifier.). This is the underlying object with id, value and extensions. The accessor "getTarget" gives direct access to the value
500         */
501        public UriType getTargetElement() { 
502          if (this.target == null)
503            if (Configuration.errorOnAutoCreate())
504              throw new Error("Attempt to auto-create ProvenanceAgentRelatedAgentComponent.target");
505            else if (Configuration.doAutoCreate())
506              this.target = new UriType(); // bb
507          return this.target;
508        }
509
510        public boolean hasTargetElement() { 
511          return this.target != null && !this.target.isEmpty();
512        }
513
514        public boolean hasTarget() { 
515          return this.target != null && !this.target.isEmpty();
516        }
517
518        /**
519         * @param value {@link #target} (An internal reference to another agent listed in this provenance by its identifier.). This is the underlying object with id, value and extensions. The accessor "getTarget" gives direct access to the value
520         */
521        public ProvenanceAgentRelatedAgentComponent setTargetElement(UriType value) { 
522          this.target = value;
523          return this;
524        }
525
526        /**
527         * @return An internal reference to another agent listed in this provenance by its identifier.
528         */
529        public String getTarget() { 
530          return this.target == null ? null : this.target.getValue();
531        }
532
533        /**
534         * @param value An internal reference to another agent listed in this provenance by its identifier.
535         */
536        public ProvenanceAgentRelatedAgentComponent setTarget(String value) { 
537            if (this.target == null)
538              this.target = new UriType();
539            this.target.setValue(value);
540          return this;
541        }
542
543        protected void listChildren(List<Property> childrenList) {
544          super.listChildren(childrenList);
545          childrenList.add(new Property("type", "CodeableConcept", "The type of relationship between agents.", 0, java.lang.Integer.MAX_VALUE, type));
546          childrenList.add(new Property("target", "uri", "An internal reference to another agent listed in this provenance by its identifier.", 0, java.lang.Integer.MAX_VALUE, target));
547        }
548
549      @Override
550      public void setProperty(String name, Base value) throws FHIRException {
551        if (name.equals("type"))
552          this.type = castToCodeableConcept(value); // CodeableConcept
553        else if (name.equals("target"))
554          this.target = castToUri(value); // UriType
555        else
556          super.setProperty(name, value);
557      }
558
559      @Override
560      public Base addChild(String name) throws FHIRException {
561        if (name.equals("type")) {
562          this.type = new CodeableConcept();
563          return this.type;
564        }
565        else if (name.equals("target")) {
566          throw new FHIRException("Cannot call addChild on a primitive type Provenance.target");
567        }
568        else
569          return super.addChild(name);
570      }
571
572      public ProvenanceAgentRelatedAgentComponent copy() {
573        ProvenanceAgentRelatedAgentComponent dst = new ProvenanceAgentRelatedAgentComponent();
574        copyValues(dst);
575        dst.type = type == null ? null : type.copy();
576        dst.target = target == null ? null : target.copy();
577        return dst;
578      }
579
580      @Override
581      public boolean equalsDeep(Base other) {
582        if (!super.equalsDeep(other))
583          return false;
584        if (!(other instanceof ProvenanceAgentRelatedAgentComponent))
585          return false;
586        ProvenanceAgentRelatedAgentComponent o = (ProvenanceAgentRelatedAgentComponent) other;
587        return compareDeep(type, o.type, true) && compareDeep(target, o.target, true);
588      }
589
590      @Override
591      public boolean equalsShallow(Base other) {
592        if (!super.equalsShallow(other))
593          return false;
594        if (!(other instanceof ProvenanceAgentRelatedAgentComponent))
595          return false;
596        ProvenanceAgentRelatedAgentComponent o = (ProvenanceAgentRelatedAgentComponent) other;
597        return compareValues(target, o.target, true);
598      }
599
600      public boolean isEmpty() {
601        return super.isEmpty() && (type == null || type.isEmpty()) && (target == null || target.isEmpty())
602          ;
603      }
604
605  public String fhirType() {
606    return "Provenance.agent.relatedAgent";
607
608  }
609
610  }
611
612    @Block()
613    public static class ProvenanceEntityComponent extends BackboneElement implements IBaseBackboneElement {
614        /**
615         * How the entity was used during the activity.
616         */
617        @Child(name = "role", type = {CodeType.class}, order=1, min=1, max=1, modifier=false, summary=true)
618        @Description(shortDefinition="derivation | revision | quotation | source", formalDefinition="How the entity was used during the activity." )
619        protected Enumeration<ProvenanceEntityRole> role;
620
621        /**
622         * The type of the entity. If the entity is a resource, then this is a resource type.
623         */
624        @Child(name = "type", type = {Coding.class}, order=2, min=1, max=1, modifier=false, summary=true)
625        @Description(shortDefinition="The type of resource in this entity", formalDefinition="The type of the entity. If the entity is a resource, then this is a resource type." )
626        protected Coding type;
627
628        /**
629         * Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.
630         */
631        @Child(name = "reference", type = {UriType.class}, order=3, min=1, max=1, modifier=false, summary=true)
632        @Description(shortDefinition="Identity of entity", formalDefinition="Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative." )
633        protected UriType reference;
634
635        /**
636         * Human-readable description of the entity.
637         */
638        @Child(name = "display", type = {StringType.class}, order=4, min=0, max=1, modifier=false, summary=true)
639        @Description(shortDefinition="Human description of entity", formalDefinition="Human-readable description of the entity." )
640        protected StringType display;
641
642        /**
643         * 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.
644         */
645        @Child(name = "agent", type = {ProvenanceAgentComponent.class}, order=5, min=0, max=1, modifier=false, summary=true)
646        @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." )
647        protected ProvenanceAgentComponent agent;
648
649        private static final long serialVersionUID = 1533729633L;
650
651    /*
652     * Constructor
653     */
654      public ProvenanceEntityComponent() {
655        super();
656      }
657
658    /*
659     * Constructor
660     */
661      public ProvenanceEntityComponent(Enumeration<ProvenanceEntityRole> role, Coding type, UriType reference) {
662        super();
663        this.role = role;
664        this.type = type;
665        this.reference = reference;
666      }
667
668        /**
669         * @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
670         */
671        public Enumeration<ProvenanceEntityRole> getRoleElement() { 
672          if (this.role == null)
673            if (Configuration.errorOnAutoCreate())
674              throw new Error("Attempt to auto-create ProvenanceEntityComponent.role");
675            else if (Configuration.doAutoCreate())
676              this.role = new Enumeration<ProvenanceEntityRole>(new ProvenanceEntityRoleEnumFactory()); // bb
677          return this.role;
678        }
679
680        public boolean hasRoleElement() { 
681          return this.role != null && !this.role.isEmpty();
682        }
683
684        public boolean hasRole() { 
685          return this.role != null && !this.role.isEmpty();
686        }
687
688        /**
689         * @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
690         */
691        public ProvenanceEntityComponent setRoleElement(Enumeration<ProvenanceEntityRole> value) { 
692          this.role = value;
693          return this;
694        }
695
696        /**
697         * @return How the entity was used during the activity.
698         */
699        public ProvenanceEntityRole getRole() { 
700          return this.role == null ? null : this.role.getValue();
701        }
702
703        /**
704         * @param value How the entity was used during the activity.
705         */
706        public ProvenanceEntityComponent setRole(ProvenanceEntityRole value) { 
707            if (this.role == null)
708              this.role = new Enumeration<ProvenanceEntityRole>(new ProvenanceEntityRoleEnumFactory());
709            this.role.setValue(value);
710          return this;
711        }
712
713        /**
714         * @return {@link #type} (The type of the entity. If the entity is a resource, then this is a resource type.)
715         */
716        public Coding getType() { 
717          if (this.type == null)
718            if (Configuration.errorOnAutoCreate())
719              throw new Error("Attempt to auto-create ProvenanceEntityComponent.type");
720            else if (Configuration.doAutoCreate())
721              this.type = new Coding(); // cc
722          return this.type;
723        }
724
725        public boolean hasType() { 
726          return this.type != null && !this.type.isEmpty();
727        }
728
729        /**
730         * @param value {@link #type} (The type of the entity. If the entity is a resource, then this is a resource type.)
731         */
732        public ProvenanceEntityComponent setType(Coding value) { 
733          this.type = value;
734          return this;
735        }
736
737        /**
738         * @return {@link #reference} (Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value
739         */
740        public UriType getReferenceElement() { 
741          if (this.reference == null)
742            if (Configuration.errorOnAutoCreate())
743              throw new Error("Attempt to auto-create ProvenanceEntityComponent.reference");
744            else if (Configuration.doAutoCreate())
745              this.reference = new UriType(); // bb
746          return this.reference;
747        }
748
749        public boolean hasReferenceElement() { 
750          return this.reference != null && !this.reference.isEmpty();
751        }
752
753        public boolean hasReference() { 
754          return this.reference != null && !this.reference.isEmpty();
755        }
756
757        /**
758         * @param value {@link #reference} (Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value
759         */
760        public ProvenanceEntityComponent setReferenceElement(UriType value) { 
761          this.reference = value;
762          return this;
763        }
764
765        /**
766         * @return Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.
767         */
768        public String getReference() { 
769          return this.reference == null ? null : this.reference.getValue();
770        }
771
772        /**
773         * @param value Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.
774         */
775        public ProvenanceEntityComponent setReference(String value) { 
776            if (this.reference == null)
777              this.reference = new UriType();
778            this.reference.setValue(value);
779          return this;
780        }
781
782        /**
783         * @return {@link #display} (Human-readable description of the entity.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value
784         */
785        public StringType getDisplayElement() { 
786          if (this.display == null)
787            if (Configuration.errorOnAutoCreate())
788              throw new Error("Attempt to auto-create ProvenanceEntityComponent.display");
789            else if (Configuration.doAutoCreate())
790              this.display = new StringType(); // bb
791          return this.display;
792        }
793
794        public boolean hasDisplayElement() { 
795          return this.display != null && !this.display.isEmpty();
796        }
797
798        public boolean hasDisplay() { 
799          return this.display != null && !this.display.isEmpty();
800        }
801
802        /**
803         * @param value {@link #display} (Human-readable description of the entity.). This is the underlying object with id, value and extensions. The accessor "getDisplay" gives direct access to the value
804         */
805        public ProvenanceEntityComponent setDisplayElement(StringType value) { 
806          this.display = value;
807          return this;
808        }
809
810        /**
811         * @return Human-readable description of the entity.
812         */
813        public String getDisplay() { 
814          return this.display == null ? null : this.display.getValue();
815        }
816
817        /**
818         * @param value Human-readable description of the entity.
819         */
820        public ProvenanceEntityComponent setDisplay(String value) { 
821          if (Utilities.noString(value))
822            this.display = null;
823          else {
824            if (this.display == null)
825              this.display = new StringType();
826            this.display.setValue(value);
827          }
828          return this;
829        }
830
831        /**
832         * @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.)
833         */
834        public ProvenanceAgentComponent getAgent() { 
835          if (this.agent == null)
836            if (Configuration.errorOnAutoCreate())
837              throw new Error("Attempt to auto-create ProvenanceEntityComponent.agent");
838            else if (Configuration.doAutoCreate())
839              this.agent = new ProvenanceAgentComponent(); // cc
840          return this.agent;
841        }
842
843        public boolean hasAgent() { 
844          return this.agent != null && !this.agent.isEmpty();
845        }
846
847        /**
848         * @param value {@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.)
849         */
850        public ProvenanceEntityComponent setAgent(ProvenanceAgentComponent value) { 
851          this.agent = value;
852          return this;
853        }
854
855        protected void listChildren(List<Property> childrenList) {
856          super.listChildren(childrenList);
857          childrenList.add(new Property("role", "code", "How the entity was used during the activity.", 0, java.lang.Integer.MAX_VALUE, role));
858          childrenList.add(new Property("type", "Coding", "The type of the entity. If the entity is a resource, then this is a resource type.", 0, java.lang.Integer.MAX_VALUE, type));
859          childrenList.add(new Property("reference", "uri", "Identity of the  Entity used. May be a logical or physical uri and maybe absolute or relative.", 0, java.lang.Integer.MAX_VALUE, reference));
860          childrenList.add(new Property("display", "string", "Human-readable description of the entity.", 0, java.lang.Integer.MAX_VALUE, display));
861          childrenList.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));
862        }
863
864      @Override
865      public void setProperty(String name, Base value) throws FHIRException {
866        if (name.equals("role"))
867          this.role = new ProvenanceEntityRoleEnumFactory().fromType(value); // Enumeration<ProvenanceEntityRole>
868        else if (name.equals("type"))
869          this.type = castToCoding(value); // Coding
870        else if (name.equals("reference"))
871          this.reference = castToUri(value); // UriType
872        else if (name.equals("display"))
873          this.display = castToString(value); // StringType
874        else if (name.equals("agent"))
875          this.agent = (ProvenanceAgentComponent) value; // ProvenanceAgentComponent
876        else
877          super.setProperty(name, value);
878      }
879
880      @Override
881      public Base addChild(String name) throws FHIRException {
882        if (name.equals("role")) {
883          throw new FHIRException("Cannot call addChild on a primitive type Provenance.role");
884        }
885        else if (name.equals("type")) {
886          this.type = new Coding();
887          return this.type;
888        }
889        else if (name.equals("reference")) {
890          throw new FHIRException("Cannot call addChild on a primitive type Provenance.reference");
891        }
892        else if (name.equals("display")) {
893          throw new FHIRException("Cannot call addChild on a primitive type Provenance.display");
894        }
895        else if (name.equals("agent")) {
896          this.agent = new ProvenanceAgentComponent();
897          return this.agent;
898        }
899        else
900          return super.addChild(name);
901      }
902
903      public ProvenanceEntityComponent copy() {
904        ProvenanceEntityComponent dst = new ProvenanceEntityComponent();
905        copyValues(dst);
906        dst.role = role == null ? null : role.copy();
907        dst.type = type == null ? null : type.copy();
908        dst.reference = reference == null ? null : reference.copy();
909        dst.display = display == null ? null : display.copy();
910        dst.agent = agent == null ? null : agent.copy();
911        return dst;
912      }
913
914      @Override
915      public boolean equalsDeep(Base other) {
916        if (!super.equalsDeep(other))
917          return false;
918        if (!(other instanceof ProvenanceEntityComponent))
919          return false;
920        ProvenanceEntityComponent o = (ProvenanceEntityComponent) other;
921        return compareDeep(role, o.role, true) && compareDeep(type, o.type, true) && compareDeep(reference, o.reference, true)
922           && compareDeep(display, o.display, true) && compareDeep(agent, o.agent, true);
923      }
924
925      @Override
926      public boolean equalsShallow(Base other) {
927        if (!super.equalsShallow(other))
928          return false;
929        if (!(other instanceof ProvenanceEntityComponent))
930          return false;
931        ProvenanceEntityComponent o = (ProvenanceEntityComponent) other;
932        return compareValues(role, o.role, true) && compareValues(reference, o.reference, true) && compareValues(display, o.display, true)
933          ;
934      }
935
936      public boolean isEmpty() {
937        return super.isEmpty() && (role == null || role.isEmpty()) && (type == null || type.isEmpty())
938           && (reference == null || reference.isEmpty()) && (display == null || display.isEmpty()) && (agent == null || agent.isEmpty())
939          ;
940      }
941
942  public String fhirType() {
943    return "Provenance.entity";
944
945  }
946
947  }
948
949    /**
950     * 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.
951     */
952    @Child(name = "target", type = {}, order=0, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
953    @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." )
954    protected List<Reference> target;
955    /**
956     * 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.)
957     */
958    protected List<Resource> targetTarget;
959
960
961    /**
962     * The period during which the activity occurred.
963     */
964    @Child(name = "period", type = {Period.class}, order=1, min=0, max=1, modifier=false, summary=true)
965    @Description(shortDefinition="When the activity occurred", formalDefinition="The period during which the activity occurred." )
966    protected Period period;
967
968    /**
969     * The instant of time at which the activity was recorded.
970     */
971    @Child(name = "recorded", type = {InstantType.class}, order=2, min=1, max=1, modifier=false, summary=true)
972    @Description(shortDefinition="When the activity was recorded / updated", formalDefinition="The instant of time at which the activity was recorded." )
973    protected InstantType recorded;
974
975    /**
976     * The reason that the activity was taking place.
977     */
978    @Child(name = "reason", type = {CodeableConcept.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
979    @Description(shortDefinition="Reason the activity is occurring", formalDefinition="The reason that the activity was taking place." )
980    protected List<CodeableConcept> reason;
981
982    /**
983     * 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.
984     */
985    @Child(name = "activity", type = {CodeableConcept.class}, order=4, min=0, max=1, modifier=false, summary=true)
986    @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." )
987    protected CodeableConcept activity;
988
989    /**
990     * Where the activity occurred, if relevant.
991     */
992    @Child(name = "location", type = {Location.class}, order=5, min=0, max=1, modifier=false, summary=true)
993    @Description(shortDefinition="Where the activity occurred, if relevant", formalDefinition="Where the activity occurred, if relevant." )
994    protected Reference location;
995
996    /**
997     * The actual object that is the target of the reference (Where the activity occurred, if relevant.)
998     */
999    protected Location locationTarget;
1000
1001    /**
1002     * 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.
1003     */
1004    @Child(name = "policy", type = {UriType.class}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1005    @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." )
1006    protected List<UriType> policy;
1007
1008    /**
1009     * An agent takes a role in an activity such that the agent can be assigned some degree of responsibility for the activity taking place. An agent can be a person, an organization, software, or other entities that may be ascribed responsibility.
1010     */
1011    @Child(name = "agent", type = {}, order=7, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1012    @Description(shortDefinition="Agents involved in creating resource", formalDefinition="An agent takes a role in an activity such that the agent can be assigned some degree of responsibility for the activity taking place. An agent can be a person, an organization, software, or other entities that may be ascribed responsibility." )
1013    protected List<ProvenanceAgentComponent> agent;
1014
1015    /**
1016     * An entity used in this activity.
1017     */
1018    @Child(name = "entity", type = {}, order=8, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1019    @Description(shortDefinition="An entity used in this activity", formalDefinition="An entity used in this activity." )
1020    protected List<ProvenanceEntityComponent> entity;
1021
1022    /**
1023     * A digital signature on the target Reference(s). The signer should match a Provenance.agent. The purpose of the signature is indicated.
1024     */
1025    @Child(name = "signature", type = {Signature.class}, order=9, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
1026    @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." )
1027    protected List<Signature> signature;
1028
1029    private static final long serialVersionUID = -1053458671L;
1030
1031  /*
1032   * Constructor
1033   */
1034    public Provenance() {
1035      super();
1036    }
1037
1038  /*
1039   * Constructor
1040   */
1041    public Provenance(InstantType recorded) {
1042      super();
1043      this.recorded = recorded;
1044    }
1045
1046    /**
1047     * @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.)
1048     */
1049    public List<Reference> getTarget() { 
1050      if (this.target == null)
1051        this.target = new ArrayList<Reference>();
1052      return this.target;
1053    }
1054
1055    public boolean hasTarget() { 
1056      if (this.target == null)
1057        return false;
1058      for (Reference item : this.target)
1059        if (!item.isEmpty())
1060          return true;
1061      return false;
1062    }
1063
1064    /**
1065     * @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.)
1066     */
1067    // syntactic sugar
1068    public Reference addTarget() { //3
1069      Reference t = new Reference();
1070      if (this.target == null)
1071        this.target = new ArrayList<Reference>();
1072      this.target.add(t);
1073      return t;
1074    }
1075
1076    // syntactic sugar
1077    public Provenance addTarget(Reference t) { //3
1078      if (t == null)
1079        return this;
1080      if (this.target == null)
1081        this.target = new ArrayList<Reference>();
1082      this.target.add(t);
1083      return this;
1084    }
1085
1086    /**
1087     * @return {@link #target} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. 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.)
1088     */
1089    public List<Resource> getTargetTarget() { 
1090      if (this.targetTarget == null)
1091        this.targetTarget = new ArrayList<Resource>();
1092      return this.targetTarget;
1093    }
1094
1095    /**
1096     * @return {@link #period} (The period during which the activity occurred.)
1097     */
1098    public Period getPeriod() { 
1099      if (this.period == null)
1100        if (Configuration.errorOnAutoCreate())
1101          throw new Error("Attempt to auto-create Provenance.period");
1102        else if (Configuration.doAutoCreate())
1103          this.period = new Period(); // cc
1104      return this.period;
1105    }
1106
1107    public boolean hasPeriod() { 
1108      return this.period != null && !this.period.isEmpty();
1109    }
1110
1111    /**
1112     * @param value {@link #period} (The period during which the activity occurred.)
1113     */
1114    public Provenance setPeriod(Period value) { 
1115      this.period = value;
1116      return this;
1117    }
1118
1119    /**
1120     * @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
1121     */
1122    public InstantType getRecordedElement() { 
1123      if (this.recorded == null)
1124        if (Configuration.errorOnAutoCreate())
1125          throw new Error("Attempt to auto-create Provenance.recorded");
1126        else if (Configuration.doAutoCreate())
1127          this.recorded = new InstantType(); // bb
1128      return this.recorded;
1129    }
1130
1131    public boolean hasRecordedElement() { 
1132      return this.recorded != null && !this.recorded.isEmpty();
1133    }
1134
1135    public boolean hasRecorded() { 
1136      return this.recorded != null && !this.recorded.isEmpty();
1137    }
1138
1139    /**
1140     * @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
1141     */
1142    public Provenance setRecordedElement(InstantType value) { 
1143      this.recorded = value;
1144      return this;
1145    }
1146
1147    /**
1148     * @return The instant of time at which the activity was recorded.
1149     */
1150    public Date getRecorded() { 
1151      return this.recorded == null ? null : this.recorded.getValue();
1152    }
1153
1154    /**
1155     * @param value The instant of time at which the activity was recorded.
1156     */
1157    public Provenance setRecorded(Date value) { 
1158        if (this.recorded == null)
1159          this.recorded = new InstantType();
1160        this.recorded.setValue(value);
1161      return this;
1162    }
1163
1164    /**
1165     * @return {@link #reason} (The reason that the activity was taking place.)
1166     */
1167    public List<CodeableConcept> getReason() { 
1168      if (this.reason == null)
1169        this.reason = new ArrayList<CodeableConcept>();
1170      return this.reason;
1171    }
1172
1173    public boolean hasReason() { 
1174      if (this.reason == null)
1175        return false;
1176      for (CodeableConcept item : this.reason)
1177        if (!item.isEmpty())
1178          return true;
1179      return false;
1180    }
1181
1182    /**
1183     * @return {@link #reason} (The reason that the activity was taking place.)
1184     */
1185    // syntactic sugar
1186    public CodeableConcept addReason() { //3
1187      CodeableConcept t = new CodeableConcept();
1188      if (this.reason == null)
1189        this.reason = new ArrayList<CodeableConcept>();
1190      this.reason.add(t);
1191      return t;
1192    }
1193
1194    // syntactic sugar
1195    public Provenance addReason(CodeableConcept t) { //3
1196      if (t == null)
1197        return this;
1198      if (this.reason == null)
1199        this.reason = new ArrayList<CodeableConcept>();
1200      this.reason.add(t);
1201      return this;
1202    }
1203
1204    /**
1205     * @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.)
1206     */
1207    public CodeableConcept getActivity() { 
1208      if (this.activity == null)
1209        if (Configuration.errorOnAutoCreate())
1210          throw new Error("Attempt to auto-create Provenance.activity");
1211        else if (Configuration.doAutoCreate())
1212          this.activity = new CodeableConcept(); // cc
1213      return this.activity;
1214    }
1215
1216    public boolean hasActivity() { 
1217      return this.activity != null && !this.activity.isEmpty();
1218    }
1219
1220    /**
1221     * @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.)
1222     */
1223    public Provenance setActivity(CodeableConcept value) { 
1224      this.activity = value;
1225      return this;
1226    }
1227
1228    /**
1229     * @return {@link #location} (Where the activity occurred, if relevant.)
1230     */
1231    public Reference getLocation() { 
1232      if (this.location == null)
1233        if (Configuration.errorOnAutoCreate())
1234          throw new Error("Attempt to auto-create Provenance.location");
1235        else if (Configuration.doAutoCreate())
1236          this.location = new Reference(); // cc
1237      return this.location;
1238    }
1239
1240    public boolean hasLocation() { 
1241      return this.location != null && !this.location.isEmpty();
1242    }
1243
1244    /**
1245     * @param value {@link #location} (Where the activity occurred, if relevant.)
1246     */
1247    public Provenance setLocation(Reference value) { 
1248      this.location = value;
1249      return this;
1250    }
1251
1252    /**
1253     * @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.)
1254     */
1255    public Location getLocationTarget() { 
1256      if (this.locationTarget == null)
1257        if (Configuration.errorOnAutoCreate())
1258          throw new Error("Attempt to auto-create Provenance.location");
1259        else if (Configuration.doAutoCreate())
1260          this.locationTarget = new Location(); // aa
1261      return this.locationTarget;
1262    }
1263
1264    /**
1265     * @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.)
1266     */
1267    public Provenance setLocationTarget(Location value) { 
1268      this.locationTarget = value;
1269      return this;
1270    }
1271
1272    /**
1273     * @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.)
1274     */
1275    public List<UriType> getPolicy() { 
1276      if (this.policy == null)
1277        this.policy = new ArrayList<UriType>();
1278      return this.policy;
1279    }
1280
1281    public boolean hasPolicy() { 
1282      if (this.policy == null)
1283        return false;
1284      for (UriType item : this.policy)
1285        if (!item.isEmpty())
1286          return true;
1287      return false;
1288    }
1289
1290    /**
1291     * @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.)
1292     */
1293    // syntactic sugar
1294    public UriType addPolicyElement() {//2 
1295      UriType t = new UriType();
1296      if (this.policy == null)
1297        this.policy = new ArrayList<UriType>();
1298      this.policy.add(t);
1299      return t;
1300    }
1301
1302    /**
1303     * @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.)
1304     */
1305    public Provenance addPolicy(String value) { //1
1306      UriType t = new UriType();
1307      t.setValue(value);
1308      if (this.policy == null)
1309        this.policy = new ArrayList<UriType>();
1310      this.policy.add(t);
1311      return this;
1312    }
1313
1314    /**
1315     * @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.)
1316     */
1317    public boolean hasPolicy(String value) { 
1318      if (this.policy == null)
1319        return false;
1320      for (UriType v : this.policy)
1321        if (v.equals(value)) // uri
1322          return true;
1323      return false;
1324    }
1325
1326    /**
1327     * @return {@link #agent} (An agent takes a role in an activity such that the agent can be assigned some degree of responsibility for the activity taking place. An agent can be a person, an organization, software, or other entities that may be ascribed responsibility.)
1328     */
1329    public List<ProvenanceAgentComponent> getAgent() { 
1330      if (this.agent == null)
1331        this.agent = new ArrayList<ProvenanceAgentComponent>();
1332      return this.agent;
1333    }
1334
1335    public boolean hasAgent() { 
1336      if (this.agent == null)
1337        return false;
1338      for (ProvenanceAgentComponent item : this.agent)
1339        if (!item.isEmpty())
1340          return true;
1341      return false;
1342    }
1343
1344    /**
1345     * @return {@link #agent} (An agent takes a role in an activity such that the agent can be assigned some degree of responsibility for the activity taking place. An agent can be a person, an organization, software, or other entities that may be ascribed responsibility.)
1346     */
1347    // syntactic sugar
1348    public ProvenanceAgentComponent addAgent() { //3
1349      ProvenanceAgentComponent t = new ProvenanceAgentComponent();
1350      if (this.agent == null)
1351        this.agent = new ArrayList<ProvenanceAgentComponent>();
1352      this.agent.add(t);
1353      return t;
1354    }
1355
1356    // syntactic sugar
1357    public Provenance addAgent(ProvenanceAgentComponent t) { //3
1358      if (t == null)
1359        return this;
1360      if (this.agent == null)
1361        this.agent = new ArrayList<ProvenanceAgentComponent>();
1362      this.agent.add(t);
1363      return this;
1364    }
1365
1366    /**
1367     * @return {@link #entity} (An entity used in this activity.)
1368     */
1369    public List<ProvenanceEntityComponent> getEntity() { 
1370      if (this.entity == null)
1371        this.entity = new ArrayList<ProvenanceEntityComponent>();
1372      return this.entity;
1373    }
1374
1375    public boolean hasEntity() { 
1376      if (this.entity == null)
1377        return false;
1378      for (ProvenanceEntityComponent item : this.entity)
1379        if (!item.isEmpty())
1380          return true;
1381      return false;
1382    }
1383
1384    /**
1385     * @return {@link #entity} (An entity used in this activity.)
1386     */
1387    // syntactic sugar
1388    public ProvenanceEntityComponent addEntity() { //3
1389      ProvenanceEntityComponent t = new ProvenanceEntityComponent();
1390      if (this.entity == null)
1391        this.entity = new ArrayList<ProvenanceEntityComponent>();
1392      this.entity.add(t);
1393      return t;
1394    }
1395
1396    // syntactic sugar
1397    public Provenance addEntity(ProvenanceEntityComponent t) { //3
1398      if (t == null)
1399        return this;
1400      if (this.entity == null)
1401        this.entity = new ArrayList<ProvenanceEntityComponent>();
1402      this.entity.add(t);
1403      return this;
1404    }
1405
1406    /**
1407     * @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.)
1408     */
1409    public List<Signature> getSignature() { 
1410      if (this.signature == null)
1411        this.signature = new ArrayList<Signature>();
1412      return this.signature;
1413    }
1414
1415    public boolean hasSignature() { 
1416      if (this.signature == null)
1417        return false;
1418      for (Signature item : this.signature)
1419        if (!item.isEmpty())
1420          return true;
1421      return false;
1422    }
1423
1424    /**
1425     * @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.)
1426     */
1427    // syntactic sugar
1428    public Signature addSignature() { //3
1429      Signature t = new Signature();
1430      if (this.signature == null)
1431        this.signature = new ArrayList<Signature>();
1432      this.signature.add(t);
1433      return t;
1434    }
1435
1436    // syntactic sugar
1437    public Provenance addSignature(Signature t) { //3
1438      if (t == null)
1439        return this;
1440      if (this.signature == null)
1441        this.signature = new ArrayList<Signature>();
1442      this.signature.add(t);
1443      return this;
1444    }
1445
1446      protected void listChildren(List<Property> childrenList) {
1447        super.listChildren(childrenList);
1448        childrenList.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));
1449        childrenList.add(new Property("period", "Period", "The period during which the activity occurred.", 0, java.lang.Integer.MAX_VALUE, period));
1450        childrenList.add(new Property("recorded", "instant", "The instant of time at which the activity was recorded.", 0, java.lang.Integer.MAX_VALUE, recorded));
1451        childrenList.add(new Property("reason", "CodeableConcept", "The reason that the activity was taking place.", 0, java.lang.Integer.MAX_VALUE, reason));
1452        childrenList.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, java.lang.Integer.MAX_VALUE, activity));
1453        childrenList.add(new Property("location", "Reference(Location)", "Where the activity occurred, if relevant.", 0, java.lang.Integer.MAX_VALUE, location));
1454        childrenList.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));
1455        childrenList.add(new Property("agent", "", "An agent takes a role in an activity such that the agent can be assigned some degree of responsibility for the activity taking place. An agent can be a person, an organization, software, or other entities that may be ascribed responsibility.", 0, java.lang.Integer.MAX_VALUE, agent));
1456        childrenList.add(new Property("entity", "", "An entity used in this activity.", 0, java.lang.Integer.MAX_VALUE, entity));
1457        childrenList.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));
1458      }
1459
1460      @Override
1461      public void setProperty(String name, Base value) throws FHIRException {
1462        if (name.equals("target"))
1463          this.getTarget().add(castToReference(value));
1464        else if (name.equals("period"))
1465          this.period = castToPeriod(value); // Period
1466        else if (name.equals("recorded"))
1467          this.recorded = castToInstant(value); // InstantType
1468        else if (name.equals("reason"))
1469          this.getReason().add(castToCodeableConcept(value));
1470        else if (name.equals("activity"))
1471          this.activity = castToCodeableConcept(value); // CodeableConcept
1472        else if (name.equals("location"))
1473          this.location = castToReference(value); // Reference
1474        else if (name.equals("policy"))
1475          this.getPolicy().add(castToUri(value));
1476        else if (name.equals("agent"))
1477          this.getAgent().add((ProvenanceAgentComponent) value);
1478        else if (name.equals("entity"))
1479          this.getEntity().add((ProvenanceEntityComponent) value);
1480        else if (name.equals("signature"))
1481          this.getSignature().add(castToSignature(value));
1482        else
1483          super.setProperty(name, value);
1484      }
1485
1486      @Override
1487      public Base addChild(String name) throws FHIRException {
1488        if (name.equals("target")) {
1489          return addTarget();
1490        }
1491        else if (name.equals("period")) {
1492          this.period = new Period();
1493          return this.period;
1494        }
1495        else if (name.equals("recorded")) {
1496          throw new FHIRException("Cannot call addChild on a primitive type Provenance.recorded");
1497        }
1498        else if (name.equals("reason")) {
1499          return addReason();
1500        }
1501        else if (name.equals("activity")) {
1502          this.activity = new CodeableConcept();
1503          return this.activity;
1504        }
1505        else if (name.equals("location")) {
1506          this.location = new Reference();
1507          return this.location;
1508        }
1509        else if (name.equals("policy")) {
1510          throw new FHIRException("Cannot call addChild on a primitive type Provenance.policy");
1511        }
1512        else if (name.equals("agent")) {
1513          return addAgent();
1514        }
1515        else if (name.equals("entity")) {
1516          return addEntity();
1517        }
1518        else if (name.equals("signature")) {
1519          return addSignature();
1520        }
1521        else
1522          return super.addChild(name);
1523      }
1524
1525  public String fhirType() {
1526    return "Provenance";
1527
1528  }
1529
1530      public Provenance copy() {
1531        Provenance dst = new Provenance();
1532        copyValues(dst);
1533        if (target != null) {
1534          dst.target = new ArrayList<Reference>();
1535          for (Reference i : target)
1536            dst.target.add(i.copy());
1537        };
1538        dst.period = period == null ? null : period.copy();
1539        dst.recorded = recorded == null ? null : recorded.copy();
1540        if (reason != null) {
1541          dst.reason = new ArrayList<CodeableConcept>();
1542          for (CodeableConcept i : reason)
1543            dst.reason.add(i.copy());
1544        };
1545        dst.activity = activity == null ? null : activity.copy();
1546        dst.location = location == null ? null : location.copy();
1547        if (policy != null) {
1548          dst.policy = new ArrayList<UriType>();
1549          for (UriType i : policy)
1550            dst.policy.add(i.copy());
1551        };
1552        if (agent != null) {
1553          dst.agent = new ArrayList<ProvenanceAgentComponent>();
1554          for (ProvenanceAgentComponent i : agent)
1555            dst.agent.add(i.copy());
1556        };
1557        if (entity != null) {
1558          dst.entity = new ArrayList<ProvenanceEntityComponent>();
1559          for (ProvenanceEntityComponent i : entity)
1560            dst.entity.add(i.copy());
1561        };
1562        if (signature != null) {
1563          dst.signature = new ArrayList<Signature>();
1564          for (Signature i : signature)
1565            dst.signature.add(i.copy());
1566        };
1567        return dst;
1568      }
1569
1570      protected Provenance typedCopy() {
1571        return copy();
1572      }
1573
1574      @Override
1575      public boolean equalsDeep(Base other) {
1576        if (!super.equalsDeep(other))
1577          return false;
1578        if (!(other instanceof Provenance))
1579          return false;
1580        Provenance o = (Provenance) other;
1581        return compareDeep(target, o.target, true) && compareDeep(period, o.period, true) && compareDeep(recorded, o.recorded, true)
1582           && compareDeep(reason, o.reason, true) && compareDeep(activity, o.activity, true) && compareDeep(location, o.location, true)
1583           && compareDeep(policy, o.policy, true) && compareDeep(agent, o.agent, true) && compareDeep(entity, o.entity, true)
1584           && compareDeep(signature, o.signature, true);
1585      }
1586
1587      @Override
1588      public boolean equalsShallow(Base other) {
1589        if (!super.equalsShallow(other))
1590          return false;
1591        if (!(other instanceof Provenance))
1592          return false;
1593        Provenance o = (Provenance) other;
1594        return compareValues(recorded, o.recorded, true) && compareValues(policy, o.policy, true);
1595      }
1596
1597      public boolean isEmpty() {
1598        return super.isEmpty() && (target == null || target.isEmpty()) && (period == null || period.isEmpty())
1599           && (recorded == null || recorded.isEmpty()) && (reason == null || reason.isEmpty()) && (activity == null || activity.isEmpty())
1600           && (location == null || location.isEmpty()) && (policy == null || policy.isEmpty()) && (agent == null || agent.isEmpty())
1601           && (entity == null || entity.isEmpty()) && (signature == null || signature.isEmpty());
1602      }
1603
1604  @Override
1605  public ResourceType getResourceType() {
1606    return ResourceType.Provenance;
1607   }
1608
1609  @SearchParamDefinition(name="sigtype", path="Provenance.signature.type", description="Indication of the reason the entity signed the object(s)", type="token" )
1610  public static final String SP_SIGTYPE = "sigtype";
1611  @SearchParamDefinition(name="agent", path="Provenance.agent.actor", description="Individual, device or organization playing role", type="reference" )
1612  public static final String SP_AGENT = "agent";
1613  @SearchParamDefinition(name="entitytype", path="Provenance.entity.type", description="The type of resource in this entity", type="token" )
1614  public static final String SP_ENTITYTYPE = "entitytype";
1615  @SearchParamDefinition(name="patient", path="Provenance.target", description="Target Reference(s) (usually version specific)", type="reference" )
1616  public static final String SP_PATIENT = "patient";
1617  @SearchParamDefinition(name="start", path="Provenance.period.start", description="Starting time with inclusive boundary", type="date" )
1618  public static final String SP_START = "start";
1619  @SearchParamDefinition(name="end", path="Provenance.period.end", description="End time with inclusive boundary, if not ongoing", type="date" )
1620  public static final String SP_END = "end";
1621  @SearchParamDefinition(name="location", path="Provenance.location", description="Where the activity occurred, if relevant", type="reference" )
1622  public static final String SP_LOCATION = "location";
1623  @SearchParamDefinition(name="userid", path="Provenance.agent.userId", description="Authorization-system identifier for the agent", type="token" )
1624  public static final String SP_USERID = "userid";
1625  @SearchParamDefinition(name="entity", path="Provenance.entity.reference", description="Identity of entity", type="uri" )
1626  public static final String SP_ENTITY = "entity";
1627  @SearchParamDefinition(name="target", path="Provenance.target", description="Target Reference(s) (usually version specific)", type="reference" )
1628  public static final String SP_TARGET = "target";
1629
1630}