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.Date;
055import java.util.List;
056
057import ca.uhn.fhir.model.api.annotation.Child;
058import ca.uhn.fhir.model.api.annotation.DatatypeDef;
059import ca.uhn.fhir.model.api.annotation.Description;
060import org.hl7.fhir.instance.model.api.ICompositeType;
061import org.hl7.fhir.exceptions.FHIRException;
062import org.hl7.fhir.utilities.Utilities;
063/**
064 * For referring to data content defined in other formats.
065 */
066@DatatypeDef(name="Attachment")
067public class Attachment extends Type implements ICompositeType {
068
069    /**
070     * Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.
071     */
072    @Child(name = "contentType", type = {CodeType.class}, order=0, min=0, max=1, modifier=false, summary=true)
073    @Description(shortDefinition="Mime type of the content, with charset etc.", formalDefinition="Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate." )
074    protected CodeType contentType;
075
076    /**
077     * The human language of the content. The value can be any valid value according to BCP 47.
078     */
079    @Child(name = "language", type = {CodeType.class}, order=1, min=0, max=1, modifier=false, summary=true)
080    @Description(shortDefinition="Human language of the content (BCP-47)", formalDefinition="The human language of the content. The value can be any valid value according to BCP 47." )
081    protected CodeType language;
082
083    /**
084     * The actual data of the attachment - a sequence of bytes. In XML, represented using base64.
085     */
086    @Child(name = "data", type = {Base64BinaryType.class}, order=2, min=0, max=1, modifier=false, summary=true)
087    @Description(shortDefinition="Data inline, base64ed", formalDefinition="The actual data of the attachment - a sequence of bytes. In XML, represented using base64." )
088    protected Base64BinaryType data;
089
090    /**
091     * An alternative location where the data can be accessed.
092     */
093    @Child(name = "url", type = {UriType.class}, order=3, min=0, max=1, modifier=false, summary=true)
094    @Description(shortDefinition="Uri where the data can be found", formalDefinition="An alternative location where the data can be accessed." )
095    protected UriType url;
096
097    /**
098     * The number of bytes of data that make up this attachment.
099     */
100    @Child(name = "size", type = {UnsignedIntType.class}, order=4, min=0, max=1, modifier=false, summary=true)
101    @Description(shortDefinition="Number of bytes of content (if url provided)", formalDefinition="The number of bytes of data that make up this attachment." )
102    protected UnsignedIntType size;
103
104    /**
105     * The calculated hash of the data using SHA-1. Represented using base64.
106     */
107    @Child(name = "hash", type = {Base64BinaryType.class}, order=5, min=0, max=1, modifier=false, summary=true)
108    @Description(shortDefinition="Hash of the data (sha-1, base64ed)", formalDefinition="The calculated hash of the data using SHA-1. Represented using base64." )
109    protected Base64BinaryType hash;
110
111    /**
112     * A label or set of text to display in place of the data.
113     */
114    @Child(name = "title", type = {StringType.class}, order=6, min=0, max=1, modifier=false, summary=true)
115    @Description(shortDefinition="Label to display in place of the data", formalDefinition="A label or set of text to display in place of the data." )
116    protected StringType title;
117
118    /**
119     * The date that the attachment was first created.
120     */
121    @Child(name = "creation", type = {DateTimeType.class}, order=7, min=0, max=1, modifier=false, summary=true)
122    @Description(shortDefinition="Date attachment was first created", formalDefinition="The date that the attachment was first created." )
123    protected DateTimeType creation;
124
125    private static final long serialVersionUID = 581007080L;
126
127  /*
128   * Constructor
129   */
130    public Attachment() {
131      super();
132    }
133
134    /**
135     * @return {@link #contentType} (Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
136     */
137    public CodeType getContentTypeElement() { 
138      if (this.contentType == null)
139        if (Configuration.errorOnAutoCreate())
140          throw new Error("Attempt to auto-create Attachment.contentType");
141        else if (Configuration.doAutoCreate())
142          this.contentType = new CodeType(); // bb
143      return this.contentType;
144    }
145
146    public boolean hasContentTypeElement() { 
147      return this.contentType != null && !this.contentType.isEmpty();
148    }
149
150    public boolean hasContentType() { 
151      return this.contentType != null && !this.contentType.isEmpty();
152    }
153
154    /**
155     * @param value {@link #contentType} (Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
156     */
157    public Attachment setContentTypeElement(CodeType value) { 
158      this.contentType = value;
159      return this;
160    }
161
162    /**
163     * @return Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.
164     */
165    public String getContentType() { 
166      return this.contentType == null ? null : this.contentType.getValue();
167    }
168
169    /**
170     * @param value Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.
171     */
172    public Attachment setContentType(String value) { 
173      if (Utilities.noString(value))
174        this.contentType = null;
175      else {
176        if (this.contentType == null)
177          this.contentType = new CodeType();
178        this.contentType.setValue(value);
179      }
180      return this;
181    }
182
183    /**
184     * @return {@link #language} (The human language of the content. The value can be any valid value according to BCP 47.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
185     */
186    public CodeType getLanguageElement() { 
187      if (this.language == null)
188        if (Configuration.errorOnAutoCreate())
189          throw new Error("Attempt to auto-create Attachment.language");
190        else if (Configuration.doAutoCreate())
191          this.language = new CodeType(); // bb
192      return this.language;
193    }
194
195    public boolean hasLanguageElement() { 
196      return this.language != null && !this.language.isEmpty();
197    }
198
199    public boolean hasLanguage() { 
200      return this.language != null && !this.language.isEmpty();
201    }
202
203    /**
204     * @param value {@link #language} (The human language of the content. The value can be any valid value according to BCP 47.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
205     */
206    public Attachment setLanguageElement(CodeType value) { 
207      this.language = value;
208      return this;
209    }
210
211    /**
212     * @return The human language of the content. The value can be any valid value according to BCP 47.
213     */
214    public String getLanguage() { 
215      return this.language == null ? null : this.language.getValue();
216    }
217
218    /**
219     * @param value The human language of the content. The value can be any valid value according to BCP 47.
220     */
221    public Attachment setLanguage(String value) { 
222      if (Utilities.noString(value))
223        this.language = null;
224      else {
225        if (this.language == null)
226          this.language = new CodeType();
227        this.language.setValue(value);
228      }
229      return this;
230    }
231
232    /**
233     * @return {@link #data} (The actual data of the attachment - a sequence of bytes. In XML, represented using base64.). This is the underlying object with id, value and extensions. The accessor "getData" gives direct access to the value
234     */
235    public Base64BinaryType getDataElement() { 
236      if (this.data == null)
237        if (Configuration.errorOnAutoCreate())
238          throw new Error("Attempt to auto-create Attachment.data");
239        else if (Configuration.doAutoCreate())
240          this.data = new Base64BinaryType(); // bb
241      return this.data;
242    }
243
244    public boolean hasDataElement() { 
245      return this.data != null && !this.data.isEmpty();
246    }
247
248    public boolean hasData() { 
249      return this.data != null && !this.data.isEmpty();
250    }
251
252    /**
253     * @param value {@link #data} (The actual data of the attachment - a sequence of bytes. In XML, represented using base64.). This is the underlying object with id, value and extensions. The accessor "getData" gives direct access to the value
254     */
255    public Attachment setDataElement(Base64BinaryType value) { 
256      this.data = value;
257      return this;
258    }
259
260    /**
261     * @return The actual data of the attachment - a sequence of bytes. In XML, represented using base64.
262     */
263    public byte[] getData() { 
264      return this.data == null ? null : this.data.getValue();
265    }
266
267    /**
268     * @param value The actual data of the attachment - a sequence of bytes. In XML, represented using base64.
269     */
270    public Attachment setData(byte[] value) { 
271      if (value == null)
272        this.data = null;
273      else {
274        if (this.data == null)
275          this.data = new Base64BinaryType();
276        this.data.setValue(value);
277      }
278      return this;
279    }
280
281    /**
282     * @return {@link #url} (An alternative location where the data can be accessed.). This is the underlying object with id, value and extensions. The accessor "getUrl" gives direct access to the value
283     */
284    public UriType getUrlElement() { 
285      if (this.url == null)
286        if (Configuration.errorOnAutoCreate())
287          throw new Error("Attempt to auto-create Attachment.url");
288        else if (Configuration.doAutoCreate())
289          this.url = new UriType(); // bb
290      return this.url;
291    }
292
293    public boolean hasUrlElement() { 
294      return this.url != null && !this.url.isEmpty();
295    }
296
297    public boolean hasUrl() { 
298      return this.url != null && !this.url.isEmpty();
299    }
300
301    /**
302     * @param value {@link #url} (An alternative location where the data can be accessed.). This is the underlying object with id, value and extensions. The accessor "getUrl" gives direct access to the value
303     */
304    public Attachment setUrlElement(UriType value) { 
305      this.url = value;
306      return this;
307    }
308
309    /**
310     * @return An alternative location where the data can be accessed.
311     */
312    public String getUrl() { 
313      return this.url == null ? null : this.url.getValue();
314    }
315
316    /**
317     * @param value An alternative location where the data can be accessed.
318     */
319    public Attachment setUrl(String value) { 
320      if (Utilities.noString(value))
321        this.url = null;
322      else {
323        if (this.url == null)
324          this.url = new UriType();
325        this.url.setValue(value);
326      }
327      return this;
328    }
329
330    /**
331     * @return {@link #size} (The number of bytes of data that make up this attachment.). This is the underlying object with id, value and extensions. The accessor "getSize" gives direct access to the value
332     */
333    public UnsignedIntType getSizeElement() { 
334      if (this.size == null)
335        if (Configuration.errorOnAutoCreate())
336          throw new Error("Attempt to auto-create Attachment.size");
337        else if (Configuration.doAutoCreate())
338          this.size = new UnsignedIntType(); // bb
339      return this.size;
340    }
341
342    public boolean hasSizeElement() { 
343      return this.size != null && !this.size.isEmpty();
344    }
345
346    public boolean hasSize() { 
347      return this.size != null && !this.size.isEmpty();
348    }
349
350    /**
351     * @param value {@link #size} (The number of bytes of data that make up this attachment.). This is the underlying object with id, value and extensions. The accessor "getSize" gives direct access to the value
352     */
353    public Attachment setSizeElement(UnsignedIntType value) { 
354      this.size = value;
355      return this;
356    }
357
358    /**
359     * @return The number of bytes of data that make up this attachment.
360     */
361    public int getSize() { 
362      return this.size == null || this.size.isEmpty() ? 0 : this.size.getValue();
363    }
364
365    /**
366     * @param value The number of bytes of data that make up this attachment.
367     */
368    public Attachment setSize(int value) { 
369        if (this.size == null)
370          this.size = new UnsignedIntType();
371        this.size.setValue(value);
372      return this;
373    }
374
375    /**
376     * @return {@link #hash} (The calculated hash of the data using SHA-1. Represented using base64.). This is the underlying object with id, value and extensions. The accessor "getHash" gives direct access to the value
377     */
378    public Base64BinaryType getHashElement() { 
379      if (this.hash == null)
380        if (Configuration.errorOnAutoCreate())
381          throw new Error("Attempt to auto-create Attachment.hash");
382        else if (Configuration.doAutoCreate())
383          this.hash = new Base64BinaryType(); // bb
384      return this.hash;
385    }
386
387    public boolean hasHashElement() { 
388      return this.hash != null && !this.hash.isEmpty();
389    }
390
391    public boolean hasHash() { 
392      return this.hash != null && !this.hash.isEmpty();
393    }
394
395    /**
396     * @param value {@link #hash} (The calculated hash of the data using SHA-1. Represented using base64.). This is the underlying object with id, value and extensions. The accessor "getHash" gives direct access to the value
397     */
398    public Attachment setHashElement(Base64BinaryType value) { 
399      this.hash = value;
400      return this;
401    }
402
403    /**
404     * @return The calculated hash of the data using SHA-1. Represented using base64.
405     */
406    public byte[] getHash() { 
407      return this.hash == null ? null : this.hash.getValue();
408    }
409
410    /**
411     * @param value The calculated hash of the data using SHA-1. Represented using base64.
412     */
413    public Attachment setHash(byte[] value) { 
414      if (value == null)
415        this.hash = null;
416      else {
417        if (this.hash == null)
418          this.hash = new Base64BinaryType();
419        this.hash.setValue(value);
420      }
421      return this;
422    }
423
424    /**
425     * @return {@link #title} (A label or set of text to display in place of the data.). This is the underlying object with id, value and extensions. The accessor "getTitle" gives direct access to the value
426     */
427    public StringType getTitleElement() { 
428      if (this.title == null)
429        if (Configuration.errorOnAutoCreate())
430          throw new Error("Attempt to auto-create Attachment.title");
431        else if (Configuration.doAutoCreate())
432          this.title = new StringType(); // bb
433      return this.title;
434    }
435
436    public boolean hasTitleElement() { 
437      return this.title != null && !this.title.isEmpty();
438    }
439
440    public boolean hasTitle() { 
441      return this.title != null && !this.title.isEmpty();
442    }
443
444    /**
445     * @param value {@link #title} (A label or set of text to display in place of the data.). This is the underlying object with id, value and extensions. The accessor "getTitle" gives direct access to the value
446     */
447    public Attachment setTitleElement(StringType value) { 
448      this.title = value;
449      return this;
450    }
451
452    /**
453     * @return A label or set of text to display in place of the data.
454     */
455    public String getTitle() { 
456      return this.title == null ? null : this.title.getValue();
457    }
458
459    /**
460     * @param value A label or set of text to display in place of the data.
461     */
462    public Attachment setTitle(String value) { 
463      if (Utilities.noString(value))
464        this.title = null;
465      else {
466        if (this.title == null)
467          this.title = new StringType();
468        this.title.setValue(value);
469      }
470      return this;
471    }
472
473    /**
474     * @return {@link #creation} (The date that the attachment was first created.). This is the underlying object with id, value and extensions. The accessor "getCreation" gives direct access to the value
475     */
476    public DateTimeType getCreationElement() { 
477      if (this.creation == null)
478        if (Configuration.errorOnAutoCreate())
479          throw new Error("Attempt to auto-create Attachment.creation");
480        else if (Configuration.doAutoCreate())
481          this.creation = new DateTimeType(); // bb
482      return this.creation;
483    }
484
485    public boolean hasCreationElement() { 
486      return this.creation != null && !this.creation.isEmpty();
487    }
488
489    public boolean hasCreation() { 
490      return this.creation != null && !this.creation.isEmpty();
491    }
492
493    /**
494     * @param value {@link #creation} (The date that the attachment was first created.). This is the underlying object with id, value and extensions. The accessor "getCreation" gives direct access to the value
495     */
496    public Attachment setCreationElement(DateTimeType value) { 
497      this.creation = value;
498      return this;
499    }
500
501    /**
502     * @return The date that the attachment was first created.
503     */
504    public Date getCreation() { 
505      return this.creation == null ? null : this.creation.getValue();
506    }
507
508    /**
509     * @param value The date that the attachment was first created.
510     */
511    public Attachment setCreation(Date value) { 
512      if (value == null)
513        this.creation = null;
514      else {
515        if (this.creation == null)
516          this.creation = new DateTimeType();
517        this.creation.setValue(value);
518      }
519      return this;
520    }
521
522      protected void listChildren(List<Property> childrenList) {
523        super.listChildren(childrenList);
524        childrenList.add(new Property("contentType", "code", "Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.", 0, java.lang.Integer.MAX_VALUE, contentType));
525        childrenList.add(new Property("language", "code", "The human language of the content. The value can be any valid value according to BCP 47.", 0, java.lang.Integer.MAX_VALUE, language));
526        childrenList.add(new Property("data", "base64Binary", "The actual data of the attachment - a sequence of bytes. In XML, represented using base64.", 0, java.lang.Integer.MAX_VALUE, data));
527        childrenList.add(new Property("url", "uri", "An alternative location where the data can be accessed.", 0, java.lang.Integer.MAX_VALUE, url));
528        childrenList.add(new Property("size", "unsignedInt", "The number of bytes of data that make up this attachment.", 0, java.lang.Integer.MAX_VALUE, size));
529        childrenList.add(new Property("hash", "base64Binary", "The calculated hash of the data using SHA-1. Represented using base64.", 0, java.lang.Integer.MAX_VALUE, hash));
530        childrenList.add(new Property("title", "string", "A label or set of text to display in place of the data.", 0, java.lang.Integer.MAX_VALUE, title));
531        childrenList.add(new Property("creation", "dateTime", "The date that the attachment was first created.", 0, java.lang.Integer.MAX_VALUE, creation));
532      }
533
534      @Override
535      public void setProperty(String name, Base value) throws FHIRException {
536        if (name.equals("contentType"))
537          this.contentType = castToCode(value); // CodeType
538        else if (name.equals("language"))
539          this.language = castToCode(value); // CodeType
540        else if (name.equals("data"))
541          this.data = castToBase64Binary(value); // Base64BinaryType
542        else if (name.equals("url"))
543          this.url = castToUri(value); // UriType
544        else if (name.equals("size"))
545          this.size = castToUnsignedInt(value); // UnsignedIntType
546        else if (name.equals("hash"))
547          this.hash = castToBase64Binary(value); // Base64BinaryType
548        else if (name.equals("title"))
549          this.title = castToString(value); // StringType
550        else if (name.equals("creation"))
551          this.creation = castToDateTime(value); // DateTimeType
552        else
553          super.setProperty(name, value);
554      }
555
556      @Override
557      public Base addChild(String name) throws FHIRException {
558        if (name.equals("contentType")) {
559          throw new FHIRException("Cannot call addChild on a primitive type Attachment.contentType");
560        }
561        else if (name.equals("language")) {
562          throw new FHIRException("Cannot call addChild on a primitive type Attachment.language");
563        }
564        else if (name.equals("data")) {
565          throw new FHIRException("Cannot call addChild on a primitive type Attachment.data");
566        }
567        else if (name.equals("url")) {
568          throw new FHIRException("Cannot call addChild on a primitive type Attachment.url");
569        }
570        else if (name.equals("size")) {
571          throw new FHIRException("Cannot call addChild on a primitive type Attachment.size");
572        }
573        else if (name.equals("hash")) {
574          throw new FHIRException("Cannot call addChild on a primitive type Attachment.hash");
575        }
576        else if (name.equals("title")) {
577          throw new FHIRException("Cannot call addChild on a primitive type Attachment.title");
578        }
579        else if (name.equals("creation")) {
580          throw new FHIRException("Cannot call addChild on a primitive type Attachment.creation");
581        }
582        else
583          return super.addChild(name);
584      }
585
586  public String fhirType() {
587    return "Attachment";
588
589  }
590
591      public Attachment copy() {
592        Attachment dst = new Attachment();
593        copyValues(dst);
594        dst.contentType = contentType == null ? null : contentType.copy();
595        dst.language = language == null ? null : language.copy();
596        dst.data = data == null ? null : data.copy();
597        dst.url = url == null ? null : url.copy();
598        dst.size = size == null ? null : size.copy();
599        dst.hash = hash == null ? null : hash.copy();
600        dst.title = title == null ? null : title.copy();
601        dst.creation = creation == null ? null : creation.copy();
602        return dst;
603      }
604
605      protected Attachment typedCopy() {
606        return copy();
607      }
608
609      @Override
610      public boolean equalsDeep(Base other) {
611        if (!super.equalsDeep(other))
612          return false;
613        if (!(other instanceof Attachment))
614          return false;
615        Attachment o = (Attachment) other;
616        return compareDeep(contentType, o.contentType, true) && compareDeep(language, o.language, true)
617           && compareDeep(data, o.data, true) && compareDeep(url, o.url, true) && compareDeep(size, o.size, true)
618           && compareDeep(hash, o.hash, true) && compareDeep(title, o.title, true) && compareDeep(creation, o.creation, true)
619          ;
620      }
621
622      @Override
623      public boolean equalsShallow(Base other) {
624        if (!super.equalsShallow(other))
625          return false;
626        if (!(other instanceof Attachment))
627          return false;
628        Attachment o = (Attachment) other;
629        return compareValues(contentType, o.contentType, true) && compareValues(language, o.language, true)
630           && compareValues(data, o.data, true) && compareValues(url, o.url, true) && compareValues(size, o.size, true)
631           && compareValues(hash, o.hash, true) && compareValues(title, o.title, true) && compareValues(creation, o.creation, true)
632          ;
633      }
634
635      public boolean isEmpty() {
636        return super.isEmpty() && (contentType == null || contentType.isEmpty()) && (language == null || language.isEmpty())
637           && (data == null || data.isEmpty()) && (url == null || url.isEmpty()) && (size == null || size.isEmpty())
638           && (hash == null || hash.isEmpty()) && (title == null || title.isEmpty()) && (creation == null || creation.isEmpty())
639          ;
640      }
641
642
643}
644