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