001package org.hl7.fhir.instance.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.*;
034
035import org.hl7.fhir.exceptions.FHIRException;
036import org.hl7.fhir.instance.model.api.IBaseMetaType;
037import org.hl7.fhir.utilities.Utilities;
038
039import ca.uhn.fhir.model.api.annotation.*;
040/**
041 * 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.
042 */
043@DatatypeDef(name="Meta")
044public class Meta extends Type implements IBaseMetaType {
045
046    /**
047     * 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.
048     */
049    @Child(name = "versionId", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
050    @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." )
051    protected IdType versionId;
052
053    /**
054     * When the resource last changed - e.g. when the version changed.
055     */
056    @Child(name = "lastUpdated", type = {InstantType.class}, order=1, min=0, max=1, modifier=false, summary=true)
057    @Description(shortDefinition="When the resource version last changed", formalDefinition="When the resource last changed - e.g. when the version changed." )
058    protected InstantType lastUpdated;
059
060    /**
061     * A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].
062     */
063    @Child(name = "profile", type = {UriType.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
064    @Description(shortDefinition="Profiles this resource claims to conform to", formalDefinition="A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]]." )
065    protected List<UriType> profile;
066
067    /**
068     * Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.
069     */
070    @Child(name = "security", type = {Coding.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
071    @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." )
072    protected List<Coding> security;
073
074    /**
075     * 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.
076     */
077    @Child(name = "tag", type = {Coding.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
078    @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." )
079    protected List<Coding> tag;
080
081    private static final long serialVersionUID = 867134915L;
082
083  /*
084   * Constructor
085   */
086    public Meta() {
087      super();
088    }
089
090    /**
091     * @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
092     */
093    public IdType getVersionIdElement() { 
094      if (this.versionId == null)
095        if (Configuration.errorOnAutoCreate())
096          throw new Error("Attempt to auto-create Meta.versionId");
097        else if (Configuration.doAutoCreate())
098          this.versionId = new IdType(); // bb
099      return this.versionId;
100    }
101
102    public boolean hasVersionIdElement() { 
103      return this.versionId != null && !this.versionId.isEmpty();
104    }
105
106    public boolean hasVersionId() { 
107      return this.versionId != null && !this.versionId.isEmpty();
108    }
109
110    /**
111     * @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
112     */
113    public Meta setVersionIdElement(IdType value) { 
114      this.versionId = value;
115      return this;
116    }
117
118    /**
119     * @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.
120     */
121    public String getVersionId() { 
122      return this.versionId == null ? null : this.versionId.getValue();
123    }
124
125    /**
126     * @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.
127     */
128    public Meta setVersionId(String value) { 
129      if (Utilities.noString(value))
130        this.versionId = null;
131      else {
132        if (this.versionId == null)
133          this.versionId = new IdType();
134        this.versionId.setValue(value);
135      }
136      return this;
137    }
138
139    /**
140     * @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
141     */
142    public InstantType getLastUpdatedElement() { 
143      if (this.lastUpdated == null)
144        if (Configuration.errorOnAutoCreate())
145          throw new Error("Attempt to auto-create Meta.lastUpdated");
146        else if (Configuration.doAutoCreate())
147          this.lastUpdated = new InstantType(); // bb
148      return this.lastUpdated;
149    }
150
151    public boolean hasLastUpdatedElement() { 
152      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
153    }
154
155    public boolean hasLastUpdated() { 
156      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
157    }
158
159    /**
160     * @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
161     */
162    public Meta setLastUpdatedElement(InstantType value) { 
163      this.lastUpdated = value;
164      return this;
165    }
166
167    /**
168     * @return When the resource last changed - e.g. when the version changed.
169     */
170    public Date getLastUpdated() { 
171      return this.lastUpdated == null ? null : this.lastUpdated.getValue();
172    }
173
174    /**
175     * @param value When the resource last changed - e.g. when the version changed.
176     */
177    public Meta setLastUpdated(Date value) { 
178      if (value == null)
179        this.lastUpdated = null;
180      else {
181        if (this.lastUpdated == null)
182          this.lastUpdated = new InstantType();
183        this.lastUpdated.setValue(value);
184      }
185      return this;
186    }
187
188    /**
189     * @return {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
190     */
191    public List<UriType> getProfile() { 
192      if (this.profile == null)
193        this.profile = new ArrayList<UriType>();
194      return this.profile;
195    }
196
197    public boolean hasProfile() { 
198      if (this.profile == null)
199        return false;
200      for (UriType item : this.profile)
201        if (!item.isEmpty())
202          return true;
203      return false;
204    }
205
206    /**
207     * @return {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
208     */
209    // syntactic sugar
210    public UriType addProfileElement() {//2 
211      UriType t = new UriType();
212      if (this.profile == null)
213        this.profile = new ArrayList<UriType>();
214      this.profile.add(t);
215      return t;
216    }
217
218    /**
219     * @param value {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
220     */
221    public Meta addProfile(String value) { //1
222      UriType t = new UriType();
223      t.setValue(value);
224      if (this.profile == null)
225        this.profile = new ArrayList<UriType>();
226      this.profile.add(t);
227      return this;
228    }
229
230    /**
231     * @param value {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
232     */
233    public boolean hasProfile(String value) { 
234      if (this.profile == null)
235        return false;
236      for (UriType v : this.profile)
237        if (v.equals(value)) // uri
238          return true;
239      return false;
240    }
241
242    /**
243     * @return {@link #security} (Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.)
244     */
245    public List<Coding> getSecurity() { 
246      if (this.security == null)
247        this.security = new ArrayList<Coding>();
248      return this.security;
249    }
250
251    public boolean hasSecurity() { 
252      if (this.security == null)
253        return false;
254      for (Coding item : this.security)
255        if (!item.isEmpty())
256          return true;
257      return false;
258    }
259
260    /**
261     * @return {@link #security} (Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.)
262     */
263    // syntactic sugar
264    public Coding addSecurity() { //3
265      Coding t = new Coding();
266      if (this.security == null)
267        this.security = new ArrayList<Coding>();
268      this.security.add(t);
269      return t;
270    }
271
272    // syntactic sugar
273    public Meta addSecurity(Coding t) { //3
274      if (t == null)
275        return this;
276      if (this.security == null)
277        this.security = new ArrayList<Coding>();
278      this.security.add(t);
279      return this;
280    }
281
282    /**
283     * @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.)
284     */
285    public List<Coding> getTag() { 
286      if (this.tag == null)
287        this.tag = new ArrayList<Coding>();
288      return this.tag;
289    }
290
291    public boolean hasTag() { 
292      if (this.tag == null)
293        return false;
294      for (Coding item : this.tag)
295        if (!item.isEmpty())
296          return true;
297      return false;
298    }
299
300    /**
301     * @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.)
302     */
303    // syntactic sugar
304    public Coding addTag() { //3
305      Coding t = new Coding();
306      if (this.tag == null)
307        this.tag = new ArrayList<Coding>();
308      this.tag.add(t);
309      return t;
310    }
311
312    // syntactic sugar
313    public Meta addTag(Coding t) { //3
314      if (t == null)
315        return this;
316      if (this.tag == null)
317        this.tag = new ArrayList<Coding>();
318      this.tag.add(t);
319      return this;
320    }
321
322      protected void listChildren(List<Property> childrenList) {
323        super.listChildren(childrenList);
324        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));
325        childrenList.add(new Property("lastUpdated", "instant", "When the resource last changed - e.g. when the version changed.", 0, java.lang.Integer.MAX_VALUE, lastUpdated));
326        childrenList.add(new Property("profile", "uri", "A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].", 0, java.lang.Integer.MAX_VALUE, profile));
327        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));
328        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));
329      }
330
331      @Override
332      public void setProperty(String name, Base value) throws FHIRException {
333        if (name.equals("versionId"))
334          this.versionId = castToId(value); // IdType
335        else if (name.equals("lastUpdated"))
336          this.lastUpdated = castToInstant(value); // InstantType
337        else if (name.equals("profile"))
338          this.getProfile().add(castToUri(value));
339        else if (name.equals("security"))
340          this.getSecurity().add(castToCoding(value));
341        else if (name.equals("tag"))
342          this.getTag().add(castToCoding(value));
343        else
344          super.setProperty(name, value);
345      }
346
347      @Override
348      public Base addChild(String name) throws FHIRException {
349        if (name.equals("versionId")) {
350          throw new FHIRException("Cannot call addChild on a primitive type Meta.versionId");
351        }
352        else if (name.equals("lastUpdated")) {
353          throw new FHIRException("Cannot call addChild on a primitive type Meta.lastUpdated");
354        }
355        else if (name.equals("profile")) {
356          throw new FHIRException("Cannot call addChild on a primitive type Meta.profile");
357        }
358        else if (name.equals("security")) {
359          return addSecurity();
360        }
361        else if (name.equals("tag")) {
362          return addTag();
363        }
364        else
365          return super.addChild(name);
366      }
367
368  public String fhirType() {
369    return "Meta";
370
371  }
372
373      public Meta copy() {
374        Meta dst = new Meta();
375        copyValues(dst);
376        dst.versionId = versionId == null ? null : versionId.copy();
377        dst.lastUpdated = lastUpdated == null ? null : lastUpdated.copy();
378        if (profile != null) {
379          dst.profile = new ArrayList<UriType>();
380          for (UriType i : profile)
381            dst.profile.add(i.copy());
382        };
383        if (security != null) {
384          dst.security = new ArrayList<Coding>();
385          for (Coding i : security)
386            dst.security.add(i.copy());
387        };
388        if (tag != null) {
389          dst.tag = new ArrayList<Coding>();
390          for (Coding i : tag)
391            dst.tag.add(i.copy());
392        };
393        return dst;
394      }
395
396      protected Meta typedCopy() {
397        return copy();
398      }
399
400      @Override
401      public boolean equalsDeep(Base other) {
402        if (!super.equalsDeep(other))
403          return false;
404        if (!(other instanceof Meta))
405          return false;
406        Meta o = (Meta) other;
407        return compareDeep(versionId, o.versionId, true) && compareDeep(lastUpdated, o.lastUpdated, true)
408           && compareDeep(profile, o.profile, true) && compareDeep(security, o.security, true) && compareDeep(tag, o.tag, true)
409          ;
410      }
411
412      @Override
413      public boolean equalsShallow(Base other) {
414        if (!super.equalsShallow(other))
415          return false;
416        if (!(other instanceof Meta))
417          return false;
418        Meta o = (Meta) other;
419        return compareValues(versionId, o.versionId, true) && compareValues(lastUpdated, o.lastUpdated, true)
420           && compareValues(profile, o.profile, true);
421      }
422
423      public boolean isEmpty() {
424        return super.isEmpty() && (versionId == null || versionId.isEmpty()) && (lastUpdated == null || lastUpdated.isEmpty())
425           && (profile == null || profile.isEmpty()) && (security == null || security.isEmpty()) && (tag == null || tag.isEmpty())
426          ;
427      }
428
429      /**
430       * Returns the first tag (if any) that has the given system and code, or returns
431       * <code>null</code> if none
432       */
433      public Coding getTag(String theSystem, String theCode) {
434        for (Coding next : getTag()) {
435          if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
436            return next;
437          }
438        }
439        return null;
440      }
441
442      /**
443       * Returns the first security label (if any) that has the given system and code, or returns
444       * <code>null</code> if none
445       */
446      public Coding getSecurity(String theSystem, String theCode) {
447        for (Coding next : getTag()) {
448          if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
449            return next;
450          }
451        }
452        return null;
453      }
454
455}
456