001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import org.hl7.fhir.r4.model.Enumerations.*;
041import ca.uhn.fhir.model.api.annotation.ResourceDef;
042import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.ChildOrder;
045import ca.uhn.fhir.model.api.annotation.Description;
046import ca.uhn.fhir.model.api.annotation.Block;
047import org.hl7.fhir.instance.model.api.*;
048import org.hl7.fhir.exceptions.FHIRException;
049/**
050 * A resource that represents the data of a single raw artifact as digital content accessible in its native format.  A Binary resource can contain any content, whether text, image, pdf, zip archive, etc.
051 */
052@ResourceDef(name="Binary", profile="http://hl7.org/fhir/StructureDefinition/Binary")
053public class Binary extends BaseBinary implements IBaseBinary {
054
055    /**
056     * MimeType of the binary content represented as a standard MimeType (BCP 13).
057     */
058    @Child(name = "contentType", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
059    @Description(shortDefinition="MimeType of the binary content", formalDefinition="MimeType of the binary content represented as a standard MimeType (BCP 13)." )
060    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/mimetypes")
061    protected CodeType contentType;
062
063    /**
064     * This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.
065     */
066    @Child(name = "securityContext", type = {Reference.class}, order=1, min=0, max=1, modifier=false, summary=true)
067    @Description(shortDefinition="Identifies another resource to use as proxy when enforcing access control", formalDefinition="This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient." )
068    protected Reference securityContext;
069
070    /**
071     * The actual object that is the target of the reference (This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.)
072     */
073    protected Resource securityContextTarget;
074
075    /**
076     * The actual content, base64 encoded.
077     */
078    @Child(name = "data", type = {Base64BinaryType.class}, order=2, min=0, max=1, modifier=false, summary=false)
079    @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." )
080    protected Base64BinaryType data;
081
082    private static final long serialVersionUID = 1353224198L;
083
084  /**
085   * Constructor
086   */
087    public Binary() {
088      super();
089    }
090
091  /**
092   * Constructor
093   */
094    public Binary(CodeType contentType) {
095      super();
096      this.contentType = contentType;
097    }
098
099    /**
100     * @return {@link #contentType} (MimeType of the binary content represented as a standard MimeType (BCP 13).). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
101     */
102    public CodeType getContentTypeElement() { 
103      if (this.contentType == null)
104        if (Configuration.errorOnAutoCreate())
105          throw new Error("Attempt to auto-create Binary.contentType");
106        else if (Configuration.doAutoCreate())
107          this.contentType = new CodeType(); // bb
108      return this.contentType;
109    }
110
111    public boolean hasContentTypeElement() { 
112      return this.contentType != null && !this.contentType.isEmpty();
113    }
114
115    public boolean hasContentType() { 
116      return this.contentType != null && !this.contentType.isEmpty();
117    }
118
119    /**
120     * @param value {@link #contentType} (MimeType of the binary content represented as a standard MimeType (BCP 13).). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
121     */
122    public Binary setContentTypeElement(CodeType value) { 
123      this.contentType = value;
124      return this;
125    }
126
127    /**
128     * @return MimeType of the binary content represented as a standard MimeType (BCP 13).
129     */
130    public String getContentType() { 
131      return this.contentType == null ? null : this.contentType.getValue();
132    }
133
134    /**
135     * @param value MimeType of the binary content represented as a standard MimeType (BCP 13).
136     */
137    public Binary setContentType(String value) { 
138        if (this.contentType == null)
139          this.contentType = new CodeType();
140        this.contentType.setValue(value);
141      return this;
142    }
143
144    /**
145     * @return {@link #securityContext} (This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.)
146     */
147    public Reference getSecurityContext() { 
148      if (this.securityContext == null)
149        if (Configuration.errorOnAutoCreate())
150          throw new Error("Attempt to auto-create Binary.securityContext");
151        else if (Configuration.doAutoCreate())
152          this.securityContext = new Reference(); // cc
153      return this.securityContext;
154    }
155
156    public boolean hasSecurityContext() { 
157      return this.securityContext != null && !this.securityContext.isEmpty();
158    }
159
160    /**
161     * @param value {@link #securityContext} (This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.)
162     */
163    public Binary setSecurityContext(Reference value) { 
164      this.securityContext = value;
165      return this;
166    }
167
168    /**
169     * @return {@link #securityContext} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.)
170     */
171    public Resource getSecurityContextTarget() { 
172      return this.securityContextTarget;
173    }
174
175    /**
176     * @param value {@link #securityContext} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.)
177     */
178    public Binary setSecurityContextTarget(Resource value) { 
179      this.securityContextTarget = value;
180      return this;
181    }
182
183    /**
184     * @return {@link #data} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getData" gives direct access to the value
185     */
186    public Base64BinaryType getDataElement() { 
187      if (this.data == null)
188        if (Configuration.errorOnAutoCreate())
189          throw new Error("Attempt to auto-create Binary.data");
190        else if (Configuration.doAutoCreate())
191          this.data = new Base64BinaryType(); // bb
192      return this.data;
193    }
194
195    public boolean hasDataElement() { 
196      return this.data != null && !this.data.isEmpty();
197    }
198
199    public boolean hasData() { 
200      return this.data != null && !this.data.isEmpty();
201    }
202
203    /**
204     * @param value {@link #data} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getData" gives direct access to the value
205     */
206    public Binary setDataElement(Base64BinaryType value) { 
207      this.data = value;
208      return this;
209    }
210
211    /**
212     * @return The actual content, base64 encoded.
213     */
214    public byte[] getData() { 
215      return this.data == null ? null : this.data.getValue();
216    }
217
218    /**
219     * @param value The actual content, base64 encoded.
220     */
221    public Binary setData(byte[] value) { 
222      if (value == null)
223        this.data = null;
224      else {
225        if (this.data == null)
226          this.data = new Base64BinaryType();
227        this.data.setValue(value);
228      }
229      return this;
230    }
231
232      protected void listChildren(List<Property> children) {
233        super.listChildren(children);
234        children.add(new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType));
235        children.add(new Property("securityContext", "Reference(Any)", "This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.", 0, 1, securityContext));
236        children.add(new Property("data", "base64Binary", "The actual content, base64 encoded.", 0, 1, data));
237      }
238
239      @Override
240      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
241        switch (_hash) {
242        case -389131437: /*contentType*/  return new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType);
243        case -1622888881: /*securityContext*/  return new Property("securityContext", "Reference(Any)", "This element identifies another resource that can be used as a proxy of the security sensitivity to use when deciding and enforcing access control rules for the Binary resource. Given that the Binary resource contains very few elements that can be used to determine the sensitivity of the data and relationships to individuals, the referenced resource stands in as a proxy equivalent for this purpose. This referenced resource may be related to the Binary (e.g. Media, DocumentReference), or may be some non-related Resource purely as a security proxy. E.g. to identify that the binary resource relates to a patient, and access should only be granted to applications that have access to the patient.", 0, 1, securityContext);
244        case 3076010: /*data*/  return new Property("data", "base64Binary", "The actual content, base64 encoded.", 0, 1, data);
245        default: return super.getNamedProperty(_hash, _name, _checkValid);
246        }
247
248      }
249
250      @Override
251      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
252        switch (hash) {
253        case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType
254        case -1622888881: /*securityContext*/ return this.securityContext == null ? new Base[0] : new Base[] {this.securityContext}; // Reference
255        case 3076010: /*data*/ return this.data == null ? new Base[0] : new Base[] {this.data}; // Base64BinaryType
256        default: return super.getProperty(hash, name, checkValid);
257        }
258
259      }
260
261      @Override
262      public Base setProperty(int hash, String name, Base value) throws FHIRException {
263        switch (hash) {
264        case -389131437: // contentType
265          this.contentType = castToCode(value); // CodeType
266          return value;
267        case -1622888881: // securityContext
268          this.securityContext = castToReference(value); // Reference
269          return value;
270        case 3076010: // data
271          this.data = castToBase64Binary(value); // Base64BinaryType
272          return value;
273        default: return super.setProperty(hash, name, value);
274        }
275
276      }
277
278      @Override
279      public Base setProperty(String name, Base value) throws FHIRException {
280        if (name.equals("contentType")) {
281          this.contentType = castToCode(value); // CodeType
282        } else if (name.equals("securityContext")) {
283          this.securityContext = castToReference(value); // Reference
284        } else if (name.equals("data")) {
285          this.data = castToBase64Binary(value); // Base64BinaryType
286        } else
287          return super.setProperty(name, value);
288        return value;
289      }
290
291      @Override
292      public Base makeProperty(int hash, String name) throws FHIRException {
293        switch (hash) {
294        case -389131437:  return getContentTypeElement();
295        case -1622888881:  return getSecurityContext(); 
296        case 3076010:  return getDataElement();
297        default: return super.makeProperty(hash, name);
298        }
299
300      }
301
302      @Override
303      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
304        switch (hash) {
305        case -389131437: /*contentType*/ return new String[] {"code"};
306        case -1622888881: /*securityContext*/ return new String[] {"Reference"};
307        case 3076010: /*data*/ return new String[] {"base64Binary"};
308        default: return super.getTypesForProperty(hash, name);
309        }
310
311      }
312
313      @Override
314      public Base addChild(String name) throws FHIRException {
315        if (name.equals("contentType")) {
316          throw new FHIRException("Cannot call addChild on a primitive type Binary.contentType");
317        }
318        else if (name.equals("securityContext")) {
319          this.securityContext = new Reference();
320          return this.securityContext;
321        }
322        else if (name.equals("data")) {
323          throw new FHIRException("Cannot call addChild on a primitive type Binary.data");
324        }
325        else
326          return super.addChild(name);
327      }
328
329  public String fhirType() {
330    return "Binary";
331
332  }
333
334      public Binary copy() {
335        Binary dst = new Binary();
336        copyValues(dst);
337        return dst;
338      }
339
340      public void copyValues(Binary dst) {
341        super.copyValues(dst);
342        dst.contentType = contentType == null ? null : contentType.copy();
343        dst.securityContext = securityContext == null ? null : securityContext.copy();
344        dst.data = data == null ? null : data.copy();
345      }
346
347      protected Binary typedCopy() {
348        return copy();
349      }
350
351      @Override
352      public boolean equalsDeep(Base other_) {
353        if (!super.equalsDeep(other_))
354          return false;
355        if (!(other_ instanceof Binary))
356          return false;
357        Binary o = (Binary) other_;
358        return compareDeep(contentType, o.contentType, true) && compareDeep(securityContext, o.securityContext, true)
359           && compareDeep(data, o.data, true);
360      }
361
362      @Override
363      public boolean equalsShallow(Base other_) {
364        if (!super.equalsShallow(other_))
365          return false;
366        if (!(other_ instanceof Binary))
367          return false;
368        Binary o = (Binary) other_;
369        return compareValues(contentType, o.contentType, true) && compareValues(data, o.data, true);
370      }
371
372      public boolean isEmpty() {
373        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(contentType, securityContext
374          , data);
375      }
376
377  @Override
378  public ResourceType getResourceType() {
379    return ResourceType.Binary;
380   }
381
382// added from java-adornments.txt:
383 
384  @Override
385  public byte[] getContent() {
386    return getData();
387  }
388
389  @Override
390  public IBaseBinary setContent(byte[] arg0) {
391    return setData(arg0);
392  }
393
394  @Override
395  public Base64BinaryType getContentElement() {
396    return getDataElement();
397  }
398
399      
400
401// end addition
402
403}