001package org.hl7.fhir.dstu2016may.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 8, 2016 03:05+1000 for FHIR v1.4.0 033import java.util.ArrayList; 034import java.util.Date; 035import java.util.List; 036 037import org.hl7.fhir.exceptions.FHIRException; 038import org.hl7.fhir.instance.model.api.ICompositeType; 039import org.hl7.fhir.utilities.Utilities; 040 041import ca.uhn.fhir.model.api.annotation.Child; 042import ca.uhn.fhir.model.api.annotation.DatatypeDef; 043import ca.uhn.fhir.model.api.annotation.Description; 044/** 045 * 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. 046 */ 047@DatatypeDef(name="Signature") 048public class Signature extends Type implements ICompositeType { 049 050 /** 051 * 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. 052 */ 053 @Child(name = "type", type = {Coding.class}, order=0, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 054 @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." ) 055 protected List<Coding> type; 056 057 /** 058 * When the digital signature was signed. 059 */ 060 @Child(name = "when", type = {InstantType.class}, order=1, min=1, max=1, modifier=false, summary=true) 061 @Description(shortDefinition="When the signature was created", formalDefinition="When the digital signature was signed." ) 062 protected InstantType when; 063 064 /** 065 * A reference to an application-usable description of the person that signed the certificate (e.g. the signature used their private key). 066 */ 067 @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) 068 @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)." ) 069 protected Type who; 070 071 /** 072 * 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. 073 */ 074 @Child(name = "contentType", type = {CodeType.class}, order=3, min=0, max=1, modifier=false, summary=true) 075 @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." ) 076 protected CodeType contentType; 077 078 /** 079 * The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 080 */ 081 @Child(name = "blob", type = {Base64BinaryType.class}, order=4, min=0, max=1, modifier=false, summary=false) 082 @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." ) 083 protected Base64BinaryType blob; 084 085 private static final long serialVersionUID = -452432714L; 086 087 /** 088 * Constructor 089 */ 090 public Signature() { 091 super(); 092 } 093 094 /** 095 * Constructor 096 */ 097 public Signature(InstantType when, Type who) { 098 super(); 099 this.when = when; 100 this.who = who; 101 } 102 103 /** 104 * @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.) 105 */ 106 public List<Coding> getType() { 107 if (this.type == null) 108 this.type = new ArrayList<Coding>(); 109 return this.type; 110 } 111 112 public boolean hasType() { 113 if (this.type == null) 114 return false; 115 for (Coding item : this.type) 116 if (!item.isEmpty()) 117 return true; 118 return false; 119 } 120 121 /** 122 * @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.) 123 */ 124 // syntactic sugar 125 public Coding addType() { //3 126 Coding t = new Coding(); 127 if (this.type == null) 128 this.type = new ArrayList<Coding>(); 129 this.type.add(t); 130 return t; 131 } 132 133 // syntactic sugar 134 public Signature addType(Coding t) { //3 135 if (t == null) 136 return this; 137 if (this.type == null) 138 this.type = new ArrayList<Coding>(); 139 this.type.add(t); 140 return this; 141 } 142 143 /** 144 * @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 145 */ 146 public InstantType getWhenElement() { 147 if (this.when == null) 148 if (Configuration.errorOnAutoCreate()) 149 throw new Error("Attempt to auto-create Signature.when"); 150 else if (Configuration.doAutoCreate()) 151 this.when = new InstantType(); // bb 152 return this.when; 153 } 154 155 public boolean hasWhenElement() { 156 return this.when != null && !this.when.isEmpty(); 157 } 158 159 public boolean hasWhen() { 160 return this.when != null && !this.when.isEmpty(); 161 } 162 163 /** 164 * @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 165 */ 166 public Signature setWhenElement(InstantType value) { 167 this.when = value; 168 return this; 169 } 170 171 /** 172 * @return When the digital signature was signed. 173 */ 174 public Date getWhen() { 175 return this.when == null ? null : this.when.getValue(); 176 } 177 178 /** 179 * @param value When the digital signature was signed. 180 */ 181 public Signature setWhen(Date value) { 182 if (this.when == null) 183 this.when = new InstantType(); 184 this.when.setValue(value); 185 return this; 186 } 187 188 /** 189 * @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).) 190 */ 191 public Type getWho() { 192 return this.who; 193 } 194 195 /** 196 * @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).) 197 */ 198 public UriType getWhoUriType() throws FHIRException { 199 if (!(this.who instanceof UriType)) 200 throw new FHIRException("Type mismatch: the type UriType was expected, but "+this.who.getClass().getName()+" was encountered"); 201 return (UriType) this.who; 202 } 203 204 public boolean hasWhoUriType() { 205 return this.who instanceof UriType; 206 } 207 208 /** 209 * @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).) 210 */ 211 public Reference getWhoReference() throws FHIRException { 212 if (!(this.who instanceof Reference)) 213 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.who.getClass().getName()+" was encountered"); 214 return (Reference) this.who; 215 } 216 217 public boolean hasWhoReference() { 218 return this.who instanceof Reference; 219 } 220 221 public boolean hasWho() { 222 return this.who != null && !this.who.isEmpty(); 223 } 224 225 /** 226 * @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).) 227 */ 228 public Signature setWho(Type value) { 229 this.who = value; 230 return this; 231 } 232 233 /** 234 * @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 235 */ 236 public CodeType getContentTypeElement() { 237 if (this.contentType == null) 238 if (Configuration.errorOnAutoCreate()) 239 throw new Error("Attempt to auto-create Signature.contentType"); 240 else if (Configuration.doAutoCreate()) 241 this.contentType = new CodeType(); // bb 242 return this.contentType; 243 } 244 245 public boolean hasContentTypeElement() { 246 return this.contentType != null && !this.contentType.isEmpty(); 247 } 248 249 public boolean hasContentType() { 250 return this.contentType != null && !this.contentType.isEmpty(); 251 } 252 253 /** 254 * @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 255 */ 256 public Signature setContentTypeElement(CodeType value) { 257 this.contentType = value; 258 return this; 259 } 260 261 /** 262 * @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. 263 */ 264 public String getContentType() { 265 return this.contentType == null ? null : this.contentType.getValue(); 266 } 267 268 /** 269 * @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. 270 */ 271 public Signature setContentType(String value) { 272 if (Utilities.noString(value)) 273 this.contentType = null; 274 else { 275 if (this.contentType == null) 276 this.contentType = new CodeType(); 277 this.contentType.setValue(value); 278 } 279 return this; 280 } 281 282 /** 283 * @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 284 */ 285 public Base64BinaryType getBlobElement() { 286 if (this.blob == null) 287 if (Configuration.errorOnAutoCreate()) 288 throw new Error("Attempt to auto-create Signature.blob"); 289 else if (Configuration.doAutoCreate()) 290 this.blob = new Base64BinaryType(); // bb 291 return this.blob; 292 } 293 294 public boolean hasBlobElement() { 295 return this.blob != null && !this.blob.isEmpty(); 296 } 297 298 public boolean hasBlob() { 299 return this.blob != null && !this.blob.isEmpty(); 300 } 301 302 /** 303 * @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 304 */ 305 public Signature setBlobElement(Base64BinaryType value) { 306 this.blob = value; 307 return this; 308 } 309 310 /** 311 * @return The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 312 */ 313 public byte[] getBlob() { 314 return this.blob == null ? null : this.blob.getValue(); 315 } 316 317 /** 318 * @param value The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 319 */ 320 public Signature setBlob(byte[] value) { 321 if (value == null) 322 this.blob = null; 323 else { 324 if (this.blob == null) 325 this.blob = new Base64BinaryType(); 326 this.blob.setValue(value); 327 } 328 return this; 329 } 330 331 protected void listChildren(List<Property> childrenList) { 332 super.listChildren(childrenList); 333 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)); 334 childrenList.add(new Property("when", "instant", "When the digital signature was signed.", 0, java.lang.Integer.MAX_VALUE, when)); 335 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)); 336 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)); 337 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)); 338 } 339 340 @Override 341 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 342 switch (hash) { 343 case 3575610: /*type*/ return this.type == null ? new Base[0] : this.type.toArray(new Base[this.type.size()]); // Coding 344 case 3648314: /*when*/ return this.when == null ? new Base[0] : new Base[] {this.when}; // InstantType 345 case 117694: /*who*/ return this.who == null ? new Base[0] : new Base[] {this.who}; // Type 346 case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType 347 case 3026845: /*blob*/ return this.blob == null ? new Base[0] : new Base[] {this.blob}; // Base64BinaryType 348 default: return super.getProperty(hash, name, checkValid); 349 } 350 351 } 352 353 @Override 354 public void setProperty(int hash, String name, Base value) throws FHIRException { 355 switch (hash) { 356 case 3575610: // type 357 this.getType().add(castToCoding(value)); // Coding 358 break; 359 case 3648314: // when 360 this.when = castToInstant(value); // InstantType 361 break; 362 case 117694: // who 363 this.who = (Type) value; // Type 364 break; 365 case -389131437: // contentType 366 this.contentType = castToCode(value); // CodeType 367 break; 368 case 3026845: // blob 369 this.blob = castToBase64Binary(value); // Base64BinaryType 370 break; 371 default: super.setProperty(hash, name, value); 372 } 373 374 } 375 376 @Override 377 public void setProperty(String name, Base value) throws FHIRException { 378 if (name.equals("type")) 379 this.getType().add(castToCoding(value)); 380 else if (name.equals("when")) 381 this.when = castToInstant(value); // InstantType 382 else if (name.equals("who[x]")) 383 this.who = (Type) value; // Type 384 else if (name.equals("contentType")) 385 this.contentType = castToCode(value); // CodeType 386 else if (name.equals("blob")) 387 this.blob = castToBase64Binary(value); // Base64BinaryType 388 else 389 super.setProperty(name, value); 390 } 391 392 @Override 393 public Base makeProperty(int hash, String name) throws FHIRException { 394 switch (hash) { 395 case 3575610: return addType(); // Coding 396 case 3648314: throw new FHIRException("Cannot make property when as it is not a complex type"); // InstantType 397 case -788654078: return getWho(); // Type 398 case -389131437: throw new FHIRException("Cannot make property contentType as it is not a complex type"); // CodeType 399 case 3026845: throw new FHIRException("Cannot make property blob as it is not a complex type"); // Base64BinaryType 400 default: return super.makeProperty(hash, name); 401 } 402 403 } 404 405 @Override 406 public Base addChild(String name) throws FHIRException { 407 if (name.equals("type")) { 408 return addType(); 409 } 410 else if (name.equals("when")) { 411 throw new FHIRException("Cannot call addChild on a primitive type Signature.when"); 412 } 413 else if (name.equals("whoUri")) { 414 this.who = new UriType(); 415 return this.who; 416 } 417 else if (name.equals("whoReference")) { 418 this.who = new Reference(); 419 return this.who; 420 } 421 else if (name.equals("contentType")) { 422 throw new FHIRException("Cannot call addChild on a primitive type Signature.contentType"); 423 } 424 else if (name.equals("blob")) { 425 throw new FHIRException("Cannot call addChild on a primitive type Signature.blob"); 426 } 427 else 428 return super.addChild(name); 429 } 430 431 public String fhirType() { 432 return "Signature"; 433 434 } 435 436 public Signature copy() { 437 Signature dst = new Signature(); 438 copyValues(dst); 439 if (type != null) { 440 dst.type = new ArrayList<Coding>(); 441 for (Coding i : type) 442 dst.type.add(i.copy()); 443 }; 444 dst.when = when == null ? null : when.copy(); 445 dst.who = who == null ? null : who.copy(); 446 dst.contentType = contentType == null ? null : contentType.copy(); 447 dst.blob = blob == null ? null : blob.copy(); 448 return dst; 449 } 450 451 protected Signature typedCopy() { 452 return copy(); 453 } 454 455 @Override 456 public boolean equalsDeep(Base other) { 457 if (!super.equalsDeep(other)) 458 return false; 459 if (!(other instanceof Signature)) 460 return false; 461 Signature o = (Signature) other; 462 return compareDeep(type, o.type, true) && compareDeep(when, o.when, true) && compareDeep(who, o.who, true) 463 && compareDeep(contentType, o.contentType, true) && compareDeep(blob, o.blob, true); 464 } 465 466 @Override 467 public boolean equalsShallow(Base other) { 468 if (!super.equalsShallow(other)) 469 return false; 470 if (!(other instanceof Signature)) 471 return false; 472 Signature o = (Signature) other; 473 return compareValues(when, o.when, true) && compareValues(contentType, o.contentType, true) && compareValues(blob, o.blob, true) 474 ; 475 } 476 477 public boolean isEmpty() { 478 return super.isEmpty() && (type == null || type.isEmpty()) && (when == null || when.isEmpty()) 479 && (who == null || who.isEmpty()) && (contentType == null || contentType.isEmpty()) && (blob == null || blob.isEmpty()) 480 ; 481 } 482 483 484} 485