001package org.hl7.fhir.dstu3.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import org.hl7.fhir.dstu3.model.Enumerations.*;
038import ca.uhn.fhir.model.api.annotation.Child;
039import ca.uhn.fhir.model.api.annotation.ChildOrder;
040import ca.uhn.fhir.model.api.annotation.Description;
041import ca.uhn.fhir.model.api.annotation.DatatypeDef;
042import ca.uhn.fhir.model.api.annotation.Block;
043import org.hl7.fhir.instance.model.api.*;
044import org.hl7.fhir.exceptions.FHIRException;
045/**
046 * The metadata about a resource. This is content in the resource that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.
047 */
048@DatatypeDef(name="Meta")
049public class Meta extends Type implements IBaseMetaType {
050
051    /**
052     * The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.
053     */
054    @Child(name = "versionId", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
055    @Description(shortDefinition="Version specific identifier", formalDefinition="The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted." )
056    protected IdType versionId;
057
058    /**
059     * When the resource last changed - e.g. when the version changed.
060     */
061    @Child(name = "lastUpdated", type = {InstantType.class}, order=1, min=0, max=1, modifier=false, summary=true)
062    @Description(shortDefinition="When the resource version last changed", formalDefinition="When the resource last changed - e.g. when the version changed." )
063    protected InstantType lastUpdated;
064
065    /**
066     * A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].
067     */
068    @Child(name = "profile", type = {UriType.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
069    @Description(shortDefinition="Profiles this resource claims to conform to", formalDefinition="A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]]." )
070    protected List<UriType> profile;
071
072    /**
073     * Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.
074     */
075    @Child(name = "security", type = {Coding.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
076    @Description(shortDefinition="Security Labels applied to this resource", formalDefinition="Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure." )
077    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/security-labels")
078    protected List<Coding> security;
079
080    /**
081     * Tags applied to this resource. Tags are intended to be used to identify and relate resources to process and workflow, and applications are not required to consider the tags when interpreting the meaning of a resource.
082     */
083    @Child(name = "tag", type = {Coding.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
084    @Description(shortDefinition="Tags applied to this resource", formalDefinition="Tags applied to this resource. Tags are intended to be used to identify and relate resources to process and workflow, and applications are not required to consider the tags when interpreting the meaning of a resource." )
085    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/common-tags")
086    protected List<Coding> tag;
087
088    private static final long serialVersionUID = 867134915L;
089
090  /**
091   * Constructor
092   */
093    public Meta() {
094      super();
095    }
096
097    /**
098     * @return {@link #versionId} (The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.). This is the underlying object with id, value and extensions. The accessor "getVersionId" gives direct access to the value
099     */
100    public IdType getVersionIdElement() { 
101      if (this.versionId == null)
102        if (Configuration.errorOnAutoCreate())
103          throw new Error("Attempt to auto-create Meta.versionId");
104        else if (Configuration.doAutoCreate())
105          this.versionId = new IdType(); // bb
106      return this.versionId;
107    }
108
109    public boolean hasVersionIdElement() { 
110      return this.versionId != null && !this.versionId.isEmpty();
111    }
112
113    public boolean hasVersionId() { 
114      return this.versionId != null && !this.versionId.isEmpty();
115    }
116
117    /**
118     * @param value {@link #versionId} (The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.). This is the underlying object with id, value and extensions. The accessor "getVersionId" gives direct access to the value
119     */
120    public Meta setVersionIdElement(IdType value) { 
121      this.versionId = value;
122      return this;
123    }
124
125    /**
126     * @return The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.
127     */
128    public String getVersionId() { 
129      return this.versionId == null ? null : this.versionId.getValue();
130    }
131
132    /**
133     * @param value The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.
134     */
135    public Meta setVersionId(String value) { 
136      if (Utilities.noString(value))
137        this.versionId = null;
138      else {
139        if (this.versionId == null)
140          this.versionId = new IdType();
141        this.versionId.setValue(value);
142      }
143      return this;
144    }
145
146    /**
147     * @return {@link #lastUpdated} (When the resource last changed - e.g. when the version changed.). This is the underlying object with id, value and extensions. The accessor "getLastUpdated" gives direct access to the value
148     */
149    public InstantType getLastUpdatedElement() { 
150      if (this.lastUpdated == null)
151        if (Configuration.errorOnAutoCreate())
152          throw new Error("Attempt to auto-create Meta.lastUpdated");
153        else if (Configuration.doAutoCreate())
154          this.lastUpdated = new InstantType(); // bb
155      return this.lastUpdated;
156    }
157
158    public boolean hasLastUpdatedElement() { 
159      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
160    }
161
162    public boolean hasLastUpdated() { 
163      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
164    }
165
166    /**
167     * @param value {@link #lastUpdated} (When the resource last changed - e.g. when the version changed.). This is the underlying object with id, value and extensions. The accessor "getLastUpdated" gives direct access to the value
168     */
169    public Meta setLastUpdatedElement(InstantType value) { 
170      this.lastUpdated = value;
171      return this;
172    }
173
174    /**
175     * @return When the resource last changed - e.g. when the version changed.
176     */
177    public Date getLastUpdated() { 
178      return this.lastUpdated == null ? null : this.lastUpdated.getValue();
179    }
180
181    /**
182     * @param value When the resource last changed - e.g. when the version changed.
183     */
184    public Meta setLastUpdated(Date value) { 
185      if (value == null)
186        this.lastUpdated = null;
187      else {
188        if (this.lastUpdated == null)
189          this.lastUpdated = new InstantType();
190        this.lastUpdated.setValue(value);
191      }
192      return this;
193    }
194
195    /**
196     * @return {@link #profile} (A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
197     */
198    public List<UriType> getProfile() { 
199      if (this.profile == null)
200        this.profile = new ArrayList<UriType>();
201      return this.profile;
202    }
203
204    /**
205     * @return Returns a reference to <code>this</code> for easy method chaining
206     */
207    public Meta setProfile(List<UriType> theProfile) { 
208      this.profile = theProfile;
209      return this;
210    }
211
212    public boolean hasProfile() { 
213      if (this.profile == null)
214        return false;
215      for (UriType item : this.profile)
216        if (!item.isEmpty())
217          return true;
218      return false;
219    }
220
221    /**
222     * @return {@link #profile} (A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
223     */
224    public UriType addProfileElement() {//2 
225      UriType t = new UriType();
226      if (this.profile == null)
227        this.profile = new ArrayList<UriType>();
228      this.profile.add(t);
229      return t;
230    }
231
232    /**
233     * @param value {@link #profile} (A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
234     */
235    public Meta addProfile(String value) { //1
236      UriType t = new UriType();
237      t.setValue(value);
238      if (this.profile == null)
239        this.profile = new ArrayList<UriType>();
240      this.profile.add(t);
241      return this;
242    }
243
244    /**
245     * @param value {@link #profile} (A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
246     */
247    public boolean hasProfile(String value) { 
248      if (this.profile == null)
249        return false;
250      for (UriType v : this.profile)
251        if (v.equals(value)) // uri
252          return true;
253      return false;
254    }
255
256    /**
257     * @return {@link #security} (Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.)
258     */
259    public List<Coding> getSecurity() { 
260      if (this.security == null)
261        this.security = new ArrayList<Coding>();
262      return this.security;
263    }
264
265    /**
266     * @return Returns a reference to <code>this</code> for easy method chaining
267     */
268    public Meta setSecurity(List<Coding> theSecurity) { 
269      this.security = theSecurity;
270      return this;
271    }
272
273    public boolean hasSecurity() { 
274      if (this.security == null)
275        return false;
276      for (Coding item : this.security)
277        if (!item.isEmpty())
278          return true;
279      return false;
280    }
281
282    public Coding addSecurity() { //3
283      Coding t = new Coding();
284      if (this.security == null)
285        this.security = new ArrayList<Coding>();
286      this.security.add(t);
287      return t;
288    }
289
290    public Meta addSecurity(Coding t) { //3
291      if (t == null)
292        return this;
293      if (this.security == null)
294        this.security = new ArrayList<Coding>();
295      this.security.add(t);
296      return this;
297    }
298
299    /**
300     * @return The first repetition of repeating field {@link #security}, creating it if it does not already exist
301     */
302    public Coding getSecurityFirstRep() { 
303      if (getSecurity().isEmpty()) {
304        addSecurity();
305      }
306      return getSecurity().get(0);
307    }
308
309    /**
310     * @return {@link #tag} (Tags applied to this resource. Tags are intended to be used to identify and relate resources to process and workflow, and applications are not required to consider the tags when interpreting the meaning of a resource.)
311     */
312    public List<Coding> getTag() { 
313      if (this.tag == null)
314        this.tag = new ArrayList<Coding>();
315      return this.tag;
316    }
317
318    /**
319     * @return Returns a reference to <code>this</code> for easy method chaining
320     */
321    public Meta setTag(List<Coding> theTag) { 
322      this.tag = theTag;
323      return this;
324    }
325
326    public boolean hasTag() { 
327      if (this.tag == null)
328        return false;
329      for (Coding item : this.tag)
330        if (!item.isEmpty())
331          return true;
332      return false;
333    }
334
335    public Coding addTag() { //3
336      Coding t = new Coding();
337      if (this.tag == null)
338        this.tag = new ArrayList<Coding>();
339      this.tag.add(t);
340      return t;
341    }
342
343    public Meta addTag(Coding t) { //3
344      if (t == null)
345        return this;
346      if (this.tag == null)
347        this.tag = new ArrayList<Coding>();
348      this.tag.add(t);
349      return this;
350    }
351
352    /**
353     * @return The first repetition of repeating field {@link #tag}, creating it if it does not already exist
354     */
355    public Coding getTagFirstRep() { 
356      if (getTag().isEmpty()) {
357        addTag();
358      }
359      return getTag().get(0);
360    }
361
362    /**
363     * Convenience method which adds a tag
364     * 
365     * @param theSystem The code system
366     * @param theCode The code
367     * @param theDisplay The display name
368     * @return Returns a reference to <code>this</code> for easy chaining
369     */
370    public Meta addTag(String theSystem, String theCode, String theDisplay) {
371     addTag().setSystem(theSystem).setCode(theCode).setDisplay(theDisplay);
372     return this;
373    }
374    /**
375     * Convenience method which adds a security tag
376     * 
377     * @param theSystem The code system
378     * @param theCode The code
379     * @param theDisplay The display name
380     * @return Returns a reference to <code>this</code> for easy chaining
381     */
382    public Meta addSecurity(String theSystem, String theCode, String theDisplay) {
383     addSecurity().setSystem(theSystem).setCode(theCode).setDisplay(theDisplay);
384     return this;
385    }
386   /**
387   * Returns the first tag (if any) that has the given system and code, or returns
388   * <code>null</code> if none
389   */
390  public Coding getTag(String theSystem, String theCode) {
391    for (Coding next : getTag()) {
392      if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
393        return next;
394      }
395    }
396    return null;
397  }
398
399  /**
400   * Returns the first security label (if any) that has the given system and code, or returns
401   * <code>null</code> if none
402   */
403  public Coding getSecurity(String theSystem, String theCode) {
404    for (Coding next : getTag()) {
405      if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
406        return next;
407      }
408    }
409    return null;
410  }
411      protected void listChildren(List<Property> childrenList) {
412        super.listChildren(childrenList);
413        childrenList.add(new Property("versionId", "id", "The version specific identifier, as it appears in the version portion of the URL. This values changes when the resource is created, updated, or deleted.", 0, java.lang.Integer.MAX_VALUE, versionId));
414        childrenList.add(new Property("lastUpdated", "instant", "When the resource last changed - e.g. when the version changed.", 0, java.lang.Integer.MAX_VALUE, lastUpdated));
415        childrenList.add(new Property("profile", "uri", "A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].", 0, java.lang.Integer.MAX_VALUE, profile));
416        childrenList.add(new Property("security", "Coding", "Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.", 0, java.lang.Integer.MAX_VALUE, security));
417        childrenList.add(new Property("tag", "Coding", "Tags applied to this resource. Tags are intended to be used to identify and relate resources to process and workflow, and applications are not required to consider the tags when interpreting the meaning of a resource.", 0, java.lang.Integer.MAX_VALUE, tag));
418      }
419
420      @Override
421      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
422        switch (hash) {
423        case -1407102957: /*versionId*/ return this.versionId == null ? new Base[0] : new Base[] {this.versionId}; // IdType
424        case 1649733957: /*lastUpdated*/ return this.lastUpdated == null ? new Base[0] : new Base[] {this.lastUpdated}; // InstantType
425        case -309425751: /*profile*/ return this.profile == null ? new Base[0] : this.profile.toArray(new Base[this.profile.size()]); // UriType
426        case 949122880: /*security*/ return this.security == null ? new Base[0] : this.security.toArray(new Base[this.security.size()]); // Coding
427        case 114586: /*tag*/ return this.tag == null ? new Base[0] : this.tag.toArray(new Base[this.tag.size()]); // Coding
428        default: return super.getProperty(hash, name, checkValid);
429        }
430
431      }
432
433      @Override
434      public Base setProperty(int hash, String name, Base value) throws FHIRException {
435        switch (hash) {
436        case -1407102957: // versionId
437          this.versionId = castToId(value); // IdType
438          return value;
439        case 1649733957: // lastUpdated
440          this.lastUpdated = castToInstant(value); // InstantType
441          return value;
442        case -309425751: // profile
443          this.getProfile().add(castToUri(value)); // UriType
444          return value;
445        case 949122880: // security
446          this.getSecurity().add(castToCoding(value)); // Coding
447          return value;
448        case 114586: // tag
449          this.getTag().add(castToCoding(value)); // Coding
450          return value;
451        default: return super.setProperty(hash, name, value);
452        }
453
454      }
455
456      @Override
457      public Base setProperty(String name, Base value) throws FHIRException {
458        if (name.equals("versionId")) {
459          this.versionId = castToId(value); // IdType
460        } else if (name.equals("lastUpdated")) {
461          this.lastUpdated = castToInstant(value); // InstantType
462        } else if (name.equals("profile")) {
463          this.getProfile().add(castToUri(value));
464        } else if (name.equals("security")) {
465          this.getSecurity().add(castToCoding(value));
466        } else if (name.equals("tag")) {
467          this.getTag().add(castToCoding(value));
468        } else
469          return super.setProperty(name, value);
470        return value;
471      }
472
473      @Override
474      public Base makeProperty(int hash, String name) throws FHIRException {
475        switch (hash) {
476        case -1407102957:  return getVersionIdElement();
477        case 1649733957:  return getLastUpdatedElement();
478        case -309425751:  return addProfileElement();
479        case 949122880:  return addSecurity(); 
480        case 114586:  return addTag(); 
481        default: return super.makeProperty(hash, name);
482        }
483
484      }
485
486      @Override
487      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
488        switch (hash) {
489        case -1407102957: /*versionId*/ return new String[] {"id"};
490        case 1649733957: /*lastUpdated*/ return new String[] {"instant"};
491        case -309425751: /*profile*/ return new String[] {"uri"};
492        case 949122880: /*security*/ return new String[] {"Coding"};
493        case 114586: /*tag*/ return new String[] {"Coding"};
494        default: return super.getTypesForProperty(hash, name);
495        }
496
497      }
498
499      @Override
500      public Base addChild(String name) throws FHIRException {
501        if (name.equals("versionId")) {
502          throw new FHIRException("Cannot call addChild on a primitive type Meta.versionId");
503        }
504        else if (name.equals("lastUpdated")) {
505          throw new FHIRException("Cannot call addChild on a primitive type Meta.lastUpdated");
506        }
507        else if (name.equals("profile")) {
508          throw new FHIRException("Cannot call addChild on a primitive type Meta.profile");
509        }
510        else if (name.equals("security")) {
511          return addSecurity();
512        }
513        else if (name.equals("tag")) {
514          return addTag();
515        }
516        else
517          return super.addChild(name);
518      }
519
520  public String fhirType() {
521    return "Meta";
522
523  }
524
525      public Meta copy() {
526        Meta dst = new Meta();
527        copyValues(dst);
528        dst.versionId = versionId == null ? null : versionId.copy();
529        dst.lastUpdated = lastUpdated == null ? null : lastUpdated.copy();
530        if (profile != null) {
531          dst.profile = new ArrayList<UriType>();
532          for (UriType i : profile)
533            dst.profile.add(i.copy());
534        };
535        if (security != null) {
536          dst.security = new ArrayList<Coding>();
537          for (Coding i : security)
538            dst.security.add(i.copy());
539        };
540        if (tag != null) {
541          dst.tag = new ArrayList<Coding>();
542          for (Coding i : tag)
543            dst.tag.add(i.copy());
544        };
545        return dst;
546      }
547
548      protected Meta typedCopy() {
549        return copy();
550      }
551
552      @Override
553      public boolean equalsDeep(Base other) {
554        if (!super.equalsDeep(other))
555          return false;
556        if (!(other instanceof Meta))
557          return false;
558        Meta o = (Meta) other;
559        return compareDeep(versionId, o.versionId, true) && compareDeep(lastUpdated, o.lastUpdated, true)
560           && compareDeep(profile, o.profile, true) && compareDeep(security, o.security, true) && compareDeep(tag, o.tag, true)
561          ;
562      }
563
564      @Override
565      public boolean equalsShallow(Base other) {
566        if (!super.equalsShallow(other))
567          return false;
568        if (!(other instanceof Meta))
569          return false;
570        Meta o = (Meta) other;
571        return compareValues(versionId, o.versionId, true) && compareValues(lastUpdated, o.lastUpdated, true)
572           && compareValues(profile, o.profile, true);
573      }
574
575      public boolean isEmpty() {
576        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(versionId, lastUpdated, profile
577          , security, tag);
578      }
579
580
581}
582