001package org.hl7.fhir.dstu2.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu2
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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
054import java.util.List;
055
056import ca.uhn.fhir.model.api.annotation.Child;
057import ca.uhn.fhir.model.api.annotation.Description;
058import org.hl7.fhir.instance.model.api.IAnyResource;
059import org.hl7.fhir.exceptions.FHIRException;
060import org.hl7.fhir.utilities.Utilities;
061/**
062 * This is the base resource type for everything.
063 */
064public abstract class Resource extends BaseResource implements IAnyResource {
065
066    /**
067     * The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
068     */
069    @Child(name = "id", type = {IdType.class}, order=0, min=0, max=1, modifier=false, summary=true)
070    @Description(shortDefinition="Logical id of this artifact", formalDefinition="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes." )
071    protected IdType id;
072
073    /**
074     * The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.
075     */
076    @Child(name = "meta", type = {Meta.class}, order=1, min=0, max=1, modifier=false, summary=true)
077    @Description(shortDefinition="Metadata about the resource", formalDefinition="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource." )
078    protected Meta meta;
079
080    /**
081     * A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
082     */
083    @Child(name = "implicitRules", type = {UriType.class}, order=2, min=0, max=1, modifier=true, summary=true)
084    @Description(shortDefinition="A set of rules under which this content was created", formalDefinition="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content." )
085    protected UriType implicitRules;
086
087    /**
088     * The base language in which the resource is written.
089     */
090    @Child(name = "language", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=false)
091    @Description(shortDefinition="Language of the resource content", formalDefinition="The base language in which the resource is written." )
092    protected CodeType language;
093
094    private static final long serialVersionUID = -559462759L;
095
096  /*
097   * Constructor
098   */
099    public Resource() {
100      super();
101    }
102
103    /**
104     * @return {@link #id} (The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
105     */
106    public IdType getIdElement() { 
107      if (this.id == null)
108        if (Configuration.errorOnAutoCreate())
109          throw new Error("Attempt to auto-create Resource.id");
110        else if (Configuration.doAutoCreate())
111          this.id = new IdType(); // bb
112      return this.id;
113    }
114
115    public boolean hasIdElement() { 
116      return this.id != null && !this.id.isEmpty();
117    }
118
119    public boolean hasId() { 
120      return this.id != null && !this.id.isEmpty();
121    }
122
123    /**
124     * @param value {@link #id} (The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.). This is the underlying object with id, value and extensions. The accessor "getId" gives direct access to the value
125     */
126    public Resource setIdElement(IdType value) { 
127      this.id = value;
128      return this;
129    }
130
131    /**
132     * @return The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
133     */
134    public String getId() { 
135      return this.id == null ? null : this.id.getValue();
136    }
137
138    /**
139     * @param value The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
140     */
141    public Resource setId(String value) { 
142      if (Utilities.noString(value))
143        this.id = null;
144      else {
145        if (this.id == null)
146          this.id = new IdType();
147        this.id.setValue(value);
148      }
149      return this;
150    }
151
152    /**
153     * @return {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.)
154     */
155    public Meta getMeta() { 
156      if (this.meta == null)
157        if (Configuration.errorOnAutoCreate())
158          throw new Error("Attempt to auto-create Resource.meta");
159        else if (Configuration.doAutoCreate())
160          this.meta = new Meta(); // cc
161      return this.meta;
162    }
163
164    public boolean hasMeta() { 
165      return this.meta != null && !this.meta.isEmpty();
166    }
167
168    /**
169     * @param value {@link #meta} (The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.)
170     */
171    public Resource setMeta(Meta value) { 
172      this.meta = value;
173      return this;
174    }
175
176    /**
177     * @return {@link #implicitRules} (A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
178     */
179    public UriType getImplicitRulesElement() { 
180      if (this.implicitRules == null)
181        if (Configuration.errorOnAutoCreate())
182          throw new Error("Attempt to auto-create Resource.implicitRules");
183        else if (Configuration.doAutoCreate())
184          this.implicitRules = new UriType(); // bb
185      return this.implicitRules;
186    }
187
188    public boolean hasImplicitRulesElement() { 
189      return this.implicitRules != null && !this.implicitRules.isEmpty();
190    }
191
192    public boolean hasImplicitRules() { 
193      return this.implicitRules != null && !this.implicitRules.isEmpty();
194    }
195
196    /**
197     * @param value {@link #implicitRules} (A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.). This is the underlying object with id, value and extensions. The accessor "getImplicitRules" gives direct access to the value
198     */
199    public Resource setImplicitRulesElement(UriType value) { 
200      this.implicitRules = value;
201      return this;
202    }
203
204    /**
205     * @return A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
206     */
207    public String getImplicitRules() { 
208      return this.implicitRules == null ? null : this.implicitRules.getValue();
209    }
210
211    /**
212     * @param value A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.
213     */
214    public Resource setImplicitRules(String value) { 
215      if (Utilities.noString(value))
216        this.implicitRules = null;
217      else {
218        if (this.implicitRules == null)
219          this.implicitRules = new UriType();
220        this.implicitRules.setValue(value);
221      }
222      return this;
223    }
224
225    /**
226     * @return {@link #language} (The base language in which the resource is written.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
227     */
228    public CodeType getLanguageElement() { 
229      if (this.language == null)
230        if (Configuration.errorOnAutoCreate())
231          throw new Error("Attempt to auto-create Resource.language");
232        else if (Configuration.doAutoCreate())
233          this.language = new CodeType(); // bb
234      return this.language;
235    }
236
237    public boolean hasLanguageElement() { 
238      return this.language != null && !this.language.isEmpty();
239    }
240
241    public boolean hasLanguage() { 
242      return this.language != null && !this.language.isEmpty();
243    }
244
245    /**
246     * @param value {@link #language} (The base language in which the resource is written.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
247     */
248    public Resource setLanguageElement(CodeType value) { 
249      this.language = value;
250      return this;
251    }
252
253    /**
254     * @return The base language in which the resource is written.
255     */
256    public String getLanguage() { 
257      return this.language == null ? null : this.language.getValue();
258    }
259
260    /**
261     * @param value The base language in which the resource is written.
262     */
263    public Resource setLanguage(String value) { 
264      if (Utilities.noString(value))
265        this.language = null;
266      else {
267        if (this.language == null)
268          this.language = new CodeType();
269        this.language.setValue(value);
270      }
271      return this;
272    }
273
274      protected void listChildren(List<Property> childrenList) {
275        childrenList.add(new Property("id", "id", "The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", 0, java.lang.Integer.MAX_VALUE, id));
276        childrenList.add(new Property("meta", "Meta", "The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content may not always be associated with version changes to the resource.", 0, java.lang.Integer.MAX_VALUE, meta));
277        childrenList.add(new Property("implicitRules", "uri", "A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content.", 0, java.lang.Integer.MAX_VALUE, implicitRules));
278        childrenList.add(new Property("language", "code", "The base language in which the resource is written.", 0, java.lang.Integer.MAX_VALUE, language));
279      }
280
281      @Override
282      public void setProperty(String name, Base value) throws FHIRException {
283        if (name.equals("id"))
284          this.id = castToId(value); // IdType
285        else if (name.equals("meta"))
286          this.meta = castToMeta(value); // Meta
287        else if (name.equals("implicitRules"))
288          this.implicitRules = castToUri(value); // UriType
289        else if (name.equals("language"))
290          this.language = castToCode(value); // CodeType
291        else
292          super.setProperty(name, value);
293      }
294
295      @Override
296      public Base addChild(String name) throws FHIRException {
297        if (name.equals("id")) {
298          throw new FHIRException("Cannot call addChild on a primitive type Resource.id");
299        }
300        else if (name.equals("meta")) {
301          this.meta = new Meta();
302          return this.meta;
303        }
304        else if (name.equals("implicitRules")) {
305          throw new FHIRException("Cannot call addChild on a primitive type Resource.implicitRules");
306        }
307        else if (name.equals("language")) {
308          throw new FHIRException("Cannot call addChild on a primitive type Resource.language");
309        }
310        else
311          return super.addChild(name);
312      }
313
314  public String fhirType() {
315    return "Resource";
316
317  }
318
319      public abstract Resource copy();
320
321      public void copyValues(Resource dst) {
322        dst.id = id == null ? null : id.copy();
323        dst.meta = meta == null ? null : meta.copy();
324        dst.implicitRules = implicitRules == null ? null : implicitRules.copy();
325        dst.language = language == null ? null : language.copy();
326      }
327
328      @Override
329      public boolean equalsDeep(Base other) {
330        if (!super.equalsDeep(other))
331          return false;
332        if (!(other instanceof Resource))
333          return false;
334        Resource o = (Resource) other;
335        return compareDeep(id, o.id, true) && compareDeep(meta, o.meta, true) && compareDeep(implicitRules, o.implicitRules, true)
336           && compareDeep(language, o.language, true);
337      }
338
339      @Override
340      public boolean equalsShallow(Base other) {
341        if (!super.equalsShallow(other))
342          return false;
343        if (!(other instanceof Resource))
344          return false;
345        Resource o = (Resource) other;
346        return compareValues(id, o.id, true) && compareValues(implicitRules, o.implicitRules, true) && compareValues(language, o.language, true)
347          ;
348      }
349
350      public boolean isEmpty() {
351        return super.isEmpty() && (id == null || id.isEmpty()) && (meta == null || meta.isEmpty()) && (implicitRules == null || implicitRules.isEmpty())
352           && (language == null || language.isEmpty());
353      }
354
355  public abstract ResourceType getResourceType();
356
357}
358