001package org.hl7.fhir.r5.model;
002
003
004/*
005 * #%L
006 * org.hl7.fhir.r5
007 * %%
008 * Copyright (C) 2014 - 2019 Health Level 7
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the \"License\");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 * 
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 * 
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an \"AS IS\" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * #L%
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// Generated on Tue, Dec 31, 2019 12:12+1100 for FHIR vcurrent
053
054import java.util.ArrayList;
055import java.util.Date;
056import java.util.List;
057import org.hl7.fhir.utilities.Utilities;
058import org.hl7.fhir.r5.model.Enumerations.*;
059import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
060import org.hl7.fhir.exceptions.FHIRException;
061import org.hl7.fhir.instance.model.api.ICompositeType;
062import ca.uhn.fhir.model.api.annotation.ResourceDef;
063import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
064import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
065import ca.uhn.fhir.model.api.annotation.Child;
066import ca.uhn.fhir.model.api.annotation.ChildOrder;
067import ca.uhn.fhir.model.api.annotation.Description;
068import ca.uhn.fhir.model.api.annotation.Block;
069
070import org.hl7.fhir.instance.model.api.IBaseBinary;
071/**
072 * 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.
073 */
074@ResourceDef(name="Binary", profile="http://hl7.org/fhir/StructureDefinition/Binary")
075public class Binary extends BaseBinary implements IBaseBinary {
076
077    /**
078     * MimeType of the binary content represented as a standard MimeType (BCP 13).
079     */
080    @Child(name = "contentType", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
081    @Description(shortDefinition="MimeType of the binary content", formalDefinition="MimeType of the binary content represented as a standard MimeType (BCP 13)." )
082    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/mimetypes")
083    protected CodeType contentType;
084
085    /**
086     * 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.
087     */
088    @Child(name = "securityContext", type = {Reference.class}, order=1, min=0, max=1, modifier=false, summary=true)
089    @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." )
090    protected Reference securityContext;
091
092    /**
093     * The actual content, base64 encoded.
094     */
095    @Child(name = "data", type = {Base64BinaryType.class}, order=2, min=0, max=1, modifier=false, summary=false)
096    @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." )
097    protected Base64BinaryType data;
098
099    private static final long serialVersionUID = 65831526L;
100
101  /**
102   * Constructor
103   */
104    public Binary() {
105      super();
106    }
107
108  /**
109   * Constructor
110   */
111    public Binary(String contentType) {
112      super();
113      this.setContentType(contentType);
114    }
115
116    /**
117     * @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
118     */
119    public CodeType getContentTypeElement() { 
120      if (this.contentType == null)
121        if (Configuration.errorOnAutoCreate())
122          throw new Error("Attempt to auto-create Binary.contentType");
123        else if (Configuration.doAutoCreate())
124          this.contentType = new CodeType(); // bb
125      return this.contentType;
126    }
127
128    public boolean hasContentTypeElement() { 
129      return this.contentType != null && !this.contentType.isEmpty();
130    }
131
132    public boolean hasContentType() { 
133      return this.contentType != null && !this.contentType.isEmpty();
134    }
135
136    /**
137     * @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
138     */
139    public Binary setContentTypeElement(CodeType value) { 
140      this.contentType = value;
141      return this;
142    }
143
144    /**
145     * @return MimeType of the binary content represented as a standard MimeType (BCP 13).
146     */
147    public String getContentType() { 
148      return this.contentType == null ? null : this.contentType.getValue();
149    }
150
151    /**
152     * @param value MimeType of the binary content represented as a standard MimeType (BCP 13).
153     */
154    public Binary setContentType(String value) { 
155        if (this.contentType == null)
156          this.contentType = new CodeType();
157        this.contentType.setValue(value);
158      return this;
159    }
160
161    /**
162     * @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.)
163     */
164    public Reference getSecurityContext() { 
165      if (this.securityContext == null)
166        if (Configuration.errorOnAutoCreate())
167          throw new Error("Attempt to auto-create Binary.securityContext");
168        else if (Configuration.doAutoCreate())
169          this.securityContext = new Reference(); // cc
170      return this.securityContext;
171    }
172
173    public boolean hasSecurityContext() { 
174      return this.securityContext != null && !this.securityContext.isEmpty();
175    }
176
177    /**
178     * @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.)
179     */
180    public Binary setSecurityContext(Reference value) { 
181      this.securityContext = value;
182      return this;
183    }
184
185    /**
186     * @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
187     */
188    public Base64BinaryType getDataElement() { 
189      if (this.data == null)
190        if (Configuration.errorOnAutoCreate())
191          throw new Error("Attempt to auto-create Binary.data");
192        else if (Configuration.doAutoCreate())
193          this.data = new Base64BinaryType(); // bb
194      return this.data;
195    }
196
197    public boolean hasDataElement() { 
198      return this.data != null && !this.data.isEmpty();
199    }
200
201    public boolean hasData() { 
202      return this.data != null && !this.data.isEmpty();
203    }
204
205    /**
206     * @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
207     */
208    public Binary setDataElement(Base64BinaryType value) { 
209      this.data = value;
210      return this;
211    }
212
213    /**
214     * @return The actual content, base64 encoded.
215     */
216    public byte[] getData() { 
217      return this.data == null ? null : this.data.getValue();
218    }
219
220    /**
221     * @param value The actual content, base64 encoded.
222     */
223    public Binary setData(byte[] value) { 
224      if (value == null)
225        this.data = null;
226      else {
227        if (this.data == null)
228          this.data = new Base64BinaryType();
229        this.data.setValue(value);
230      }
231      return this;
232    }
233
234      protected void listChildren(List<Property> children) {
235        super.listChildren(children);
236        children.add(new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType));
237        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));
238        children.add(new Property("data", "base64Binary", "The actual content, base64 encoded.", 0, 1, data));
239      }
240
241      @Override
242      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
243        switch (_hash) {
244        case -389131437: /*contentType*/  return new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType);
245        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);
246        case 3076010: /*data*/  return new Property("data", "base64Binary", "The actual content, base64 encoded.", 0, 1, data);
247        default: return super.getNamedProperty(_hash, _name, _checkValid);
248        }
249
250      }
251
252      @Override
253      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
254        switch (hash) {
255        case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType
256        case -1622888881: /*securityContext*/ return this.securityContext == null ? new Base[0] : new Base[] {this.securityContext}; // Reference
257        case 3076010: /*data*/ return this.data == null ? new Base[0] : new Base[] {this.data}; // Base64BinaryType
258        default: return super.getProperty(hash, name, checkValid);
259        }
260
261      }
262
263      @Override
264      public Base setProperty(int hash, String name, Base value) throws FHIRException {
265        switch (hash) {
266        case -389131437: // contentType
267          this.contentType = TypeConvertor.castToCode(value); // CodeType
268          return value;
269        case -1622888881: // securityContext
270          this.securityContext = TypeConvertor.castToReference(value); // Reference
271          return value;
272        case 3076010: // data
273          this.data = TypeConvertor.castToBase64Binary(value); // Base64BinaryType
274          return value;
275        default: return super.setProperty(hash, name, value);
276        }
277
278      }
279
280      @Override
281      public Base setProperty(String name, Base value) throws FHIRException {
282        if (name.equals("contentType")) {
283          this.contentType = TypeConvertor.castToCode(value); // CodeType
284        } else if (name.equals("securityContext")) {
285          this.securityContext = TypeConvertor.castToReference(value); // Reference
286        } else if (name.equals("data")) {
287          this.data = TypeConvertor.castToBase64Binary(value); // Base64BinaryType
288        } else
289          return super.setProperty(name, value);
290        return value;
291      }
292
293      @Override
294      public Base makeProperty(int hash, String name) throws FHIRException {
295        switch (hash) {
296        case -389131437:  return getContentTypeElement();
297        case -1622888881:  return getSecurityContext();
298        case 3076010:  return getDataElement();
299        default: return super.makeProperty(hash, name);
300        }
301
302      }
303
304      @Override
305      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
306        switch (hash) {
307        case -389131437: /*contentType*/ return new String[] {"code"};
308        case -1622888881: /*securityContext*/ return new String[] {"Reference"};
309        case 3076010: /*data*/ return new String[] {"base64Binary"};
310        default: return super.getTypesForProperty(hash, name);
311        }
312
313      }
314
315      @Override
316      public Base addChild(String name) throws FHIRException {
317        if (name.equals("contentType")) {
318          throw new FHIRException("Cannot call addChild on a primitive type Binary.contentType");
319        }
320        else if (name.equals("securityContext")) {
321          this.securityContext = new Reference();
322          return this.securityContext;
323        }
324        else if (name.equals("data")) {
325          throw new FHIRException("Cannot call addChild on a primitive type Binary.data");
326        }
327        else
328          return super.addChild(name);
329      }
330
331  public String fhirType() {
332    return "Binary";
333
334  }
335
336      public Binary copy() {
337        Binary dst = new Binary();
338        copyValues(dst);
339        return dst;
340      }
341
342      public void copyValues(Binary dst) {
343        super.copyValues(dst);
344        dst.contentType = contentType == null ? null : contentType.copy();
345        dst.securityContext = securityContext == null ? null : securityContext.copy();
346        dst.data = data == null ? null : data.copy();
347      }
348
349      protected Binary typedCopy() {
350        return copy();
351      }
352
353      @Override
354      public boolean equalsDeep(Base other_) {
355        if (!super.equalsDeep(other_))
356          return false;
357        if (!(other_ instanceof Binary))
358          return false;
359        Binary o = (Binary) other_;
360        return compareDeep(contentType, o.contentType, true) && compareDeep(securityContext, o.securityContext, true)
361           && compareDeep(data, o.data, true);
362      }
363
364      @Override
365      public boolean equalsShallow(Base other_) {
366        if (!super.equalsShallow(other_))
367          return false;
368        if (!(other_ instanceof Binary))
369          return false;
370        Binary o = (Binary) other_;
371        return compareValues(contentType, o.contentType, true) && compareValues(data, o.data, true);
372      }
373
374      public boolean isEmpty() {
375        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(contentType, securityContext
376          , data);
377      }
378
379  @Override
380  public ResourceType getResourceType() {
381    return ResourceType.Binary;
382   }
383
384// Manual code (from Configuration.txt)t:
385 
386  @Override
387  public byte[] getContent() {
388    return getData();
389  }
390
391  @Override
392  public IBaseBinary setContent(byte[] arg0) {
393    return setData(arg0);
394  }
395
396  @Override
397  public Base64BinaryType getContentElement() {
398    return getDataElement();
399  }
400
401      
402
403// end addition
404
405}
406