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