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