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.IBaseBinary;
060import org.hl7.fhir.utilities.Utilities;
061import org.hl7.fhir.r5.model.Enumerations.*;
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/**
070 * 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.
071 */
072@ResourceDef(name="Binary", profile="http://hl7.org/fhir/StructureDefinition/Binary")
073public class Binary extends BaseBinary implements IBaseBinary {
074
075    /**
076     * MimeType of the binary content represented as a standard MimeType (BCP 13).
077     */
078    @Child(name = "contentType", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
079    @Description(shortDefinition="MimeType of the binary content", formalDefinition="MimeType of the binary content represented as a standard MimeType (BCP 13)." )
080    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/mimetypes")
081    protected CodeType contentType;
082
083    /**
084     * 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.
085     */
086    @Child(name = "securityContext", type = {Reference.class}, order=1, min=0, max=1, modifier=false, summary=true)
087    @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." )
088    protected Reference securityContext;
089
090    /**
091     * The actual content, base64 encoded.
092     */
093    @Child(name = "data", type = {Base64BinaryType.class}, order=2, min=0, max=1, modifier=false, summary=false)
094    @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." )
095    protected Base64BinaryType data;
096
097    private static final long serialVersionUID = 65831526L;
098
099  /**
100   * Constructor
101   */
102    public Binary() {
103      super();
104    }
105
106  /**
107   * Constructor
108   */
109    public Binary(CodeType contentType) {
110      super();
111      this.contentType = contentType;
112    }
113
114    /**
115     * @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
116     */
117    public CodeType getContentTypeElement() { 
118      if (this.contentType == null)
119        if (Configuration.errorOnAutoCreate())
120          throw new Error("Attempt to auto-create Binary.contentType");
121        else if (Configuration.doAutoCreate())
122          this.contentType = new CodeType(); // bb
123      return this.contentType;
124    }
125
126    public boolean hasContentTypeElement() { 
127      return this.contentType != null && !this.contentType.isEmpty();
128    }
129
130    public boolean hasContentType() { 
131      return this.contentType != null && !this.contentType.isEmpty();
132    }
133
134    /**
135     * @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
136     */
137    public Binary setContentTypeElement(CodeType value) { 
138      this.contentType = value;
139      return this;
140    }
141
142    /**
143     * @return MimeType of the binary content represented as a standard MimeType (BCP 13).
144     */
145    public String getContentType() { 
146      return this.contentType == null ? null : this.contentType.getValue();
147    }
148
149    /**
150     * @param value MimeType of the binary content represented as a standard MimeType (BCP 13).
151     */
152    public Binary setContentType(String value) { 
153        if (this.contentType == null)
154          this.contentType = new CodeType();
155        this.contentType.setValue(value);
156      return this;
157    }
158
159    /**
160     * @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.)
161     */
162    public Reference getSecurityContext() { 
163      if (this.securityContext == null)
164        if (Configuration.errorOnAutoCreate())
165          throw new Error("Attempt to auto-create Binary.securityContext");
166        else if (Configuration.doAutoCreate())
167          this.securityContext = new Reference(); // cc
168      return this.securityContext;
169    }
170
171    public boolean hasSecurityContext() { 
172      return this.securityContext != null && !this.securityContext.isEmpty();
173    }
174
175    /**
176     * @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.)
177     */
178    public Binary setSecurityContext(Reference value) { 
179      this.securityContext = 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. 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. 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}
404