001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1 033 034import java.util.*; 035 036import org.hl7.fhir.utilities.Utilities; 037import org.hl7.fhir.dstu3.model.Enumerations.*; 038import ca.uhn.fhir.model.api.annotation.Child; 039import ca.uhn.fhir.model.api.annotation.ChildOrder; 040import ca.uhn.fhir.model.api.annotation.Description; 041import ca.uhn.fhir.model.api.annotation.DatatypeDef; 042import ca.uhn.fhir.model.api.annotation.Block; 043import org.hl7.fhir.instance.model.api.*; 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 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/signature-type") 057 protected List<Coding> type; 058 059 /** 060 * When the digital signature was signed. 061 */ 062 @Child(name = "when", type = {InstantType.class}, order=1, min=1, max=1, modifier=false, summary=true) 063 @Description(shortDefinition="When the signature was created", formalDefinition="When the digital signature was signed." ) 064 protected InstantType when; 065 066 /** 067 * A reference to an application-usable description of the identity that signed (e.g. the signature used their private key). 068 */ 069 @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) 070 @Description(shortDefinition="Who signed", formalDefinition="A reference to an application-usable description of the identity that signed (e.g. the signature used their private key)." ) 071 protected Type who; 072 073 /** 074 * A reference to an application-usable description of the identity that is represented by the signature. 075 */ 076 @Child(name = "onBehalfOf", type = {UriType.class, Practitioner.class, RelatedPerson.class, Patient.class, Device.class, Organization.class}, order=3, min=0, max=1, modifier=false, summary=true) 077 @Description(shortDefinition="The party represented", formalDefinition="A reference to an application-usable description of the identity that is represented by the signature." ) 078 protected Type onBehalfOf; 079 080 /** 081 * 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. 082 */ 083 @Child(name = "contentType", type = {CodeType.class}, order=4, min=0, max=1, modifier=false, summary=true) 084 @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." ) 085 protected CodeType contentType; 086 087 /** 088 * The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 089 */ 090 @Child(name = "blob", type = {Base64BinaryType.class}, order=5, min=0, max=1, modifier=false, summary=false) 091 @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." ) 092 protected Base64BinaryType blob; 093 094 private static final long serialVersionUID = 1133697310L; 095 096 /** 097 * Constructor 098 */ 099 public Signature() { 100 super(); 101 } 102 103 /** 104 * Constructor 105 */ 106 public Signature(InstantType when, Type who) { 107 super(); 108 this.when = when; 109 this.who = who; 110 } 111 112 /** 113 * @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.) 114 */ 115 public List<Coding> getType() { 116 if (this.type == null) 117 this.type = new ArrayList<Coding>(); 118 return this.type; 119 } 120 121 /** 122 * @return Returns a reference to <code>this</code> for easy method chaining 123 */ 124 public Signature setType(List<Coding> theType) { 125 this.type = theType; 126 return this; 127 } 128 129 public boolean hasType() { 130 if (this.type == null) 131 return false; 132 for (Coding item : this.type) 133 if (!item.isEmpty()) 134 return true; 135 return false; 136 } 137 138 public Coding addType() { //3 139 Coding t = new Coding(); 140 if (this.type == null) 141 this.type = new ArrayList<Coding>(); 142 this.type.add(t); 143 return t; 144 } 145 146 public Signature addType(Coding t) { //3 147 if (t == null) 148 return this; 149 if (this.type == null) 150 this.type = new ArrayList<Coding>(); 151 this.type.add(t); 152 return this; 153 } 154 155 /** 156 * @return The first repetition of repeating field {@link #type}, creating it if it does not already exist 157 */ 158 public Coding getTypeFirstRep() { 159 if (getType().isEmpty()) { 160 addType(); 161 } 162 return getType().get(0); 163 } 164 165 /** 166 * @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 167 */ 168 public InstantType getWhenElement() { 169 if (this.when == null) 170 if (Configuration.errorOnAutoCreate()) 171 throw new Error("Attempt to auto-create Signature.when"); 172 else if (Configuration.doAutoCreate()) 173 this.when = new InstantType(); // bb 174 return this.when; 175 } 176 177 public boolean hasWhenElement() { 178 return this.when != null && !this.when.isEmpty(); 179 } 180 181 public boolean hasWhen() { 182 return this.when != null && !this.when.isEmpty(); 183 } 184 185 /** 186 * @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 187 */ 188 public Signature setWhenElement(InstantType value) { 189 this.when = value; 190 return this; 191 } 192 193 /** 194 * @return When the digital signature was signed. 195 */ 196 public Date getWhen() { 197 return this.when == null ? null : this.when.getValue(); 198 } 199 200 /** 201 * @param value When the digital signature was signed. 202 */ 203 public Signature setWhen(Date value) { 204 if (this.when == null) 205 this.when = new InstantType(); 206 this.when.setValue(value); 207 return this; 208 } 209 210 /** 211 * @return {@link #who} (A reference to an application-usable description of the identity that signed (e.g. the signature used their private key).) 212 */ 213 public Type getWho() { 214 return this.who; 215 } 216 217 /** 218 * @return {@link #who} (A reference to an application-usable description of the identity that signed (e.g. the signature used their private key).) 219 */ 220 public UriType getWhoUriType() throws FHIRException { 221 if (!(this.who instanceof UriType)) 222 throw new FHIRException("Type mismatch: the type UriType was expected, but "+this.who.getClass().getName()+" was encountered"); 223 return (UriType) this.who; 224 } 225 226 public boolean hasWhoUriType() { 227 return this.who instanceof UriType; 228 } 229 230 /** 231 * @return {@link #who} (A reference to an application-usable description of the identity that signed (e.g. the signature used their private key).) 232 */ 233 public Reference getWhoReference() throws FHIRException { 234 if (!(this.who instanceof Reference)) 235 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.who.getClass().getName()+" was encountered"); 236 return (Reference) this.who; 237 } 238 239 public boolean hasWhoReference() { 240 return this.who instanceof Reference; 241 } 242 243 public boolean hasWho() { 244 return this.who != null && !this.who.isEmpty(); 245 } 246 247 /** 248 * @param value {@link #who} (A reference to an application-usable description of the identity that signed (e.g. the signature used their private key).) 249 */ 250 public Signature setWho(Type value) { 251 this.who = value; 252 return this; 253 } 254 255 /** 256 * @return {@link #onBehalfOf} (A reference to an application-usable description of the identity that is represented by the signature.) 257 */ 258 public Type getOnBehalfOf() { 259 return this.onBehalfOf; 260 } 261 262 /** 263 * @return {@link #onBehalfOf} (A reference to an application-usable description of the identity that is represented by the signature.) 264 */ 265 public UriType getOnBehalfOfUriType() throws FHIRException { 266 if (!(this.onBehalfOf instanceof UriType)) 267 throw new FHIRException("Type mismatch: the type UriType was expected, but "+this.onBehalfOf.getClass().getName()+" was encountered"); 268 return (UriType) this.onBehalfOf; 269 } 270 271 public boolean hasOnBehalfOfUriType() { 272 return this.onBehalfOf instanceof UriType; 273 } 274 275 /** 276 * @return {@link #onBehalfOf} (A reference to an application-usable description of the identity that is represented by the signature.) 277 */ 278 public Reference getOnBehalfOfReference() throws FHIRException { 279 if (!(this.onBehalfOf instanceof Reference)) 280 throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.onBehalfOf.getClass().getName()+" was encountered"); 281 return (Reference) this.onBehalfOf; 282 } 283 284 public boolean hasOnBehalfOfReference() { 285 return this.onBehalfOf instanceof Reference; 286 } 287 288 public boolean hasOnBehalfOf() { 289 return this.onBehalfOf != null && !this.onBehalfOf.isEmpty(); 290 } 291 292 /** 293 * @param value {@link #onBehalfOf} (A reference to an application-usable description of the identity that is represented by the signature.) 294 */ 295 public Signature setOnBehalfOf(Type value) { 296 this.onBehalfOf = value; 297 return this; 298 } 299 300 /** 301 * @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 302 */ 303 public CodeType getContentTypeElement() { 304 if (this.contentType == null) 305 if (Configuration.errorOnAutoCreate()) 306 throw new Error("Attempt to auto-create Signature.contentType"); 307 else if (Configuration.doAutoCreate()) 308 this.contentType = new CodeType(); // bb 309 return this.contentType; 310 } 311 312 public boolean hasContentTypeElement() { 313 return this.contentType != null && !this.contentType.isEmpty(); 314 } 315 316 public boolean hasContentType() { 317 return this.contentType != null && !this.contentType.isEmpty(); 318 } 319 320 /** 321 * @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 322 */ 323 public Signature setContentTypeElement(CodeType value) { 324 this.contentType = value; 325 return this; 326 } 327 328 /** 329 * @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. 330 */ 331 public String getContentType() { 332 return this.contentType == null ? null : this.contentType.getValue(); 333 } 334 335 /** 336 * @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. 337 */ 338 public Signature setContentType(String value) { 339 if (Utilities.noString(value)) 340 this.contentType = null; 341 else { 342 if (this.contentType == null) 343 this.contentType = new CodeType(); 344 this.contentType.setValue(value); 345 } 346 return this; 347 } 348 349 /** 350 * @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 351 */ 352 public Base64BinaryType getBlobElement() { 353 if (this.blob == null) 354 if (Configuration.errorOnAutoCreate()) 355 throw new Error("Attempt to auto-create Signature.blob"); 356 else if (Configuration.doAutoCreate()) 357 this.blob = new Base64BinaryType(); // bb 358 return this.blob; 359 } 360 361 public boolean hasBlobElement() { 362 return this.blob != null && !this.blob.isEmpty(); 363 } 364 365 public boolean hasBlob() { 366 return this.blob != null && !this.blob.isEmpty(); 367 } 368 369 /** 370 * @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 371 */ 372 public Signature setBlobElement(Base64BinaryType value) { 373 this.blob = value; 374 return this; 375 } 376 377 /** 378 * @return The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 379 */ 380 public byte[] getBlob() { 381 return this.blob == null ? null : this.blob.getValue(); 382 } 383 384 /** 385 * @param value The base64 encoding of the Signature content. When signature is not recorded electronically this element would be empty. 386 */ 387 public Signature setBlob(byte[] value) { 388 if (value == null) 389 this.blob = null; 390 else { 391 if (this.blob == null) 392 this.blob = new Base64BinaryType(); 393 this.blob.setValue(value); 394 } 395 return this; 396 } 397 398 protected void listChildren(List<Property> childrenList) { 399 super.listChildren(childrenList); 400 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)); 401 childrenList.add(new Property("when", "instant", "When the digital signature was signed.", 0, java.lang.Integer.MAX_VALUE, when)); 402 childrenList.add(new Property("who[x]", "uri|Reference(Practitioner|RelatedPerson|Patient|Device|Organization)", "A reference to an application-usable description of the identity that signed (e.g. the signature used their private key).", 0, java.lang.Integer.MAX_VALUE, who)); 403 childrenList.add(new Property("onBehalfOf[x]", "uri|Reference(Practitioner|RelatedPerson|Patient|Device|Organization)", "A reference to an application-usable description of the identity that is represented by the signature.", 0, java.lang.Integer.MAX_VALUE, onBehalfOf)); 404 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)); 405 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)); 406 } 407 408 @Override 409 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 410 switch (hash) { 411 case 3575610: /*type*/ return this.type == null ? new Base[0] : this.type.toArray(new Base[this.type.size()]); // Coding 412 case 3648314: /*when*/ return this.when == null ? new Base[0] : new Base[] {this.when}; // InstantType 413 case 117694: /*who*/ return this.who == null ? new Base[0] : new Base[] {this.who}; // Type 414 case -14402964: /*onBehalfOf*/ return this.onBehalfOf == null ? new Base[0] : new Base[] {this.onBehalfOf}; // Type 415 case -389131437: /*contentType*/ return this.contentType == null ? new Base[0] : new Base[] {this.contentType}; // CodeType 416 case 3026845: /*blob*/ return this.blob == null ? new Base[0] : new Base[] {this.blob}; // Base64BinaryType 417 default: return super.getProperty(hash, name, checkValid); 418 } 419 420 } 421 422 @Override 423 public Base setProperty(int hash, String name, Base value) throws FHIRException { 424 switch (hash) { 425 case 3575610: // type 426 this.getType().add(castToCoding(value)); // Coding 427 return value; 428 case 3648314: // when 429 this.when = castToInstant(value); // InstantType 430 return value; 431 case 117694: // who 432 this.who = castToType(value); // Type 433 return value; 434 case -14402964: // onBehalfOf 435 this.onBehalfOf = castToType(value); // Type 436 return value; 437 case -389131437: // contentType 438 this.contentType = castToCode(value); // CodeType 439 return value; 440 case 3026845: // blob 441 this.blob = castToBase64Binary(value); // Base64BinaryType 442 return value; 443 default: return super.setProperty(hash, name, value); 444 } 445 446 } 447 448 @Override 449 public Base setProperty(String name, Base value) throws FHIRException { 450 if (name.equals("type")) { 451 this.getType().add(castToCoding(value)); 452 } else if (name.equals("when")) { 453 this.when = castToInstant(value); // InstantType 454 } else if (name.equals("who[x]")) { 455 this.who = castToType(value); // Type 456 } else if (name.equals("onBehalfOf[x]")) { 457 this.onBehalfOf = castToType(value); // Type 458 } else if (name.equals("contentType")) { 459 this.contentType = castToCode(value); // CodeType 460 } else if (name.equals("blob")) { 461 this.blob = castToBase64Binary(value); // Base64BinaryType 462 } else 463 return super.setProperty(name, value); 464 return value; 465 } 466 467 @Override 468 public Base makeProperty(int hash, String name) throws FHIRException { 469 switch (hash) { 470 case 3575610: return addType(); 471 case 3648314: return getWhenElement(); 472 case -788654078: return getWho(); 473 case 117694: return getWho(); 474 case 418120340: return getOnBehalfOf(); 475 case -14402964: return getOnBehalfOf(); 476 case -389131437: return getContentTypeElement(); 477 case 3026845: return getBlobElement(); 478 default: return super.makeProperty(hash, name); 479 } 480 481 } 482 483 @Override 484 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 485 switch (hash) { 486 case 3575610: /*type*/ return new String[] {"Coding"}; 487 case 3648314: /*when*/ return new String[] {"instant"}; 488 case 117694: /*who*/ return new String[] {"uri", "Reference"}; 489 case -14402964: /*onBehalfOf*/ return new String[] {"uri", "Reference"}; 490 case -389131437: /*contentType*/ return new String[] {"code"}; 491 case 3026845: /*blob*/ return new String[] {"base64Binary"}; 492 default: return super.getTypesForProperty(hash, name); 493 } 494 495 } 496 497 @Override 498 public Base addChild(String name) throws FHIRException { 499 if (name.equals("type")) { 500 return addType(); 501 } 502 else if (name.equals("when")) { 503 throw new FHIRException("Cannot call addChild on a primitive type Signature.when"); 504 } 505 else if (name.equals("whoUri")) { 506 this.who = new UriType(); 507 return this.who; 508 } 509 else if (name.equals("whoReference")) { 510 this.who = new Reference(); 511 return this.who; 512 } 513 else if (name.equals("onBehalfOfUri")) { 514 this.onBehalfOf = new UriType(); 515 return this.onBehalfOf; 516 } 517 else if (name.equals("onBehalfOfReference")) { 518 this.onBehalfOf = new Reference(); 519 return this.onBehalfOf; 520 } 521 else if (name.equals("contentType")) { 522 throw new FHIRException("Cannot call addChild on a primitive type Signature.contentType"); 523 } 524 else if (name.equals("blob")) { 525 throw new FHIRException("Cannot call addChild on a primitive type Signature.blob"); 526 } 527 else 528 return super.addChild(name); 529 } 530 531 public String fhirType() { 532 return "Signature"; 533 534 } 535 536 public Signature copy() { 537 Signature dst = new Signature(); 538 copyValues(dst); 539 if (type != null) { 540 dst.type = new ArrayList<Coding>(); 541 for (Coding i : type) 542 dst.type.add(i.copy()); 543 }; 544 dst.when = when == null ? null : when.copy(); 545 dst.who = who == null ? null : who.copy(); 546 dst.onBehalfOf = onBehalfOf == null ? null : onBehalfOf.copy(); 547 dst.contentType = contentType == null ? null : contentType.copy(); 548 dst.blob = blob == null ? null : blob.copy(); 549 return dst; 550 } 551 552 protected Signature typedCopy() { 553 return copy(); 554 } 555 556 @Override 557 public boolean equalsDeep(Base other) { 558 if (!super.equalsDeep(other)) 559 return false; 560 if (!(other instanceof Signature)) 561 return false; 562 Signature o = (Signature) other; 563 return compareDeep(type, o.type, true) && compareDeep(when, o.when, true) && compareDeep(who, o.who, true) 564 && compareDeep(onBehalfOf, o.onBehalfOf, true) && compareDeep(contentType, o.contentType, true) 565 && compareDeep(blob, o.blob, true); 566 } 567 568 @Override 569 public boolean equalsShallow(Base other) { 570 if (!super.equalsShallow(other)) 571 return false; 572 if (!(other instanceof Signature)) 573 return false; 574 Signature o = (Signature) other; 575 return compareValues(when, o.when, true) && compareValues(contentType, o.contentType, true) && compareValues(blob, o.blob, true) 576 ; 577 } 578 579 public boolean isEmpty() { 580 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, when, who, onBehalfOf 581 , contentType, blob); 582 } 583 584 585} 586