001package org.hl7.fhir.r4.model; 002 003 004 005/* 006 Copyright (c) 2011+, HL7, Inc. 007 All rights reserved. 008 009 Redistribution and use in source and binary forms, with or without modification, 010 are permitted provided that the following conditions are met: 011 012 * Redistributions of source code must retain the above copyright notice, this 013 list of conditions and the following disclaimer. 014 * Redistributions in binary form must reproduce the above copyright notice, 015 this list of conditions and the following disclaimer in the documentation 016 and/or other materials provided with the distribution. 017 * Neither the name of HL7 nor the names of its contributors may be used to 018 endorse or promote products derived from this software without specific 019 prior written permission. 020 021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 024 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 026 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 027 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 030 POSSIBILITY OF SUCH DAMAGE. 031 032*/ 033 034 035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1 036 037import java.util.*; 038 039import org.hl7.fhir.utilities.Utilities; 040import ca.uhn.fhir.model.api.annotation.Child; 041import ca.uhn.fhir.model.api.annotation.ChildOrder; 042import ca.uhn.fhir.model.api.annotation.Description; 043import ca.uhn.fhir.model.api.annotation.DatatypeDef; 044import ca.uhn.fhir.model.api.annotation.Block; 045import org.hl7.fhir.instance.model.api.*; 046import org.hl7.fhir.exceptions.FHIRException; 047/** 048 * A contributor to the content of a knowledge asset, including authors, editors, reviewers, and endorsers. 049 */ 050@DatatypeDef(name="Contributor") 051public class Contributor extends Type implements ICompositeType { 052 053 public enum ContributorType { 054 /** 055 * An author of the content of the module. 056 */ 057 AUTHOR, 058 /** 059 * An editor of the content of the module. 060 */ 061 EDITOR, 062 /** 063 * A reviewer of the content of the module. 064 */ 065 REVIEWER, 066 /** 067 * An endorser of the content of the module. 068 */ 069 ENDORSER, 070 /** 071 * added to help the parsers with the generic types 072 */ 073 NULL; 074 public static ContributorType fromCode(String codeString) throws FHIRException { 075 if (codeString == null || "".equals(codeString)) 076 return null; 077 if ("author".equals(codeString)) 078 return AUTHOR; 079 if ("editor".equals(codeString)) 080 return EDITOR; 081 if ("reviewer".equals(codeString)) 082 return REVIEWER; 083 if ("endorser".equals(codeString)) 084 return ENDORSER; 085 if (Configuration.isAcceptInvalidEnums()) 086 return null; 087 else 088 throw new FHIRException("Unknown ContributorType code '"+codeString+"'"); 089 } 090 public String toCode() { 091 switch (this) { 092 case AUTHOR: return "author"; 093 case EDITOR: return "editor"; 094 case REVIEWER: return "reviewer"; 095 case ENDORSER: return "endorser"; 096 default: return "?"; 097 } 098 } 099 public String getSystem() { 100 switch (this) { 101 case AUTHOR: return "http://hl7.org/fhir/contributor-type"; 102 case EDITOR: return "http://hl7.org/fhir/contributor-type"; 103 case REVIEWER: return "http://hl7.org/fhir/contributor-type"; 104 case ENDORSER: return "http://hl7.org/fhir/contributor-type"; 105 default: return "?"; 106 } 107 } 108 public String getDefinition() { 109 switch (this) { 110 case AUTHOR: return "An author of the content of the module."; 111 case EDITOR: return "An editor of the content of the module."; 112 case REVIEWER: return "A reviewer of the content of the module."; 113 case ENDORSER: return "An endorser of the content of the module."; 114 default: return "?"; 115 } 116 } 117 public String getDisplay() { 118 switch (this) { 119 case AUTHOR: return "Author"; 120 case EDITOR: return "Editor"; 121 case REVIEWER: return "Reviewer"; 122 case ENDORSER: return "Endorser"; 123 default: return "?"; 124 } 125 } 126 } 127 128 public static class ContributorTypeEnumFactory implements EnumFactory<ContributorType> { 129 public ContributorType fromCode(String codeString) throws IllegalArgumentException { 130 if (codeString == null || "".equals(codeString)) 131 if (codeString == null || "".equals(codeString)) 132 return null; 133 if ("author".equals(codeString)) 134 return ContributorType.AUTHOR; 135 if ("editor".equals(codeString)) 136 return ContributorType.EDITOR; 137 if ("reviewer".equals(codeString)) 138 return ContributorType.REVIEWER; 139 if ("endorser".equals(codeString)) 140 return ContributorType.ENDORSER; 141 throw new IllegalArgumentException("Unknown ContributorType code '"+codeString+"'"); 142 } 143 public Enumeration<ContributorType> fromType(Base code) throws FHIRException { 144 if (code == null) 145 return null; 146 if (code.isEmpty()) 147 return new Enumeration<ContributorType>(this); 148 String codeString = ((PrimitiveType) code).asStringValue(); 149 if (codeString == null || "".equals(codeString)) 150 return null; 151 if ("author".equals(codeString)) 152 return new Enumeration<ContributorType>(this, ContributorType.AUTHOR); 153 if ("editor".equals(codeString)) 154 return new Enumeration<ContributorType>(this, ContributorType.EDITOR); 155 if ("reviewer".equals(codeString)) 156 return new Enumeration<ContributorType>(this, ContributorType.REVIEWER); 157 if ("endorser".equals(codeString)) 158 return new Enumeration<ContributorType>(this, ContributorType.ENDORSER); 159 throw new FHIRException("Unknown ContributorType code '"+codeString+"'"); 160 } 161 public String toCode(ContributorType code) { 162 if (code == ContributorType.AUTHOR) 163 return "author"; 164 if (code == ContributorType.EDITOR) 165 return "editor"; 166 if (code == ContributorType.REVIEWER) 167 return "reviewer"; 168 if (code == ContributorType.ENDORSER) 169 return "endorser"; 170 return "?"; 171 } 172 public String toSystem(ContributorType code) { 173 return code.getSystem(); 174 } 175 } 176 177 /** 178 * The type of contributor. 179 */ 180 @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true) 181 @Description(shortDefinition="author | editor | reviewer | endorser", formalDefinition="The type of contributor." ) 182 @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/contributor-type") 183 protected Enumeration<ContributorType> type; 184 185 /** 186 * The name of the individual or organization responsible for the contribution. 187 */ 188 @Child(name = "name", type = {StringType.class}, order=1, min=1, max=1, modifier=false, summary=true) 189 @Description(shortDefinition="Who contributed the content", formalDefinition="The name of the individual or organization responsible for the contribution." ) 190 protected StringType name; 191 192 /** 193 * Contact details to assist a user in finding and communicating with the contributor. 194 */ 195 @Child(name = "contact", type = {ContactDetail.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true) 196 @Description(shortDefinition="Contact details of the contributor", formalDefinition="Contact details to assist a user in finding and communicating with the contributor." ) 197 protected List<ContactDetail> contact; 198 199 private static final long serialVersionUID = -609887113L; 200 201 /** 202 * Constructor 203 */ 204 public Contributor() { 205 super(); 206 } 207 208 /** 209 * Constructor 210 */ 211 public Contributor(Enumeration<ContributorType> type, StringType name) { 212 super(); 213 this.type = type; 214 this.name = name; 215 } 216 217 /** 218 * @return {@link #type} (The type of contributor.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 219 */ 220 public Enumeration<ContributorType> getTypeElement() { 221 if (this.type == null) 222 if (Configuration.errorOnAutoCreate()) 223 throw new Error("Attempt to auto-create Contributor.type"); 224 else if (Configuration.doAutoCreate()) 225 this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); // bb 226 return this.type; 227 } 228 229 public boolean hasTypeElement() { 230 return this.type != null && !this.type.isEmpty(); 231 } 232 233 public boolean hasType() { 234 return this.type != null && !this.type.isEmpty(); 235 } 236 237 /** 238 * @param value {@link #type} (The type of contributor.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value 239 */ 240 public Contributor setTypeElement(Enumeration<ContributorType> value) { 241 this.type = value; 242 return this; 243 } 244 245 /** 246 * @return The type of contributor. 247 */ 248 public ContributorType getType() { 249 return this.type == null ? null : this.type.getValue(); 250 } 251 252 /** 253 * @param value The type of contributor. 254 */ 255 public Contributor setType(ContributorType value) { 256 if (this.type == null) 257 this.type = new Enumeration<ContributorType>(new ContributorTypeEnumFactory()); 258 this.type.setValue(value); 259 return this; 260 } 261 262 /** 263 * @return {@link #name} (The name of the individual or organization responsible for the contribution.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value 264 */ 265 public StringType getNameElement() { 266 if (this.name == null) 267 if (Configuration.errorOnAutoCreate()) 268 throw new Error("Attempt to auto-create Contributor.name"); 269 else if (Configuration.doAutoCreate()) 270 this.name = new StringType(); // bb 271 return this.name; 272 } 273 274 public boolean hasNameElement() { 275 return this.name != null && !this.name.isEmpty(); 276 } 277 278 public boolean hasName() { 279 return this.name != null && !this.name.isEmpty(); 280 } 281 282 /** 283 * @param value {@link #name} (The name of the individual or organization responsible for the contribution.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value 284 */ 285 public Contributor setNameElement(StringType value) { 286 this.name = value; 287 return this; 288 } 289 290 /** 291 * @return The name of the individual or organization responsible for the contribution. 292 */ 293 public String getName() { 294 return this.name == null ? null : this.name.getValue(); 295 } 296 297 /** 298 * @param value The name of the individual or organization responsible for the contribution. 299 */ 300 public Contributor setName(String value) { 301 if (this.name == null) 302 this.name = new StringType(); 303 this.name.setValue(value); 304 return this; 305 } 306 307 /** 308 * @return {@link #contact} (Contact details to assist a user in finding and communicating with the contributor.) 309 */ 310 public List<ContactDetail> getContact() { 311 if (this.contact == null) 312 this.contact = new ArrayList<ContactDetail>(); 313 return this.contact; 314 } 315 316 /** 317 * @return Returns a reference to <code>this</code> for easy method chaining 318 */ 319 public Contributor setContact(List<ContactDetail> theContact) { 320 this.contact = theContact; 321 return this; 322 } 323 324 public boolean hasContact() { 325 if (this.contact == null) 326 return false; 327 for (ContactDetail item : this.contact) 328 if (!item.isEmpty()) 329 return true; 330 return false; 331 } 332 333 public ContactDetail addContact() { //3 334 ContactDetail t = new ContactDetail(); 335 if (this.contact == null) 336 this.contact = new ArrayList<ContactDetail>(); 337 this.contact.add(t); 338 return t; 339 } 340 341 public Contributor addContact(ContactDetail t) { //3 342 if (t == null) 343 return this; 344 if (this.contact == null) 345 this.contact = new ArrayList<ContactDetail>(); 346 this.contact.add(t); 347 return this; 348 } 349 350 /** 351 * @return The first repetition of repeating field {@link #contact}, creating it if it does not already exist 352 */ 353 public ContactDetail getContactFirstRep() { 354 if (getContact().isEmpty()) { 355 addContact(); 356 } 357 return getContact().get(0); 358 } 359 360 protected void listChildren(List<Property> children) { 361 super.listChildren(children); 362 children.add(new Property("type", "code", "The type of contributor.", 0, 1, type)); 363 children.add(new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name)); 364 children.add(new Property("contact", "ContactDetail", "Contact details to assist a user in finding and communicating with the contributor.", 0, java.lang.Integer.MAX_VALUE, contact)); 365 } 366 367 @Override 368 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 369 switch (_hash) { 370 case 3575610: /*type*/ return new Property("type", "code", "The type of contributor.", 0, 1, type); 371 case 3373707: /*name*/ return new Property("name", "string", "The name of the individual or organization responsible for the contribution.", 0, 1, name); 372 case 951526432: /*contact*/ return new Property("contact", "ContactDetail", "Contact details to assist a user in finding and communicating with the contributor.", 0, java.lang.Integer.MAX_VALUE, contact); 373 default: return super.getNamedProperty(_hash, _name, _checkValid); 374 } 375 376 } 377 378 @Override 379 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 380 switch (hash) { 381 case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<ContributorType> 382 case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType 383 case 951526432: /*contact*/ return this.contact == null ? new Base[0] : this.contact.toArray(new Base[this.contact.size()]); // ContactDetail 384 default: return super.getProperty(hash, name, checkValid); 385 } 386 387 } 388 389 @Override 390 public Base setProperty(int hash, String name, Base value) throws FHIRException { 391 switch (hash) { 392 case 3575610: // type 393 value = new ContributorTypeEnumFactory().fromType(castToCode(value)); 394 this.type = (Enumeration) value; // Enumeration<ContributorType> 395 return value; 396 case 3373707: // name 397 this.name = castToString(value); // StringType 398 return value; 399 case 951526432: // contact 400 this.getContact().add(castToContactDetail(value)); // ContactDetail 401 return value; 402 default: return super.setProperty(hash, name, value); 403 } 404 405 } 406 407 @Override 408 public Base setProperty(String name, Base value) throws FHIRException { 409 if (name.equals("type")) { 410 value = new ContributorTypeEnumFactory().fromType(castToCode(value)); 411 this.type = (Enumeration) value; // Enumeration<ContributorType> 412 } else if (name.equals("name")) { 413 this.name = castToString(value); // StringType 414 } else if (name.equals("contact")) { 415 this.getContact().add(castToContactDetail(value)); 416 } else 417 return super.setProperty(name, value); 418 return value; 419 } 420 421 @Override 422 public Base makeProperty(int hash, String name) throws FHIRException { 423 switch (hash) { 424 case 3575610: return getTypeElement(); 425 case 3373707: return getNameElement(); 426 case 951526432: return addContact(); 427 default: return super.makeProperty(hash, name); 428 } 429 430 } 431 432 @Override 433 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 434 switch (hash) { 435 case 3575610: /*type*/ return new String[] {"code"}; 436 case 3373707: /*name*/ return new String[] {"string"}; 437 case 951526432: /*contact*/ return new String[] {"ContactDetail"}; 438 default: return super.getTypesForProperty(hash, name); 439 } 440 441 } 442 443 @Override 444 public Base addChild(String name) throws FHIRException { 445 if (name.equals("type")) { 446 throw new FHIRException("Cannot call addChild on a primitive type Contributor.type"); 447 } 448 else if (name.equals("name")) { 449 throw new FHIRException("Cannot call addChild on a primitive type Contributor.name"); 450 } 451 else if (name.equals("contact")) { 452 return addContact(); 453 } 454 else 455 return super.addChild(name); 456 } 457 458 public String fhirType() { 459 return "Contributor"; 460 461 } 462 463 public Contributor copy() { 464 Contributor dst = new Contributor(); 465 copyValues(dst); 466 return dst; 467 } 468 469 public void copyValues(Contributor dst) { 470 super.copyValues(dst); 471 dst.type = type == null ? null : type.copy(); 472 dst.name = name == null ? null : name.copy(); 473 if (contact != null) { 474 dst.contact = new ArrayList<ContactDetail>(); 475 for (ContactDetail i : contact) 476 dst.contact.add(i.copy()); 477 }; 478 } 479 480 protected Contributor typedCopy() { 481 return copy(); 482 } 483 484 @Override 485 public boolean equalsDeep(Base other_) { 486 if (!super.equalsDeep(other_)) 487 return false; 488 if (!(other_ instanceof Contributor)) 489 return false; 490 Contributor o = (Contributor) other_; 491 return compareDeep(type, o.type, true) && compareDeep(name, o.name, true) && compareDeep(contact, o.contact, true) 492 ; 493 } 494 495 @Override 496 public boolean equalsShallow(Base other_) { 497 if (!super.equalsShallow(other_)) 498 return false; 499 if (!(other_ instanceof Contributor)) 500 return false; 501 Contributor o = (Contributor) other_; 502 return compareValues(type, o.type, true) && compareValues(name, o.name, true); 503 } 504 505 public boolean isEmpty() { 506 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, name, contact); 507 } 508 509 510}