001package org.hl7.fhir.r4.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 Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1 033import java.util.ArrayList; 034import java.util.List; 035 036import org.hl7.fhir.exceptions.FHIRException; 037import org.hl7.fhir.instance.model.api.ICompositeType; 038 039import ca.uhn.fhir.model.api.annotation.Child; 040import ca.uhn.fhir.model.api.annotation.DatatypeDef; 041import ca.uhn.fhir.model.api.annotation.Description; 042 043/** 044 * A contributor to the content of a knowledge asset, including authors, 045 * editors, reviewers, and endorsers. 046 */ 047@DatatypeDef(name = "Contributor") 048public class Contributor extends Type implements ICompositeType { 049 050 public enum ContributorType { 051 /** 052 * An author of the content of the module. 053 */ 054 AUTHOR, 055 /** 056 * An editor of the content of the module. 057 */ 058 EDITOR, 059 /** 060 * A reviewer of the content of the module. 061 */ 062 REVIEWER, 063 /** 064 * An endorser of the content of the module. 065 */ 066 ENDORSER, 067 /** 068 * added to help the parsers with the generic types 069 */ 070 NULL; 071 072 public static ContributorType fromCode(String codeString) throws FHIRException { 073 if (codeString == null || "".equals(codeString)) 074 return null; 075 if ("author".equals(codeString)) 076 return AUTHOR; 077 if ("editor".equals(codeString)) 078 return EDITOR; 079 if ("reviewer".equals(codeString)) 080 return REVIEWER; 081 if ("endorser".equals(codeString)) 082 return ENDORSER; 083 if (Configuration.isAcceptInvalidEnums()) 084 return null; 085 else 086 throw new FHIRException("Unknown ContributorType code '" + codeString + "'"); 087 } 088 089 public String toCode() { 090 switch (this) { 091 case AUTHOR: 092 return "author"; 093 case EDITOR: 094 return "editor"; 095 case REVIEWER: 096 return "reviewer"; 097 case ENDORSER: 098 return "endorser"; 099 case NULL: 100 return null; 101 default: 102 return "?"; 103 } 104 } 105 106 public String getSystem() { 107 switch (this) { 108 case AUTHOR: 109 return "http://hl7.org/fhir/contributor-type"; 110 case EDITOR: 111 return "http://hl7.org/fhir/contributor-type"; 112 case REVIEWER: 113 return "http://hl7.org/fhir/contributor-type"; 114 case ENDORSER: 115 return "http://hl7.org/fhir/contributor-type"; 116 case NULL: 117 return null; 118 default: 119 return "?"; 120 } 121 } 122 123 public String getDefinition() { 124 switch (this) { 125 case AUTHOR: 126 return "An author of the content of the module."; 127 case EDITOR: 128 return "An editor of the content of the module."; 129 case REVIEWER: 130 return "A reviewer of the content of the module."; 131 case ENDORSER: 132 return "An endorser of the content of the module."; 133 case NULL: 134 return null; 135 default: 136 return "?"; 137 } 138 } 139 140 public String getDisplay() { 141 switch (this) { 142 case AUTHOR: 143 return "Author"; 144 case EDITOR: 145 return "Editor"; 146 case REVIEWER: 147 return "Reviewer"; 148 case ENDORSER: 149 return "Endorser"; 150 case NULL: 151 return null; 152 default: 153 return "?"; 154 } 155 } 156 } 157 158 public static class ContributorTypeEnumFactory implements EnumFactory<ContributorType> { 159 public ContributorType fromCode(String codeString) throws IllegalArgumentException { 160 if (codeString == null || "".equals(codeString)) 161 if (codeString == null || "".equals(codeString)) 162 return null; 163 if ("author".equals(codeString)) 164 return ContributorType.AUTHOR; 165 if ("editor".equals(codeString)) 166 return ContributorType.EDITOR; 167 if ("reviewer".equals(codeString)) 168 return ContributorType.REVIEWER; 169 if ("endorser".equals(codeString)) 170 return ContributorType.ENDORSER; 171 throw new IllegalArgumentException("Unknown ContributorType code '" + codeString + "'"); 172 } 173 174 public Enumeration<ContributorType> fromType(PrimitiveType<?> code) throws FHIRException { 175 if (code == null) 176 return null; 177 if (code.isEmpty()) 178 return new Enumeration<ContributorType>(this, ContributorType.NULL, code); 179 String codeString = code.asStringValue(); 180 if (codeString == null || "".equals(codeString)) 181 return new Enumeration<ContributorType>(this, ContributorType.NULL, code); 182 if ("author".equals(codeString)) 183 return new Enumeration<ContributorType>(this, ContributorType.AUTHOR, code); 184 if ("editor".equals(codeString)) 185 return new Enumeration<ContributorType>(this, ContributorType.EDITOR, code); 186 if ("reviewer".equals(codeString)) 187 return new Enumeration<ContributorType>(this, ContributorType.REVIEWER, code); 188 if ("endorser".equals(codeString)) 189 return new Enumeration<ContributorType>(this, ContributorType.ENDORSER, code); 190 throw new FHIRException("Unknown ContributorType code '" + codeString + "'"); 191 } 192 193 public String toCode(ContributorType code) { 194 if (code == ContributorType.AUTHOR) 195 return "author"; 196 if (code == ContributorType.EDITOR) 197 return "editor"; 198 if (code == ContributorType.REVIEWER) 199 return "reviewer"; 200 if (code == ContributorType.ENDORSER) 201 return "endorser"; 202 return "?"; 203 } 204 205 public String toSystem(ContributorType code) { 206 return code.getSystem(); 207 } 208 } 209 210 /** 211 * The type of contributor. 212 */ 213 @Child(name = "type", type = { CodeType.class }, order = 0, min = 1, max = 1, modifier = false, summary = true) 214 @Description(shortDefinition = "author | editor | reviewer | endorser", formalDefinition = "The type of contributor.") 215 @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/contributor-type") 216 protected Enumeration<ContributorType> type; 217 218 /** 219 * The name of the individual or organization responsible for the contribution. 220 */ 221 @Child(name = "name", type = { StringType.class }, order = 1, min = 1, max = 1, modifier = false, summary = true) 222 @Description(shortDefinition = "Who contributed the content", formalDefinition = "The name of the individual or organization responsible for the contribution.") 223 protected StringType name; 224 225 /** 226 * Contact details to assist a user in finding and communicating with the 227 * contributor. 228 */ 229 @Child(name = "contact", type = { 230 ContactDetail.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 231 @Description(shortDefinition = "Contact details of the contributor", formalDefinition = "Contact details to assist a user in finding and communicating with the contributor.") 232 protected List<ContactDetail> contact; 233 234 private static final long serialVersionUID = -609887113L; 235 236 /** 237 * Constructor 238 */ 239 public Contributor() { 240 super(); 241 } 242 243 /** 244 * Constructor 245 */ 246 public Contributor(Enumeration<ContributorType> type, StringType name) { 247 super(); 248 this.type = type; 249 this.name = name; 250 } 251 252 /** 253 * @return {@link #type} (The type of contributor.). This is the underlying 254 * object with id, value and extensions. The accessor "getType" gives 255 * direct access to the value 256 */ 257 public Enumeration<ContributorType> getTypeElement() { 258 if (this.type == null) 259 if (Configuration.errorOnAutoCreate()) 260 throw new Error("Attempt to auto-create Contributor.type"); 261 else if (Configuration.doAutoCreate()) 262 this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); // bb 263 return this.type; 264 } 265 266 public boolean hasTypeElement() { 267 return this.type != null && !this.type.isEmpty(); 268 } 269 270 public boolean hasType() { 271 return this.type != null && !this.type.isEmpty(); 272 } 273 274 /** 275 * @param value {@link #type} (The type of contributor.). This is the underlying 276 * object with id, value and extensions. The accessor "getType" 277 * gives direct access to the value 278 */ 279 public Contributor setTypeElement(Enumeration<ContributorType> value) { 280 this.type = value; 281 return this; 282 } 283 284 /** 285 * @return The type of contributor. 286 */ 287 public ContributorType getType() { 288 return this.type == null ? null : this.type.getValue(); 289 } 290 291 /** 292 * @param value The type of contributor. 293 */ 294 public Contributor setType(ContributorType value) { 295 if (this.type == null) 296 this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); 297 this.type.setValue(value); 298 return this; 299 } 300 301 /** 302 * @return {@link #name} (The name of the individual or organization responsible 303 * for the contribution.). This is the underlying object with id, value 304 * and extensions. The accessor "getName" gives direct access to the 305 * value 306 */ 307 public StringType getNameElement() { 308 if (this.name == null) 309 if (Configuration.errorOnAutoCreate()) 310 throw new Error("Attempt to auto-create Contributor.name"); 311 else if (Configuration.doAutoCreate()) 312 this.name = new StringType(); // bb 313 return this.name; 314 } 315 316 public boolean hasNameElement() { 317 return this.name != null && !this.name.isEmpty(); 318 } 319 320 public boolean hasName() { 321 return this.name != null && !this.name.isEmpty(); 322 } 323 324 /** 325 * @param value {@link #name} (The name of the individual or organization 326 * responsible for the contribution.). This is the underlying 327 * object with id, value and extensions. The accessor "getName" 328 * gives direct access to the value 329 */ 330 public Contributor setNameElement(StringType value) { 331 this.name = value; 332 return this; 333 } 334 335 /** 336 * @return The name of the individual or organization responsible for the 337 * contribution. 338 */ 339 public String getName() { 340 return this.name == null ? null : this.name.getValue(); 341 } 342 343 /** 344 * @param value The name of the individual or organization responsible for the 345 * contribution. 346 */ 347 public Contributor setName(String value) { 348 if (this.name == null) 349 this.name = new StringType(); 350 this.name.setValue(value); 351 return this; 352 } 353 354 /** 355 * @return {@link #contact} (Contact details to assist a user in finding and 356 * communicating with the contributor.) 357 */ 358 public List<ContactDetail> getContact() { 359 if (this.contact == null) 360 this.contact = new ArrayList<ContactDetail>(); 361 return this.contact; 362 } 363 364 /** 365 * @return Returns a reference to <code>this</code> for easy method chaining 366 */ 367 public Contributor setContact(List<ContactDetail> theContact) { 368 this.contact = theContact; 369 return this; 370 } 371 372 public boolean hasContact() { 373 if (this.contact == null) 374 return false; 375 for (ContactDetail item : this.contact) 376 if (!item.isEmpty()) 377 return true; 378 return false; 379 } 380 381 public ContactDetail addContact() { // 3 382 ContactDetail t = new ContactDetail(); 383 if (this.contact == null) 384 this.contact = new ArrayList<ContactDetail>(); 385 this.contact.add(t); 386 return t; 387 } 388 389 public Contributor addContact(ContactDetail t) { // 3 390 if (t == null) 391 return this; 392 if (this.contact == null) 393 this.contact = new ArrayList<ContactDetail>(); 394 this.contact.add(t); 395 return this; 396 } 397 398 /** 399 * @return The first repetition of repeating field {@link #contact}, creating it 400 * if it does not already exist 401 */ 402 public ContactDetail getContactFirstRep() { 403 if (getContact().isEmpty()) { 404 addContact(); 405 } 406 return getContact().get(0); 407 } 408 409 protected void listChildren(List<Property> children) { 410 super.listChildren(children); 411 children.add(new Property("type", "code", "The type of contributor.", 0, 1, type)); 412 children.add(new Property("name", "string", 413 "The name of the individual or organization responsible for the contribution.", 0, 1, name)); 414 children.add(new Property("contact", "ContactDetail", 415 "Contact details to assist a user in finding and communicating with the contributor.", 0, 416 java.lang.Integer.MAX_VALUE, contact)); 417 } 418 419 @Override 420 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 421 switch (_hash) { 422 case 3575610: 423 /* type */ return new Property("type", "code", "The type of contributor.", 0, 1, type); 424 case 3373707: 425 /* name */ return new Property("name", "string", 426 "The name of the individual or organization responsible for the contribution.", 0, 1, name); 427 case 951526432: 428 /* contact */ return new Property("contact", "ContactDetail", 429 "Contact details to assist a user in finding and communicating with the contributor.", 0, 430 java.lang.Integer.MAX_VALUE, contact); 431 default: 432 return super.getNamedProperty(_hash, _name, _checkValid); 433 } 434 435 } 436 437 @Override 438 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 439 switch (hash) { 440 case 3575610: 441 /* type */ return this.type == null ? new Base[0] : new Base[] { this.type }; // Enumeration<ContributorType> 442 case 3373707: 443 /* name */ return this.name == null ? new Base[0] : new Base[] { this.name }; // StringType 444 case 951526432: 445 /* contact */ return this.contact == null ? new Base[0] : this.contact.toArray(new Base[this.contact.size()]); // ContactDetail 446 default: 447 return super.getProperty(hash, name, checkValid); 448 } 449 450 } 451 452 @Override 453 public Base setProperty(int hash, String name, Base value) throws FHIRException { 454 switch (hash) { 455 case 3575610: // type 456 value = new ContributorTypeEnumFactory().fromType(castToCode(value)); 457 this.type = (Enumeration) value; // Enumeration<ContributorType> 458 return value; 459 case 3373707: // name 460 this.name = castToString(value); // StringType 461 return value; 462 case 951526432: // contact 463 this.getContact().add(castToContactDetail(value)); // ContactDetail 464 return value; 465 default: 466 return super.setProperty(hash, name, value); 467 } 468 469 } 470 471 @Override 472 public Base setProperty(String name, Base value) throws FHIRException { 473 if (name.equals("type")) { 474 value = new ContributorTypeEnumFactory().fromType(castToCode(value)); 475 this.type = (Enumeration) value; // Enumeration<ContributorType> 476 } else if (name.equals("name")) { 477 this.name = castToString(value); // StringType 478 } else if (name.equals("contact")) { 479 this.getContact().add(castToContactDetail(value)); 480 } else 481 return super.setProperty(name, value); 482 return value; 483 } 484 485 @Override 486 public Base makeProperty(int hash, String name) throws FHIRException { 487 switch (hash) { 488 case 3575610: 489 return getTypeElement(); 490 case 3373707: 491 return getNameElement(); 492 case 951526432: 493 return addContact(); 494 default: 495 return super.makeProperty(hash, name); 496 } 497 498 } 499 500 @Override 501 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 502 switch (hash) { 503 case 3575610: 504 /* type */ return new String[] { "code" }; 505 case 3373707: 506 /* name */ return new String[] { "string" }; 507 case 951526432: 508 /* contact */ return new String[] { "ContactDetail" }; 509 default: 510 return super.getTypesForProperty(hash, name); 511 } 512 513 } 514 515 @Override 516 public Base addChild(String name) throws FHIRException { 517 if (name.equals("type")) { 518 throw new FHIRException("Cannot call addChild on a singleton property Contributor.type"); 519 } else if (name.equals("name")) { 520 throw new FHIRException("Cannot call addChild on a singleton property Contributor.name"); 521 } else if (name.equals("contact")) { 522 return addContact(); 523 } else 524 return super.addChild(name); 525 } 526 527 public String fhirType() { 528 return "Contributor"; 529 530 } 531 532 public Contributor copy() { 533 Contributor dst = new Contributor(); 534 copyValues(dst); 535 return dst; 536 } 537 538 public void copyValues(Contributor dst) { 539 super.copyValues(dst); 540 dst.type = type == null ? null : type.copy(); 541 dst.name = name == null ? null : name.copy(); 542 if (contact != null) { 543 dst.contact = new ArrayList<ContactDetail>(); 544 for (ContactDetail i : contact) 545 dst.contact.add(i.copy()); 546 } 547 ; 548 } 549 550 protected Contributor typedCopy() { 551 return copy(); 552 } 553 554 @Override 555 public boolean equalsDeep(Base other_) { 556 if (!super.equalsDeep(other_)) 557 return false; 558 if (!(other_ instanceof Contributor)) 559 return false; 560 Contributor o = (Contributor) other_; 561 return compareDeep(type, o.type, true) && compareDeep(name, o.name, true) && compareDeep(contact, o.contact, true); 562 } 563 564 @Override 565 public boolean equalsShallow(Base other_) { 566 if (!super.equalsShallow(other_)) 567 return false; 568 if (!(other_ instanceof Contributor)) 569 return false; 570 Contributor o = (Contributor) other_; 571 return compareValues(type, o.type, true) && compareValues(name, o.name, true); 572 } 573 574 public boolean isEmpty() { 575 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, name, contact); 576 } 577 578}