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