001package org.hl7.fhir.r4.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 6, 2018 17:51-0400 for FHIR v3.4.0
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import org.hl7.fhir.r4.model.Enumerations.*;
038import ca.uhn.fhir.model.api.annotation.ResourceDef;
039import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.ChildOrder;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.Block;
044import org.hl7.fhir.instance.model.api.*;
045import org.hl7.fhir.exceptions.FHIRException;
046/**
047 * A binary resource can contain any content, whether text, image, pdf, zip archive, etc.
048 */
049@ResourceDef(name="Binary", profile="http://hl7.org/fhir/Profile/Binary")
050public class Binary extends BaseBinary implements IBaseBinary {
051
052    /**
053     * MimeType of the binary content represented as a standard MimeType (BCP 13).
054     */
055    @Child(name = "contentType", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
056    @Description(shortDefinition="MimeType of the binary content", formalDefinition="MimeType of the binary content represented as a standard MimeType (BCP 13)." )
057    protected CodeType contentType;
058
059    /**
060     * Treat this binary as if it was this other resource for access control purposes.
061     */
062    @Child(name = "securityContext", type = {Reference.class}, order=1, min=0, max=1, modifier=false, summary=true)
063    @Description(shortDefinition="Access Control Management", formalDefinition="Treat this binary as if it was this other resource for access control purposes." )
064    protected Reference securityContext;
065
066    /**
067     * The actual object that is the target of the reference (Treat this binary as if it was this other resource for access control purposes.)
068     */
069    protected Resource securityContextTarget;
070
071    /**
072     * The actual content, base64 encoded.
073     */
074    @Child(name = "content", type = {Base64BinaryType.class}, order=2, min=1, max=1, modifier=false, summary=true)
075    @Description(shortDefinition="The actual content", formalDefinition="The actual content, base64 encoded." )
076    protected Base64BinaryType content;
077
078    private static final long serialVersionUID = 1111991335L;
079
080  /**
081   * Constructor
082   */
083    public Binary() {
084      super();
085    }
086
087  /**
088   * Constructor
089   */
090    public Binary(CodeType contentType, Base64BinaryType content) {
091      super();
092      this.contentType = contentType;
093      this.content = content;
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} (Treat this binary as if it was this other resource for access control purposes.)
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} (Treat this binary as if it was this other resource for access control purposes.)
159     */
160    public Binary setSecurityContext(Reference value) { 
161      this.securityContext = value;
162      return this;
163    }
164
165    /**
166     * @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. (Treat this binary as if it was this other resource for access control purposes.)
167     */
168    public Resource getSecurityContextTarget() { 
169      return this.securityContextTarget;
170    }
171
172    /**
173     * @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. (Treat this binary as if it was this other resource for access control purposes.)
174     */
175    public Binary setSecurityContextTarget(Resource value) { 
176      this.securityContextTarget = value;
177      return this;
178    }
179
180    /**
181     * @return {@link #content} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getContent" gives direct access to the value
182     */
183    public Base64BinaryType getContentElement() { 
184      if (this.content == null)
185        if (Configuration.errorOnAutoCreate())
186          throw new Error("Attempt to auto-create Binary.content");
187        else if (Configuration.doAutoCreate())
188          this.content = new Base64BinaryType(); // bb
189      return this.content;
190    }
191
192    public boolean hasContentElement() { 
193      return this.content != null && !this.content.isEmpty();
194    }
195
196    public boolean hasContent() { 
197      return this.content != null && !this.content.isEmpty();
198    }
199
200    /**
201     * @param value {@link #content} (The actual content, base64 encoded.). This is the underlying object with id, value and extensions. The accessor "getContent" gives direct access to the value
202     */
203    public Binary setContentElement(Base64BinaryType value) { 
204      this.content = value;
205      return this;
206    }
207
208    /**
209     * @return The actual content, base64 encoded.
210     */
211    public byte[] getContent() { 
212      return this.content == null ? null : this.content.getValue();
213    }
214
215    /**
216     * @param value The actual content, base64 encoded.
217     */
218    public Binary setContent(byte[] value) { 
219        if (this.content == null)
220          this.content = new Base64BinaryType();
221        this.content.setValue(value);
222      return this;
223    }
224
225      protected void listChildren(List<Property> children) {
226        super.listChildren(children);
227        children.add(new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType));
228        children.add(new Property("securityContext", "Reference(Any)", "Treat this binary as if it was this other resource for access control purposes.", 0, 1, securityContext));
229        children.add(new Property("content", "base64Binary", "The actual content, base64 encoded.", 0, 1, content));
230      }
231
232      @Override
233      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
234        switch (_hash) {
235        case -389131437: /*contentType*/  return new Property("contentType", "code", "MimeType of the binary content represented as a standard MimeType (BCP 13).", 0, 1, contentType);
236        case -1622888881: /*securityContext*/  return new Property("securityContext", "Reference(Any)", "Treat this binary as if it was this other resource for access control purposes.", 0, 1, securityContext);
237        case 951530617: /*content*/  return new Property("content", "base64Binary", "The actual content, base64 encoded.", 0, 1, content);
238        default: return super.getNamedProperty(_hash, _name, _checkValid);
239        }
240
241      }
242
243      @Override
244      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
245        switch (hash) {
246        case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType
247        case -1622888881: /*securityContext*/ return this.securityContext == null ? new Base[0] : new Base[] {this.securityContext}; // Reference
248        case 951530617: /*content*/ return this.content == null ? new Base[0] : new Base[] {this.content}; // Base64BinaryType
249        default: return super.getProperty(hash, name, checkValid);
250        }
251
252      }
253
254      @Override
255      public Base setProperty(int hash, String name, Base value) throws FHIRException {
256        switch (hash) {
257        case -389131437: // contentType
258          this.contentType = castToCode(value); // CodeType
259          return value;
260        case -1622888881: // securityContext
261          this.securityContext = castToReference(value); // Reference
262          return value;
263        case 951530617: // content
264          this.content = castToBase64Binary(value); // Base64BinaryType
265          return value;
266        default: return super.setProperty(hash, name, value);
267        }
268
269      }
270
271      @Override
272      public Base setProperty(String name, Base value) throws FHIRException {
273        if (name.equals("contentType")) {
274          this.contentType = castToCode(value); // CodeType
275        } else if (name.equals("securityContext")) {
276          this.securityContext = castToReference(value); // Reference
277        } else if (name.equals("content")) {
278          this.content = castToBase64Binary(value); // Base64BinaryType
279        } else
280          return super.setProperty(name, value);
281        return value;
282      }
283
284      @Override
285      public Base makeProperty(int hash, String name) throws FHIRException {
286        switch (hash) {
287        case -389131437:  return getContentTypeElement();
288        case -1622888881:  return getSecurityContext(); 
289        case 951530617:  return getContentElement();
290        default: return super.makeProperty(hash, name);
291        }
292
293      }
294
295      @Override
296      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
297        switch (hash) {
298        case -389131437: /*contentType*/ return new String[] {"code"};
299        case -1622888881: /*securityContext*/ return new String[] {"Reference"};
300        case 951530617: /*content*/ return new String[] {"base64Binary"};
301        default: return super.getTypesForProperty(hash, name);
302        }
303
304      }
305
306      @Override
307      public Base addChild(String name) throws FHIRException {
308        if (name.equals("contentType")) {
309          throw new FHIRException("Cannot call addChild on a primitive type Binary.contentType");
310        }
311        else if (name.equals("securityContext")) {
312          this.securityContext = new Reference();
313          return this.securityContext;
314        }
315        else if (name.equals("content")) {
316          throw new FHIRException("Cannot call addChild on a primitive type Binary.content");
317        }
318        else
319          return super.addChild(name);
320      }
321
322  public String fhirType() {
323    return "Binary";
324
325  }
326
327      public Binary copy() {
328        Binary dst = new Binary();
329        copyValues(dst);
330        dst.contentType = contentType == null ? null : contentType.copy();
331        dst.securityContext = securityContext == null ? null : securityContext.copy();
332        dst.content = content == null ? null : content.copy();
333        return dst;
334      }
335
336      protected Binary typedCopy() {
337        return copy();
338      }
339
340      @Override
341      public boolean equalsDeep(Base other_) {
342        if (!super.equalsDeep(other_))
343          return false;
344        if (!(other_ instanceof Binary))
345          return false;
346        Binary o = (Binary) other_;
347        return compareDeep(contentType, o.contentType, true) && compareDeep(securityContext, o.securityContext, true)
348           && compareDeep(content, o.content, true);
349      }
350
351      @Override
352      public boolean equalsShallow(Base other_) {
353        if (!super.equalsShallow(other_))
354          return false;
355        if (!(other_ instanceof Binary))
356          return false;
357        Binary o = (Binary) other_;
358        return compareValues(contentType, o.contentType, true) && compareValues(content, o.content, true);
359      }
360
361      public boolean isEmpty() {
362        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(contentType, securityContext
363          , content);
364      }
365
366  @Override
367  public ResourceType getResourceType() {
368    return ResourceType.Binary;
369   }
370
371
372}
373