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