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 ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * Optional Extension Element - found in all resources.
046 */
047@DatatypeDef(name="Extension")
048public class Extension extends BaseExtension implements IBaseExtension<Extension, Type>, IBaseHasExtensions {
049
050    /**
051     * Source of the definition for the extension code - a logical name or a URL.
052     */
053    @Child(name = "url", type = {UriType.class}, order=0, min=1, max=1, modifier=false, summary=false)
054    @Description(shortDefinition="identifies the meaning of the extension", formalDefinition="Source of the definition for the extension code - a logical name or a URL." )
055    protected UriType url;
056
057    /**
058     * Value of extension - may be a resource or one of a constrained set of the data types (see Extensibility in the spec for list).
059     */
060    @Child(name = "value", type = {}, order=1, min=0, max=1, modifier=false, summary=false)
061    @Description(shortDefinition="Value of extension", formalDefinition="Value of extension - may be a resource or one of a constrained set of the data types (see Extensibility in the spec for list)." )
062    protected org.hl7.fhir.dstu3.model.Type value;
063
064    private static final long serialVersionUID = 1240831878L;
065
066  /**
067   * Constructor
068   */
069    public Extension() {
070      super();
071    }
072
073  /**
074   * Constructor
075   */
076    public Extension(UriType url) {
077      super();
078      this.url = url;
079    }
080
081    /**
082     * Constructor
083     */
084    public Extension(String theUrl) {
085      setUrl(theUrl);
086    }
087
088    /**
089     * Constructor
090     */
091    public Extension(String theUrl, IBaseDatatype theValue) {
092      setUrl(theUrl);
093      setValue(theValue);
094    }
095
096    /**
097     * @return {@link #url} (Source of the definition for the extension code - a logical name or a URL.). This is the underlying object with id, value and extensions. The accessor "getUrl" gives direct access to the value
098     */
099    public UriType getUrlElement() { 
100      if (this.url == null)
101        if (Configuration.errorOnAutoCreate())
102          throw new Error("Attempt to auto-create Extension.url");
103        else if (Configuration.doAutoCreate())
104          this.url = new UriType(); // bb
105      return this.url;
106    }
107
108    public boolean hasUrlElement() { 
109      return this.url != null && !this.url.isEmpty();
110    }
111
112    public boolean hasUrl() { 
113      return this.url != null && !this.url.isEmpty();
114    }
115
116    /**
117     * @param value {@link #url} (Source of the definition for the extension code - a logical name or a URL.). This is the underlying object with id, value and extensions. The accessor "getUrl" gives direct access to the value
118     */
119    public Extension setUrlElement(UriType value) { 
120      this.url = value;
121      return this;
122    }
123
124    /**
125     * @return Source of the definition for the extension code - a logical name or a URL.
126     */
127    public String getUrl() { 
128      return this.url == null ? null : this.url.getValue();
129    }
130
131    /**
132     * @param value Source of the definition for the extension code - a logical name or a URL.
133     */
134    public Extension setUrl(String value) { 
135        if (this.url == null)
136          this.url = new UriType();
137        this.url.setValue(value);
138      return this;
139    }
140
141    /**
142     * @return {@link #value} (Value of extension - may be a resource or one of a constrained set of the data types (see Extensibility in the spec for list).)
143     */
144    public org.hl7.fhir.dstu3.model.Type getValue() { 
145      return this.value;
146    }
147
148    public boolean hasValue() { 
149      return this.value != null && !this.value.isEmpty();
150    }
151
152    /**
153     * @param value {@link #value} (Value of extension - may be a resource or one of a constrained set of the data types (see Extensibility in the spec for list).)
154     */
155    public Extension setValue(org.hl7.fhir.dstu3.model.Type value) { 
156      this.value = value;
157      return this;
158    }
159
160      protected void listChildren(List<Property> childrenList) {
161        super.listChildren(childrenList);
162        childrenList.add(new Property("url", "uri", "Source of the definition for the extension code - a logical name or a URL.", 0, java.lang.Integer.MAX_VALUE, url));
163        childrenList.add(new Property("value[x]", "*", "Value of extension - may be a resource or one of a constrained set of the data types (see Extensibility in the spec for list).", 0, java.lang.Integer.MAX_VALUE, value));
164      }
165
166      @Override
167      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
168        switch (hash) {
169        case 116079: /*url*/ return this.url == null ? new Base[0] : new Base[] {this.url}; // UriType
170        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // org.hl7.fhir.dstu3.model.Type
171        default: return super.getProperty(hash, name, checkValid);
172        }
173
174      }
175
176      @Override
177      public Base setProperty(int hash, String name, Base value) throws FHIRException {
178        switch (hash) {
179        case 116079: // url
180          this.url = castToUri(value); // UriType
181          return value;
182        case 111972721: // value
183          this.value = castToType(value); // org.hl7.fhir.dstu3.model.Type
184          return value;
185        default: return super.setProperty(hash, name, value);
186        }
187
188      }
189
190      @Override
191      public Base setProperty(String name, Base value) throws FHIRException {
192        if (name.equals("url")) {
193          this.url = castToUri(value); // UriType
194        } else if (name.equals("value[x]")) {
195          this.value = castToType(value); // org.hl7.fhir.dstu3.model.Type
196        } else
197          return super.setProperty(name, value);
198        return value;
199      }
200
201      @Override
202      public Base makeProperty(int hash, String name) throws FHIRException {
203        switch (hash) {
204        case 116079:  return getUrlElement();
205        case -1410166417:  return getValue(); 
206        case 111972721:  return getValue(); 
207        default: return super.makeProperty(hash, name);
208        }
209
210      }
211
212      @Override
213      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
214        switch (hash) {
215        case 116079: /*url*/ return new String[] {"uri"};
216        case 111972721: /*value*/ return new String[] {"*"};
217        default: return super.getTypesForProperty(hash, name);
218        }
219
220      }
221
222      @Override
223      public Base addChild(String name) throws FHIRException {
224        if (name.equals("url")) {
225          throw new FHIRException("Cannot call addChild on a primitive type Extension.url");
226        }
227        else if (name.equals("valueBoolean")) {
228          this.value = new BooleanType();
229          return this.value;
230        }
231        else if (name.equals("valueInteger")) {
232          this.value = new IntegerType();
233          return this.value;
234        }
235        else if (name.equals("valueDecimal")) {
236          this.value = new DecimalType();
237          return this.value;
238        }
239        else if (name.equals("valueBase64Binary")) {
240          this.value = new Base64BinaryType();
241          return this.value;
242        }
243        else if (name.equals("valueInstant")) {
244          this.value = new InstantType();
245          return this.value;
246        }
247        else if (name.equals("valueString")) {
248          this.value = new StringType();
249          return this.value;
250        }
251        else if (name.equals("valueUri")) {
252          this.value = new UriType();
253          return this.value;
254        }
255        else if (name.equals("valueDate")) {
256          this.value = new DateType();
257          return this.value;
258        }
259        else if (name.equals("valueDateTime")) {
260          this.value = new DateTimeType();
261          return this.value;
262        }
263        else if (name.equals("valueTime")) {
264          this.value = new TimeType();
265          return this.value;
266        }
267        else if (name.equals("valueCode")) {
268          this.value = new CodeType();
269          return this.value;
270        }
271        else if (name.equals("valueOid")) {
272          this.value = new OidType();
273          return this.value;
274        }
275        else if (name.equals("valueId")) {
276          this.value = new IdType();
277          return this.value;
278        }
279        else if (name.equals("valueUnsignedInt")) {
280          this.value = new UnsignedIntType();
281          return this.value;
282        }
283        else if (name.equals("valuePositiveInt")) {
284          this.value = new PositiveIntType();
285          return this.value;
286        }
287        else if (name.equals("valueMarkdown")) {
288          this.value = new MarkdownType();
289          return this.value;
290        }
291        else if (name.equals("valueAnnotation")) {
292          this.value = new Annotation();
293          return this.value;
294        }
295        else if (name.equals("valueAttachment")) {
296          this.value = new Attachment();
297          return this.value;
298        }
299        else if (name.equals("valueIdentifier")) {
300          this.value = new Identifier();
301          return this.value;
302        }
303        else if (name.equals("valueCodeableConcept")) {
304          this.value = new CodeableConcept();
305          return this.value;
306        }
307        else if (name.equals("valueCoding")) {
308          this.value = new Coding();
309          return this.value;
310        }
311        else if (name.equals("valueQuantity")) {
312          this.value = new Quantity();
313          return this.value;
314        }
315        else if (name.equals("valueRange")) {
316          this.value = new Range();
317          return this.value;
318        }
319        else if (name.equals("valuePeriod")) {
320          this.value = new Period();
321          return this.value;
322        }
323        else if (name.equals("valueRatio")) {
324          this.value = new Ratio();
325          return this.value;
326        }
327        else if (name.equals("valueSampledData")) {
328          this.value = new SampledData();
329          return this.value;
330        }
331        else if (name.equals("valueSignature")) {
332          this.value = new Signature();
333          return this.value;
334        }
335        else if (name.equals("valueHumanName")) {
336          this.value = new HumanName();
337          return this.value;
338        }
339        else if (name.equals("valueAddress")) {
340          this.value = new Address();
341          return this.value;
342        }
343        else if (name.equals("valueContactPoint")) {
344          this.value = new ContactPoint();
345          return this.value;
346        }
347        else if (name.equals("valueTiming")) {
348          this.value = new Timing();
349          return this.value;
350        }
351        else if (name.equals("valueReference")) {
352          this.value = new Reference();
353          return this.value;
354        }
355        else if (name.equals("valueMeta")) {
356          this.value = new Meta();
357          return this.value;
358        }
359        else
360          return super.addChild(name);
361      }
362
363  public String fhirType() {
364    return "Extension";
365
366  }
367
368      public Extension copy() {
369        Extension dst = new Extension();
370        copyValues(dst);
371        dst.url = url == null ? null : url.copy();
372        dst.value = value == null ? null : value.copy();
373        return dst;
374      }
375
376      protected Extension typedCopy() {
377        return copy();
378      }
379
380      @Override
381      public boolean equalsDeep(Base other) {
382        if (!super.equalsDeep(other))
383          return false;
384        if (!(other instanceof Extension))
385          return false;
386        Extension o = (Extension) other;
387        return compareDeep(url, o.url, true) && compareDeep(value, o.value, true);
388      }
389
390      @Override
391      public boolean equalsShallow(Base other) {
392        if (!super.equalsShallow(other))
393          return false;
394        if (!(other instanceof Extension))
395          return false;
396        Extension o = (Extension) other;
397        return compareValues(url, o.url, true);
398      }
399
400      public boolean isEmpty() {
401        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(url, value);
402      }
403
404
405}
406