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