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