001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.DatatypeDef;
042import ca.uhn.fhir.model.api.annotation.Description;
043import org.hl7.fhir.instance.model.api.IBaseMetaType;
044import org.hl7.fhir.exceptions.FHIRException;
045import org.hl7.fhir.utilities.Utilities;
046/**
047 * 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.
048 */
049@DatatypeDef(name="Meta")
050public class Meta extends Type implements IBaseMetaType {
051
052    /**
053     * 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.
054     */
055    @Child(name = "versionId", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
056    @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." )
057    protected IdType versionId;
058
059    /**
060     * When the resource last changed - e.g. when the version changed.
061     */
062    @Child(name = "lastUpdated", type = {InstantType.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @Description(shortDefinition="When the resource version last changed", formalDefinition="When the resource last changed - e.g. when the version changed." )
064    protected InstantType lastUpdated;
065
066    /**
067     * A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].
068     */
069    @Child(name = "profile", type = {UriType.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
070    @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]]]." )
071    protected List<UriType> profile;
072
073    /**
074     * Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.
075     */
076    @Child(name = "security", type = {Coding.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
077    @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." )
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    protected List<Coding> tag;
086
087    private static final long serialVersionUID = 867134915L;
088
089  /*
090   * Constructor
091   */
092    public Meta() {
093      super();
094    }
095
096    /**
097     * @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
098     */
099    public IdType getVersionIdElement() { 
100      if (this.versionId == null)
101        if (Configuration.errorOnAutoCreate())
102          throw new Error("Attempt to auto-create Meta.versionId");
103        else if (Configuration.doAutoCreate())
104          this.versionId = new IdType(); // bb
105      return this.versionId;
106    }
107
108    public boolean hasVersionIdElement() { 
109      return this.versionId != null && !this.versionId.isEmpty();
110    }
111
112    public boolean hasVersionId() { 
113      return this.versionId != null && !this.versionId.isEmpty();
114    }
115
116    /**
117     * @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
118     */
119    public Meta setVersionIdElement(IdType value) { 
120      this.versionId = value;
121      return this;
122    }
123
124    /**
125     * @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.
126     */
127    public String getVersionId() { 
128      return this.versionId == null ? null : this.versionId.getValue();
129    }
130
131    /**
132     * @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.
133     */
134    public Meta setVersionId(String value) { 
135      if (Utilities.noString(value))
136        this.versionId = null;
137      else {
138        if (this.versionId == null)
139          this.versionId = new IdType();
140        this.versionId.setValue(value);
141      }
142      return this;
143    }
144
145    /**
146     * @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
147     */
148    public InstantType getLastUpdatedElement() { 
149      if (this.lastUpdated == null)
150        if (Configuration.errorOnAutoCreate())
151          throw new Error("Attempt to auto-create Meta.lastUpdated");
152        else if (Configuration.doAutoCreate())
153          this.lastUpdated = new InstantType(); // bb
154      return this.lastUpdated;
155    }
156
157    public boolean hasLastUpdatedElement() { 
158      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
159    }
160
161    public boolean hasLastUpdated() { 
162      return this.lastUpdated != null && !this.lastUpdated.isEmpty();
163    }
164
165    /**
166     * @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
167     */
168    public Meta setLastUpdatedElement(InstantType value) { 
169      this.lastUpdated = value;
170      return this;
171    }
172
173    /**
174     * @return When the resource last changed - e.g. when the version changed.
175     */
176    public Date getLastUpdated() { 
177      return this.lastUpdated == null ? null : this.lastUpdated.getValue();
178    }
179
180    /**
181     * @param value When the resource last changed - e.g. when the version changed.
182     */
183    public Meta setLastUpdated(Date value) { 
184      if (value == null)
185        this.lastUpdated = null;
186      else {
187        if (this.lastUpdated == null)
188          this.lastUpdated = new InstantType();
189        this.lastUpdated.setValue(value);
190      }
191      return this;
192    }
193
194    /**
195     * @return {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
196     */
197    public List<UriType> getProfile() { 
198      if (this.profile == null)
199        this.profile = new ArrayList<UriType>();
200      return this.profile;
201    }
202
203    public boolean hasProfile() { 
204      if (this.profile == null)
205        return false;
206      for (UriType item : this.profile)
207        if (!item.isEmpty())
208          return true;
209      return false;
210    }
211
212    /**
213     * @return {@link #profile} (A list of profiles [[[StructureDefinition]]]s that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].)
214     */
215    // syntactic sugar
216    public UriType addProfileElement() {//2 
217      UriType t = new UriType();
218      if (this.profile == null)
219        this.profile = new ArrayList<UriType>();
220      this.profile.add(t);
221      return t;
222    }
223
224    /**
225     * @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]]].)
226     */
227    public Meta addProfile(String value) { //1
228      UriType t = new UriType();
229      t.setValue(value);
230      if (this.profile == null)
231        this.profile = new ArrayList<UriType>();
232      this.profile.add(t);
233      return this;
234    }
235
236    /**
237     * @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]]].)
238     */
239    public boolean hasProfile(String value) { 
240      if (this.profile == null)
241        return false;
242      for (UriType v : this.profile)
243        if (v.equals(value)) // uri
244          return true;
245      return false;
246    }
247
248    /**
249     * @return {@link #security} (Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.)
250     */
251    public List<Coding> getSecurity() { 
252      if (this.security == null)
253        this.security = new ArrayList<Coding>();
254      return this.security;
255    }
256
257  /**
258   * Returns the first security label (if any) that has the given system and code, or returns
259   * <code>null</code> if none
260   */
261  public Coding getSecurity(String theSystem, String theCode) {
262    for (Coding next : getSecurity()) {
263      if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
264        return next;
265      }
266    }
267    return null;
268  }
269
270  public boolean hasSecurity() {
271      if (this.security == null)
272        return false;
273      for (Coding item : this.security)
274        if (!item.isEmpty())
275          return true;
276      return false;
277    }
278
279    /**
280     * @return {@link #security} (Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.)
281     */
282    // syntactic sugar
283    public Coding addSecurity() { //3
284      Coding t = new Coding();
285      if (this.security == null)
286        this.security = new ArrayList<Coding>();
287      this.security.add(t);
288      return t;
289    }
290
291    // syntactic sugar
292    public Meta addSecurity(Coding t) { //3
293      if (t == null)
294        return this;
295      if (this.security == null)
296        this.security = new ArrayList<Coding>();
297      this.security.add(t);
298      return this;
299    }
300
301    /**
302     * @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.)
303     */
304    public List<Coding> getTag() { 
305      if (this.tag == null)
306        this.tag = new ArrayList<Coding>();
307      return this.tag;
308    }
309
310  /**
311   * Returns the first tag (if any) that has the given system and code, or returns
312   * <code>null</code> if none
313   */
314  public Coding getTag(String theSystem, String theCode) {
315    for (Coding next : getTag()) {
316      if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
317        return next;
318      }
319    }
320    return null;
321  }
322
323  public boolean hasTag() {
324      if (this.tag == null)
325        return false;
326      for (Coding item : this.tag)
327        if (!item.isEmpty())
328          return true;
329      return false;
330    }
331
332    /**
333     * @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.)
334     */
335    // syntactic sugar
336    public Coding addTag() { //3
337      Coding t = new Coding();
338      if (this.tag == null)
339        this.tag = new ArrayList<Coding>();
340      this.tag.add(t);
341      return t;
342    }
343
344    // syntactic sugar
345    public Meta addTag(Coding t) { //3
346      if (t == null)
347        return this;
348      if (this.tag == null)
349        this.tag = new ArrayList<Coding>();
350      this.tag.add(t);
351      return this;
352    }
353
354      protected void listChildren(List<Property> childrenList) {
355        super.listChildren(childrenList);
356        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));
357        childrenList.add(new Property("lastUpdated", "instant", "When the resource last changed - e.g. when the version changed.", 0, java.lang.Integer.MAX_VALUE, lastUpdated));
358        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));
359        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));
360        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));
361      }
362
363      @Override
364      public void setProperty(String name, Base value) throws FHIRException {
365        if (name.equals("versionId"))
366          this.versionId = castToId(value); // IdType
367        else if (name.equals("lastUpdated"))
368          this.lastUpdated = castToInstant(value); // InstantType
369        else if (name.equals("profile"))
370          this.getProfile().add(castToUri(value));
371        else if (name.equals("security"))
372          this.getSecurity().add(castToCoding(value));
373        else if (name.equals("tag"))
374          this.getTag().add(castToCoding(value));
375        else
376          super.setProperty(name, value);
377      }
378
379      @Override
380      public Base addChild(String name) throws FHIRException {
381        if (name.equals("versionId")) {
382          throw new FHIRException("Cannot call addChild on a primitive type Meta.versionId");
383        }
384        else if (name.equals("lastUpdated")) {
385          throw new FHIRException("Cannot call addChild on a primitive type Meta.lastUpdated");
386        }
387        else if (name.equals("profile")) {
388          throw new FHIRException("Cannot call addChild on a primitive type Meta.profile");
389        }
390        else if (name.equals("security")) {
391          return addSecurity();
392        }
393        else if (name.equals("tag")) {
394          return addTag();
395        }
396        else
397          return super.addChild(name);
398      }
399
400  public String fhirType() {
401    return "Meta";
402
403  }
404
405      public Meta copy() {
406        Meta dst = new Meta();
407        copyValues(dst);
408        dst.versionId = versionId == null ? null : versionId.copy();
409        dst.lastUpdated = lastUpdated == null ? null : lastUpdated.copy();
410        if (profile != null) {
411          dst.profile = new ArrayList<UriType>();
412          for (UriType i : profile)
413            dst.profile.add(i.copy());
414        };
415        if (security != null) {
416          dst.security = new ArrayList<Coding>();
417          for (Coding i : security)
418            dst.security.add(i.copy());
419        };
420        if (tag != null) {
421          dst.tag = new ArrayList<Coding>();
422          for (Coding i : tag)
423            dst.tag.add(i.copy());
424        };
425        return dst;
426      }
427
428      protected Meta typedCopy() {
429        return copy();
430      }
431
432      @Override
433      public boolean equalsDeep(Base other) {
434        if (!super.equalsDeep(other))
435          return false;
436        if (!(other instanceof Meta))
437          return false;
438        Meta o = (Meta) other;
439        return compareDeep(versionId, o.versionId, true) && compareDeep(lastUpdated, o.lastUpdated, true)
440           && compareDeep(profile, o.profile, true) && compareDeep(security, o.security, true) && compareDeep(tag, o.tag, true)
441          ;
442      }
443
444      @Override
445      public boolean equalsShallow(Base other) {
446        if (!super.equalsShallow(other))
447          return false;
448        if (!(other instanceof Meta))
449          return false;
450        Meta o = (Meta) other;
451        return compareValues(versionId, o.versionId, true) && compareValues(lastUpdated, o.lastUpdated, true)
452           && compareValues(profile, o.profile, true);
453      }
454
455      public boolean isEmpty() {
456        return super.isEmpty() && (versionId == null || versionId.isEmpty()) && (lastUpdated == null || lastUpdated.isEmpty())
457           && (profile == null || profile.isEmpty()) && (security == null || security.isEmpty()) && (tag == null || tag.isEmpty())
458          ;
459      }
460
461
462}