001package org.hl7.fhir.dstu2016may.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 Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
036import java.util.ArrayList;
037import java.util.Date;
038import java.util.List;
039
040import org.hl7.fhir.exceptions.FHIRException;
041import org.hl7.fhir.instance.model.api.ICompositeType;
042import org.hl7.fhir.utilities.Utilities;
043
044import ca.uhn.fhir.model.api.annotation.Child;
045import ca.uhn.fhir.model.api.annotation.DatatypeDef;
046import ca.uhn.fhir.model.api.annotation.Description;
047/**
048 * 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.
049 */
050@DatatypeDef(name="Signature")
051public class Signature extends Type implements ICompositeType {
052
053    /**
054     * 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.
055     */
056    @Child(name = "type", type = {Coding.class}, order=0, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
057    @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." )
058    protected List<Coding> type;
059
060    /**
061     * When the digital signature was signed.
062     */
063    @Child(name = "when", type = {InstantType.class}, order=1, min=1, max=1, modifier=false, summary=true)
064    @Description(shortDefinition="When the signature was created", formalDefinition="When the digital signature was signed." )
065    protected InstantType when;
066
067    /**
068     * A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key).
069     */
070    @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)
071    @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)." )
072    protected Type who;
073
074    /**
075     * 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, etc.
076     */
077    @Child(name = "contentType", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=true)
078    @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, etc." )
079    protected CodeType contentType;
080
081    /**
082     * The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.
083     */
084    @Child(name = "blob", type = {Base64BinaryType.class}, order=4, min=0, max=1, modifier=false, summary=false)
085    @Description(shortDefinition="The actual signature content (XML DigSig. JWT, picture, etc.)", formalDefinition="The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty." )
086    protected Base64BinaryType blob;
087
088    private static final long serialVersionUID = -452432714L;
089
090  /**
091   * Constructor
092   */
093    public Signature() {
094      super();
095    }
096
097  /**
098   * Constructor
099   */
100    public Signature(InstantType when, Type who) {
101      super();
102      this.when = when;
103      this.who = who;
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, etc.). 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, etc.). 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, etc.
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, etc.
273     */
274    public Signature setContentType(String value) { 
275      if (Utilities.noString(value))
276        this.contentType = null;
277      else {
278        if (this.contentType == null)
279          this.contentType = new CodeType();
280        this.contentType.setValue(value);
281      }
282      return this;
283    }
284
285    /**
286     * @return {@link #blob} (The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.). This is the underlying object with id, value and extensions. The accessor "getBlob" gives direct access to the value
287     */
288    public Base64BinaryType getBlobElement() { 
289      if (this.blob == null)
290        if (Configuration.errorOnAutoCreate())
291          throw new Error("Attempt to auto-create Signature.blob");
292        else if (Configuration.doAutoCreate())
293          this.blob = new Base64BinaryType(); // bb
294      return this.blob;
295    }
296
297    public boolean hasBlobElement() { 
298      return this.blob != null && !this.blob.isEmpty();
299    }
300
301    public boolean hasBlob() { 
302      return this.blob != null && !this.blob.isEmpty();
303    }
304
305    /**
306     * @param value {@link #blob} (The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.). This is the underlying object with id, value and extensions. The accessor "getBlob" gives direct access to the value
307     */
308    public Signature setBlobElement(Base64BinaryType value) { 
309      this.blob = value;
310      return this;
311    }
312
313    /**
314     * @return The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.
315     */
316    public byte[] getBlob() { 
317      return this.blob == null ? null : this.blob.getValue();
318    }
319
320    /**
321     * @param value The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.
322     */
323    public Signature setBlob(byte[] value) { 
324      if (value == null)
325        this.blob = null;
326      else {
327        if (this.blob == null)
328          this.blob = new Base64BinaryType();
329        this.blob.setValue(value);
330      }
331      return this;
332    }
333
334      protected void listChildren(List<Property> childrenList) {
335        super.listChildren(childrenList);
336        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));
337        childrenList.add(new Property("when", "instant", "When the digital signature was signed.", 0, java.lang.Integer.MAX_VALUE, when));
338        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));
339        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, etc.", 0, java.lang.Integer.MAX_VALUE, contentType));
340        childrenList.add(new Property("blob", "base64Binary", "The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty.", 0, java.lang.Integer.MAX_VALUE, blob));
341      }
342
343      @Override
344      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
345        switch (hash) {
346        case 3575610: /*type*/ return this.type == null ? new Base[0] : this.type.toArray(new Base[this.type.size()]); // Coding
347        case 3648314: /*when*/ return this.when == null ? new Base[0] : new Base[] {this.when}; // InstantType
348        case 117694: /*who*/ return this.who == null ? new Base[0] : new Base[] {this.who}; // Type
349        case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType
350        case 3026845: /*blob*/ return this.blob == null ? new Base[0] : new Base[] {this.blob}; // Base64BinaryType
351        default: return super.getProperty(hash, name, checkValid);
352        }
353
354      }
355
356      @Override
357      public void setProperty(int hash, String name, Base value) throws FHIRException {
358        switch (hash) {
359        case 3575610: // type
360          this.getType().add(castToCoding(value)); // Coding
361          break;
362        case 3648314: // when
363          this.when = castToInstant(value); // InstantType
364          break;
365        case 117694: // who
366          this.who = (Type) value; // Type
367          break;
368        case -389131437: // contentType
369          this.contentType = castToCode(value); // CodeType
370          break;
371        case 3026845: // blob
372          this.blob = castToBase64Binary(value); // Base64BinaryType
373          break;
374        default: super.setProperty(hash, name, value);
375        }
376
377      }
378
379      @Override
380      public void setProperty(String name, Base value) throws FHIRException {
381        if (name.equals("type"))
382          this.getType().add(castToCoding(value));
383        else if (name.equals("when"))
384          this.when = castToInstant(value); // InstantType
385        else if (name.equals("who[x]"))
386          this.who = (Type) value; // Type
387        else if (name.equals("contentType"))
388          this.contentType = castToCode(value); // CodeType
389        else if (name.equals("blob"))
390          this.blob = castToBase64Binary(value); // Base64BinaryType
391        else
392          super.setProperty(name, value);
393      }
394
395      @Override
396      public Base makeProperty(int hash, String name) throws FHIRException {
397        switch (hash) {
398        case 3575610:  return addType(); // Coding
399        case 3648314: throw new FHIRException("Cannot make property when as it is not a complex type"); // InstantType
400        case -788654078:  return getWho(); // Type
401        case -389131437: throw new FHIRException("Cannot make property contentType as it is not a complex type"); // CodeType
402        case 3026845: throw new FHIRException("Cannot make property blob as it is not a complex type"); // Base64BinaryType
403        default: return super.makeProperty(hash, name);
404        }
405
406      }
407
408      @Override
409      public Base addChild(String name) throws FHIRException {
410        if (name.equals("type")) {
411          return addType();
412        }
413        else if (name.equals("when")) {
414          throw new FHIRException("Cannot call addChild on a primitive type Signature.when");
415        }
416        else if (name.equals("whoUri")) {
417          this.who = new UriType();
418          return this.who;
419        }
420        else if (name.equals("whoReference")) {
421          this.who = new Reference();
422          return this.who;
423        }
424        else if (name.equals("contentType")) {
425          throw new FHIRException("Cannot call addChild on a primitive type Signature.contentType");
426        }
427        else if (name.equals("blob")) {
428          throw new FHIRException("Cannot call addChild on a primitive type Signature.blob");
429        }
430        else
431          return super.addChild(name);
432      }
433
434  public String fhirType() {
435    return "Signature";
436
437  }
438
439      public Signature copy() {
440        Signature dst = new Signature();
441        copyValues(dst);
442        if (type != null) {
443          dst.type = new ArrayList<Coding>();
444          for (Coding i : type)
445            dst.type.add(i.copy());
446        };
447        dst.when = when == null ? null : when.copy();
448        dst.who = who == null ? null : who.copy();
449        dst.contentType = contentType == null ? null : contentType.copy();
450        dst.blob = blob == null ? null : blob.copy();
451        return dst;
452      }
453
454      protected Signature typedCopy() {
455        return copy();
456      }
457
458      @Override
459      public boolean equalsDeep(Base other) {
460        if (!super.equalsDeep(other))
461          return false;
462        if (!(other instanceof Signature))
463          return false;
464        Signature o = (Signature) other;
465        return compareDeep(type, o.type, true) && compareDeep(when, o.when, true) && compareDeep(who, o.who, true)
466           && compareDeep(contentType, o.contentType, true) && compareDeep(blob, o.blob, true);
467      }
468
469      @Override
470      public boolean equalsShallow(Base other) {
471        if (!super.equalsShallow(other))
472          return false;
473        if (!(other instanceof Signature))
474          return false;
475        Signature o = (Signature) other;
476        return compareValues(when, o.when, true) && compareValues(contentType, o.contentType, true) && compareValues(blob, o.blob, true)
477          ;
478      }
479
480      public boolean isEmpty() {
481        return super.isEmpty() && (type == null || type.isEmpty()) && (when == null || when.isEmpty())
482           && (who == null || who.isEmpty()) && (contentType == null || contentType.isEmpty()) && (blob == null || blob.isEmpty())
483          ;
484      }
485
486
487}