001package org.hl7.fhir.r5.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r5
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  Copyright (c) 2011+, HL7, Inc.
025  All rights reserved.
026  
027  Redistribution and use in source and binary forms, with or without modification, 
028  are permitted provided that the following conditions are met:
029  
030   * Redistributions of source code must retain the above copyright notice, this 
031     list of conditions and the following disclaimer.
032   * Redistributions in binary form must reproduce the above copyright notice, 
033     this list of conditions and the following disclaimer in the documentation 
034     and/or other materials provided with the distribution.
035   * Neither the name of HL7 nor the names of its contributors may be used to 
036     endorse or promote products derived from this software without specific 
037     prior written permission.
038  
039  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
040  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
041  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
042  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
043  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
044  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
045  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
046  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
047  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
048  POSSIBILITY OF SUCH DAMAGE.
049  
050*/
051
052// Generated on Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0
053import java.util.ArrayList;
054import java.util.Date;
055import java.util.List;
056import org.hl7.fhir.exceptions.FHIRException;
057import org.hl7.fhir.instance.model.api.ICompositeType;
058
059import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;
060import org.hl7.fhir.instance.model.api.IBaseExtension;
061import org.hl7.fhir.instance.model.api.IBaseDatatype;
062import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
063import org.hl7.fhir.utilities.Utilities;
064import ca.uhn.fhir.model.api.annotation.Child;
065import ca.uhn.fhir.model.api.annotation.ChildOrder;
066import ca.uhn.fhir.model.api.annotation.DatatypeDef;
067import ca.uhn.fhir.model.api.annotation.Description;
068import ca.uhn.fhir.model.api.annotation.Block;
069/**
070 * Optional Extension Element - found in all resources.
071 */
072@DatatypeDef(name="Extension")
073public class Extension extends BaseExtension implements IBaseExtension<Extension, Type>, IBaseHasExtensions {
074
075    /**
076     * Source of the definition for the extension code - a logical name or a URL.
077     */
078    @Child(name = "url", type = {UriType.class}, order=0, min=1, max=1, modifier=false, summary=false)
079    @Description(shortDefinition="identifies the meaning of the extension", formalDefinition="Source of the definition for the extension code - a logical name or a URL." )
080    protected UriType url;
081
082    /**
083     * Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).
084     */
085    @Child(name = "value", type = {}, order=1, min=0, max=1, modifier=false, summary=false)
086    @Description(shortDefinition="Value of extension", formalDefinition="Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list)." )
087    protected org.hl7.fhir.r5.model.Type value;
088
089    private static final long serialVersionUID = 405953844L;
090
091  /**
092   * Constructor
093   */
094    public Extension() {
095      super();
096    }
097
098  /**
099   * Constructor
100   */
101    public Extension(UriType url) {
102      super();
103      this.url = url;
104    }
105
106    /**
107     * Constructor
108     */
109    public Extension(String theUrl) {
110      setUrl(theUrl);
111    }
112
113    /**
114     * Constructor
115     */
116    public Extension(String theUrl, IBaseDatatype theValue) {
117      setUrl(theUrl);
118      setValue(theValue);
119    }
120
121    /**
122     * @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
123     */
124    public UriType getUrlElement() { 
125      if (this.url == null)
126        if (Configuration.errorOnAutoCreate())
127          throw new Error("Attempt to auto-create Extension.url");
128        else if (Configuration.doAutoCreate())
129          this.url = new UriType(); // bb
130      return this.url;
131    }
132
133    public boolean hasUrlElement() { 
134      return this.url != null && !this.url.isEmpty();
135    }
136
137    public boolean hasUrl() { 
138      return this.url != null && !this.url.isEmpty();
139    }
140
141    /**
142     * @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
143     */
144    public Extension setUrlElement(UriType value) { 
145      this.url = value;
146      return this;
147    }
148
149    /**
150     * @return Source of the definition for the extension code - a logical name or a URL.
151     */
152    public String getUrl() { 
153      return this.url == null ? null : this.url.getValue();
154    }
155
156    /**
157     * @param value Source of the definition for the extension code - a logical name or a URL.
158     */
159    public Extension setUrl(String value) { 
160        if (this.url == null)
161          this.url = new UriType();
162        this.url.setValue(value);
163      return this;
164    }
165
166    /**
167     * @return {@link #value} (Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).)
168     */
169    public org.hl7.fhir.r5.model.Type getValue() { 
170      return this.value;
171    }
172
173    public boolean hasValue() { 
174      return this.value != null && !this.value.isEmpty();
175    }
176
177    /**
178     * @param value {@link #value} (Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).)
179     */
180    public Extension setValue(org.hl7.fhir.r5.model.Type value) { 
181      this.value = value;
182      return this;
183    }
184
185      protected void listChildren(List<Property> children) {
186        super.listChildren(children);
187        children.add(new Property("url", "uri", "Source of the definition for the extension code - a logical name or a URL.", 0, 1, url));
188        children.add(new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value));
189      }
190
191      @Override
192      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
193        switch (_hash) {
194        case 116079: /*url*/  return new Property("url", "uri", "Source of the definition for the extension code - a logical name or a URL.", 0, 1, url);
195        case -1410166417: /*value[x]*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
196        case 111972721: /*value*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
197        case -1535024575: /*valueBase64Binary*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
198        case 733421943: /*valueBoolean*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
199        case -786218365: /*valueCanonical*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
200        case -766209282: /*valueCode*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
201        case -766192449: /*valueDate*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
202        case 1047929900: /*valueDateTime*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
203        case -2083993440: /*valueDecimal*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
204        case 231604844: /*valueId*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
205        case -1668687056: /*valueInstant*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
206        case -1668204915: /*valueInteger*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
207        case -497880704: /*valueMarkdown*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
208        case -1410178407: /*valueOid*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
209        case -1249932027: /*valuePositiveInt*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
210        case -1424603934: /*valueString*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
211        case -765708322: /*valueTime*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
212        case 26529417: /*valueUnsignedInt*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
213        case -1410172357: /*valueUri*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
214        case -1410172354: /*valueUrl*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
215        case -765667124: /*valueUuid*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
216        case -478981821: /*valueAddress*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
217        case -67108992: /*valueAnnotation*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
218        case -475566732: /*valueAttachment*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
219        case 924902896: /*valueCodeableConcept*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
220        case -1887705029: /*valueCoding*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
221        case 944904545: /*valueContactPoint*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
222        case -2026205465: /*valueHumanName*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
223        case -130498310: /*valueIdentifier*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
224        case -1524344174: /*valuePeriod*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
225        case -2029823716: /*valueQuantity*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
226        case 2030761548: /*valueRange*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
227        case 2030767386: /*valueRatio*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
228        case 1755241690: /*valueReference*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
229        case -962229101: /*valueSampledData*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
230        case -540985785: /*valueSignature*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
231        case -1406282469: /*valueTiming*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
232        case -1858636920: /*valueDosage*/  return new Property("value[x]", "*", "Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).", 0, 1, value);
233        default: return super.getNamedProperty(_hash, _name, _checkValid);
234        }
235
236      }
237
238      @Override
239      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
240        switch (hash) {
241        case 116079: /*url*/ return this.url == null ? new Base[0] : new Base[] {this.url}; // UriType
242        case 111972721: /*value*/ return this.value == null ? new Base[0] : new Base[] {this.value}; // org.hl7.fhir.r5.model.Type
243        default: return super.getProperty(hash, name, checkValid);
244        }
245
246      }
247
248      @Override
249      public Base setProperty(int hash, String name, Base value) throws FHIRException {
250        switch (hash) {
251        case 116079: // url
252          this.url = castToUri(value); // UriType
253          return value;
254        case 111972721: // value
255          this.value = castToType(value); // org.hl7.fhir.r5.model.Type
256          return value;
257        default: return super.setProperty(hash, name, value);
258        }
259
260      }
261
262      @Override
263      public Base setProperty(String name, Base value) throws FHIRException {
264        if (name.equals("url")) {
265          this.url = castToUri(value); // UriType
266        } else if (name.equals("value[x]")) {
267          this.value = castToType(value); // org.hl7.fhir.r5.model.Type
268        } else
269          return super.setProperty(name, value);
270        return value;
271      }
272
273      @Override
274      public Base makeProperty(int hash, String name) throws FHIRException {
275        switch (hash) {
276        case 116079:  return getUrlElement();
277        case -1410166417:  return getValue();
278        case 111972721:  return getValue();
279        default: return super.makeProperty(hash, name);
280        }
281
282      }
283
284      @Override
285      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
286        switch (hash) {
287        case 116079: /*url*/ return new String[] {"uri"};
288        case 111972721: /*value*/ return new String[] {"*"};
289        default: return super.getTypesForProperty(hash, name);
290        }
291
292      }
293
294      @Override
295      public Base addChild(String name) throws FHIRException {
296        if (name.equals("url")) {
297          throw new FHIRException("Cannot call addChild on a primitive type Extension.url");
298        }
299        else if (name.equals("valueBase64Binary")) {
300          this.value = new Base64BinaryType();
301          return this.value;
302        }
303        else if (name.equals("valueBoolean")) {
304          this.value = new BooleanType();
305          return this.value;
306        }
307        else if (name.equals("valueCanonical")) {
308          this.value = new CanonicalType();
309          return this.value;
310        }
311        else if (name.equals("valueCode")) {
312          this.value = new CodeType();
313          return this.value;
314        }
315        else if (name.equals("valueDate")) {
316          this.value = new DateType();
317          return this.value;
318        }
319        else if (name.equals("valueDateTime")) {
320          this.value = new DateTimeType();
321          return this.value;
322        }
323        else if (name.equals("valueDecimal")) {
324          this.value = new DecimalType();
325          return this.value;
326        }
327        else if (name.equals("valueId")) {
328          this.value = new IdType();
329          return this.value;
330        }
331        else if (name.equals("valueInstant")) {
332          this.value = new InstantType();
333          return this.value;
334        }
335        else if (name.equals("valueInteger")) {
336          this.value = new IntegerType();
337          return this.value;
338        }
339        else if (name.equals("valueMarkdown")) {
340          this.value = new MarkdownType();
341          return this.value;
342        }
343        else if (name.equals("valueOid")) {
344          this.value = new OidType();
345          return this.value;
346        }
347        else if (name.equals("valuePositiveInt")) {
348          this.value = new PositiveIntType();
349          return this.value;
350        }
351        else if (name.equals("valueString")) {
352          this.value = new StringType();
353          return this.value;
354        }
355        else if (name.equals("valueTime")) {
356          this.value = new TimeType();
357          return this.value;
358        }
359        else if (name.equals("valueUnsignedInt")) {
360          this.value = new UnsignedIntType();
361          return this.value;
362        }
363        else if (name.equals("valueUri")) {
364          this.value = new UriType();
365          return this.value;
366        }
367        else if (name.equals("valueUrl")) {
368          this.value = new UrlType();
369          return this.value;
370        }
371        else if (name.equals("valueUuid")) {
372          this.value = new UuidType();
373          return this.value;
374        }
375        else if (name.equals("valueAddress")) {
376          this.value = new Address();
377          return this.value;
378        }
379        else if (name.equals("valueAge")) {
380          this.value = new Age();
381          return this.value;
382        }
383        else if (name.equals("valueAnnotation")) {
384          this.value = new Annotation();
385          return this.value;
386        }
387        else if (name.equals("valueAttachment")) {
388          this.value = new Attachment();
389          return this.value;
390        }
391        else if (name.equals("valueCodeableConcept")) {
392          this.value = new CodeableConcept();
393          return this.value;
394        }
395        else if (name.equals("valueCoding")) {
396          this.value = new Coding();
397          return this.value;
398        }
399        else if (name.equals("valueContactPoint")) {
400          this.value = new ContactPoint();
401          return this.value;
402        }
403        else if (name.equals("valueCount")) {
404          this.value = new Count();
405          return this.value;
406        }
407        else if (name.equals("valueDistance")) {
408          this.value = new Distance();
409          return this.value;
410        }
411        else if (name.equals("valueDuration")) {
412          this.value = new Duration();
413          return this.value;
414        }
415        else if (name.equals("valueHumanName")) {
416          this.value = new HumanName();
417          return this.value;
418        }
419        else if (name.equals("valueIdentifier")) {
420          this.value = new Identifier();
421          return this.value;
422        }
423        else if (name.equals("valueMoney")) {
424          this.value = new Money();
425          return this.value;
426        }
427        else if (name.equals("valuePeriod")) {
428          this.value = new Period();
429          return this.value;
430        }
431        else if (name.equals("valueQuantity")) {
432          this.value = new Quantity();
433          return this.value;
434        }
435        else if (name.equals("valueRange")) {
436          this.value = new Range();
437          return this.value;
438        }
439        else if (name.equals("valueRatio")) {
440          this.value = new Ratio();
441          return this.value;
442        }
443        else if (name.equals("valueReference")) {
444          this.value = new Reference();
445          return this.value;
446        }
447        else if (name.equals("valueSampledData")) {
448          this.value = new SampledData();
449          return this.value;
450        }
451        else if (name.equals("valueSignature")) {
452          this.value = new Signature();
453          return this.value;
454        }
455        else if (name.equals("valueTiming")) {
456          this.value = new Timing();
457          return this.value;
458        }
459        else if (name.equals("valueContactDetail")) {
460          this.value = new ContactDetail();
461          return this.value;
462        }
463        else if (name.equals("valueContributor")) {
464          this.value = new Contributor();
465          return this.value;
466        }
467        else if (name.equals("valueDataRequirement")) {
468          this.value = new DataRequirement();
469          return this.value;
470        }
471        else if (name.equals("valueExpression")) {
472          this.value = new Expression();
473          return this.value;
474        }
475        else if (name.equals("valueParameterDefinition")) {
476          this.value = new ParameterDefinition();
477          return this.value;
478        }
479        else if (name.equals("valueRelatedArtifact")) {
480          this.value = new RelatedArtifact();
481          return this.value;
482        }
483        else if (name.equals("valueTriggerDefinition")) {
484          this.value = new TriggerDefinition();
485          return this.value;
486        }
487        else if (name.equals("valueUsageContext")) {
488          this.value = new UsageContext();
489          return this.value;
490        }
491        else if (name.equals("valueDosage")) {
492          this.value = new Dosage();
493          return this.value;
494        }
495        else if (name.equals("valueMeta")) {
496          this.value = new Meta();
497          return this.value;
498        }
499        else
500          return super.addChild(name);
501      }
502
503  public String fhirType() {
504    return "Extension";
505
506  }
507
508      public Extension copy() {
509        Extension dst = new Extension();
510        copyValues(dst);
511        return dst;
512      }
513
514      public void copyValues(Extension dst) {
515        super.copyValues(dst);
516        dst.url = url == null ? null : url.copy();
517        dst.value = value == null ? null : value.copy();
518      }
519
520      protected Extension typedCopy() {
521        return copy();
522      }
523
524      @Override
525      public boolean equalsDeep(Base other_) {
526        if (!super.equalsDeep(other_))
527          return false;
528        if (!(other_ instanceof Extension))
529          return false;
530        Extension o = (Extension) other_;
531        return compareDeep(url, o.url, true) && compareDeep(value, o.value, true);
532      }
533
534      @Override
535      public boolean equalsShallow(Base other_) {
536        if (!super.equalsShallow(other_))
537          return false;
538        if (!(other_ instanceof Extension))
539          return false;
540        Extension o = (Extension) other_;
541        return compareValues(url, o.url, true);
542      }
543
544      public boolean isEmpty() {
545        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(url, value);
546      }
547
548
549}
550