001package org.hl7.fhir.dstu2.model;
002
003
004
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012  
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033*/
034
035// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.DatatypeDef;
042import ca.uhn.fhir.model.api.annotation.Description;
043import org.hl7.fhir.instance.model.api.ICompositeType;
044import org.hl7.fhir.exceptions.FHIRException;
045/**
046 * A digital signature along with supporting context. The signature may be electronic/cryptographic in nature, or a graphical image representing a hand-written signature, or a signature process. Different Signature approaches have different utilities.
047 */
048@DatatypeDef(name="Signature")
049public class Signature extends Type implements ICompositeType {
050
051    /**
052     * An indication of the reason that the entity signed this document. This may be explicitly included as part of the signature information and can be used when determining accountability for various actions concerning the document.
053     */
054    @Child(name = "type", type = {Coding.class}, order=0, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
055    @Description(shortDefinition="Indication of the reason the entity signed the object(s)", formalDefinition="An indication of the reason that the entity signed this document. This may be explicitly included as part of the signature information and can be used when determining accountability for various actions concerning the document." )
056    protected List<Coding> type;
057
058    /**
059     * When the digital signature was signed.
060     */
061    @Child(name = "when", type = {InstantType.class}, order=1, min=1, max=1, modifier=false, summary=true)
062    @Description(shortDefinition="When the signature was created", formalDefinition="When the digital signature was signed." )
063    protected InstantType when;
064
065    /**
066     * A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).
067     */
068    @Child(name = "who", type = {UriType.class, Practitioner.class, RelatedPerson.class, Patient.class, Device.class, Organization.class}, order=2, min=1, max=1, modifier=false, summary=true)
069    @Description(shortDefinition="Who signed the signature", formalDefinition="A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key)." )
070    protected Type who;
071
072    /**
073     * A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.
074     */
075    @Child(name = "contentType", type = {CodeType.class}, order=3, min=1, max=1, modifier=false, summary=true)
076    @Description(shortDefinition="The technical format of the signature", formalDefinition="A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature." )
077    protected CodeType contentType;
078
079    /**
080     * The base64 encoding of the Signature content.
081     */
082    @Child(name = "blob", type = {Base64BinaryType.class}, order=4, min=1, max=1, modifier=false, summary=true)
083    @Description(shortDefinition="The actual signature content (XML DigSig. JWT, picture, etc.)", formalDefinition="The base64 encoding of the Signature content." )
084    protected Base64BinaryType blob;
085
086    private static final long serialVersionUID = -452432714L;
087
088  /*
089   * Constructor
090   */
091    public Signature() {
092      super();
093    }
094
095  /*
096   * Constructor
097   */
098    public Signature(InstantType when, Type who, CodeType contentType, Base64BinaryType blob) {
099      super();
100      this.when = when;
101      this.who = who;
102      this.contentType = contentType;
103      this.blob = blob;
104    }
105
106    /**
107     * @return {@link #type} (An indication of the reason that the entity signed this document. This may be explicitly included as part of the signature information and can be used when determining accountability for various actions concerning the document.)
108     */
109    public List<Coding> getType() { 
110      if (this.type == null)
111        this.type = new ArrayList<Coding>();
112      return this.type;
113    }
114
115    public boolean hasType() { 
116      if (this.type == null)
117        return false;
118      for (Coding item : this.type)
119        if (!item.isEmpty())
120          return true;
121      return false;
122    }
123
124    /**
125     * @return {@link #type} (An indication of the reason that the entity signed this document. This may be explicitly included as part of the signature information and can be used when determining accountability for various actions concerning the document.)
126     */
127    // syntactic sugar
128    public Coding addType() { //3
129      Coding t = new Coding();
130      if (this.type == null)
131        this.type = new ArrayList<Coding>();
132      this.type.add(t);
133      return t;
134    }
135
136    // syntactic sugar
137    public Signature addType(Coding t) { //3
138      if (t == null)
139        return this;
140      if (this.type == null)
141        this.type = new ArrayList<Coding>();
142      this.type.add(t);
143      return this;
144    }
145
146    /**
147     * @return {@link #when} (When the digital signature was signed.). This is the underlying object with id, value and extensions. The accessor "getWhen" gives direct access to the value
148     */
149    public InstantType getWhenElement() { 
150      if (this.when == null)
151        if (Configuration.errorOnAutoCreate())
152          throw new Error("Attempt to auto-create Signature.when");
153        else if (Configuration.doAutoCreate())
154          this.when = new InstantType(); // bb
155      return this.when;
156    }
157
158    public boolean hasWhenElement() { 
159      return this.when != null && !this.when.isEmpty();
160    }
161
162    public boolean hasWhen() { 
163      return this.when != null && !this.when.isEmpty();
164    }
165
166    /**
167     * @param value {@link #when} (When the digital signature was signed.). This is the underlying object with id, value and extensions. The accessor "getWhen" gives direct access to the value
168     */
169    public Signature setWhenElement(InstantType value) { 
170      this.when = value;
171      return this;
172    }
173
174    /**
175     * @return When the digital signature was signed.
176     */
177    public Date getWhen() { 
178      return this.when == null ? null : this.when.getValue();
179    }
180
181    /**
182     * @param value When the digital signature was signed.
183     */
184    public Signature setWhen(Date value) { 
185        if (this.when == null)
186          this.when = new InstantType();
187        this.when.setValue(value);
188      return this;
189    }
190
191    /**
192     * @return {@link #who} (A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).)
193     */
194    public Type getWho() { 
195      return this.who;
196    }
197
198    /**
199     * @return {@link #who} (A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).)
200     */
201    public UriType getWhoUriType() throws FHIRException { 
202      if (!(this.who instanceof UriType))
203        throw new FHIRException("Type mismatch: the type UriType was expected, but "+this.who.getClass().getName()+" was encountered");
204      return (UriType) this.who;
205    }
206
207    public boolean hasWhoUriType() { 
208      return this.who instanceof UriType;
209    }
210
211    /**
212     * @return {@link #who} (A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).)
213     */
214    public Reference getWhoReference() throws FHIRException { 
215      if (!(this.who instanceof Reference))
216        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.who.getClass().getName()+" was encountered");
217      return (Reference) this.who;
218    }
219
220    public boolean hasWhoReference() { 
221      return this.who instanceof Reference;
222    }
223
224    public boolean hasWho() { 
225      return this.who != null && !this.who.isEmpty();
226    }
227
228    /**
229     * @param value {@link #who} (A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).)
230     */
231    public Signature setWho(Type value) { 
232      this.who = value;
233      return this;
234    }
235
236    /**
237     * @return {@link #contentType} (A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
238     */
239    public CodeType getContentTypeElement() { 
240      if (this.contentType == null)
241        if (Configuration.errorOnAutoCreate())
242          throw new Error("Attempt to auto-create Signature.contentType");
243        else if (Configuration.doAutoCreate())
244          this.contentType = new CodeType(); // bb
245      return this.contentType;
246    }
247
248    public boolean hasContentTypeElement() { 
249      return this.contentType != null && !this.contentType.isEmpty();
250    }
251
252    public boolean hasContentType() { 
253      return this.contentType != null && !this.contentType.isEmpty();
254    }
255
256    /**
257     * @param value {@link #contentType} (A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.). This is the underlying object with id, value and extensions. The accessor "getContentType" gives direct access to the value
258     */
259    public Signature setContentTypeElement(CodeType value) { 
260      this.contentType = value;
261      return this;
262    }
263
264    /**
265     * @return A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.
266     */
267    public String getContentType() { 
268      return this.contentType == null ? null : this.contentType.getValue();
269    }
270
271    /**
272     * @param value A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.
273     */
274    public Signature setContentType(String value) { 
275        if (this.contentType == null)
276          this.contentType = new CodeType();
277        this.contentType.setValue(value);
278      return this;
279    }
280
281    /**
282     * @return {@link #blob} (The base64 encoding of the Signature content.). This is the underlying object with id, value and extensions. The accessor "getBlob" gives direct access to the value
283     */
284    public Base64BinaryType getBlobElement() { 
285      if (this.blob == null)
286        if (Configuration.errorOnAutoCreate())
287          throw new Error("Attempt to auto-create Signature.blob");
288        else if (Configuration.doAutoCreate())
289          this.blob = new Base64BinaryType(); // bb
290      return this.blob;
291    }
292
293    public boolean hasBlobElement() { 
294      return this.blob != null && !this.blob.isEmpty();
295    }
296
297    public boolean hasBlob() { 
298      return this.blob != null && !this.blob.isEmpty();
299    }
300
301    /**
302     * @param value {@link #blob} (The base64 encoding of the Signature content.). This is the underlying object with id, value and extensions. The accessor "getBlob" gives direct access to the value
303     */
304    public Signature setBlobElement(Base64BinaryType value) { 
305      this.blob = value;
306      return this;
307    }
308
309    /**
310     * @return The base64 encoding of the Signature content.
311     */
312    public byte[] getBlob() { 
313      return this.blob == null ? null : this.blob.getValue();
314    }
315
316    /**
317     * @param value The base64 encoding of the Signature content.
318     */
319    public Signature setBlob(byte[] value) { 
320        if (this.blob == null)
321          this.blob = new Base64BinaryType();
322        this.blob.setValue(value);
323      return this;
324    }
325
326      protected void listChildren(List<Property> childrenList) {
327        super.listChildren(childrenList);
328        childrenList.add(new Property("type", "Coding", "An indication of the reason that the entity signed this document. This may be explicitly included as part of the signature information and can be used when determining accountability for various actions concerning the document.", 0, java.lang.Integer.MAX_VALUE, type));
329        childrenList.add(new Property("when", "instant", "When the digital signature was signed.", 0, java.lang.Integer.MAX_VALUE, when));
330        childrenList.add(new Property("who[x]", "uri|Reference(Practitioner|RelatedPerson|Patient|Device|Organization)", "A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).", 0, java.lang.Integer.MAX_VALUE, who));
331        childrenList.add(new Property("contentType", "code", "A mime type that indicates the technical format of the signature. Important mime types are application/signature+xml for X ML DigSig, application/jwt for JWT, and image/* for a graphical image of a signature.", 0, java.lang.Integer.MAX_VALUE, contentType));
332        childrenList.add(new Property("blob", "base64Binary", "The base64 encoding of the Signature content.", 0, java.lang.Integer.MAX_VALUE, blob));
333      }
334
335      @Override
336      public void setProperty(String name, Base value) throws FHIRException {
337        if (name.equals("type"))
338          this.getType().add(castToCoding(value));
339        else if (name.equals("when"))
340          this.when = castToInstant(value); // InstantType
341        else if (name.equals("who[x]"))
342          this.who = (Type) value; // Type
343        else if (name.equals("contentType"))
344          this.contentType = castToCode(value); // CodeType
345        else if (name.equals("blob"))
346          this.blob = castToBase64Binary(value); // Base64BinaryType
347        else
348          super.setProperty(name, value);
349      }
350
351      @Override
352      public Base addChild(String name) throws FHIRException {
353        if (name.equals("type")) {
354          return addType();
355        }
356        else if (name.equals("when")) {
357          throw new FHIRException("Cannot call addChild on a primitive type Signature.when");
358        }
359        else if (name.equals("whoUri")) {
360          this.who = new UriType();
361          return this.who;
362        }
363        else if (name.equals("whoReference")) {
364          this.who = new Reference();
365          return this.who;
366        }
367        else if (name.equals("contentType")) {
368          throw new FHIRException("Cannot call addChild on a primitive type Signature.contentType");
369        }
370        else if (name.equals("blob")) {
371          throw new FHIRException("Cannot call addChild on a primitive type Signature.blob");
372        }
373        else
374          return super.addChild(name);
375      }
376
377  public String fhirType() {
378    return "Signature";
379
380  }
381
382      public Signature copy() {
383        Signature dst = new Signature();
384        copyValues(dst);
385        if (type != null) {
386          dst.type = new ArrayList<Coding>();
387          for (Coding i : type)
388            dst.type.add(i.copy());
389        };
390        dst.when = when == null ? null : when.copy();
391        dst.who = who == null ? null : who.copy();
392        dst.contentType = contentType == null ? null : contentType.copy();
393        dst.blob = blob == null ? null : blob.copy();
394        return dst;
395      }
396
397      protected Signature typedCopy() {
398        return copy();
399      }
400
401      @Override
402      public boolean equalsDeep(Base other) {
403        if (!super.equalsDeep(other))
404          return false;
405        if (!(other instanceof Signature))
406          return false;
407        Signature o = (Signature) other;
408        return compareDeep(type, o.type, true) && compareDeep(when, o.when, true) && compareDeep(who, o.who, true)
409           && compareDeep(contentType, o.contentType, true) && compareDeep(blob, o.blob, true);
410      }
411
412      @Override
413      public boolean equalsShallow(Base other) {
414        if (!super.equalsShallow(other))
415          return false;
416        if (!(other instanceof Signature))
417          return false;
418        Signature o = (Signature) other;
419        return compareValues(when, o.when, true) && compareValues(contentType, o.contentType, true) && compareValues(blob, o.blob, true)
420          ;
421      }
422
423      public boolean isEmpty() {
424        return super.isEmpty() && (type == null || type.isEmpty()) && (when == null || when.isEmpty())
425           && (who == null || who.isEmpty()) && (contentType == null || contentType.isEmpty()) && (blob == null || blob.isEmpty())
426          ;
427      }
428
429
430}