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